inode.c 25 KB

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