inode.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  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/mount.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/ncp_fs.h>
  31. #include <net/sock.h>
  32. #include "ncplib_kernel.h"
  33. #include "getopt.h"
  34. #define NCP_DEFAULT_FILE_MODE 0600
  35. #define NCP_DEFAULT_DIR_MODE 0700
  36. #define NCP_DEFAULT_TIME_OUT 10
  37. #define NCP_DEFAULT_RETRY_COUNT 20
  38. static void ncp_delete_inode(struct inode *);
  39. static void ncp_put_super(struct super_block *);
  40. static int ncp_statfs(struct dentry *, struct kstatfs *);
  41. static int ncp_show_options(struct seq_file *, struct vfsmount *);
  42. static struct kmem_cache * ncp_inode_cachep;
  43. static struct inode *ncp_alloc_inode(struct super_block *sb)
  44. {
  45. struct ncp_inode_info *ei;
  46. ei = (struct ncp_inode_info *)kmem_cache_alloc(ncp_inode_cachep, GFP_KERNEL);
  47. if (!ei)
  48. return NULL;
  49. return &ei->vfs_inode;
  50. }
  51. static void ncp_destroy_inode(struct inode *inode)
  52. {
  53. kmem_cache_free(ncp_inode_cachep, NCP_FINFO(inode));
  54. }
  55. static void init_once(void *foo)
  56. {
  57. struct ncp_inode_info *ei = (struct ncp_inode_info *) foo;
  58. mutex_init(&ei->open_mutex);
  59. inode_init_once(&ei->vfs_inode);
  60. }
  61. static int init_inodecache(void)
  62. {
  63. ncp_inode_cachep = kmem_cache_create("ncp_inode_cache",
  64. sizeof(struct ncp_inode_info),
  65. 0, (SLAB_RECLAIM_ACCOUNT|
  66. SLAB_MEM_SPREAD),
  67. init_once);
  68. if (ncp_inode_cachep == NULL)
  69. return -ENOMEM;
  70. return 0;
  71. }
  72. static void destroy_inodecache(void)
  73. {
  74. kmem_cache_destroy(ncp_inode_cachep);
  75. }
  76. static int ncp_remount(struct super_block *sb, int *flags, char* data)
  77. {
  78. *flags |= MS_NODIRATIME;
  79. return 0;
  80. }
  81. static const struct super_operations ncp_sops =
  82. {
  83. .alloc_inode = ncp_alloc_inode,
  84. .destroy_inode = ncp_destroy_inode,
  85. .drop_inode = generic_delete_inode,
  86. .delete_inode = ncp_delete_inode,
  87. .put_super = ncp_put_super,
  88. .statfs = ncp_statfs,
  89. .remount_fs = ncp_remount,
  90. .show_options = ncp_show_options,
  91. };
  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 const 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 int ncp_show_options(struct seq_file *seq, struct vfsmount *mnt)
  268. {
  269. struct ncp_server *server = NCP_SBP(mnt->mnt_sb);
  270. unsigned int tmp;
  271. if (server->m.uid != 0)
  272. seq_printf(seq, ",uid=%u", server->m.uid);
  273. if (server->m.gid != 0)
  274. seq_printf(seq, ",gid=%u", server->m.gid);
  275. if (server->m.mounted_uid != 0)
  276. seq_printf(seq, ",owner=%u", server->m.mounted_uid);
  277. tmp = server->m.file_mode & S_IALLUGO;
  278. if (tmp != NCP_DEFAULT_FILE_MODE)
  279. seq_printf(seq, ",mode=0%o", tmp);
  280. tmp = server->m.dir_mode & S_IALLUGO;
  281. if (tmp != NCP_DEFAULT_DIR_MODE)
  282. seq_printf(seq, ",dirmode=0%o", tmp);
  283. if (server->m.time_out != NCP_DEFAULT_TIME_OUT * HZ / 100) {
  284. tmp = server->m.time_out * 100 / HZ;
  285. seq_printf(seq, ",timeout=%u", tmp);
  286. }
  287. if (server->m.retry_count != NCP_DEFAULT_RETRY_COUNT)
  288. seq_printf(seq, ",retry=%u", server->m.retry_count);
  289. if (server->m.flags != 0)
  290. seq_printf(seq, ",flags=%lu", server->m.flags);
  291. if (server->m.wdog_pid != NULL)
  292. seq_printf(seq, ",wdogpid=%u", pid_vnr(server->m.wdog_pid));
  293. return 0;
  294. }
  295. static const struct ncp_option ncp_opts[] = {
  296. { "uid", OPT_INT, 'u' },
  297. { "gid", OPT_INT, 'g' },
  298. { "owner", OPT_INT, 'o' },
  299. { "mode", OPT_INT, 'm' },
  300. { "dirmode", OPT_INT, 'd' },
  301. { "timeout", OPT_INT, 't' },
  302. { "retry", OPT_INT, 'r' },
  303. { "flags", OPT_INT, 'f' },
  304. { "wdogpid", OPT_INT, 'w' },
  305. { "ncpfd", OPT_INT, 'n' },
  306. { "infofd", OPT_INT, 'i' }, /* v5 */
  307. { "version", OPT_INT, 'v' },
  308. { NULL, 0, 0 } };
  309. static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options) {
  310. int optval;
  311. char *optarg;
  312. unsigned long optint;
  313. int version = 0;
  314. int ret;
  315. data->flags = 0;
  316. data->int_flags = 0;
  317. data->mounted_uid = 0;
  318. data->wdog_pid = NULL;
  319. data->ncp_fd = ~0;
  320. data->time_out = NCP_DEFAULT_TIME_OUT;
  321. data->retry_count = NCP_DEFAULT_RETRY_COUNT;
  322. data->uid = 0;
  323. data->gid = 0;
  324. data->file_mode = NCP_DEFAULT_FILE_MODE;
  325. data->dir_mode = NCP_DEFAULT_DIR_MODE;
  326. data->info_fd = -1;
  327. data->mounted_vol[0] = 0;
  328. while ((optval = ncp_getopt("ncpfs", &options, ncp_opts, NULL, &optarg, &optint)) != 0) {
  329. ret = optval;
  330. if (ret < 0)
  331. goto err;
  332. switch (optval) {
  333. case 'u':
  334. data->uid = optint;
  335. break;
  336. case 'g':
  337. data->gid = optint;
  338. break;
  339. case 'o':
  340. data->mounted_uid = optint;
  341. break;
  342. case 'm':
  343. data->file_mode = optint;
  344. break;
  345. case 'd':
  346. data->dir_mode = optint;
  347. break;
  348. case 't':
  349. data->time_out = optint;
  350. break;
  351. case 'r':
  352. data->retry_count = optint;
  353. break;
  354. case 'f':
  355. data->flags = optint;
  356. break;
  357. case 'w':
  358. data->wdog_pid = find_get_pid(optint);
  359. break;
  360. case 'n':
  361. data->ncp_fd = optint;
  362. break;
  363. case 'i':
  364. data->info_fd = optint;
  365. break;
  366. case 'v':
  367. ret = -ECHRNG;
  368. if (optint < NCP_MOUNT_VERSION_V4)
  369. goto err;
  370. if (optint > NCP_MOUNT_VERSION_V5)
  371. goto err;
  372. version = optint;
  373. break;
  374. }
  375. }
  376. return 0;
  377. err:
  378. put_pid(data->wdog_pid);
  379. data->wdog_pid = NULL;
  380. return ret;
  381. }
  382. static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
  383. {
  384. struct ncp_mount_data_kernel data;
  385. struct ncp_server *server;
  386. struct file *ncp_filp;
  387. struct inode *root_inode;
  388. struct inode *sock_inode;
  389. struct socket *sock;
  390. int error;
  391. int default_bufsize;
  392. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  393. int options;
  394. #endif
  395. struct ncp_entry_info finfo;
  396. data.wdog_pid = NULL;
  397. server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
  398. if (!server)
  399. return -ENOMEM;
  400. sb->s_fs_info = server;
  401. error = -EFAULT;
  402. if (raw_data == NULL)
  403. goto out;
  404. switch (*(int*)raw_data) {
  405. case NCP_MOUNT_VERSION:
  406. {
  407. struct ncp_mount_data* md = (struct ncp_mount_data*)raw_data;
  408. data.flags = md->flags;
  409. data.int_flags = NCP_IMOUNT_LOGGEDIN_POSSIBLE;
  410. data.mounted_uid = md->mounted_uid;
  411. data.wdog_pid = find_get_pid(md->wdog_pid);
  412. data.ncp_fd = md->ncp_fd;
  413. data.time_out = md->time_out;
  414. data.retry_count = md->retry_count;
  415. data.uid = md->uid;
  416. data.gid = md->gid;
  417. data.file_mode = md->file_mode;
  418. data.dir_mode = md->dir_mode;
  419. data.info_fd = -1;
  420. memcpy(data.mounted_vol, md->mounted_vol,
  421. NCP_VOLNAME_LEN+1);
  422. }
  423. break;
  424. case NCP_MOUNT_VERSION_V4:
  425. {
  426. struct ncp_mount_data_v4* md = (struct ncp_mount_data_v4*)raw_data;
  427. data.flags = md->flags;
  428. data.int_flags = 0;
  429. data.mounted_uid = md->mounted_uid;
  430. data.wdog_pid = find_get_pid(md->wdog_pid);
  431. data.ncp_fd = md->ncp_fd;
  432. data.time_out = md->time_out;
  433. data.retry_count = md->retry_count;
  434. data.uid = md->uid;
  435. data.gid = md->gid;
  436. data.file_mode = md->file_mode;
  437. data.dir_mode = md->dir_mode;
  438. data.info_fd = -1;
  439. data.mounted_vol[0] = 0;
  440. }
  441. break;
  442. default:
  443. error = -ECHRNG;
  444. if (memcmp(raw_data, "vers", 4) == 0) {
  445. error = ncp_parse_options(&data, raw_data);
  446. }
  447. if (error)
  448. goto out;
  449. break;
  450. }
  451. error = -EBADF;
  452. ncp_filp = fget(data.ncp_fd);
  453. if (!ncp_filp)
  454. goto out;
  455. error = -ENOTSOCK;
  456. sock_inode = ncp_filp->f_path.dentry->d_inode;
  457. if (!S_ISSOCK(sock_inode->i_mode))
  458. goto out_fput;
  459. sock = SOCKET_I(sock_inode);
  460. if (!sock)
  461. goto out_fput;
  462. if (sock->type == SOCK_STREAM)
  463. default_bufsize = 0xF000;
  464. else
  465. default_bufsize = 1024;
  466. sb->s_flags |= MS_NODIRATIME; /* probably even noatime */
  467. sb->s_maxbytes = 0xFFFFFFFFU;
  468. sb->s_blocksize = 1024; /* Eh... Is this correct? */
  469. sb->s_blocksize_bits = 10;
  470. sb->s_magic = NCP_SUPER_MAGIC;
  471. sb->s_op = &ncp_sops;
  472. server = NCP_SBP(sb);
  473. memset(server, 0, sizeof(*server));
  474. server->ncp_filp = ncp_filp;
  475. server->ncp_sock = sock;
  476. if (data.info_fd != -1) {
  477. struct socket *info_sock;
  478. error = -EBADF;
  479. server->info_filp = fget(data.info_fd);
  480. if (!server->info_filp)
  481. goto out_fput;
  482. error = -ENOTSOCK;
  483. sock_inode = server->info_filp->f_path.dentry->d_inode;
  484. if (!S_ISSOCK(sock_inode->i_mode))
  485. goto out_fput2;
  486. info_sock = SOCKET_I(sock_inode);
  487. if (!info_sock)
  488. goto out_fput2;
  489. error = -EBADFD;
  490. if (info_sock->type != SOCK_STREAM)
  491. goto out_fput2;
  492. server->info_sock = info_sock;
  493. }
  494. /* server->lock = 0; */
  495. mutex_init(&server->mutex);
  496. server->packet = NULL;
  497. /* server->buffer_size = 0; */
  498. /* server->conn_status = 0; */
  499. /* server->root_dentry = NULL; */
  500. /* server->root_setuped = 0; */
  501. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  502. /* server->sign_wanted = 0; */
  503. /* server->sign_active = 0; */
  504. #endif
  505. server->auth.auth_type = NCP_AUTH_NONE;
  506. /* server->auth.object_name_len = 0; */
  507. /* server->auth.object_name = NULL; */
  508. /* server->auth.object_type = 0; */
  509. /* server->priv.len = 0; */
  510. /* server->priv.data = NULL; */
  511. server->m = data;
  512. /* Althought anything producing this is buggy, it happens
  513. now because of PATH_MAX changes.. */
  514. if (server->m.time_out < 1) {
  515. server->m.time_out = 10;
  516. printk(KERN_INFO "You need to recompile your ncpfs utils..\n");
  517. }
  518. server->m.time_out = server->m.time_out * HZ / 100;
  519. server->m.file_mode = (server->m.file_mode & S_IRWXUGO) | S_IFREG;
  520. server->m.dir_mode = (server->m.dir_mode & S_IRWXUGO) | S_IFDIR;
  521. #ifdef CONFIG_NCPFS_NLS
  522. /* load the default NLS charsets */
  523. server->nls_vol = load_nls_default();
  524. server->nls_io = load_nls_default();
  525. #endif /* CONFIG_NCPFS_NLS */
  526. server->dentry_ttl = 0; /* no caching */
  527. INIT_LIST_HEAD(&server->tx.requests);
  528. mutex_init(&server->rcv.creq_mutex);
  529. server->tx.creq = NULL;
  530. server->rcv.creq = NULL;
  531. server->data_ready = sock->sk->sk_data_ready;
  532. server->write_space = sock->sk->sk_write_space;
  533. server->error_report = sock->sk->sk_error_report;
  534. sock->sk->sk_user_data = server;
  535. init_timer(&server->timeout_tm);
  536. #undef NCP_PACKET_SIZE
  537. #define NCP_PACKET_SIZE 131072
  538. error = -ENOMEM;
  539. server->packet_size = NCP_PACKET_SIZE;
  540. server->packet = vmalloc(NCP_PACKET_SIZE);
  541. if (server->packet == NULL)
  542. goto out_nls;
  543. server->txbuf = vmalloc(NCP_PACKET_SIZE);
  544. if (server->txbuf == NULL)
  545. goto out_packet;
  546. server->rxbuf = vmalloc(NCP_PACKET_SIZE);
  547. if (server->rxbuf == NULL)
  548. goto out_txbuf;
  549. sock->sk->sk_data_ready = ncp_tcp_data_ready;
  550. sock->sk->sk_error_report = ncp_tcp_error_report;
  551. if (sock->type == SOCK_STREAM) {
  552. server->rcv.ptr = (unsigned char*)&server->rcv.buf;
  553. server->rcv.len = 10;
  554. server->rcv.state = 0;
  555. INIT_WORK(&server->rcv.tq, ncp_tcp_rcv_proc);
  556. INIT_WORK(&server->tx.tq, ncp_tcp_tx_proc);
  557. sock->sk->sk_write_space = ncp_tcp_write_space;
  558. } else {
  559. INIT_WORK(&server->rcv.tq, ncpdgram_rcv_proc);
  560. INIT_WORK(&server->timeout_tq, ncpdgram_timeout_proc);
  561. server->timeout_tm.data = (unsigned long)server;
  562. server->timeout_tm.function = ncpdgram_timeout_call;
  563. }
  564. ncp_lock_server(server);
  565. error = ncp_connect(server);
  566. ncp_unlock_server(server);
  567. if (error < 0)
  568. goto out_rxbuf;
  569. DPRINTK("ncp_fill_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
  570. error = -EMSGSIZE; /* -EREMOTESIDEINCOMPATIBLE */
  571. #ifdef CONFIG_NCPFS_PACKET_SIGNING
  572. if (ncp_negotiate_size_and_options(server, default_bufsize,
  573. NCP_DEFAULT_OPTIONS, &(server->buffer_size), &options) == 0)
  574. {
  575. if (options != NCP_DEFAULT_OPTIONS)
  576. {
  577. if (ncp_negotiate_size_and_options(server,
  578. default_bufsize,
  579. options & 2,
  580. &(server->buffer_size), &options) != 0)
  581. {
  582. goto out_disconnect;
  583. }
  584. }
  585. if (options & 2)
  586. server->sign_wanted = 1;
  587. }
  588. else
  589. #endif /* CONFIG_NCPFS_PACKET_SIGNING */
  590. if (ncp_negotiate_buffersize(server, default_bufsize,
  591. &(server->buffer_size)) != 0)
  592. goto out_disconnect;
  593. DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
  594. memset(&finfo, 0, sizeof(finfo));
  595. finfo.i.attributes = aDIR;
  596. finfo.i.dataStreamSize = 0; /* ignored */
  597. finfo.i.dirEntNum = 0;
  598. finfo.i.DosDirNum = 0;
  599. #ifdef CONFIG_NCPFS_SMALLDOS
  600. finfo.i.NSCreator = NW_NS_DOS;
  601. #endif
  602. finfo.volume = NCP_NUMBER_OF_VOLUMES;
  603. /* set dates of mountpoint to Jan 1, 1986; 00:00 */
  604. finfo.i.creationTime = finfo.i.modifyTime
  605. = cpu_to_le16(0x0000);
  606. finfo.i.creationDate = finfo.i.modifyDate
  607. = finfo.i.lastAccessDate
  608. = cpu_to_le16(0x0C21);
  609. finfo.i.nameLen = 0;
  610. finfo.i.entryName[0] = '\0';
  611. finfo.opened = 0;
  612. finfo.ino = 2; /* tradition */
  613. server->name_space[finfo.volume] = NW_NS_DOS;
  614. error = -ENOMEM;
  615. root_inode = ncp_iget(sb, &finfo);
  616. if (!root_inode)
  617. goto out_disconnect;
  618. DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);
  619. sb->s_root = d_alloc_root(root_inode);
  620. if (!sb->s_root)
  621. goto out_no_root;
  622. sb->s_root->d_op = &ncp_root_dentry_operations;
  623. return 0;
  624. out_no_root:
  625. iput(root_inode);
  626. out_disconnect:
  627. ncp_lock_server(server);
  628. ncp_disconnect(server);
  629. ncp_unlock_server(server);
  630. out_rxbuf:
  631. ncp_stop_tasks(server);
  632. vfree(server->rxbuf);
  633. out_txbuf:
  634. vfree(server->txbuf);
  635. out_packet:
  636. vfree(server->packet);
  637. out_nls:
  638. #ifdef CONFIG_NCPFS_NLS
  639. unload_nls(server->nls_io);
  640. unload_nls(server->nls_vol);
  641. #endif
  642. out_fput2:
  643. if (server->info_filp)
  644. fput(server->info_filp);
  645. out_fput:
  646. /* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
  647. *
  648. * The previously used put_filp(ncp_filp); was bogous, since
  649. * it doesn't proper unlocking.
  650. */
  651. fput(ncp_filp);
  652. out:
  653. put_pid(data.wdog_pid);
  654. sb->s_fs_info = NULL;
  655. kfree(server);
  656. return error;
  657. }
  658. static void ncp_put_super(struct super_block *sb)
  659. {
  660. struct ncp_server *server = NCP_SBP(sb);
  661. lock_kernel();
  662. ncp_lock_server(server);
  663. ncp_disconnect(server);
  664. ncp_unlock_server(server);
  665. ncp_stop_tasks(server);
  666. #ifdef CONFIG_NCPFS_NLS
  667. /* unload the NLS charsets */
  668. if (server->nls_vol)
  669. {
  670. unload_nls(server->nls_vol);
  671. server->nls_vol = NULL;
  672. }
  673. if (server->nls_io)
  674. {
  675. unload_nls(server->nls_io);
  676. server->nls_io = NULL;
  677. }
  678. #endif /* CONFIG_NCPFS_NLS */
  679. if (server->info_filp)
  680. fput(server->info_filp);
  681. fput(server->ncp_filp);
  682. kill_pid(server->m.wdog_pid, SIGTERM, 1);
  683. put_pid(server->m.wdog_pid);
  684. kfree(server->priv.data);
  685. kfree(server->auth.object_name);
  686. vfree(server->rxbuf);
  687. vfree(server->txbuf);
  688. vfree(server->packet);
  689. sb->s_fs_info = NULL;
  690. kfree(server);
  691. unlock_kernel();
  692. }
  693. static int ncp_statfs(struct dentry *dentry, struct kstatfs *buf)
  694. {
  695. struct dentry* d;
  696. struct inode* i;
  697. struct ncp_inode_info* ni;
  698. struct ncp_server* s;
  699. struct ncp_volume_info vi;
  700. struct super_block *sb = dentry->d_sb;
  701. int err;
  702. __u8 dh;
  703. d = sb->s_root;
  704. if (!d) {
  705. goto dflt;
  706. }
  707. i = d->d_inode;
  708. if (!i) {
  709. goto dflt;
  710. }
  711. ni = NCP_FINFO(i);
  712. if (!ni) {
  713. goto dflt;
  714. }
  715. s = NCP_SBP(sb);
  716. if (!s) {
  717. goto dflt;
  718. }
  719. if (!s->m.mounted_vol[0]) {
  720. goto dflt;
  721. }
  722. err = ncp_dirhandle_alloc(s, ni->volNumber, ni->DosDirNum, &dh);
  723. if (err) {
  724. goto dflt;
  725. }
  726. err = ncp_get_directory_info(s, dh, &vi);
  727. ncp_dirhandle_free(s, dh);
  728. if (err) {
  729. goto dflt;
  730. }
  731. buf->f_type = NCP_SUPER_MAGIC;
  732. buf->f_bsize = vi.sectors_per_block * 512;
  733. buf->f_blocks = vi.total_blocks;
  734. buf->f_bfree = vi.free_blocks;
  735. buf->f_bavail = vi.free_blocks;
  736. buf->f_files = vi.total_dir_entries;
  737. buf->f_ffree = vi.available_dir_entries;
  738. buf->f_namelen = 12;
  739. return 0;
  740. /* We cannot say how much disk space is left on a mounted
  741. NetWare Server, because free space is distributed over
  742. volumes, and the current user might have disk quotas. So
  743. free space is not that simple to determine. Our decision
  744. here is to err conservatively. */
  745. dflt:;
  746. buf->f_type = NCP_SUPER_MAGIC;
  747. buf->f_bsize = NCP_BLOCK_SIZE;
  748. buf->f_blocks = 0;
  749. buf->f_bfree = 0;
  750. buf->f_bavail = 0;
  751. buf->f_namelen = 12;
  752. return 0;
  753. }
  754. int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
  755. {
  756. struct inode *inode = dentry->d_inode;
  757. int result = 0;
  758. __le32 info_mask;
  759. struct nw_modify_dos_info info;
  760. struct ncp_server *server;
  761. result = -EIO;
  762. lock_kernel();
  763. server = NCP_SERVER(inode);
  764. if ((!server) || !ncp_conn_valid(server))
  765. goto out;
  766. /* ageing the dentry to force validation */
  767. ncp_age_dentry(server, dentry);
  768. result = inode_change_ok(inode, attr);
  769. if (result < 0)
  770. goto out;
  771. result = -EPERM;
  772. if (((attr->ia_valid & ATTR_UID) &&
  773. (attr->ia_uid != server->m.uid)))
  774. goto out;
  775. if (((attr->ia_valid & ATTR_GID) &&
  776. (attr->ia_gid != server->m.gid)))
  777. goto out;
  778. if (((attr->ia_valid & ATTR_MODE) &&
  779. (attr->ia_mode &
  780. ~(S_IFREG | S_IFDIR | S_IRWXUGO))))
  781. goto out;
  782. info_mask = 0;
  783. memset(&info, 0, sizeof(info));
  784. #if 1
  785. if ((attr->ia_valid & ATTR_MODE) != 0)
  786. {
  787. umode_t newmode = attr->ia_mode;
  788. info_mask |= DM_ATTRIBUTES;
  789. if (S_ISDIR(inode->i_mode)) {
  790. newmode &= server->m.dir_mode;
  791. } else {
  792. #ifdef CONFIG_NCPFS_EXTRAS
  793. if (server->m.flags & NCP_MOUNT_EXTRAS) {
  794. /* any non-default execute bit set */
  795. if (newmode & ~server->m.file_mode & S_IXUGO)
  796. info.attributes |= aSHARED | aSYSTEM;
  797. /* read for group/world and not in default file_mode */
  798. else if (newmode & ~server->m.file_mode & S_IRUGO)
  799. info.attributes |= aSHARED;
  800. } else
  801. #endif
  802. newmode &= server->m.file_mode;
  803. }
  804. if (newmode & S_IWUGO)
  805. info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
  806. else
  807. info.attributes |= (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
  808. #ifdef CONFIG_NCPFS_NFS_NS
  809. if (ncp_is_nfs_extras(server, NCP_FINFO(inode)->volNumber)) {
  810. result = ncp_modify_nfs_info(server,
  811. NCP_FINFO(inode)->volNumber,
  812. NCP_FINFO(inode)->dirEntNum,
  813. attr->ia_mode, 0);
  814. if (result != 0)
  815. goto out;
  816. info.attributes &= ~(aSHARED | aSYSTEM);
  817. {
  818. /* mark partial success */
  819. struct iattr tmpattr;
  820. tmpattr.ia_valid = ATTR_MODE;
  821. tmpattr.ia_mode = attr->ia_mode;
  822. result = inode_setattr(inode, &tmpattr);
  823. if (result)
  824. goto out;
  825. }
  826. }
  827. #endif
  828. }
  829. #endif
  830. /* Do SIZE before attributes, otherwise mtime together with size does not work...
  831. */
  832. if ((attr->ia_valid & ATTR_SIZE) != 0) {
  833. int written;
  834. DPRINTK("ncpfs: trying to change size to %ld\n",
  835. attr->ia_size);
  836. if ((result = ncp_make_open(inode, O_WRONLY)) < 0) {
  837. result = -EACCES;
  838. goto out;
  839. }
  840. ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
  841. attr->ia_size, 0, "", &written);
  842. /* According to ndir, the changes only take effect after
  843. closing the file */
  844. ncp_inode_close(inode);
  845. result = ncp_make_closed(inode);
  846. if (result)
  847. goto out;
  848. {
  849. struct iattr tmpattr;
  850. tmpattr.ia_valid = ATTR_SIZE;
  851. tmpattr.ia_size = attr->ia_size;
  852. result = inode_setattr(inode, &tmpattr);
  853. if (result)
  854. goto out;
  855. }
  856. }
  857. if ((attr->ia_valid & ATTR_CTIME) != 0) {
  858. info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);
  859. ncp_date_unix2dos(attr->ia_ctime.tv_sec,
  860. &info.creationTime, &info.creationDate);
  861. }
  862. if ((attr->ia_valid & ATTR_MTIME) != 0) {
  863. info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
  864. ncp_date_unix2dos(attr->ia_mtime.tv_sec,
  865. &info.modifyTime, &info.modifyDate);
  866. }
  867. if ((attr->ia_valid & ATTR_ATIME) != 0) {
  868. __le16 dummy;
  869. info_mask |= (DM_LAST_ACCESS_DATE);
  870. ncp_date_unix2dos(attr->ia_atime.tv_sec,
  871. &dummy, &info.lastAccessDate);
  872. }
  873. if (info_mask != 0) {
  874. result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
  875. inode, info_mask, &info);
  876. if (result != 0) {
  877. result = -EACCES;
  878. if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE)) {
  879. /* NetWare seems not to allow this. I
  880. do not know why. So, just tell the
  881. user everything went fine. This is
  882. a terrible hack, but I do not know
  883. how to do this correctly. */
  884. result = 0;
  885. } else
  886. goto out;
  887. }
  888. #ifdef CONFIG_NCPFS_STRONG
  889. if ((!result) && (info_mask & DM_ATTRIBUTES))
  890. NCP_FINFO(inode)->nwattr = info.attributes;
  891. #endif
  892. }
  893. if (!result)
  894. result = inode_setattr(inode, attr);
  895. out:
  896. unlock_kernel();
  897. return result;
  898. }
  899. static int ncp_get_sb(struct file_system_type *fs_type,
  900. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  901. {
  902. return get_sb_nodev(fs_type, flags, data, ncp_fill_super, mnt);
  903. }
  904. static struct file_system_type ncp_fs_type = {
  905. .owner = THIS_MODULE,
  906. .name = "ncpfs",
  907. .get_sb = ncp_get_sb,
  908. .kill_sb = kill_anon_super,
  909. .fs_flags = FS_BINARY_MOUNTDATA,
  910. };
  911. static int __init init_ncp_fs(void)
  912. {
  913. int err;
  914. DPRINTK("ncpfs: init_ncp_fs called\n");
  915. err = init_inodecache();
  916. if (err)
  917. goto out1;
  918. err = register_filesystem(&ncp_fs_type);
  919. if (err)
  920. goto out;
  921. return 0;
  922. out:
  923. destroy_inodecache();
  924. out1:
  925. return err;
  926. }
  927. static void __exit exit_ncp_fs(void)
  928. {
  929. DPRINTK("ncpfs: exit_ncp_fs called\n");
  930. unregister_filesystem(&ncp_fs_type);
  931. destroy_inodecache();
  932. }
  933. module_init(init_ncp_fs)
  934. module_exit(exit_ncp_fs)
  935. MODULE_LICENSE("GPL");