vfs_inode.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. /*
  2. * linux/fs/9p/vfs_inode.c
  3. *
  4. * This file contains vfs inode ops for the 9P2000 protocol.
  5. *
  6. * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
  7. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to:
  20. * Free Software Foundation
  21. * 51 Franklin Street, Fifth Floor
  22. * Boston, MA 02111-1301 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/errno.h>
  27. #include <linux/fs.h>
  28. #include <linux/file.h>
  29. #include <linux/pagemap.h>
  30. #include <linux/stat.h>
  31. #include <linux/string.h>
  32. #include <linux/inet.h>
  33. #include <linux/namei.h>
  34. #include <linux/idr.h>
  35. #include <linux/sched.h>
  36. #include <linux/slab.h>
  37. #include <linux/xattr.h>
  38. #include <linux/posix_acl.h>
  39. #include <net/9p/9p.h>
  40. #include <net/9p/client.h>
  41. #include "v9fs.h"
  42. #include "v9fs_vfs.h"
  43. #include "fid.h"
  44. #include "cache.h"
  45. #include "xattr.h"
  46. #include "acl.h"
  47. static const struct inode_operations v9fs_dir_inode_operations;
  48. static const struct inode_operations v9fs_dir_inode_operations_dotu;
  49. static const struct inode_operations v9fs_file_inode_operations;
  50. static const struct inode_operations v9fs_symlink_inode_operations;
  51. /**
  52. * unixmode2p9mode - convert unix mode bits to plan 9
  53. * @v9ses: v9fs session information
  54. * @mode: mode to convert
  55. *
  56. */
  57. static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
  58. {
  59. int res;
  60. res = mode & 0777;
  61. if (S_ISDIR(mode))
  62. res |= P9_DMDIR;
  63. if (v9fs_proto_dotu(v9ses)) {
  64. if (S_ISLNK(mode))
  65. res |= P9_DMSYMLINK;
  66. if (v9ses->nodev == 0) {
  67. if (S_ISSOCK(mode))
  68. res |= P9_DMSOCKET;
  69. if (S_ISFIFO(mode))
  70. res |= P9_DMNAMEDPIPE;
  71. if (S_ISBLK(mode))
  72. res |= P9_DMDEVICE;
  73. if (S_ISCHR(mode))
  74. res |= P9_DMDEVICE;
  75. }
  76. if ((mode & S_ISUID) == S_ISUID)
  77. res |= P9_DMSETUID;
  78. if ((mode & S_ISGID) == S_ISGID)
  79. res |= P9_DMSETGID;
  80. if ((mode & S_ISVTX) == S_ISVTX)
  81. res |= P9_DMSETVTX;
  82. if ((mode & P9_DMLINK))
  83. res |= P9_DMLINK;
  84. }
  85. return res;
  86. }
  87. /**
  88. * p9mode2unixmode- convert plan9 mode bits to unix mode bits
  89. * @v9ses: v9fs session information
  90. * @mode: mode to convert
  91. *
  92. */
  93. static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
  94. {
  95. int res;
  96. res = mode & 0777;
  97. if ((mode & P9_DMDIR) == P9_DMDIR)
  98. res |= S_IFDIR;
  99. else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
  100. res |= S_IFLNK;
  101. else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
  102. && (v9ses->nodev == 0))
  103. res |= S_IFSOCK;
  104. else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
  105. && (v9ses->nodev == 0))
  106. res |= S_IFIFO;
  107. else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
  108. && (v9ses->nodev == 0))
  109. res |= S_IFBLK;
  110. else
  111. res |= S_IFREG;
  112. if (v9fs_proto_dotu(v9ses)) {
  113. if ((mode & P9_DMSETUID) == P9_DMSETUID)
  114. res |= S_ISUID;
  115. if ((mode & P9_DMSETGID) == P9_DMSETGID)
  116. res |= S_ISGID;
  117. if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
  118. res |= S_ISVTX;
  119. }
  120. return res;
  121. }
  122. /**
  123. * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
  124. * @uflags: flags to convert
  125. * @extended: if .u extensions are active
  126. */
  127. int v9fs_uflags2omode(int uflags, int extended)
  128. {
  129. int ret;
  130. ret = 0;
  131. switch (uflags&3) {
  132. default:
  133. case O_RDONLY:
  134. ret = P9_OREAD;
  135. break;
  136. case O_WRONLY:
  137. ret = P9_OWRITE;
  138. break;
  139. case O_RDWR:
  140. ret = P9_ORDWR;
  141. break;
  142. }
  143. if (uflags & O_TRUNC)
  144. ret |= P9_OTRUNC;
  145. if (extended) {
  146. if (uflags & O_EXCL)
  147. ret |= P9_OEXCL;
  148. if (uflags & O_APPEND)
  149. ret |= P9_OAPPEND;
  150. }
  151. return ret;
  152. }
  153. /**
  154. * v9fs_blank_wstat - helper function to setup a 9P stat structure
  155. * @wstat: structure to initialize
  156. *
  157. */
  158. void
  159. v9fs_blank_wstat(struct p9_wstat *wstat)
  160. {
  161. wstat->type = ~0;
  162. wstat->dev = ~0;
  163. wstat->qid.type = ~0;
  164. wstat->qid.version = ~0;
  165. *((long long *)&wstat->qid.path) = ~0;
  166. wstat->mode = ~0;
  167. wstat->atime = ~0;
  168. wstat->mtime = ~0;
  169. wstat->length = ~0;
  170. wstat->name = NULL;
  171. wstat->uid = NULL;
  172. wstat->gid = NULL;
  173. wstat->muid = NULL;
  174. wstat->n_uid = ~0;
  175. wstat->n_gid = ~0;
  176. wstat->n_muid = ~0;
  177. wstat->extension = NULL;
  178. }
  179. /**
  180. * v9fs_alloc_inode - helper function to allocate an inode
  181. *
  182. */
  183. struct inode *v9fs_alloc_inode(struct super_block *sb)
  184. {
  185. struct v9fs_inode *v9inode;
  186. v9inode = (struct v9fs_inode *)kmem_cache_alloc(v9fs_inode_cache,
  187. GFP_KERNEL);
  188. if (!v9inode)
  189. return NULL;
  190. #ifdef CONFIG_9P_FSCACHE
  191. v9inode->fscache = NULL;
  192. v9inode->fscache_key = NULL;
  193. spin_lock_init(&v9inode->fscache_lock);
  194. #endif
  195. v9inode->writeback_fid = NULL;
  196. v9inode->cache_validity = 0;
  197. return &v9inode->vfs_inode;
  198. }
  199. /**
  200. * v9fs_destroy_inode - destroy an inode
  201. *
  202. */
  203. static void v9fs_i_callback(struct rcu_head *head)
  204. {
  205. struct inode *inode = container_of(head, struct inode, i_rcu);
  206. INIT_LIST_HEAD(&inode->i_dentry);
  207. kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
  208. }
  209. void v9fs_destroy_inode(struct inode *inode)
  210. {
  211. call_rcu(&inode->i_rcu, v9fs_i_callback);
  212. }
  213. int v9fs_init_inode(struct v9fs_session_info *v9ses,
  214. struct inode *inode, int mode)
  215. {
  216. int err = 0;
  217. inode_init_owner(inode, NULL, mode);
  218. inode->i_blocks = 0;
  219. inode->i_rdev = 0;
  220. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  221. inode->i_mapping->a_ops = &v9fs_addr_operations;
  222. switch (mode & S_IFMT) {
  223. case S_IFIFO:
  224. case S_IFBLK:
  225. case S_IFCHR:
  226. case S_IFSOCK:
  227. if (v9fs_proto_dotl(v9ses)) {
  228. inode->i_op = &v9fs_file_inode_operations_dotl;
  229. inode->i_fop = &v9fs_file_operations_dotl;
  230. } else if (v9fs_proto_dotu(v9ses)) {
  231. inode->i_op = &v9fs_file_inode_operations;
  232. inode->i_fop = &v9fs_file_operations;
  233. } else {
  234. P9_DPRINTK(P9_DEBUG_ERROR,
  235. "special files without extended mode\n");
  236. err = -EINVAL;
  237. goto error;
  238. }
  239. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  240. break;
  241. case S_IFREG:
  242. if (v9fs_proto_dotl(v9ses)) {
  243. inode->i_op = &v9fs_file_inode_operations_dotl;
  244. if (v9ses->cache)
  245. inode->i_fop =
  246. &v9fs_cached_file_operations_dotl;
  247. else
  248. inode->i_fop = &v9fs_file_operations_dotl;
  249. } else {
  250. inode->i_op = &v9fs_file_inode_operations;
  251. if (v9ses->cache)
  252. inode->i_fop = &v9fs_cached_file_operations;
  253. else
  254. inode->i_fop = &v9fs_file_operations;
  255. }
  256. break;
  257. case S_IFLNK:
  258. if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
  259. P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
  260. "legacy protocol.\n");
  261. err = -EINVAL;
  262. goto error;
  263. }
  264. if (v9fs_proto_dotl(v9ses))
  265. inode->i_op = &v9fs_symlink_inode_operations_dotl;
  266. else
  267. inode->i_op = &v9fs_symlink_inode_operations;
  268. break;
  269. case S_IFDIR:
  270. inc_nlink(inode);
  271. if (v9fs_proto_dotl(v9ses))
  272. inode->i_op = &v9fs_dir_inode_operations_dotl;
  273. else if (v9fs_proto_dotu(v9ses))
  274. inode->i_op = &v9fs_dir_inode_operations_dotu;
  275. else
  276. inode->i_op = &v9fs_dir_inode_operations;
  277. if (v9fs_proto_dotl(v9ses))
  278. inode->i_fop = &v9fs_dir_operations_dotl;
  279. else
  280. inode->i_fop = &v9fs_dir_operations;
  281. break;
  282. default:
  283. P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
  284. mode, mode & S_IFMT);
  285. err = -EINVAL;
  286. goto error;
  287. }
  288. error:
  289. return err;
  290. }
  291. /**
  292. * v9fs_get_inode - helper function to setup an inode
  293. * @sb: superblock
  294. * @mode: mode to setup inode with
  295. *
  296. */
  297. struct inode *v9fs_get_inode(struct super_block *sb, int mode)
  298. {
  299. int err;
  300. struct inode *inode;
  301. struct v9fs_session_info *v9ses = sb->s_fs_info;
  302. P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
  303. inode = new_inode(sb);
  304. if (!inode) {
  305. P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
  306. return ERR_PTR(-ENOMEM);
  307. }
  308. err = v9fs_init_inode(v9ses, inode, mode);
  309. if (err) {
  310. iput(inode);
  311. return ERR_PTR(err);
  312. }
  313. return inode;
  314. }
  315. /*
  316. static struct v9fs_fid*
  317. v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
  318. {
  319. int err;
  320. int nfid;
  321. struct v9fs_fid *ret;
  322. struct v9fs_fcall *fcall;
  323. nfid = v9fs_get_idpool(&v9ses->fidpool);
  324. if (nfid < 0) {
  325. eprintk(KERN_WARNING, "no free fids available\n");
  326. return ERR_PTR(-ENOSPC);
  327. }
  328. err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
  329. &fcall);
  330. if (err < 0) {
  331. if (fcall && fcall->id == RWALK)
  332. goto clunk_fid;
  333. PRINT_FCALL_ERROR("walk error", fcall);
  334. v9fs_put_idpool(nfid, &v9ses->fidpool);
  335. goto error;
  336. }
  337. kfree(fcall);
  338. fcall = NULL;
  339. ret = v9fs_fid_create(v9ses, nfid);
  340. if (!ret) {
  341. err = -ENOMEM;
  342. goto clunk_fid;
  343. }
  344. err = v9fs_fid_insert(ret, dentry);
  345. if (err < 0) {
  346. v9fs_fid_destroy(ret);
  347. goto clunk_fid;
  348. }
  349. return ret;
  350. clunk_fid:
  351. v9fs_t_clunk(v9ses, nfid);
  352. error:
  353. kfree(fcall);
  354. return ERR_PTR(err);
  355. }
  356. */
  357. /**
  358. * v9fs_clear_inode - release an inode
  359. * @inode: inode to release
  360. *
  361. */
  362. void v9fs_evict_inode(struct inode *inode)
  363. {
  364. struct v9fs_inode *v9inode = V9FS_I(inode);
  365. truncate_inode_pages(inode->i_mapping, 0);
  366. end_writeback(inode);
  367. filemap_fdatawrite(inode->i_mapping);
  368. #ifdef CONFIG_9P_FSCACHE
  369. v9fs_cache_inode_put_cookie(inode);
  370. #endif
  371. /* clunk the fid stashed in writeback_fid */
  372. if (v9inode->writeback_fid) {
  373. p9_client_clunk(v9inode->writeback_fid);
  374. v9inode->writeback_fid = NULL;
  375. }
  376. }
  377. static struct inode *v9fs_qid_iget(struct super_block *sb,
  378. struct p9_qid *qid,
  379. struct p9_wstat *st)
  380. {
  381. int retval, umode;
  382. unsigned long i_ino;
  383. struct inode *inode;
  384. struct v9fs_session_info *v9ses = sb->s_fs_info;
  385. i_ino = v9fs_qid2ino(qid);
  386. inode = iget_locked(sb, i_ino);
  387. if (!inode)
  388. return ERR_PTR(-ENOMEM);
  389. if (!(inode->i_state & I_NEW))
  390. return inode;
  391. /*
  392. * initialize the inode with the stat info
  393. * FIXME!! we may need support for stale inodes
  394. * later.
  395. */
  396. umode = p9mode2unixmode(v9ses, st->mode);
  397. retval = v9fs_init_inode(v9ses, inode, umode);
  398. if (retval)
  399. goto error;
  400. v9fs_stat2inode(st, inode, sb);
  401. #ifdef CONFIG_9P_FSCACHE
  402. v9fs_fscache_set_key(inode, &st->qid);
  403. v9fs_cache_inode_get_cookie(inode);
  404. #endif
  405. unlock_new_inode(inode);
  406. return inode;
  407. error:
  408. unlock_new_inode(inode);
  409. iput(inode);
  410. return ERR_PTR(retval);
  411. }
  412. struct inode *
  413. v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  414. struct super_block *sb)
  415. {
  416. struct p9_wstat *st;
  417. struct inode *inode = NULL;
  418. st = p9_client_stat(fid);
  419. if (IS_ERR(st))
  420. return ERR_CAST(st);
  421. inode = v9fs_qid_iget(sb, &st->qid, st);
  422. p9stat_free(st);
  423. kfree(st);
  424. return inode;
  425. }
  426. /**
  427. * v9fs_remove - helper function to remove files and directories
  428. * @dir: directory inode that is being deleted
  429. * @file: dentry that is being deleted
  430. * @rmdir: removing a directory
  431. *
  432. */
  433. static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
  434. {
  435. int retval;
  436. struct p9_fid *v9fid;
  437. struct inode *file_inode;
  438. P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
  439. rmdir);
  440. file_inode = file->d_inode;
  441. v9fid = v9fs_fid_clone(file);
  442. if (IS_ERR(v9fid))
  443. return PTR_ERR(v9fid);
  444. retval = p9_client_remove(v9fid);
  445. if (!retval) {
  446. /*
  447. * directories on unlink should have zero
  448. * link count
  449. */
  450. if (rmdir) {
  451. clear_nlink(file_inode);
  452. drop_nlink(dir);
  453. } else
  454. drop_nlink(file_inode);
  455. v9fs_invalidate_inode_attr(file_inode);
  456. v9fs_invalidate_inode_attr(dir);
  457. }
  458. return retval;
  459. }
  460. /**
  461. * v9fs_create - Create a file
  462. * @v9ses: session information
  463. * @dir: directory that dentry is being created in
  464. * @dentry: dentry that is being created
  465. * @extension: 9p2000.u extension string to support devices, etc.
  466. * @perm: create permissions
  467. * @mode: open mode
  468. *
  469. */
  470. static struct p9_fid *
  471. v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
  472. struct dentry *dentry, char *extension, u32 perm, u8 mode)
  473. {
  474. int err;
  475. char *name;
  476. struct p9_fid *dfid, *ofid, *fid;
  477. struct inode *inode;
  478. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  479. err = 0;
  480. ofid = NULL;
  481. fid = NULL;
  482. name = (char *) dentry->d_name.name;
  483. dfid = v9fs_fid_lookup(dentry->d_parent);
  484. if (IS_ERR(dfid)) {
  485. err = PTR_ERR(dfid);
  486. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  487. return ERR_PTR(err);
  488. }
  489. /* clone a fid to use for creation */
  490. ofid = p9_client_walk(dfid, 0, NULL, 1);
  491. if (IS_ERR(ofid)) {
  492. err = PTR_ERR(ofid);
  493. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  494. return ERR_PTR(err);
  495. }
  496. err = p9_client_fcreate(ofid, name, perm, mode, extension);
  497. if (err < 0) {
  498. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
  499. goto error;
  500. }
  501. /* now walk from the parent so we can get unopened fid */
  502. fid = p9_client_walk(dfid, 1, &name, 1);
  503. if (IS_ERR(fid)) {
  504. err = PTR_ERR(fid);
  505. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  506. fid = NULL;
  507. goto error;
  508. }
  509. /* instantiate inode and assign the unopened fid to the dentry */
  510. inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
  511. if (IS_ERR(inode)) {
  512. err = PTR_ERR(inode);
  513. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
  514. goto error;
  515. }
  516. d_instantiate(dentry, inode);
  517. err = v9fs_fid_add(dentry, fid);
  518. if (err < 0)
  519. goto error;
  520. return ofid;
  521. error:
  522. if (ofid)
  523. p9_client_clunk(ofid);
  524. if (fid)
  525. p9_client_clunk(fid);
  526. return ERR_PTR(err);
  527. }
  528. /**
  529. * v9fs_vfs_create - VFS hook to create files
  530. * @dir: directory inode that is being created
  531. * @dentry: dentry that is being deleted
  532. * @mode: create permissions
  533. * @nd: path information
  534. *
  535. */
  536. static int
  537. v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
  538. struct nameidata *nd)
  539. {
  540. int err;
  541. u32 perm;
  542. int flags;
  543. struct file *filp;
  544. struct v9fs_inode *v9inode;
  545. struct v9fs_session_info *v9ses;
  546. struct p9_fid *fid, *inode_fid;
  547. err = 0;
  548. fid = NULL;
  549. v9ses = v9fs_inode2v9ses(dir);
  550. perm = unixmode2p9mode(v9ses, mode);
  551. if (nd && nd->flags & LOOKUP_OPEN)
  552. flags = nd->intent.open.flags - 1;
  553. else
  554. flags = O_RDWR;
  555. fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
  556. v9fs_uflags2omode(flags,
  557. v9fs_proto_dotu(v9ses)));
  558. if (IS_ERR(fid)) {
  559. err = PTR_ERR(fid);
  560. fid = NULL;
  561. goto error;
  562. }
  563. v9fs_invalidate_inode_attr(dir);
  564. /* if we are opening a file, assign the open fid to the file */
  565. if (nd && nd->flags & LOOKUP_OPEN) {
  566. v9inode = V9FS_I(dentry->d_inode);
  567. if (v9ses->cache && !v9inode->writeback_fid) {
  568. /*
  569. * clone a fid and add it to writeback_fid
  570. * we do it during open time instead of
  571. * page dirty time via write_begin/page_mkwrite
  572. * because we want write after unlink usecase
  573. * to work.
  574. */
  575. inode_fid = v9fs_writeback_fid(dentry);
  576. if (IS_ERR(inode_fid)) {
  577. err = PTR_ERR(inode_fid);
  578. goto error;
  579. }
  580. v9inode->writeback_fid = (void *) inode_fid;
  581. }
  582. filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
  583. if (IS_ERR(filp)) {
  584. err = PTR_ERR(filp);
  585. goto error;
  586. }
  587. filp->private_data = fid;
  588. #ifdef CONFIG_9P_FSCACHE
  589. if (v9ses->cache)
  590. v9fs_cache_inode_set_cookie(dentry->d_inode, filp);
  591. #endif
  592. } else
  593. p9_client_clunk(fid);
  594. return 0;
  595. error:
  596. if (fid)
  597. p9_client_clunk(fid);
  598. return err;
  599. }
  600. /**
  601. * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
  602. * @dir: inode that is being unlinked
  603. * @dentry: dentry that is being unlinked
  604. * @mode: mode for new directory
  605. *
  606. */
  607. static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  608. {
  609. int err;
  610. u32 perm;
  611. struct p9_fid *fid;
  612. struct v9fs_session_info *v9ses;
  613. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  614. err = 0;
  615. v9ses = v9fs_inode2v9ses(dir);
  616. perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
  617. fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
  618. if (IS_ERR(fid)) {
  619. err = PTR_ERR(fid);
  620. fid = NULL;
  621. } else {
  622. inc_nlink(dir);
  623. v9fs_invalidate_inode_attr(dir);
  624. }
  625. if (fid)
  626. p9_client_clunk(fid);
  627. return err;
  628. }
  629. /**
  630. * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
  631. * @dir: inode that is being walked from
  632. * @dentry: dentry that is being walked to?
  633. * @nameidata: path data
  634. *
  635. */
  636. struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
  637. struct nameidata *nameidata)
  638. {
  639. struct super_block *sb;
  640. struct v9fs_session_info *v9ses;
  641. struct p9_fid *dfid, *fid;
  642. struct inode *inode;
  643. char *name;
  644. int result = 0;
  645. P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
  646. dir, dentry->d_name.name, dentry, nameidata);
  647. if (dentry->d_name.len > NAME_MAX)
  648. return ERR_PTR(-ENAMETOOLONG);
  649. sb = dir->i_sb;
  650. v9ses = v9fs_inode2v9ses(dir);
  651. /* We can walk d_parent because we hold the dir->i_mutex */
  652. dfid = v9fs_fid_lookup(dentry->d_parent);
  653. if (IS_ERR(dfid))
  654. return ERR_CAST(dfid);
  655. name = (char *) dentry->d_name.name;
  656. fid = p9_client_walk(dfid, 1, &name, 1);
  657. if (IS_ERR(fid)) {
  658. result = PTR_ERR(fid);
  659. if (result == -ENOENT) {
  660. inode = NULL;
  661. goto inst_out;
  662. }
  663. return ERR_PTR(result);
  664. }
  665. inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
  666. if (IS_ERR(inode)) {
  667. result = PTR_ERR(inode);
  668. inode = NULL;
  669. goto error;
  670. }
  671. result = v9fs_fid_add(dentry, fid);
  672. if (result < 0)
  673. goto error_iput;
  674. inst_out:
  675. d_add(dentry, inode);
  676. return NULL;
  677. error_iput:
  678. iput(inode);
  679. error:
  680. p9_client_clunk(fid);
  681. return ERR_PTR(result);
  682. }
  683. /**
  684. * v9fs_vfs_unlink - VFS unlink hook to delete an inode
  685. * @i: inode that is being unlinked
  686. * @d: dentry that is being unlinked
  687. *
  688. */
  689. int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
  690. {
  691. return v9fs_remove(i, d, 0);
  692. }
  693. /**
  694. * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
  695. * @i: inode that is being unlinked
  696. * @d: dentry that is being unlinked
  697. *
  698. */
  699. int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
  700. {
  701. return v9fs_remove(i, d, 1);
  702. }
  703. /**
  704. * v9fs_vfs_rename - VFS hook to rename an inode
  705. * @old_dir: old dir inode
  706. * @old_dentry: old dentry
  707. * @new_dir: new dir inode
  708. * @new_dentry: new dentry
  709. *
  710. */
  711. int
  712. v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  713. struct inode *new_dir, struct dentry *new_dentry)
  714. {
  715. int retval;
  716. struct inode *old_inode;
  717. struct inode *new_inode;
  718. struct v9fs_session_info *v9ses;
  719. struct p9_fid *oldfid;
  720. struct p9_fid *olddirfid;
  721. struct p9_fid *newdirfid;
  722. struct p9_wstat wstat;
  723. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  724. retval = 0;
  725. old_inode = old_dentry->d_inode;
  726. new_inode = new_dentry->d_inode;
  727. v9ses = v9fs_inode2v9ses(old_inode);
  728. oldfid = v9fs_fid_lookup(old_dentry);
  729. if (IS_ERR(oldfid))
  730. return PTR_ERR(oldfid);
  731. olddirfid = v9fs_fid_clone(old_dentry->d_parent);
  732. if (IS_ERR(olddirfid)) {
  733. retval = PTR_ERR(olddirfid);
  734. goto done;
  735. }
  736. newdirfid = v9fs_fid_clone(new_dentry->d_parent);
  737. if (IS_ERR(newdirfid)) {
  738. retval = PTR_ERR(newdirfid);
  739. goto clunk_olddir;
  740. }
  741. down_write(&v9ses->rename_sem);
  742. if (v9fs_proto_dotl(v9ses)) {
  743. retval = p9_client_rename(oldfid, newdirfid,
  744. (char *) new_dentry->d_name.name);
  745. if (retval != -ENOSYS)
  746. goto clunk_newdir;
  747. }
  748. if (old_dentry->d_parent != new_dentry->d_parent) {
  749. /*
  750. * 9P .u can only handle file rename in the same directory
  751. */
  752. P9_DPRINTK(P9_DEBUG_ERROR,
  753. "old dir and new dir are different\n");
  754. retval = -EXDEV;
  755. goto clunk_newdir;
  756. }
  757. v9fs_blank_wstat(&wstat);
  758. wstat.muid = v9ses->uname;
  759. wstat.name = (char *) new_dentry->d_name.name;
  760. retval = p9_client_wstat(oldfid, &wstat);
  761. clunk_newdir:
  762. if (!retval) {
  763. if (new_inode) {
  764. if (S_ISDIR(new_inode->i_mode))
  765. clear_nlink(new_inode);
  766. else
  767. drop_nlink(new_inode);
  768. /*
  769. * Work around vfs rename rehash bug with
  770. * FS_RENAME_DOES_D_MOVE
  771. */
  772. v9fs_invalidate_inode_attr(new_inode);
  773. }
  774. if (S_ISDIR(old_inode->i_mode)) {
  775. if (!new_inode)
  776. inc_nlink(new_dir);
  777. drop_nlink(old_dir);
  778. }
  779. v9fs_invalidate_inode_attr(old_inode);
  780. v9fs_invalidate_inode_attr(old_dir);
  781. v9fs_invalidate_inode_attr(new_dir);
  782. /* successful rename */
  783. d_move(old_dentry, new_dentry);
  784. }
  785. up_write(&v9ses->rename_sem);
  786. p9_client_clunk(newdirfid);
  787. clunk_olddir:
  788. p9_client_clunk(olddirfid);
  789. done:
  790. return retval;
  791. }
  792. /**
  793. * v9fs_vfs_getattr - retrieve file metadata
  794. * @mnt: mount information
  795. * @dentry: file to get attributes on
  796. * @stat: metadata structure to populate
  797. *
  798. */
  799. static int
  800. v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  801. struct kstat *stat)
  802. {
  803. int err;
  804. struct v9fs_session_info *v9ses;
  805. struct p9_fid *fid;
  806. struct p9_wstat *st;
  807. P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
  808. err = -EPERM;
  809. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  810. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  811. generic_fillattr(dentry->d_inode, stat);
  812. return 0;
  813. }
  814. fid = v9fs_fid_lookup(dentry);
  815. if (IS_ERR(fid))
  816. return PTR_ERR(fid);
  817. st = p9_client_stat(fid);
  818. if (IS_ERR(st))
  819. return PTR_ERR(st);
  820. v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb);
  821. generic_fillattr(dentry->d_inode, stat);
  822. p9stat_free(st);
  823. kfree(st);
  824. return 0;
  825. }
  826. /**
  827. * v9fs_vfs_setattr - set file metadata
  828. * @dentry: file whose metadata to set
  829. * @iattr: metadata assignment structure
  830. *
  831. */
  832. static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
  833. {
  834. int retval;
  835. struct v9fs_session_info *v9ses;
  836. struct p9_fid *fid;
  837. struct p9_wstat wstat;
  838. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  839. retval = -EPERM;
  840. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  841. fid = v9fs_fid_lookup(dentry);
  842. if(IS_ERR(fid))
  843. return PTR_ERR(fid);
  844. v9fs_blank_wstat(&wstat);
  845. if (iattr->ia_valid & ATTR_MODE)
  846. wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
  847. if (iattr->ia_valid & ATTR_MTIME)
  848. wstat.mtime = iattr->ia_mtime.tv_sec;
  849. if (iattr->ia_valid & ATTR_ATIME)
  850. wstat.atime = iattr->ia_atime.tv_sec;
  851. if (iattr->ia_valid & ATTR_SIZE)
  852. wstat.length = iattr->ia_size;
  853. if (v9fs_proto_dotu(v9ses)) {
  854. if (iattr->ia_valid & ATTR_UID)
  855. wstat.n_uid = iattr->ia_uid;
  856. if (iattr->ia_valid & ATTR_GID)
  857. wstat.n_gid = iattr->ia_gid;
  858. }
  859. retval = p9_client_wstat(fid, &wstat);
  860. if (retval < 0)
  861. return retval;
  862. v9fs_invalidate_inode_attr(dentry->d_inode);
  863. if ((iattr->ia_valid & ATTR_SIZE) &&
  864. iattr->ia_size != i_size_read(dentry->d_inode)) {
  865. retval = vmtruncate(dentry->d_inode, iattr->ia_size);
  866. if (retval)
  867. return retval;
  868. }
  869. setattr_copy(dentry->d_inode, iattr);
  870. mark_inode_dirty(dentry->d_inode);
  871. return 0;
  872. }
  873. /**
  874. * v9fs_stat2inode - populate an inode structure with mistat info
  875. * @stat: Plan 9 metadata (mistat) structure
  876. * @inode: inode to populate
  877. * @sb: superblock of filesystem
  878. *
  879. */
  880. void
  881. v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
  882. struct super_block *sb)
  883. {
  884. char ext[32];
  885. char tag_name[14];
  886. unsigned int i_nlink;
  887. struct v9fs_session_info *v9ses = sb->s_fs_info;
  888. struct v9fs_inode *v9inode = V9FS_I(inode);
  889. inode->i_nlink = 1;
  890. inode->i_atime.tv_sec = stat->atime;
  891. inode->i_mtime.tv_sec = stat->mtime;
  892. inode->i_ctime.tv_sec = stat->mtime;
  893. inode->i_uid = v9ses->dfltuid;
  894. inode->i_gid = v9ses->dfltgid;
  895. if (v9fs_proto_dotu(v9ses)) {
  896. inode->i_uid = stat->n_uid;
  897. inode->i_gid = stat->n_gid;
  898. }
  899. if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
  900. if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
  901. /*
  902. * Hadlink support got added later to
  903. * to the .u extension. So there can be
  904. * server out there that doesn't support
  905. * this even with .u extension. So check
  906. * for non NULL stat->extension
  907. */
  908. strncpy(ext, stat->extension, sizeof(ext));
  909. /* HARDLINKCOUNT %u */
  910. sscanf(ext, "%13s %u", tag_name, &i_nlink);
  911. if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
  912. inode->i_nlink = i_nlink;
  913. }
  914. }
  915. inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
  916. if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
  917. char type = 0;
  918. int major = -1;
  919. int minor = -1;
  920. strncpy(ext, stat->extension, sizeof(ext));
  921. sscanf(ext, "%c %u %u", &type, &major, &minor);
  922. switch (type) {
  923. case 'c':
  924. inode->i_mode &= ~S_IFBLK;
  925. inode->i_mode |= S_IFCHR;
  926. break;
  927. case 'b':
  928. break;
  929. default:
  930. P9_DPRINTK(P9_DEBUG_ERROR,
  931. "Unknown special type %c %s\n", type,
  932. stat->extension);
  933. };
  934. inode->i_rdev = MKDEV(major, minor);
  935. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  936. } else
  937. inode->i_rdev = 0;
  938. i_size_write(inode, stat->length);
  939. /* not real number of blocks, but 512 byte ones ... */
  940. inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
  941. v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
  942. }
  943. /**
  944. * v9fs_qid2ino - convert qid into inode number
  945. * @qid: qid to hash
  946. *
  947. * BUG: potential for inode number collisions?
  948. */
  949. ino_t v9fs_qid2ino(struct p9_qid *qid)
  950. {
  951. u64 path = qid->path + 2;
  952. ino_t i = 0;
  953. if (sizeof(ino_t) == sizeof(path))
  954. memcpy(&i, &path, sizeof(ino_t));
  955. else
  956. i = (ino_t) (path ^ (path >> 32));
  957. return i;
  958. }
  959. /**
  960. * v9fs_readlink - read a symlink's location (internal version)
  961. * @dentry: dentry for symlink
  962. * @buffer: buffer to load symlink location into
  963. * @buflen: length of buffer
  964. *
  965. */
  966. static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
  967. {
  968. int retval;
  969. struct v9fs_session_info *v9ses;
  970. struct p9_fid *fid;
  971. struct p9_wstat *st;
  972. P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
  973. retval = -EPERM;
  974. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  975. fid = v9fs_fid_lookup(dentry);
  976. if (IS_ERR(fid))
  977. return PTR_ERR(fid);
  978. if (!v9fs_proto_dotu(v9ses))
  979. return -EBADF;
  980. st = p9_client_stat(fid);
  981. if (IS_ERR(st))
  982. return PTR_ERR(st);
  983. if (!(st->mode & P9_DMSYMLINK)) {
  984. retval = -EINVAL;
  985. goto done;
  986. }
  987. /* copy extension buffer into buffer */
  988. strncpy(buffer, st->extension, buflen);
  989. P9_DPRINTK(P9_DEBUG_VFS,
  990. "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
  991. retval = strnlen(buffer, buflen);
  992. done:
  993. p9stat_free(st);
  994. kfree(st);
  995. return retval;
  996. }
  997. /**
  998. * v9fs_vfs_follow_link - follow a symlink path
  999. * @dentry: dentry for symlink
  1000. * @nd: nameidata
  1001. *
  1002. */
  1003. static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  1004. {
  1005. int len = 0;
  1006. char *link = __getname();
  1007. P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
  1008. if (!link)
  1009. link = ERR_PTR(-ENOMEM);
  1010. else {
  1011. len = v9fs_readlink(dentry, link, PATH_MAX);
  1012. if (len < 0) {
  1013. __putname(link);
  1014. link = ERR_PTR(len);
  1015. } else
  1016. link[min(len, PATH_MAX-1)] = 0;
  1017. }
  1018. nd_set_link(nd, link);
  1019. return NULL;
  1020. }
  1021. /**
  1022. * v9fs_vfs_put_link - release a symlink path
  1023. * @dentry: dentry for symlink
  1024. * @nd: nameidata
  1025. * @p: unused
  1026. *
  1027. */
  1028. void
  1029. v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
  1030. {
  1031. char *s = nd_get_link(nd);
  1032. P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
  1033. IS_ERR(s) ? "<error>" : s);
  1034. if (!IS_ERR(s))
  1035. __putname(s);
  1036. }
  1037. /**
  1038. * v9fs_vfs_mkspecial - create a special file
  1039. * @dir: inode to create special file in
  1040. * @dentry: dentry to create
  1041. * @mode: mode to create special file
  1042. * @extension: 9p2000.u format extension string representing special file
  1043. *
  1044. */
  1045. static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
  1046. int mode, const char *extension)
  1047. {
  1048. u32 perm;
  1049. struct p9_fid *fid;
  1050. struct v9fs_session_info *v9ses;
  1051. v9ses = v9fs_inode2v9ses(dir);
  1052. if (!v9fs_proto_dotu(v9ses)) {
  1053. P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
  1054. return -EPERM;
  1055. }
  1056. perm = unixmode2p9mode(v9ses, mode);
  1057. fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
  1058. P9_OREAD);
  1059. if (IS_ERR(fid))
  1060. return PTR_ERR(fid);
  1061. v9fs_invalidate_inode_attr(dir);
  1062. p9_client_clunk(fid);
  1063. return 0;
  1064. }
  1065. /**
  1066. * v9fs_vfs_symlink - helper function to create symlinks
  1067. * @dir: directory inode containing symlink
  1068. * @dentry: dentry for symlink
  1069. * @symname: symlink data
  1070. *
  1071. * See Also: 9P2000.u RFC for more information
  1072. *
  1073. */
  1074. static int
  1075. v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
  1076. {
  1077. P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino,
  1078. dentry->d_name.name, symname);
  1079. return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
  1080. }
  1081. /**
  1082. * v9fs_vfs_link - create a hardlink
  1083. * @old_dentry: dentry for file to link to
  1084. * @dir: inode destination for new link
  1085. * @dentry: dentry for link
  1086. *
  1087. */
  1088. static int
  1089. v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
  1090. struct dentry *dentry)
  1091. {
  1092. int retval;
  1093. char *name;
  1094. struct p9_fid *oldfid;
  1095. P9_DPRINTK(P9_DEBUG_VFS,
  1096. " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
  1097. old_dentry->d_name.name);
  1098. oldfid = v9fs_fid_clone(old_dentry);
  1099. if (IS_ERR(oldfid))
  1100. return PTR_ERR(oldfid);
  1101. name = __getname();
  1102. if (unlikely(!name)) {
  1103. retval = -ENOMEM;
  1104. goto clunk_fid;
  1105. }
  1106. sprintf(name, "%d\n", oldfid->fid);
  1107. retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
  1108. __putname(name);
  1109. if (!retval)
  1110. v9fs_invalidate_inode_attr(dir);
  1111. clunk_fid:
  1112. p9_client_clunk(oldfid);
  1113. return retval;
  1114. }
  1115. /**
  1116. * v9fs_vfs_mknod - create a special file
  1117. * @dir: inode destination for new link
  1118. * @dentry: dentry for file
  1119. * @mode: mode for creation
  1120. * @rdev: device associated with special file
  1121. *
  1122. */
  1123. static int
  1124. v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
  1125. {
  1126. int retval;
  1127. char *name;
  1128. P9_DPRINTK(P9_DEBUG_VFS,
  1129. " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
  1130. dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
  1131. if (!new_valid_dev(rdev))
  1132. return -EINVAL;
  1133. name = __getname();
  1134. if (!name)
  1135. return -ENOMEM;
  1136. /* build extension */
  1137. if (S_ISBLK(mode))
  1138. sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
  1139. else if (S_ISCHR(mode))
  1140. sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
  1141. else if (S_ISFIFO(mode))
  1142. *name = 0;
  1143. else if (S_ISSOCK(mode))
  1144. *name = 0;
  1145. else {
  1146. __putname(name);
  1147. return -EINVAL;
  1148. }
  1149. retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
  1150. __putname(name);
  1151. return retval;
  1152. }
  1153. int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
  1154. {
  1155. loff_t i_size;
  1156. struct p9_wstat *st;
  1157. struct v9fs_session_info *v9ses;
  1158. v9ses = v9fs_inode2v9ses(inode);
  1159. st = p9_client_stat(fid);
  1160. if (IS_ERR(st))
  1161. return PTR_ERR(st);
  1162. spin_lock(&inode->i_lock);
  1163. /*
  1164. * We don't want to refresh inode->i_size,
  1165. * because we may have cached data
  1166. */
  1167. i_size = inode->i_size;
  1168. v9fs_stat2inode(st, inode, inode->i_sb);
  1169. if (v9ses->cache)
  1170. inode->i_size = i_size;
  1171. spin_unlock(&inode->i_lock);
  1172. p9stat_free(st);
  1173. kfree(st);
  1174. return 0;
  1175. }
  1176. static const struct inode_operations v9fs_dir_inode_operations_dotu = {
  1177. .create = v9fs_vfs_create,
  1178. .lookup = v9fs_vfs_lookup,
  1179. .symlink = v9fs_vfs_symlink,
  1180. .link = v9fs_vfs_link,
  1181. .unlink = v9fs_vfs_unlink,
  1182. .mkdir = v9fs_vfs_mkdir,
  1183. .rmdir = v9fs_vfs_rmdir,
  1184. .mknod = v9fs_vfs_mknod,
  1185. .rename = v9fs_vfs_rename,
  1186. .getattr = v9fs_vfs_getattr,
  1187. .setattr = v9fs_vfs_setattr,
  1188. };
  1189. static const struct inode_operations v9fs_dir_inode_operations = {
  1190. .create = v9fs_vfs_create,
  1191. .lookup = v9fs_vfs_lookup,
  1192. .unlink = v9fs_vfs_unlink,
  1193. .mkdir = v9fs_vfs_mkdir,
  1194. .rmdir = v9fs_vfs_rmdir,
  1195. .mknod = v9fs_vfs_mknod,
  1196. .rename = v9fs_vfs_rename,
  1197. .getattr = v9fs_vfs_getattr,
  1198. .setattr = v9fs_vfs_setattr,
  1199. };
  1200. static const struct inode_operations v9fs_file_inode_operations = {
  1201. .getattr = v9fs_vfs_getattr,
  1202. .setattr = v9fs_vfs_setattr,
  1203. };
  1204. static const struct inode_operations v9fs_symlink_inode_operations = {
  1205. .readlink = generic_readlink,
  1206. .follow_link = v9fs_vfs_follow_link,
  1207. .put_link = v9fs_vfs_put_link,
  1208. .getattr = v9fs_vfs_getattr,
  1209. .setattr = v9fs_vfs_setattr,
  1210. };