inode.c 25 KB

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