inode.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /*
  2. * inode.c
  3. *
  4. * Copyright (C) 1995, 1996 by Volker Lendecke
  5. * Modified for big endian by J.F. Chadima and David S. Miller
  6. * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
  7. * Modified 1998 Wolfram Pienkoss for NLS
  8. * Modified 2000 Ben Harris, University of Cambridge for NFS NS meta-info
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <asm/system.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/byteorder.h>
  15. #include <linux/time.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/string.h>
  19. #include <linux/stat.h>
  20. #include <linux/errno.h>
  21. #include <linux/file.h>
  22. #include <linux/fcntl.h>
  23. #include <linux/slab.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/init.h>
  26. #include <linux/smp_lock.h>
  27. #include <linux/vfs.h>
  28. #include <linux/ncp_fs.h>
  29. #include <net/sock.h>
  30. #include "ncplib_kernel.h"
  31. #include "getopt.h"
  32. static void ncp_delete_inode(struct inode *);
  33. static void ncp_put_super(struct super_block *);
  34. static int ncp_statfs(struct dentry *, struct kstatfs *);
  35. static struct kmem_cache * ncp_inode_cachep;
  36. static struct inode *ncp_alloc_inode(struct super_block *sb)
  37. {
  38. struct ncp_inode_info *ei;
  39. ei = (struct ncp_inode_info *)kmem_cache_alloc(ncp_inode_cachep, GFP_KERNEL);
  40. if (!ei)
  41. return NULL;
  42. return &ei->vfs_inode;
  43. }
  44. static void ncp_destroy_inode(struct inode *inode)
  45. {
  46. kmem_cache_free(ncp_inode_cachep, NCP_FINFO(inode));
  47. }
  48. static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
  49. {
  50. struct ncp_inode_info *ei = (struct ncp_inode_info *) foo;
  51. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  52. SLAB_CTOR_CONSTRUCTOR) {
  53. mutex_init(&ei->open_mutex);
  54. inode_init_once(&ei->vfs_inode);
  55. }
  56. }
  57. static int init_inodecache(void)
  58. {
  59. ncp_inode_cachep = kmem_cache_create("ncp_inode_cache",
  60. sizeof(struct ncp_inode_info),
  61. 0, (SLAB_RECLAIM_ACCOUNT|
  62. SLAB_MEM_SPREAD),
  63. init_once, NULL);
  64. if (ncp_inode_cachep == NULL)
  65. return -ENOMEM;
  66. return 0;
  67. }
  68. static void destroy_inodecache(void)
  69. {
  70. kmem_cache_destroy(ncp_inode_cachep);
  71. }
  72. static int ncp_remount(struct super_block *sb, int *flags, char* data)
  73. {
  74. *flags |= MS_NODIRATIME;
  75. return 0;
  76. }
  77. static struct super_operations ncp_sops =
  78. {
  79. .alloc_inode = ncp_alloc_inode,
  80. .destroy_inode = ncp_destroy_inode,
  81. .drop_inode = generic_delete_inode,
  82. .delete_inode = ncp_delete_inode,
  83. .put_super = ncp_put_super,
  84. .statfs = ncp_statfs,
  85. .remount_fs = ncp_remount,
  86. };
  87. extern struct dentry_operations ncp_root_dentry_operations;
  88. #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
  89. extern const struct address_space_operations ncp_symlink_aops;
  90. extern int ncp_symlink(struct inode*, struct dentry*, const char*);
  91. #endif
  92. /*
  93. * Fill in the ncpfs-specific information in the inode.
  94. */
  95. static void ncp_update_dirent(struct inode *inode, struct ncp_entry_info *nwinfo)
  96. {
  97. NCP_FINFO(inode)->DosDirNum = nwinfo->i.DosDirNum;
  98. NCP_FINFO(inode)->dirEntNum = nwinfo->i.dirEntNum;
  99. NCP_FINFO(inode)->volNumber = nwinfo->volume;
  100. }
  101. void ncp_update_inode(struct inode *inode, struct ncp_entry_info *nwinfo)
  102. {
  103. ncp_update_dirent(inode, nwinfo);
  104. NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;
  105. NCP_FINFO(inode)->access = nwinfo->access;
  106. memcpy(NCP_FINFO(inode)->file_handle, nwinfo->file_handle,
  107. sizeof(nwinfo->file_handle));
  108. DPRINTK("ncp_update_inode: updated %s, volnum=%d, dirent=%u\n",
  109. nwinfo->i.entryName, NCP_FINFO(inode)->volNumber,
  110. NCP_FINFO(inode)->dirEntNum);
  111. }
  112. static void ncp_update_dates(struct inode *inode, struct nw_info_struct *nwi)
  113. {
  114. /* NFS namespace mode overrides others if it's set. */
  115. DPRINTK(KERN_DEBUG "ncp_update_dates_and_mode: (%s) nfs.mode=0%o\n",
  116. nwi->entryName, nwi->nfs.mode);
  117. if (nwi->nfs.mode) {
  118. /* XXX Security? */
  119. inode->i_mode = nwi->nfs.mode;
  120. }
  121. inode->i_blocks = (inode->i_size + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;
  122. inode->i_mtime.tv_sec = ncp_date_dos2unix(nwi->modifyTime, nwi->modifyDate);
  123. inode->i_ctime.tv_sec = ncp_date_dos2unix(nwi->creationTime, nwi->creationDate);
  124. inode->i_atime.tv_sec = ncp_date_dos2unix(0, nwi->lastAccessDate);
  125. inode->i_atime.tv_nsec = 0;
  126. inode->i_mtime.tv_nsec = 0;
  127. inode->i_ctime.tv_nsec = 0;
  128. }
  129. static void ncp_update_attrs(struct inode *inode, struct ncp_entry_info *nwinfo)
  130. {
  131. struct nw_info_struct *nwi = &nwinfo->i;
  132. struct ncp_server *server = NCP_SERVER(inode);
  133. if (nwi->attributes & aDIR) {
  134. inode->i_mode = server->m.dir_mode;
  135. /* for directories dataStreamSize seems to be some
  136. Object ID ??? */
  137. inode->i_size = NCP_BLOCK_SIZE;
  138. } else {
  139. inode->i_mode = server->m.file_mode;
  140. inode->i_size = le32_to_cpu(nwi->dataStreamSize);
  141. #ifdef CONFIG_NCPFS_EXTRAS
  142. if ((server->m.flags & (NCP_MOUNT_EXTRAS|NCP_MOUNT_SYMLINKS))
  143. && (nwi->attributes & aSHARED)) {
  144. switch (nwi->attributes & (aHIDDEN|aSYSTEM)) {
  145. case aHIDDEN:
  146. if (server->m.flags & NCP_MOUNT_SYMLINKS) {
  147. if (/* (inode->i_size >= NCP_MIN_SYMLINK_SIZE)
  148. && */ (inode->i_size <= NCP_MAX_SYMLINK_SIZE)) {
  149. inode->i_mode = (inode->i_mode & ~S_IFMT) | S_IFLNK;
  150. NCP_FINFO(inode)->flags |= NCPI_KLUDGE_SYMLINK;
  151. break;
  152. }
  153. }
  154. /* FALLTHROUGH */
  155. case 0:
  156. if (server->m.flags & NCP_MOUNT_EXTRAS)
  157. inode->i_mode |= S_IRUGO;
  158. break;
  159. case aSYSTEM:
  160. if (server->m.flags & NCP_MOUNT_EXTRAS)
  161. inode->i_mode |= (inode->i_mode >> 2) & S_IXUGO;
  162. break;
  163. /* case aSYSTEM|aHIDDEN: */
  164. default:
  165. /* reserved combination */
  166. break;
  167. }
  168. }
  169. #endif
  170. }
  171. if (nwi->attributes & aRONLY) inode->i_mode &= ~S_IWUGO;
  172. }
  173. void ncp_update_inode2(struct inode* inode, struct ncp_entry_info *nwinfo)
  174. {
  175. NCP_FINFO(inode)->flags = 0;
  176. if (!atomic_read(&NCP_FINFO(inode)->opened)) {
  177. NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;
  178. ncp_update_attrs(inode, nwinfo);
  179. }
  180. ncp_update_dates(inode, &nwinfo->i);
  181. ncp_update_dirent(inode, nwinfo);
  182. }
  183. /*
  184. * Fill in the inode based on the ncp_entry_info structure.
  185. */
  186. static void ncp_set_attr(struct inode *inode, struct ncp_entry_info *nwinfo)
  187. {
  188. struct ncp_server *server = NCP_SERVER(inode);
  189. NCP_FINFO(inode)->flags = 0;
  190. ncp_update_attrs(inode, nwinfo);
  191. DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
  192. inode->i_nlink = 1;
  193. inode->i_uid = server->m.uid;
  194. inode->i_gid = server->m.gid;
  195. ncp_update_dates(inode, &nwinfo->i);
  196. ncp_update_inode(inode, nwinfo);
  197. }
  198. #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
  199. static struct inode_operations ncp_symlink_inode_operations = {
  200. .readlink = generic_readlink,
  201. .follow_link = page_follow_link_light,
  202. .put_link = page_put_link,
  203. .setattr = ncp_notify_change,
  204. };
  205. #endif
  206. /*
  207. * Get a new inode.
  208. */
  209. struct inode *
  210. ncp_iget(struct super_block *sb, struct ncp_entry_info *info)
  211. {
  212. struct inode *inode;
  213. if (info == NULL) {
  214. printk(KERN_ERR "ncp_iget: info is NULL\n");
  215. return NULL;
  216. }
  217. inode = new_inode(sb);
  218. if (inode) {
  219. atomic_set(&NCP_FINFO(inode)->opened, info->opened);
  220. inode->i_ino = info->ino;
  221. ncp_set_attr(inode, info);
  222. if (S_ISREG(inode->i_mode)) {
  223. inode->i_op = &ncp_file_inode_operations;
  224. inode->i_fop = &ncp_file_operations;
  225. } else if (S_ISDIR(inode->i_mode)) {
  226. inode->i_op = &ncp_dir_inode_operations;
  227. inode->i_fop = &ncp_dir_operations;
  228. #ifdef CONFIG_NCPFS_NFS_NS
  229. } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
  230. init_special_inode(inode, inode->i_mode,
  231. new_decode_dev(info->i.nfs.rdev));
  232. #endif
  233. #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
  234. } else if (S_ISLNK(inode->i_mode)) {
  235. inode->i_op = &ncp_symlink_inode_operations;
  236. inode->i_data.a_ops = &ncp_symlink_aops;
  237. #endif
  238. } else {
  239. make_bad_inode(inode);
  240. }
  241. insert_inode_hash(inode);
  242. } else
  243. printk(KERN_ERR "ncp_iget: iget failed!\n");
  244. return inode;
  245. }
  246. static void
  247. ncp_delete_inode(struct inode *inode)
  248. {
  249. truncate_inode_pages(&inode->i_data, 0);
  250. if (S_ISDIR(inode->i_mode)) {
  251. DDPRINTK("ncp_delete_inode: put directory %ld\n", inode->i_ino);
  252. }
  253. if (ncp_make_closed(inode) != 0) {
  254. /* We can't do anything but complain. */
  255. printk(KERN_ERR "ncp_delete_inode: could not close\n");
  256. }
  257. clear_inode(inode);
  258. }
  259. static void ncp_stop_tasks(struct ncp_server *server) {
  260. struct sock* sk = server->ncp_sock->sk;
  261. sk->sk_error_report = server->error_report;
  262. sk->sk_data_ready = server->data_ready;
  263. sk->sk_write_space = server->write_space;
  264. del_timer_sync(&server->timeout_tm);
  265. flush_scheduled_work();
  266. }
  267. static const struct ncp_option ncp_opts[] = {
  268. { "uid", OPT_INT, 'u' },
  269. { "gid", OPT_INT, 'g' },
  270. { "owner", OPT_INT, 'o' },
  271. { "mode", OPT_INT, 'm' },
  272. { "dirmode", OPT_INT, 'd' },
  273. { "timeout", OPT_INT, 't' },
  274. { "retry", OPT_INT, 'r' },
  275. { "flags", OPT_INT, 'f' },
  276. { "wdogpid", OPT_INT, 'w' },
  277. { "ncpfd", OPT_INT, 'n' },
  278. { "infofd", OPT_INT, 'i' }, /* v5 */
  279. { "version", OPT_INT, 'v' },
  280. { NULL, 0, 0 } };
  281. static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options) {
  282. int optval;
  283. char *optarg;
  284. unsigned long optint;
  285. int version = 0;
  286. int ret;
  287. data->flags = 0;
  288. data->int_flags = 0;
  289. data->mounted_uid = 0;
  290. data->wdog_pid = NULL;
  291. data->ncp_fd = ~0;
  292. data->time_out = 10;
  293. data->retry_count = 20;
  294. data->uid = 0;
  295. data->gid = 0;
  296. data->file_mode = 0600;
  297. data->dir_mode = 0700;
  298. data->info_fd = -1;
  299. data->mounted_vol[0] = 0;
  300. while ((optval = ncp_getopt("ncpfs", &options, ncp_opts, NULL, &optarg, &optint)) != 0) {
  301. ret = optval;
  302. if (ret < 0)
  303. goto err;
  304. switch (optval) {
  305. case 'u':
  306. data->uid = optint;
  307. break;
  308. case 'g':
  309. data->gid = optint;
  310. break;
  311. case 'o':
  312. data->mounted_uid = optint;
  313. break;
  314. case 'm':
  315. data->file_mode = optint;
  316. break;
  317. case 'd':
  318. data->dir_mode = optint;
  319. break;
  320. case 't':
  321. data->time_out = optint;
  322. break;
  323. case 'r':
  324. data->retry_count = optint;
  325. break;
  326. case 'f':
  327. data->flags = optint;
  328. break;
  329. case 'w':
  330. data->wdog_pid = find_get_pid(optint);
  331. break;
  332. case 'n':
  333. data->ncp_fd = optint;
  334. break;
  335. case 'i':
  336. data->info_fd = optint;
  337. break;
  338. case 'v':
  339. ret = -ECHRNG;
  340. if (optint < NCP_MOUNT_VERSION_V4)
  341. goto err;
  342. if (optint > NCP_MOUNT_VERSION_V5)
  343. goto err;
  344. version = optint;
  345. break;
  346. }
  347. }
  348. return 0;
  349. err:
  350. put_pid(data->wdog_pid);
  351. data->wdog_pid = NULL;
  352. return ret;
  353. }
  354. static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
  355. {
  356. struct ncp_mount_data_kernel data;
  357. struct ncp_server *server;
  358. struct file *ncp_filp;
  359. struct inode *root_inode;
  360. struct inode *sock_inode;
  361. struct socket *sock;
  362. int error;
  363. int default_bufsize;
  364. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  365. int options;
  366. #endif
  367. struct ncp_entry_info finfo;
  368. data.wdog_pid = NULL;
  369. server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
  370. if (!server)
  371. return -ENOMEM;
  372. sb->s_fs_info = server;
  373. error = -EFAULT;
  374. if (raw_data == NULL)
  375. goto out;
  376. switch (*(int*)raw_data) {
  377. case NCP_MOUNT_VERSION:
  378. {
  379. struct ncp_mount_data* md = (struct ncp_mount_data*)raw_data;
  380. data.flags = md->flags;
  381. data.int_flags = NCP_IMOUNT_LOGGEDIN_POSSIBLE;
  382. data.mounted_uid = md->mounted_uid;
  383. data.wdog_pid = find_get_pid(md->wdog_pid);
  384. data.ncp_fd = md->ncp_fd;
  385. data.time_out = md->time_out;
  386. data.retry_count = md->retry_count;
  387. data.uid = md->uid;
  388. data.gid = md->gid;
  389. data.file_mode = md->file_mode;
  390. data.dir_mode = md->dir_mode;
  391. data.info_fd = -1;
  392. memcpy(data.mounted_vol, md->mounted_vol,
  393. NCP_VOLNAME_LEN+1);
  394. }
  395. break;
  396. case NCP_MOUNT_VERSION_V4:
  397. {
  398. struct ncp_mount_data_v4* md = (struct ncp_mount_data_v4*)raw_data;
  399. data.flags = md->flags;
  400. data.int_flags = 0;
  401. data.mounted_uid = md->mounted_uid;
  402. data.wdog_pid = find_get_pid(md->wdog_pid);
  403. data.ncp_fd = md->ncp_fd;
  404. data.time_out = md->time_out;
  405. data.retry_count = md->retry_count;
  406. data.uid = md->uid;
  407. data.gid = md->gid;
  408. data.file_mode = md->file_mode;
  409. data.dir_mode = md->dir_mode;
  410. data.info_fd = -1;
  411. data.mounted_vol[0] = 0;
  412. }
  413. break;
  414. default:
  415. error = -ECHRNG;
  416. if (memcmp(raw_data, "vers", 4) == 0) {
  417. error = ncp_parse_options(&data, raw_data);
  418. }
  419. if (error)
  420. goto out;
  421. break;
  422. }
  423. error = -EBADF;
  424. ncp_filp = fget(data.ncp_fd);
  425. if (!ncp_filp)
  426. goto out;
  427. error = -ENOTSOCK;
  428. sock_inode = ncp_filp->f_path.dentry->d_inode;
  429. if (!S_ISSOCK(sock_inode->i_mode))
  430. goto out_fput;
  431. sock = SOCKET_I(sock_inode);
  432. if (!sock)
  433. goto out_fput;
  434. if (sock->type == SOCK_STREAM)
  435. default_bufsize = 0xF000;
  436. else
  437. default_bufsize = 1024;
  438. sb->s_flags |= MS_NODIRATIME; /* probably even noatime */
  439. sb->s_maxbytes = 0xFFFFFFFFU;
  440. sb->s_blocksize = 1024; /* Eh... Is this correct? */
  441. sb->s_blocksize_bits = 10;
  442. sb->s_magic = NCP_SUPER_MAGIC;
  443. sb->s_op = &ncp_sops;
  444. server = NCP_SBP(sb);
  445. memset(server, 0, sizeof(*server));
  446. server->ncp_filp = ncp_filp;
  447. server->ncp_sock = sock;
  448. if (data.info_fd != -1) {
  449. struct socket *info_sock;
  450. error = -EBADF;
  451. server->info_filp = fget(data.info_fd);
  452. if (!server->info_filp)
  453. goto out_fput;
  454. error = -ENOTSOCK;
  455. sock_inode = server->info_filp->f_path.dentry->d_inode;
  456. if (!S_ISSOCK(sock_inode->i_mode))
  457. goto out_fput2;
  458. info_sock = SOCKET_I(sock_inode);
  459. if (!info_sock)
  460. goto out_fput2;
  461. error = -EBADFD;
  462. if (info_sock->type != SOCK_STREAM)
  463. goto out_fput2;
  464. server->info_sock = info_sock;
  465. }
  466. /* server->lock = 0; */
  467. mutex_init(&server->mutex);
  468. server->packet = NULL;
  469. /* server->buffer_size = 0; */
  470. /* server->conn_status = 0; */
  471. /* server->root_dentry = NULL; */
  472. /* server->root_setuped = 0; */
  473. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  474. /* server->sign_wanted = 0; */
  475. /* server->sign_active = 0; */
  476. #endif
  477. server->auth.auth_type = NCP_AUTH_NONE;
  478. /* server->auth.object_name_len = 0; */
  479. /* server->auth.object_name = NULL; */
  480. /* server->auth.object_type = 0; */
  481. /* server->priv.len = 0; */
  482. /* server->priv.data = NULL; */
  483. server->m = data;
  484. /* Althought anything producing this is buggy, it happens
  485. now because of PATH_MAX changes.. */
  486. if (server->m.time_out < 1) {
  487. server->m.time_out = 10;
  488. printk(KERN_INFO "You need to recompile your ncpfs utils..\n");
  489. }
  490. server->m.time_out = server->m.time_out * HZ / 100;
  491. server->m.file_mode = (server->m.file_mode & S_IRWXUGO) | S_IFREG;
  492. server->m.dir_mode = (server->m.dir_mode & S_IRWXUGO) | S_IFDIR;
  493. #ifdef CONFIG_NCPFS_NLS
  494. /* load the default NLS charsets */
  495. server->nls_vol = load_nls_default();
  496. server->nls_io = load_nls_default();
  497. #endif /* CONFIG_NCPFS_NLS */
  498. server->dentry_ttl = 0; /* no caching */
  499. INIT_LIST_HEAD(&server->tx.requests);
  500. mutex_init(&server->rcv.creq_mutex);
  501. server->tx.creq = NULL;
  502. server->rcv.creq = NULL;
  503. server->data_ready = sock->sk->sk_data_ready;
  504. server->write_space = sock->sk->sk_write_space;
  505. server->error_report = sock->sk->sk_error_report;
  506. sock->sk->sk_user_data = server;
  507. init_timer(&server->timeout_tm);
  508. #undef NCP_PACKET_SIZE
  509. #define NCP_PACKET_SIZE 131072
  510. error = -ENOMEM;
  511. server->packet_size = NCP_PACKET_SIZE;
  512. server->packet = vmalloc(NCP_PACKET_SIZE);
  513. if (server->packet == NULL)
  514. goto out_nls;
  515. sock->sk->sk_data_ready = ncp_tcp_data_ready;
  516. sock->sk->sk_error_report = ncp_tcp_error_report;
  517. if (sock->type == SOCK_STREAM) {
  518. server->rcv.ptr = (unsigned char*)&server->rcv.buf;
  519. server->rcv.len = 10;
  520. server->rcv.state = 0;
  521. INIT_WORK(&server->rcv.tq, ncp_tcp_rcv_proc);
  522. INIT_WORK(&server->tx.tq, ncp_tcp_tx_proc);
  523. sock->sk->sk_write_space = ncp_tcp_write_space;
  524. } else {
  525. INIT_WORK(&server->rcv.tq, ncpdgram_rcv_proc);
  526. INIT_WORK(&server->timeout_tq, ncpdgram_timeout_proc);
  527. server->timeout_tm.data = (unsigned long)server;
  528. server->timeout_tm.function = ncpdgram_timeout_call;
  529. }
  530. ncp_lock_server(server);
  531. error = ncp_connect(server);
  532. ncp_unlock_server(server);
  533. if (error < 0)
  534. goto out_packet;
  535. DPRINTK("ncp_fill_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
  536. error = -EMSGSIZE; /* -EREMOTESIDEINCOMPATIBLE */
  537. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  538. if (ncp_negotiate_size_and_options(server, default_bufsize,
  539. NCP_DEFAULT_OPTIONS, &(server->buffer_size), &options) == 0)
  540. {
  541. if (options != NCP_DEFAULT_OPTIONS)
  542. {
  543. if (ncp_negotiate_size_and_options(server,
  544. default_bufsize,
  545. options & 2,
  546. &(server->buffer_size), &options) != 0)
  547. {
  548. goto out_disconnect;
  549. }
  550. }
  551. if (options & 2)
  552. server->sign_wanted = 1;
  553. }
  554. else
  555. #endif /* CONFIG_NCPFS_PACKET_SIGNING */
  556. if (ncp_negotiate_buffersize(server, default_bufsize,
  557. &(server->buffer_size)) != 0)
  558. goto out_disconnect;
  559. DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
  560. memset(&finfo, 0, sizeof(finfo));
  561. finfo.i.attributes = aDIR;
  562. finfo.i.dataStreamSize = 0; /* ignored */
  563. finfo.i.dirEntNum = 0;
  564. finfo.i.DosDirNum = 0;
  565. #ifdef CONFIG_NCPFS_SMALLDOS
  566. finfo.i.NSCreator = NW_NS_DOS;
  567. #endif
  568. finfo.volume = NCP_NUMBER_OF_VOLUMES;
  569. /* set dates of mountpoint to Jan 1, 1986; 00:00 */
  570. finfo.i.creationTime = finfo.i.modifyTime
  571. = cpu_to_le16(0x0000);
  572. finfo.i.creationDate = finfo.i.modifyDate
  573. = finfo.i.lastAccessDate
  574. = cpu_to_le16(0x0C21);
  575. finfo.i.nameLen = 0;
  576. finfo.i.entryName[0] = '\0';
  577. finfo.opened = 0;
  578. finfo.ino = 2; /* tradition */
  579. server->name_space[finfo.volume] = NW_NS_DOS;
  580. error = -ENOMEM;
  581. root_inode = ncp_iget(sb, &finfo);
  582. if (!root_inode)
  583. goto out_disconnect;
  584. DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);
  585. sb->s_root = d_alloc_root(root_inode);
  586. if (!sb->s_root)
  587. goto out_no_root;
  588. sb->s_root->d_op = &ncp_root_dentry_operations;
  589. return 0;
  590. out_no_root:
  591. iput(root_inode);
  592. out_disconnect:
  593. ncp_lock_server(server);
  594. ncp_disconnect(server);
  595. ncp_unlock_server(server);
  596. out_packet:
  597. ncp_stop_tasks(server);
  598. vfree(server->packet);
  599. out_nls:
  600. #ifdef CONFIG_NCPFS_NLS
  601. unload_nls(server->nls_io);
  602. unload_nls(server->nls_vol);
  603. #endif
  604. out_fput2:
  605. if (server->info_filp)
  606. fput(server->info_filp);
  607. out_fput:
  608. /* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
  609. *
  610. * The previously used put_filp(ncp_filp); was bogous, since
  611. * it doesn't proper unlocking.
  612. */
  613. fput(ncp_filp);
  614. out:
  615. put_pid(data.wdog_pid);
  616. sb->s_fs_info = NULL;
  617. kfree(server);
  618. return error;
  619. }
  620. static void ncp_put_super(struct super_block *sb)
  621. {
  622. struct ncp_server *server = NCP_SBP(sb);
  623. ncp_lock_server(server);
  624. ncp_disconnect(server);
  625. ncp_unlock_server(server);
  626. ncp_stop_tasks(server);
  627. #ifdef CONFIG_NCPFS_NLS
  628. /* unload the NLS charsets */
  629. if (server->nls_vol)
  630. {
  631. unload_nls(server->nls_vol);
  632. server->nls_vol = NULL;
  633. }
  634. if (server->nls_io)
  635. {
  636. unload_nls(server->nls_io);
  637. server->nls_io = NULL;
  638. }
  639. #endif /* CONFIG_NCPFS_NLS */
  640. if (server->info_filp)
  641. fput(server->info_filp);
  642. fput(server->ncp_filp);
  643. kill_pid(server->m.wdog_pid, SIGTERM, 1);
  644. put_pid(server->m.wdog_pid);
  645. kfree(server->priv.data);
  646. kfree(server->auth.object_name);
  647. vfree(server->packet);
  648. sb->s_fs_info = NULL;
  649. kfree(server);
  650. }
  651. static int ncp_statfs(struct dentry *dentry, struct kstatfs *buf)
  652. {
  653. struct dentry* d;
  654. struct inode* i;
  655. struct ncp_inode_info* ni;
  656. struct ncp_server* s;
  657. struct ncp_volume_info vi;
  658. struct super_block *sb = dentry->d_sb;
  659. int err;
  660. __u8 dh;
  661. d = sb->s_root;
  662. if (!d) {
  663. goto dflt;
  664. }
  665. i = d->d_inode;
  666. if (!i) {
  667. goto dflt;
  668. }
  669. ni = NCP_FINFO(i);
  670. if (!ni) {
  671. goto dflt;
  672. }
  673. s = NCP_SBP(sb);
  674. if (!s) {
  675. goto dflt;
  676. }
  677. if (!s->m.mounted_vol[0]) {
  678. goto dflt;
  679. }
  680. err = ncp_dirhandle_alloc(s, ni->volNumber, ni->DosDirNum, &dh);
  681. if (err) {
  682. goto dflt;
  683. }
  684. err = ncp_get_directory_info(s, dh, &vi);
  685. ncp_dirhandle_free(s, dh);
  686. if (err) {
  687. goto dflt;
  688. }
  689. buf->f_type = NCP_SUPER_MAGIC;
  690. buf->f_bsize = vi.sectors_per_block * 512;
  691. buf->f_blocks = vi.total_blocks;
  692. buf->f_bfree = vi.free_blocks;
  693. buf->f_bavail = vi.free_blocks;
  694. buf->f_files = vi.total_dir_entries;
  695. buf->f_ffree = vi.available_dir_entries;
  696. buf->f_namelen = 12;
  697. return 0;
  698. /* We cannot say how much disk space is left on a mounted
  699. NetWare Server, because free space is distributed over
  700. volumes, and the current user might have disk quotas. So
  701. free space is not that simple to determine. Our decision
  702. here is to err conservatively. */
  703. dflt:;
  704. buf->f_type = NCP_SUPER_MAGIC;
  705. buf->f_bsize = NCP_BLOCK_SIZE;
  706. buf->f_blocks = 0;
  707. buf->f_bfree = 0;
  708. buf->f_bavail = 0;
  709. buf->f_namelen = 12;
  710. return 0;
  711. }
  712. int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
  713. {
  714. struct inode *inode = dentry->d_inode;
  715. int result = 0;
  716. __le32 info_mask;
  717. struct nw_modify_dos_info info;
  718. struct ncp_server *server;
  719. result = -EIO;
  720. lock_kernel();
  721. server = NCP_SERVER(inode);
  722. if ((!server) || !ncp_conn_valid(server))
  723. goto out;
  724. /* ageing the dentry to force validation */
  725. ncp_age_dentry(server, dentry);
  726. result = inode_change_ok(inode, attr);
  727. if (result < 0)
  728. goto out;
  729. result = -EPERM;
  730. if (((attr->ia_valid & ATTR_UID) &&
  731. (attr->ia_uid != server->m.uid)))
  732. goto out;
  733. if (((attr->ia_valid & ATTR_GID) &&
  734. (attr->ia_gid != server->m.gid)))
  735. goto out;
  736. if (((attr->ia_valid & ATTR_MODE) &&
  737. (attr->ia_mode &
  738. ~(S_IFREG | S_IFDIR | S_IRWXUGO))))
  739. goto out;
  740. info_mask = 0;
  741. memset(&info, 0, sizeof(info));
  742. #if 1
  743. if ((attr->ia_valid & ATTR_MODE) != 0)
  744. {
  745. umode_t newmode = attr->ia_mode;
  746. info_mask |= DM_ATTRIBUTES;
  747. if (S_ISDIR(inode->i_mode)) {
  748. newmode &= server->m.dir_mode;
  749. } else {
  750. #ifdef CONFIG_NCPFS_EXTRAS
  751. if (server->m.flags & NCP_MOUNT_EXTRAS) {
  752. /* any non-default execute bit set */
  753. if (newmode & ~server->m.file_mode & S_IXUGO)
  754. info.attributes |= aSHARED | aSYSTEM;
  755. /* read for group/world and not in default file_mode */
  756. else if (newmode & ~server->m.file_mode & S_IRUGO)
  757. info.attributes |= aSHARED;
  758. } else
  759. #endif
  760. newmode &= server->m.file_mode;
  761. }
  762. if (newmode & S_IWUGO)
  763. info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
  764. else
  765. info.attributes |= (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
  766. #ifdef CONFIG_NCPFS_NFS_NS
  767. if (ncp_is_nfs_extras(server, NCP_FINFO(inode)->volNumber)) {
  768. result = ncp_modify_nfs_info(server,
  769. NCP_FINFO(inode)->volNumber,
  770. NCP_FINFO(inode)->dirEntNum,
  771. attr->ia_mode, 0);
  772. if (result != 0)
  773. goto out;
  774. info.attributes &= ~(aSHARED | aSYSTEM);
  775. {
  776. /* mark partial success */
  777. struct iattr tmpattr;
  778. tmpattr.ia_valid = ATTR_MODE;
  779. tmpattr.ia_mode = attr->ia_mode;
  780. result = inode_setattr(inode, &tmpattr);
  781. if (result)
  782. goto out;
  783. }
  784. }
  785. #endif
  786. }
  787. #endif
  788. /* Do SIZE before attributes, otherwise mtime together with size does not work...
  789. */
  790. if ((attr->ia_valid & ATTR_SIZE) != 0) {
  791. int written;
  792. DPRINTK("ncpfs: trying to change size to %ld\n",
  793. attr->ia_size);
  794. if ((result = ncp_make_open(inode, O_WRONLY)) < 0) {
  795. result = -EACCES;
  796. goto out;
  797. }
  798. ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
  799. attr->ia_size, 0, "", &written);
  800. /* According to ndir, the changes only take effect after
  801. closing the file */
  802. ncp_inode_close(inode);
  803. result = ncp_make_closed(inode);
  804. if (result)
  805. goto out;
  806. {
  807. struct iattr tmpattr;
  808. tmpattr.ia_valid = ATTR_SIZE;
  809. tmpattr.ia_size = attr->ia_size;
  810. result = inode_setattr(inode, &tmpattr);
  811. if (result)
  812. goto out;
  813. }
  814. }
  815. if ((attr->ia_valid & ATTR_CTIME) != 0) {
  816. info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);
  817. ncp_date_unix2dos(attr->ia_ctime.tv_sec,
  818. &info.creationTime, &info.creationDate);
  819. }
  820. if ((attr->ia_valid & ATTR_MTIME) != 0) {
  821. info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
  822. ncp_date_unix2dos(attr->ia_mtime.tv_sec,
  823. &info.modifyTime, &info.modifyDate);
  824. }
  825. if ((attr->ia_valid & ATTR_ATIME) != 0) {
  826. __le16 dummy;
  827. info_mask |= (DM_LAST_ACCESS_DATE);
  828. ncp_date_unix2dos(attr->ia_atime.tv_sec,
  829. &dummy, &info.lastAccessDate);
  830. }
  831. if (info_mask != 0) {
  832. result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
  833. inode, info_mask, &info);
  834. if (result != 0) {
  835. result = -EACCES;
  836. if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE)) {
  837. /* NetWare seems not to allow this. I
  838. do not know why. So, just tell the
  839. user everything went fine. This is
  840. a terrible hack, but I do not know
  841. how to do this correctly. */
  842. result = 0;
  843. } else
  844. goto out;
  845. }
  846. #ifdef CONFIG_NCPFS_STRONG
  847. if ((!result) && (info_mask & DM_ATTRIBUTES))
  848. NCP_FINFO(inode)->nwattr = info.attributes;
  849. #endif
  850. }
  851. if (!result)
  852. result = inode_setattr(inode, attr);
  853. out:
  854. unlock_kernel();
  855. return result;
  856. }
  857. static int ncp_get_sb(struct file_system_type *fs_type,
  858. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  859. {
  860. return get_sb_nodev(fs_type, flags, data, ncp_fill_super, mnt);
  861. }
  862. static struct file_system_type ncp_fs_type = {
  863. .owner = THIS_MODULE,
  864. .name = "ncpfs",
  865. .get_sb = ncp_get_sb,
  866. .kill_sb = kill_anon_super,
  867. };
  868. static int __init init_ncp_fs(void)
  869. {
  870. int err;
  871. DPRINTK("ncpfs: init_module called\n");
  872. err = init_inodecache();
  873. if (err)
  874. goto out1;
  875. err = register_filesystem(&ncp_fs_type);
  876. if (err)
  877. goto out;
  878. return 0;
  879. out:
  880. destroy_inodecache();
  881. out1:
  882. return err;
  883. }
  884. static void __exit exit_ncp_fs(void)
  885. {
  886. DPRINTK("ncpfs: cleanup_module called\n");
  887. unregister_filesystem(&ncp_fs_type);
  888. destroy_inodecache();
  889. }
  890. module_init(init_ncp_fs)
  891. module_exit(exit_ncp_fs)
  892. MODULE_LICENSE("GPL");