vfs_inode.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  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 <net/9p/9p.h>
  39. #include <net/9p/client.h>
  40. #include "v9fs.h"
  41. #include "v9fs_vfs.h"
  42. #include "fid.h"
  43. #include "cache.h"
  44. #include "xattr.h"
  45. static const struct inode_operations v9fs_dir_inode_operations;
  46. static const struct inode_operations v9fs_dir_inode_operations_dotu;
  47. static const struct inode_operations v9fs_dir_inode_operations_dotl;
  48. static const struct inode_operations v9fs_file_inode_operations;
  49. static const struct inode_operations v9fs_file_inode_operations_dotl;
  50. static const struct inode_operations v9fs_symlink_inode_operations;
  51. static const struct inode_operations v9fs_symlink_inode_operations_dotl;
  52. /**
  53. * unixmode2p9mode - convert unix mode bits to plan 9
  54. * @v9ses: v9fs session information
  55. * @mode: mode to convert
  56. *
  57. */
  58. static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
  59. {
  60. int res;
  61. res = mode & 0777;
  62. if (S_ISDIR(mode))
  63. res |= P9_DMDIR;
  64. if (v9fs_proto_dotu(v9ses)) {
  65. if (S_ISLNK(mode))
  66. res |= P9_DMSYMLINK;
  67. if (v9ses->nodev == 0) {
  68. if (S_ISSOCK(mode))
  69. res |= P9_DMSOCKET;
  70. if (S_ISFIFO(mode))
  71. res |= P9_DMNAMEDPIPE;
  72. if (S_ISBLK(mode))
  73. res |= P9_DMDEVICE;
  74. if (S_ISCHR(mode))
  75. res |= P9_DMDEVICE;
  76. }
  77. if ((mode & S_ISUID) == S_ISUID)
  78. res |= P9_DMSETUID;
  79. if ((mode & S_ISGID) == S_ISGID)
  80. res |= P9_DMSETGID;
  81. if ((mode & S_ISVTX) == S_ISVTX)
  82. res |= P9_DMSETVTX;
  83. if ((mode & P9_DMLINK))
  84. res |= P9_DMLINK;
  85. }
  86. return res;
  87. }
  88. /**
  89. * p9mode2unixmode- convert plan9 mode bits to unix mode bits
  90. * @v9ses: v9fs session information
  91. * @mode: mode to convert
  92. *
  93. */
  94. static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
  95. {
  96. int res;
  97. res = mode & 0777;
  98. if ((mode & P9_DMDIR) == P9_DMDIR)
  99. res |= S_IFDIR;
  100. else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
  101. res |= S_IFLNK;
  102. else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
  103. && (v9ses->nodev == 0))
  104. res |= S_IFSOCK;
  105. else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
  106. && (v9ses->nodev == 0))
  107. res |= S_IFIFO;
  108. else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
  109. && (v9ses->nodev == 0))
  110. res |= S_IFBLK;
  111. else
  112. res |= S_IFREG;
  113. if (v9fs_proto_dotu(v9ses)) {
  114. if ((mode & P9_DMSETUID) == P9_DMSETUID)
  115. res |= S_ISUID;
  116. if ((mode & P9_DMSETGID) == P9_DMSETGID)
  117. res |= S_ISGID;
  118. if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
  119. res |= S_ISVTX;
  120. }
  121. return res;
  122. }
  123. /**
  124. * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
  125. * @uflags: flags to convert
  126. * @extended: if .u extensions are active
  127. */
  128. int v9fs_uflags2omode(int uflags, int extended)
  129. {
  130. int ret;
  131. ret = 0;
  132. switch (uflags&3) {
  133. default:
  134. case O_RDONLY:
  135. ret = P9_OREAD;
  136. break;
  137. case O_WRONLY:
  138. ret = P9_OWRITE;
  139. break;
  140. case O_RDWR:
  141. ret = P9_ORDWR;
  142. break;
  143. }
  144. if (uflags & O_TRUNC)
  145. ret |= P9_OTRUNC;
  146. if (extended) {
  147. if (uflags & O_EXCL)
  148. ret |= P9_OEXCL;
  149. if (uflags & O_APPEND)
  150. ret |= P9_OAPPEND;
  151. }
  152. return ret;
  153. }
  154. /**
  155. * v9fs_blank_wstat - helper function to setup a 9P stat structure
  156. * @wstat: structure to initialize
  157. *
  158. */
  159. void
  160. v9fs_blank_wstat(struct p9_wstat *wstat)
  161. {
  162. wstat->type = ~0;
  163. wstat->dev = ~0;
  164. wstat->qid.type = ~0;
  165. wstat->qid.version = ~0;
  166. *((long long *)&wstat->qid.path) = ~0;
  167. wstat->mode = ~0;
  168. wstat->atime = ~0;
  169. wstat->mtime = ~0;
  170. wstat->length = ~0;
  171. wstat->name = NULL;
  172. wstat->uid = NULL;
  173. wstat->gid = NULL;
  174. wstat->muid = NULL;
  175. wstat->n_uid = ~0;
  176. wstat->n_gid = ~0;
  177. wstat->n_muid = ~0;
  178. wstat->extension = NULL;
  179. }
  180. #ifdef CONFIG_9P_FSCACHE
  181. /**
  182. * v9fs_alloc_inode - helper function to allocate an inode
  183. * This callback is executed before setting up the inode so that we
  184. * can associate a vcookie with each inode.
  185. *
  186. */
  187. struct inode *v9fs_alloc_inode(struct super_block *sb)
  188. {
  189. struct v9fs_cookie *vcookie;
  190. vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache,
  191. GFP_KERNEL);
  192. if (!vcookie)
  193. return NULL;
  194. vcookie->fscache = NULL;
  195. vcookie->qid = NULL;
  196. spin_lock_init(&vcookie->lock);
  197. return &vcookie->inode;
  198. }
  199. /**
  200. * v9fs_destroy_inode - destroy an inode
  201. *
  202. */
  203. void v9fs_destroy_inode(struct inode *inode)
  204. {
  205. kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
  206. }
  207. #endif
  208. /**
  209. * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
  210. * new file system object. This checks the S_ISGID to determine the owning
  211. * group of the new file system object.
  212. */
  213. static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
  214. {
  215. BUG_ON(dir_inode == NULL);
  216. if (dir_inode->i_mode & S_ISGID) {
  217. /* set_gid bit is set.*/
  218. return dir_inode->i_gid;
  219. }
  220. return current_fsgid();
  221. }
  222. /**
  223. * v9fs_dentry_from_dir_inode - helper function to get the dentry from
  224. * dir inode.
  225. *
  226. */
  227. static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
  228. {
  229. struct dentry *dentry;
  230. spin_lock(&dcache_lock);
  231. /* Directory should have only one entry. */
  232. BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
  233. dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
  234. spin_unlock(&dcache_lock);
  235. return dentry;
  236. }
  237. /**
  238. * v9fs_get_inode - helper function to setup an inode
  239. * @sb: superblock
  240. * @mode: mode to setup inode with
  241. *
  242. */
  243. struct inode *v9fs_get_inode(struct super_block *sb, int mode)
  244. {
  245. int err;
  246. struct inode *inode;
  247. struct v9fs_session_info *v9ses = sb->s_fs_info;
  248. P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
  249. inode = new_inode(sb);
  250. if (!inode) {
  251. P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
  252. return ERR_PTR(-ENOMEM);
  253. }
  254. inode_init_owner(inode, NULL, mode);
  255. inode->i_blocks = 0;
  256. inode->i_rdev = 0;
  257. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  258. inode->i_mapping->a_ops = &v9fs_addr_operations;
  259. switch (mode & S_IFMT) {
  260. case S_IFIFO:
  261. case S_IFBLK:
  262. case S_IFCHR:
  263. case S_IFSOCK:
  264. if (v9fs_proto_dotl(v9ses)) {
  265. inode->i_op = &v9fs_file_inode_operations_dotl;
  266. inode->i_fop = &v9fs_file_operations_dotl;
  267. } else if (v9fs_proto_dotu(v9ses)) {
  268. inode->i_op = &v9fs_file_inode_operations;
  269. inode->i_fop = &v9fs_file_operations;
  270. } else {
  271. P9_DPRINTK(P9_DEBUG_ERROR,
  272. "special files without extended mode\n");
  273. err = -EINVAL;
  274. goto error;
  275. }
  276. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  277. break;
  278. case S_IFREG:
  279. if (v9fs_proto_dotl(v9ses)) {
  280. inode->i_op = &v9fs_file_inode_operations_dotl;
  281. inode->i_fop = &v9fs_file_operations_dotl;
  282. } else {
  283. inode->i_op = &v9fs_file_inode_operations;
  284. inode->i_fop = &v9fs_file_operations;
  285. }
  286. break;
  287. case S_IFLNK:
  288. if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
  289. P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
  290. "legacy protocol.\n");
  291. err = -EINVAL;
  292. goto error;
  293. }
  294. if (v9fs_proto_dotl(v9ses))
  295. inode->i_op = &v9fs_symlink_inode_operations_dotl;
  296. else
  297. inode->i_op = &v9fs_symlink_inode_operations;
  298. break;
  299. case S_IFDIR:
  300. inc_nlink(inode);
  301. if (v9fs_proto_dotl(v9ses))
  302. inode->i_op = &v9fs_dir_inode_operations_dotl;
  303. else if (v9fs_proto_dotu(v9ses))
  304. inode->i_op = &v9fs_dir_inode_operations_dotu;
  305. else
  306. inode->i_op = &v9fs_dir_inode_operations;
  307. if (v9fs_proto_dotl(v9ses))
  308. inode->i_fop = &v9fs_dir_operations_dotl;
  309. else
  310. inode->i_fop = &v9fs_dir_operations;
  311. break;
  312. default:
  313. P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
  314. mode, mode & S_IFMT);
  315. err = -EINVAL;
  316. goto error;
  317. }
  318. return inode;
  319. error:
  320. iput(inode);
  321. return ERR_PTR(err);
  322. }
  323. /*
  324. static struct v9fs_fid*
  325. v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
  326. {
  327. int err;
  328. int nfid;
  329. struct v9fs_fid *ret;
  330. struct v9fs_fcall *fcall;
  331. nfid = v9fs_get_idpool(&v9ses->fidpool);
  332. if (nfid < 0) {
  333. eprintk(KERN_WARNING, "no free fids available\n");
  334. return ERR_PTR(-ENOSPC);
  335. }
  336. err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
  337. &fcall);
  338. if (err < 0) {
  339. if (fcall && fcall->id == RWALK)
  340. goto clunk_fid;
  341. PRINT_FCALL_ERROR("walk error", fcall);
  342. v9fs_put_idpool(nfid, &v9ses->fidpool);
  343. goto error;
  344. }
  345. kfree(fcall);
  346. fcall = NULL;
  347. ret = v9fs_fid_create(v9ses, nfid);
  348. if (!ret) {
  349. err = -ENOMEM;
  350. goto clunk_fid;
  351. }
  352. err = v9fs_fid_insert(ret, dentry);
  353. if (err < 0) {
  354. v9fs_fid_destroy(ret);
  355. goto clunk_fid;
  356. }
  357. return ret;
  358. clunk_fid:
  359. v9fs_t_clunk(v9ses, nfid);
  360. error:
  361. kfree(fcall);
  362. return ERR_PTR(err);
  363. }
  364. */
  365. /**
  366. * v9fs_clear_inode - release an inode
  367. * @inode: inode to release
  368. *
  369. */
  370. void v9fs_clear_inode(struct inode *inode)
  371. {
  372. filemap_fdatawrite(inode->i_mapping);
  373. #ifdef CONFIG_9P_FSCACHE
  374. v9fs_cache_inode_put_cookie(inode);
  375. #endif
  376. }
  377. static struct inode *
  378. v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  379. struct super_block *sb)
  380. {
  381. int err, umode;
  382. struct inode *ret = NULL;
  383. struct p9_wstat *st;
  384. st = p9_client_stat(fid);
  385. if (IS_ERR(st))
  386. return ERR_CAST(st);
  387. umode = p9mode2unixmode(v9ses, st->mode);
  388. ret = v9fs_get_inode(sb, umode);
  389. if (IS_ERR(ret)) {
  390. err = PTR_ERR(ret);
  391. goto error;
  392. }
  393. v9fs_stat2inode(st, ret, sb);
  394. ret->i_ino = v9fs_qid2ino(&st->qid);
  395. #ifdef CONFIG_9P_FSCACHE
  396. v9fs_vcookie_set_qid(ret, &st->qid);
  397. v9fs_cache_inode_get_cookie(ret);
  398. #endif
  399. p9stat_free(st);
  400. kfree(st);
  401. return ret;
  402. error:
  403. p9stat_free(st);
  404. kfree(st);
  405. return ERR_PTR(err);
  406. }
  407. static struct inode *
  408. v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  409. struct super_block *sb)
  410. {
  411. struct inode *ret = NULL;
  412. int err;
  413. struct p9_stat_dotl *st;
  414. st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
  415. if (IS_ERR(st))
  416. return ERR_CAST(st);
  417. ret = v9fs_get_inode(sb, st->st_mode);
  418. if (IS_ERR(ret)) {
  419. err = PTR_ERR(ret);
  420. goto error;
  421. }
  422. v9fs_stat2inode_dotl(st, ret);
  423. ret->i_ino = v9fs_qid2ino(&st->qid);
  424. #ifdef CONFIG_9P_FSCACHE
  425. v9fs_vcookie_set_qid(ret, &st->qid);
  426. v9fs_cache_inode_get_cookie(ret);
  427. #endif
  428. kfree(st);
  429. return ret;
  430. error:
  431. kfree(st);
  432. return ERR_PTR(err);
  433. }
  434. /**
  435. * v9fs_inode_from_fid - Helper routine to populate an inode by
  436. * issuing a attribute request
  437. * @v9ses: session information
  438. * @fid: fid to issue attribute request for
  439. * @sb: superblock on which to create inode
  440. *
  441. */
  442. static inline struct inode *
  443. v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  444. struct super_block *sb)
  445. {
  446. if (v9fs_proto_dotl(v9ses))
  447. return v9fs_inode_dotl(v9ses, fid, sb);
  448. else
  449. return v9fs_inode(v9ses, fid, sb);
  450. }
  451. /**
  452. * v9fs_remove - helper function to remove files and directories
  453. * @dir: directory inode that is being deleted
  454. * @file: dentry that is being deleted
  455. * @rmdir: removing a directory
  456. *
  457. */
  458. static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
  459. {
  460. int retval;
  461. struct inode *file_inode;
  462. struct p9_fid *v9fid;
  463. P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
  464. rmdir);
  465. file_inode = file->d_inode;
  466. v9fid = v9fs_fid_clone(file);
  467. if (IS_ERR(v9fid))
  468. return PTR_ERR(v9fid);
  469. retval = p9_client_remove(v9fid);
  470. if (!retval)
  471. drop_nlink(file_inode);
  472. return retval;
  473. }
  474. static int
  475. v9fs_open_created(struct inode *inode, struct file *file)
  476. {
  477. return 0;
  478. }
  479. /**
  480. * v9fs_create - Create a file
  481. * @v9ses: session information
  482. * @dir: directory that dentry is being created in
  483. * @dentry: dentry that is being created
  484. * @extension: 9p2000.u extension string to support devices, etc.
  485. * @perm: create permissions
  486. * @mode: open mode
  487. *
  488. */
  489. static struct p9_fid *
  490. v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
  491. struct dentry *dentry, char *extension, u32 perm, u8 mode)
  492. {
  493. int err;
  494. char *name;
  495. struct p9_fid *dfid, *ofid, *fid;
  496. struct inode *inode;
  497. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  498. err = 0;
  499. ofid = NULL;
  500. fid = NULL;
  501. name = (char *) dentry->d_name.name;
  502. dfid = v9fs_fid_lookup(dentry->d_parent);
  503. if (IS_ERR(dfid)) {
  504. err = PTR_ERR(dfid);
  505. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  506. return ERR_PTR(err);
  507. }
  508. /* clone a fid to use for creation */
  509. ofid = p9_client_walk(dfid, 0, NULL, 1);
  510. if (IS_ERR(ofid)) {
  511. err = PTR_ERR(ofid);
  512. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  513. return ERR_PTR(err);
  514. }
  515. err = p9_client_fcreate(ofid, name, perm, mode, extension);
  516. if (err < 0) {
  517. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
  518. goto error;
  519. }
  520. /* now walk from the parent so we can get unopened fid */
  521. fid = p9_client_walk(dfid, 1, &name, 1);
  522. if (IS_ERR(fid)) {
  523. err = PTR_ERR(fid);
  524. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  525. fid = NULL;
  526. goto error;
  527. }
  528. /* instantiate inode and assign the unopened fid to the dentry */
  529. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  530. if (IS_ERR(inode)) {
  531. err = PTR_ERR(inode);
  532. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
  533. goto error;
  534. }
  535. if (v9ses->cache)
  536. dentry->d_op = &v9fs_cached_dentry_operations;
  537. else
  538. dentry->d_op = &v9fs_dentry_operations;
  539. d_instantiate(dentry, inode);
  540. err = v9fs_fid_add(dentry, fid);
  541. if (err < 0)
  542. goto error;
  543. return ofid;
  544. error:
  545. if (ofid)
  546. p9_client_clunk(ofid);
  547. if (fid)
  548. p9_client_clunk(fid);
  549. return ERR_PTR(err);
  550. }
  551. /**
  552. * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
  553. * @dir: directory inode that is being created
  554. * @dentry: dentry that is being deleted
  555. * @mode: create permissions
  556. * @nd: path information
  557. *
  558. */
  559. static int
  560. v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int mode,
  561. struct nameidata *nd)
  562. {
  563. int err = 0;
  564. char *name = NULL;
  565. gid_t gid;
  566. int flags;
  567. struct v9fs_session_info *v9ses;
  568. struct p9_fid *fid = NULL;
  569. struct p9_fid *dfid, *ofid;
  570. struct file *filp;
  571. struct p9_qid qid;
  572. struct inode *inode;
  573. v9ses = v9fs_inode2v9ses(dir);
  574. if (nd && nd->flags & LOOKUP_OPEN)
  575. flags = nd->intent.open.flags - 1;
  576. else
  577. flags = O_RDWR;
  578. name = (char *) dentry->d_name.name;
  579. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
  580. "mode:0x%x\n", name, flags, mode);
  581. dfid = v9fs_fid_lookup(dentry->d_parent);
  582. if (IS_ERR(dfid)) {
  583. err = PTR_ERR(dfid);
  584. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  585. return err;
  586. }
  587. /* clone a fid to use for creation */
  588. ofid = p9_client_walk(dfid, 0, NULL, 1);
  589. if (IS_ERR(ofid)) {
  590. err = PTR_ERR(ofid);
  591. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  592. return err;
  593. }
  594. gid = v9fs_get_fsgid_for_create(dir);
  595. err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
  596. if (err < 0) {
  597. P9_DPRINTK(P9_DEBUG_VFS,
  598. "p9_client_open_dotl failed in creat %d\n",
  599. err);
  600. goto error;
  601. }
  602. /* No need to populate the inode if we are not opening the file AND
  603. * not in cached mode.
  604. */
  605. if (!v9ses->cache && !(nd && nd->flags & LOOKUP_OPEN)) {
  606. /* Not in cached mode. No need to populate inode with stat */
  607. dentry->d_op = &v9fs_dentry_operations;
  608. p9_client_clunk(ofid);
  609. d_instantiate(dentry, NULL);
  610. return 0;
  611. }
  612. /* Now walk from the parent so we can get an unopened fid. */
  613. fid = p9_client_walk(dfid, 1, &name, 1);
  614. if (IS_ERR(fid)) {
  615. err = PTR_ERR(fid);
  616. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  617. fid = NULL;
  618. goto error;
  619. }
  620. /* instantiate inode and assign the unopened fid to dentry */
  621. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  622. if (IS_ERR(inode)) {
  623. err = PTR_ERR(inode);
  624. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
  625. goto error;
  626. }
  627. dentry->d_op = &v9fs_cached_dentry_operations;
  628. d_instantiate(dentry, inode);
  629. err = v9fs_fid_add(dentry, fid);
  630. if (err < 0)
  631. goto error;
  632. /* if we are opening a file, assign the open fid to the file */
  633. if (nd && nd->flags & LOOKUP_OPEN) {
  634. filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
  635. if (IS_ERR(filp)) {
  636. p9_client_clunk(ofid);
  637. return PTR_ERR(filp);
  638. }
  639. filp->private_data = ofid;
  640. } else
  641. p9_client_clunk(ofid);
  642. return 0;
  643. error:
  644. if (ofid)
  645. p9_client_clunk(ofid);
  646. if (fid)
  647. p9_client_clunk(fid);
  648. return err;
  649. }
  650. /**
  651. * v9fs_vfs_create - VFS hook to create files
  652. * @dir: directory inode that is being created
  653. * @dentry: dentry that is being deleted
  654. * @mode: create permissions
  655. * @nd: path information
  656. *
  657. */
  658. static int
  659. v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
  660. struct nameidata *nd)
  661. {
  662. int err;
  663. u32 perm;
  664. int flags;
  665. struct v9fs_session_info *v9ses;
  666. struct p9_fid *fid;
  667. struct file *filp;
  668. err = 0;
  669. fid = NULL;
  670. v9ses = v9fs_inode2v9ses(dir);
  671. perm = unixmode2p9mode(v9ses, mode);
  672. if (nd && nd->flags & LOOKUP_OPEN)
  673. flags = nd->intent.open.flags - 1;
  674. else
  675. flags = O_RDWR;
  676. fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
  677. v9fs_uflags2omode(flags,
  678. v9fs_proto_dotu(v9ses)));
  679. if (IS_ERR(fid)) {
  680. err = PTR_ERR(fid);
  681. fid = NULL;
  682. goto error;
  683. }
  684. /* if we are opening a file, assign the open fid to the file */
  685. if (nd && nd->flags & LOOKUP_OPEN) {
  686. filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
  687. if (IS_ERR(filp)) {
  688. err = PTR_ERR(filp);
  689. goto error;
  690. }
  691. filp->private_data = fid;
  692. } else
  693. p9_client_clunk(fid);
  694. return 0;
  695. error:
  696. if (fid)
  697. p9_client_clunk(fid);
  698. return err;
  699. }
  700. /**
  701. * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
  702. * @dir: inode that is being unlinked
  703. * @dentry: dentry that is being unlinked
  704. * @mode: mode for new directory
  705. *
  706. */
  707. static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  708. {
  709. int err;
  710. u32 perm;
  711. struct v9fs_session_info *v9ses;
  712. struct p9_fid *fid;
  713. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  714. err = 0;
  715. v9ses = v9fs_inode2v9ses(dir);
  716. perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
  717. fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
  718. if (IS_ERR(fid)) {
  719. err = PTR_ERR(fid);
  720. fid = NULL;
  721. }
  722. if (fid)
  723. p9_client_clunk(fid);
  724. return err;
  725. }
  726. /**
  727. * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
  728. * @dir: inode that is being unlinked
  729. * @dentry: dentry that is being unlinked
  730. * @mode: mode for new directory
  731. *
  732. */
  733. static int v9fs_vfs_mkdir_dotl(struct inode *dir, struct dentry *dentry,
  734. int mode)
  735. {
  736. int err;
  737. struct v9fs_session_info *v9ses;
  738. struct p9_fid *fid = NULL, *dfid = NULL;
  739. gid_t gid;
  740. char *name;
  741. struct inode *inode;
  742. struct p9_qid qid;
  743. struct dentry *dir_dentry;
  744. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  745. err = 0;
  746. v9ses = v9fs_inode2v9ses(dir);
  747. mode |= S_IFDIR;
  748. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  749. dfid = v9fs_fid_lookup(dir_dentry);
  750. if (IS_ERR(dfid)) {
  751. err = PTR_ERR(dfid);
  752. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  753. dfid = NULL;
  754. goto error;
  755. }
  756. gid = v9fs_get_fsgid_for_create(dir);
  757. if (gid < 0) {
  758. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
  759. goto error;
  760. }
  761. name = (char *) dentry->d_name.name;
  762. err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
  763. if (err < 0)
  764. goto error;
  765. /* instantiate inode and assign the unopened fid to the dentry */
  766. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  767. fid = p9_client_walk(dfid, 1, &name, 1);
  768. if (IS_ERR(fid)) {
  769. err = PTR_ERR(fid);
  770. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  771. err);
  772. fid = NULL;
  773. goto error;
  774. }
  775. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  776. if (IS_ERR(inode)) {
  777. err = PTR_ERR(inode);
  778. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  779. err);
  780. goto error;
  781. }
  782. dentry->d_op = &v9fs_cached_dentry_operations;
  783. d_instantiate(dentry, inode);
  784. err = v9fs_fid_add(dentry, fid);
  785. if (err < 0)
  786. goto error;
  787. fid = NULL;
  788. }
  789. error:
  790. if (fid)
  791. p9_client_clunk(fid);
  792. return err;
  793. }
  794. /**
  795. * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
  796. * @dir: inode that is being walked from
  797. * @dentry: dentry that is being walked to?
  798. * @nameidata: path data
  799. *
  800. */
  801. static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
  802. struct nameidata *nameidata)
  803. {
  804. struct super_block *sb;
  805. struct v9fs_session_info *v9ses;
  806. struct p9_fid *dfid, *fid;
  807. struct inode *inode;
  808. char *name;
  809. int result = 0;
  810. P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
  811. dir, dentry->d_name.name, dentry, nameidata);
  812. if (dentry->d_name.len > NAME_MAX)
  813. return ERR_PTR(-ENAMETOOLONG);
  814. sb = dir->i_sb;
  815. v9ses = v9fs_inode2v9ses(dir);
  816. /* We can walk d_parent because we hold the dir->i_mutex */
  817. dfid = v9fs_fid_lookup(dentry->d_parent);
  818. if (IS_ERR(dfid))
  819. return ERR_CAST(dfid);
  820. name = (char *) dentry->d_name.name;
  821. fid = p9_client_walk(dfid, 1, &name, 1);
  822. if (IS_ERR(fid)) {
  823. result = PTR_ERR(fid);
  824. if (result == -ENOENT) {
  825. inode = NULL;
  826. goto inst_out;
  827. }
  828. return ERR_PTR(result);
  829. }
  830. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  831. if (IS_ERR(inode)) {
  832. result = PTR_ERR(inode);
  833. inode = NULL;
  834. goto error;
  835. }
  836. result = v9fs_fid_add(dentry, fid);
  837. if (result < 0)
  838. goto error;
  839. inst_out:
  840. if (v9ses->cache)
  841. dentry->d_op = &v9fs_cached_dentry_operations;
  842. else
  843. dentry->d_op = &v9fs_dentry_operations;
  844. d_add(dentry, inode);
  845. return NULL;
  846. error:
  847. p9_client_clunk(fid);
  848. return ERR_PTR(result);
  849. }
  850. /**
  851. * v9fs_vfs_unlink - VFS unlink hook to delete an inode
  852. * @i: inode that is being unlinked
  853. * @d: dentry that is being unlinked
  854. *
  855. */
  856. static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
  857. {
  858. return v9fs_remove(i, d, 0);
  859. }
  860. /**
  861. * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
  862. * @i: inode that is being unlinked
  863. * @d: dentry that is being unlinked
  864. *
  865. */
  866. static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
  867. {
  868. return v9fs_remove(i, d, 1);
  869. }
  870. /**
  871. * v9fs_vfs_rename - VFS hook to rename an inode
  872. * @old_dir: old dir inode
  873. * @old_dentry: old dentry
  874. * @new_dir: new dir inode
  875. * @new_dentry: new dentry
  876. *
  877. */
  878. static int
  879. v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  880. struct inode *new_dir, struct dentry *new_dentry)
  881. {
  882. struct inode *old_inode;
  883. struct v9fs_session_info *v9ses;
  884. struct p9_fid *oldfid;
  885. struct p9_fid *olddirfid;
  886. struct p9_fid *newdirfid;
  887. struct p9_wstat wstat;
  888. int retval;
  889. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  890. retval = 0;
  891. old_inode = old_dentry->d_inode;
  892. v9ses = v9fs_inode2v9ses(old_inode);
  893. oldfid = v9fs_fid_lookup(old_dentry);
  894. if (IS_ERR(oldfid))
  895. return PTR_ERR(oldfid);
  896. olddirfid = v9fs_fid_clone(old_dentry->d_parent);
  897. if (IS_ERR(olddirfid)) {
  898. retval = PTR_ERR(olddirfid);
  899. goto done;
  900. }
  901. newdirfid = v9fs_fid_clone(new_dentry->d_parent);
  902. if (IS_ERR(newdirfid)) {
  903. retval = PTR_ERR(newdirfid);
  904. goto clunk_olddir;
  905. }
  906. down_write(&v9ses->rename_sem);
  907. if (v9fs_proto_dotl(v9ses)) {
  908. retval = p9_client_rename(oldfid, newdirfid,
  909. (char *) new_dentry->d_name.name);
  910. if (retval != -ENOSYS)
  911. goto clunk_newdir;
  912. }
  913. if (old_dentry->d_parent != new_dentry->d_parent) {
  914. /*
  915. * 9P .u can only handle file rename in the same directory
  916. */
  917. P9_DPRINTK(P9_DEBUG_ERROR,
  918. "old dir and new dir are different\n");
  919. retval = -EXDEV;
  920. goto clunk_newdir;
  921. }
  922. v9fs_blank_wstat(&wstat);
  923. wstat.muid = v9ses->uname;
  924. wstat.name = (char *) new_dentry->d_name.name;
  925. retval = p9_client_wstat(oldfid, &wstat);
  926. clunk_newdir:
  927. if (!retval)
  928. /* successful rename */
  929. d_move(old_dentry, new_dentry);
  930. up_write(&v9ses->rename_sem);
  931. p9_client_clunk(newdirfid);
  932. clunk_olddir:
  933. p9_client_clunk(olddirfid);
  934. done:
  935. return retval;
  936. }
  937. /**
  938. * v9fs_vfs_getattr - retrieve file metadata
  939. * @mnt: mount information
  940. * @dentry: file to get attributes on
  941. * @stat: metadata structure to populate
  942. *
  943. */
  944. static int
  945. v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  946. struct kstat *stat)
  947. {
  948. int err;
  949. struct v9fs_session_info *v9ses;
  950. struct p9_fid *fid;
  951. struct p9_wstat *st;
  952. P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
  953. err = -EPERM;
  954. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  955. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
  956. return simple_getattr(mnt, dentry, stat);
  957. fid = v9fs_fid_lookup(dentry);
  958. if (IS_ERR(fid))
  959. return PTR_ERR(fid);
  960. st = p9_client_stat(fid);
  961. if (IS_ERR(st))
  962. return PTR_ERR(st);
  963. v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb);
  964. generic_fillattr(dentry->d_inode, stat);
  965. kfree(st);
  966. return 0;
  967. }
  968. static int
  969. v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
  970. struct kstat *stat)
  971. {
  972. int err;
  973. struct v9fs_session_info *v9ses;
  974. struct p9_fid *fid;
  975. struct p9_stat_dotl *st;
  976. P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
  977. err = -EPERM;
  978. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  979. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
  980. return simple_getattr(mnt, dentry, stat);
  981. fid = v9fs_fid_lookup(dentry);
  982. if (IS_ERR(fid))
  983. return PTR_ERR(fid);
  984. /* Ask for all the fields in stat structure. Server will return
  985. * whatever it supports
  986. */
  987. st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
  988. if (IS_ERR(st))
  989. return PTR_ERR(st);
  990. v9fs_stat2inode_dotl(st, dentry->d_inode);
  991. generic_fillattr(dentry->d_inode, stat);
  992. /* Change block size to what the server returned */
  993. stat->blksize = st->st_blksize;
  994. kfree(st);
  995. return 0;
  996. }
  997. /**
  998. * v9fs_vfs_setattr - set file metadata
  999. * @dentry: file whose metadata to set
  1000. * @iattr: metadata assignment structure
  1001. *
  1002. */
  1003. static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
  1004. {
  1005. int retval;
  1006. struct v9fs_session_info *v9ses;
  1007. struct p9_fid *fid;
  1008. struct p9_wstat wstat;
  1009. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  1010. retval = -EPERM;
  1011. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  1012. fid = v9fs_fid_lookup(dentry);
  1013. if(IS_ERR(fid))
  1014. return PTR_ERR(fid);
  1015. v9fs_blank_wstat(&wstat);
  1016. if (iattr->ia_valid & ATTR_MODE)
  1017. wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
  1018. if (iattr->ia_valid & ATTR_MTIME)
  1019. wstat.mtime = iattr->ia_mtime.tv_sec;
  1020. if (iattr->ia_valid & ATTR_ATIME)
  1021. wstat.atime = iattr->ia_atime.tv_sec;
  1022. if (iattr->ia_valid & ATTR_SIZE)
  1023. wstat.length = iattr->ia_size;
  1024. if (v9fs_proto_dotu(v9ses)) {
  1025. if (iattr->ia_valid & ATTR_UID)
  1026. wstat.n_uid = iattr->ia_uid;
  1027. if (iattr->ia_valid & ATTR_GID)
  1028. wstat.n_gid = iattr->ia_gid;
  1029. }
  1030. retval = p9_client_wstat(fid, &wstat);
  1031. if (retval >= 0)
  1032. retval = inode_setattr(dentry->d_inode, iattr);
  1033. return retval;
  1034. }
  1035. /**
  1036. * v9fs_vfs_setattr_dotl - set file metadata
  1037. * @dentry: file whose metadata to set
  1038. * @iattr: metadata assignment structure
  1039. *
  1040. */
  1041. static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
  1042. {
  1043. int retval;
  1044. struct v9fs_session_info *v9ses;
  1045. struct p9_fid *fid;
  1046. struct p9_iattr_dotl p9attr;
  1047. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  1048. retval = inode_change_ok(dentry->d_inode, iattr);
  1049. if (retval)
  1050. return retval;
  1051. p9attr.valid = iattr->ia_valid;
  1052. p9attr.mode = iattr->ia_mode;
  1053. p9attr.uid = iattr->ia_uid;
  1054. p9attr.gid = iattr->ia_gid;
  1055. p9attr.size = iattr->ia_size;
  1056. p9attr.atime_sec = iattr->ia_atime.tv_sec;
  1057. p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
  1058. p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
  1059. p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
  1060. retval = -EPERM;
  1061. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  1062. fid = v9fs_fid_lookup(dentry);
  1063. if (IS_ERR(fid))
  1064. return PTR_ERR(fid);
  1065. retval = p9_client_setattr(fid, &p9attr);
  1066. if (retval >= 0)
  1067. retval = inode_setattr(dentry->d_inode, iattr);
  1068. return retval;
  1069. }
  1070. /**
  1071. * v9fs_stat2inode - populate an inode structure with mistat info
  1072. * @stat: Plan 9 metadata (mistat) structure
  1073. * @inode: inode to populate
  1074. * @sb: superblock of filesystem
  1075. *
  1076. */
  1077. void
  1078. v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
  1079. struct super_block *sb)
  1080. {
  1081. char ext[32];
  1082. char tag_name[14];
  1083. unsigned int i_nlink;
  1084. struct v9fs_session_info *v9ses = sb->s_fs_info;
  1085. inode->i_nlink = 1;
  1086. inode->i_atime.tv_sec = stat->atime;
  1087. inode->i_mtime.tv_sec = stat->mtime;
  1088. inode->i_ctime.tv_sec = stat->mtime;
  1089. inode->i_uid = v9ses->dfltuid;
  1090. inode->i_gid = v9ses->dfltgid;
  1091. if (v9fs_proto_dotu(v9ses)) {
  1092. inode->i_uid = stat->n_uid;
  1093. inode->i_gid = stat->n_gid;
  1094. }
  1095. if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
  1096. if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
  1097. /*
  1098. * Hadlink support got added later to
  1099. * to the .u extension. So there can be
  1100. * server out there that doesn't support
  1101. * this even with .u extension. So check
  1102. * for non NULL stat->extension
  1103. */
  1104. strncpy(ext, stat->extension, sizeof(ext));
  1105. /* HARDLINKCOUNT %u */
  1106. sscanf(ext, "%13s %u", tag_name, &i_nlink);
  1107. if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
  1108. inode->i_nlink = i_nlink;
  1109. }
  1110. }
  1111. inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
  1112. if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
  1113. char type = 0;
  1114. int major = -1;
  1115. int minor = -1;
  1116. strncpy(ext, stat->extension, sizeof(ext));
  1117. sscanf(ext, "%c %u %u", &type, &major, &minor);
  1118. switch (type) {
  1119. case 'c':
  1120. inode->i_mode &= ~S_IFBLK;
  1121. inode->i_mode |= S_IFCHR;
  1122. break;
  1123. case 'b':
  1124. break;
  1125. default:
  1126. P9_DPRINTK(P9_DEBUG_ERROR,
  1127. "Unknown special type %c %s\n", type,
  1128. stat->extension);
  1129. };
  1130. inode->i_rdev = MKDEV(major, minor);
  1131. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  1132. } else
  1133. inode->i_rdev = 0;
  1134. i_size_write(inode, stat->length);
  1135. /* not real number of blocks, but 512 byte ones ... */
  1136. inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
  1137. }
  1138. /**
  1139. * v9fs_stat2inode_dotl - populate an inode structure with stat info
  1140. * @stat: stat structure
  1141. * @inode: inode to populate
  1142. * @sb: superblock of filesystem
  1143. *
  1144. */
  1145. void
  1146. v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
  1147. {
  1148. if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
  1149. inode->i_atime.tv_sec = stat->st_atime_sec;
  1150. inode->i_atime.tv_nsec = stat->st_atime_nsec;
  1151. inode->i_mtime.tv_sec = stat->st_mtime_sec;
  1152. inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
  1153. inode->i_ctime.tv_sec = stat->st_ctime_sec;
  1154. inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
  1155. inode->i_uid = stat->st_uid;
  1156. inode->i_gid = stat->st_gid;
  1157. inode->i_nlink = stat->st_nlink;
  1158. inode->i_mode = stat->st_mode;
  1159. inode->i_rdev = new_decode_dev(stat->st_rdev);
  1160. if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
  1161. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  1162. i_size_write(inode, stat->st_size);
  1163. inode->i_blocks = stat->st_blocks;
  1164. } else {
  1165. if (stat->st_result_mask & P9_STATS_ATIME) {
  1166. inode->i_atime.tv_sec = stat->st_atime_sec;
  1167. inode->i_atime.tv_nsec = stat->st_atime_nsec;
  1168. }
  1169. if (stat->st_result_mask & P9_STATS_MTIME) {
  1170. inode->i_mtime.tv_sec = stat->st_mtime_sec;
  1171. inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
  1172. }
  1173. if (stat->st_result_mask & P9_STATS_CTIME) {
  1174. inode->i_ctime.tv_sec = stat->st_ctime_sec;
  1175. inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
  1176. }
  1177. if (stat->st_result_mask & P9_STATS_UID)
  1178. inode->i_uid = stat->st_uid;
  1179. if (stat->st_result_mask & P9_STATS_GID)
  1180. inode->i_gid = stat->st_gid;
  1181. if (stat->st_result_mask & P9_STATS_NLINK)
  1182. inode->i_nlink = stat->st_nlink;
  1183. if (stat->st_result_mask & P9_STATS_MODE) {
  1184. inode->i_mode = stat->st_mode;
  1185. if ((S_ISBLK(inode->i_mode)) ||
  1186. (S_ISCHR(inode->i_mode)))
  1187. init_special_inode(inode, inode->i_mode,
  1188. inode->i_rdev);
  1189. }
  1190. if (stat->st_result_mask & P9_STATS_RDEV)
  1191. inode->i_rdev = new_decode_dev(stat->st_rdev);
  1192. if (stat->st_result_mask & P9_STATS_SIZE)
  1193. i_size_write(inode, stat->st_size);
  1194. if (stat->st_result_mask & P9_STATS_BLOCKS)
  1195. inode->i_blocks = stat->st_blocks;
  1196. }
  1197. if (stat->st_result_mask & P9_STATS_GEN)
  1198. inode->i_generation = stat->st_gen;
  1199. /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
  1200. * because the inode structure does not have fields for them.
  1201. */
  1202. }
  1203. /**
  1204. * v9fs_qid2ino - convert qid into inode number
  1205. * @qid: qid to hash
  1206. *
  1207. * BUG: potential for inode number collisions?
  1208. */
  1209. ino_t v9fs_qid2ino(struct p9_qid *qid)
  1210. {
  1211. u64 path = qid->path + 2;
  1212. ino_t i = 0;
  1213. if (sizeof(ino_t) == sizeof(path))
  1214. memcpy(&i, &path, sizeof(ino_t));
  1215. else
  1216. i = (ino_t) (path ^ (path >> 32));
  1217. return i;
  1218. }
  1219. /**
  1220. * v9fs_readlink - read a symlink's location (internal version)
  1221. * @dentry: dentry for symlink
  1222. * @buffer: buffer to load symlink location into
  1223. * @buflen: length of buffer
  1224. *
  1225. */
  1226. static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
  1227. {
  1228. int retval;
  1229. struct v9fs_session_info *v9ses;
  1230. struct p9_fid *fid;
  1231. struct p9_wstat *st;
  1232. P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
  1233. retval = -EPERM;
  1234. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  1235. fid = v9fs_fid_lookup(dentry);
  1236. if (IS_ERR(fid))
  1237. return PTR_ERR(fid);
  1238. if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses))
  1239. return -EBADF;
  1240. st = p9_client_stat(fid);
  1241. if (IS_ERR(st))
  1242. return PTR_ERR(st);
  1243. if (!(st->mode & P9_DMSYMLINK)) {
  1244. retval = -EINVAL;
  1245. goto done;
  1246. }
  1247. /* copy extension buffer into buffer */
  1248. strncpy(buffer, st->extension, buflen);
  1249. P9_DPRINTK(P9_DEBUG_VFS,
  1250. "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
  1251. retval = strnlen(buffer, buflen);
  1252. done:
  1253. kfree(st);
  1254. return retval;
  1255. }
  1256. /**
  1257. * v9fs_vfs_follow_link - follow a symlink path
  1258. * @dentry: dentry for symlink
  1259. * @nd: nameidata
  1260. *
  1261. */
  1262. static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  1263. {
  1264. int len = 0;
  1265. char *link = __getname();
  1266. P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
  1267. if (!link)
  1268. link = ERR_PTR(-ENOMEM);
  1269. else {
  1270. len = v9fs_readlink(dentry, link, PATH_MAX);
  1271. if (len < 0) {
  1272. __putname(link);
  1273. link = ERR_PTR(len);
  1274. } else
  1275. link[min(len, PATH_MAX-1)] = 0;
  1276. }
  1277. nd_set_link(nd, link);
  1278. return NULL;
  1279. }
  1280. /**
  1281. * v9fs_vfs_put_link - release a symlink path
  1282. * @dentry: dentry for symlink
  1283. * @nd: nameidata
  1284. * @p: unused
  1285. *
  1286. */
  1287. static void
  1288. v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
  1289. {
  1290. char *s = nd_get_link(nd);
  1291. P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
  1292. IS_ERR(s) ? "<error>" : s);
  1293. if (!IS_ERR(s))
  1294. __putname(s);
  1295. }
  1296. /**
  1297. * v9fs_vfs_mkspecial - create a special file
  1298. * @dir: inode to create special file in
  1299. * @dentry: dentry to create
  1300. * @mode: mode to create special file
  1301. * @extension: 9p2000.u format extension string representing special file
  1302. *
  1303. */
  1304. static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
  1305. int mode, const char *extension)
  1306. {
  1307. u32 perm;
  1308. struct v9fs_session_info *v9ses;
  1309. struct p9_fid *fid;
  1310. v9ses = v9fs_inode2v9ses(dir);
  1311. if (!v9fs_proto_dotu(v9ses)) {
  1312. P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
  1313. return -EPERM;
  1314. }
  1315. perm = unixmode2p9mode(v9ses, mode);
  1316. fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
  1317. P9_OREAD);
  1318. if (IS_ERR(fid))
  1319. return PTR_ERR(fid);
  1320. p9_client_clunk(fid);
  1321. return 0;
  1322. }
  1323. /**
  1324. * v9fs_vfs_symlink_dotl - helper function to create symlinks
  1325. * @dir: directory inode containing symlink
  1326. * @dentry: dentry for symlink
  1327. * @symname: symlink data
  1328. *
  1329. * See Also: 9P2000.L RFC for more information
  1330. *
  1331. */
  1332. static int
  1333. v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
  1334. const char *symname)
  1335. {
  1336. struct v9fs_session_info *v9ses;
  1337. struct p9_fid *dfid;
  1338. struct p9_fid *fid = NULL;
  1339. struct inode *inode;
  1340. struct p9_qid qid;
  1341. char *name;
  1342. int err;
  1343. gid_t gid;
  1344. name = (char *) dentry->d_name.name;
  1345. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
  1346. dir->i_ino, name, symname);
  1347. v9ses = v9fs_inode2v9ses(dir);
  1348. dfid = v9fs_fid_lookup(dentry->d_parent);
  1349. if (IS_ERR(dfid)) {
  1350. err = PTR_ERR(dfid);
  1351. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  1352. return err;
  1353. }
  1354. gid = v9fs_get_fsgid_for_create(dir);
  1355. if (gid < 0) {
  1356. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_egid failed %d\n", gid);
  1357. goto error;
  1358. }
  1359. /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
  1360. err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
  1361. if (err < 0) {
  1362. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
  1363. goto error;
  1364. }
  1365. if (v9ses->cache) {
  1366. /* Now walk from the parent so we can get an unopened fid. */
  1367. fid = p9_client_walk(dfid, 1, &name, 1);
  1368. if (IS_ERR(fid)) {
  1369. err = PTR_ERR(fid);
  1370. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  1371. err);
  1372. fid = NULL;
  1373. goto error;
  1374. }
  1375. /* instantiate inode and assign the unopened fid to dentry */
  1376. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  1377. if (IS_ERR(inode)) {
  1378. err = PTR_ERR(inode);
  1379. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  1380. err);
  1381. goto error;
  1382. }
  1383. dentry->d_op = &v9fs_cached_dentry_operations;
  1384. d_instantiate(dentry, inode);
  1385. err = v9fs_fid_add(dentry, fid);
  1386. if (err < 0)
  1387. goto error;
  1388. fid = NULL;
  1389. } else {
  1390. /* Not in cached mode. No need to populate inode with stat */
  1391. inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
  1392. if (IS_ERR(inode)) {
  1393. err = PTR_ERR(inode);
  1394. goto error;
  1395. }
  1396. dentry->d_op = &v9fs_dentry_operations;
  1397. d_instantiate(dentry, inode);
  1398. }
  1399. error:
  1400. if (fid)
  1401. p9_client_clunk(fid);
  1402. return err;
  1403. }
  1404. /**
  1405. * v9fs_vfs_symlink - helper function to create symlinks
  1406. * @dir: directory inode containing symlink
  1407. * @dentry: dentry for symlink
  1408. * @symname: symlink data
  1409. *
  1410. * See Also: 9P2000.u RFC for more information
  1411. *
  1412. */
  1413. static int
  1414. v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
  1415. {
  1416. P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino,
  1417. dentry->d_name.name, symname);
  1418. return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
  1419. }
  1420. /**
  1421. * v9fs_vfs_link - create a hardlink
  1422. * @old_dentry: dentry for file to link to
  1423. * @dir: inode destination for new link
  1424. * @dentry: dentry for link
  1425. *
  1426. */
  1427. static int
  1428. v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
  1429. struct dentry *dentry)
  1430. {
  1431. int retval;
  1432. struct p9_fid *oldfid;
  1433. char *name;
  1434. P9_DPRINTK(P9_DEBUG_VFS,
  1435. " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
  1436. old_dentry->d_name.name);
  1437. oldfid = v9fs_fid_clone(old_dentry);
  1438. if (IS_ERR(oldfid))
  1439. return PTR_ERR(oldfid);
  1440. name = __getname();
  1441. if (unlikely(!name)) {
  1442. retval = -ENOMEM;
  1443. goto clunk_fid;
  1444. }
  1445. sprintf(name, "%d\n", oldfid->fid);
  1446. retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
  1447. __putname(name);
  1448. clunk_fid:
  1449. p9_client_clunk(oldfid);
  1450. return retval;
  1451. }
  1452. /**
  1453. * v9fs_vfs_link_dotl - create a hardlink for dotl
  1454. * @old_dentry: dentry for file to link to
  1455. * @dir: inode destination for new link
  1456. * @dentry: dentry for link
  1457. *
  1458. */
  1459. static int
  1460. v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
  1461. struct dentry *dentry)
  1462. {
  1463. int err;
  1464. struct p9_fid *dfid, *oldfid;
  1465. char *name;
  1466. struct v9fs_session_info *v9ses;
  1467. struct dentry *dir_dentry;
  1468. P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
  1469. dir->i_ino, old_dentry->d_name.name,
  1470. dentry->d_name.name);
  1471. v9ses = v9fs_inode2v9ses(dir);
  1472. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  1473. dfid = v9fs_fid_lookup(dir_dentry);
  1474. if (IS_ERR(dfid))
  1475. return PTR_ERR(dfid);
  1476. oldfid = v9fs_fid_lookup(old_dentry);
  1477. if (IS_ERR(oldfid))
  1478. return PTR_ERR(oldfid);
  1479. name = (char *) dentry->d_name.name;
  1480. err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
  1481. if (err < 0) {
  1482. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
  1483. return err;
  1484. }
  1485. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  1486. /* Get the latest stat info from server. */
  1487. struct p9_fid *fid;
  1488. struct p9_stat_dotl *st;
  1489. fid = v9fs_fid_lookup(old_dentry);
  1490. if (IS_ERR(fid))
  1491. return PTR_ERR(fid);
  1492. st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
  1493. if (IS_ERR(st))
  1494. return PTR_ERR(st);
  1495. v9fs_stat2inode_dotl(st, old_dentry->d_inode);
  1496. kfree(st);
  1497. } else {
  1498. /* Caching disabled. No need to get upto date stat info.
  1499. * This dentry will be released immediately. So, just i_count++
  1500. */
  1501. atomic_inc(&old_dentry->d_inode->i_count);
  1502. }
  1503. dentry->d_op = old_dentry->d_op;
  1504. d_instantiate(dentry, old_dentry->d_inode);
  1505. return err;
  1506. }
  1507. /**
  1508. * v9fs_vfs_mknod - create a special file
  1509. * @dir: inode destination for new link
  1510. * @dentry: dentry for file
  1511. * @mode: mode for creation
  1512. * @rdev: device associated with special file
  1513. *
  1514. */
  1515. static int
  1516. v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
  1517. {
  1518. int retval;
  1519. char *name;
  1520. P9_DPRINTK(P9_DEBUG_VFS,
  1521. " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
  1522. dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
  1523. if (!new_valid_dev(rdev))
  1524. return -EINVAL;
  1525. name = __getname();
  1526. if (!name)
  1527. return -ENOMEM;
  1528. /* build extension */
  1529. if (S_ISBLK(mode))
  1530. sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
  1531. else if (S_ISCHR(mode))
  1532. sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
  1533. else if (S_ISFIFO(mode))
  1534. *name = 0;
  1535. else if (S_ISSOCK(mode))
  1536. *name = 0;
  1537. else {
  1538. __putname(name);
  1539. return -EINVAL;
  1540. }
  1541. retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
  1542. __putname(name);
  1543. return retval;
  1544. }
  1545. /**
  1546. * v9fs_vfs_mknod_dotl - create a special file
  1547. * @dir: inode destination for new link
  1548. * @dentry: dentry for file
  1549. * @mode: mode for creation
  1550. * @rdev: device associated with special file
  1551. *
  1552. */
  1553. static int
  1554. v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int mode,
  1555. dev_t rdev)
  1556. {
  1557. int err;
  1558. char *name;
  1559. struct v9fs_session_info *v9ses;
  1560. struct p9_fid *fid = NULL, *dfid = NULL;
  1561. struct inode *inode;
  1562. gid_t gid;
  1563. struct p9_qid qid;
  1564. struct dentry *dir_dentry;
  1565. P9_DPRINTK(P9_DEBUG_VFS,
  1566. " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
  1567. dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
  1568. if (!new_valid_dev(rdev))
  1569. return -EINVAL;
  1570. v9ses = v9fs_inode2v9ses(dir);
  1571. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  1572. dfid = v9fs_fid_lookup(dir_dentry);
  1573. if (IS_ERR(dfid)) {
  1574. err = PTR_ERR(dfid);
  1575. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  1576. dfid = NULL;
  1577. goto error;
  1578. }
  1579. gid = v9fs_get_fsgid_for_create(dir);
  1580. if (gid < 0) {
  1581. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
  1582. goto error;
  1583. }
  1584. name = (char *) dentry->d_name.name;
  1585. err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
  1586. if (err < 0)
  1587. goto error;
  1588. /* instantiate inode and assign the unopened fid to the dentry */
  1589. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  1590. fid = p9_client_walk(dfid, 1, &name, 1);
  1591. if (IS_ERR(fid)) {
  1592. err = PTR_ERR(fid);
  1593. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  1594. err);
  1595. fid = NULL;
  1596. goto error;
  1597. }
  1598. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  1599. if (IS_ERR(inode)) {
  1600. err = PTR_ERR(inode);
  1601. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  1602. err);
  1603. goto error;
  1604. }
  1605. dentry->d_op = &v9fs_cached_dentry_operations;
  1606. d_instantiate(dentry, inode);
  1607. err = v9fs_fid_add(dentry, fid);
  1608. if (err < 0)
  1609. goto error;
  1610. fid = NULL;
  1611. } else {
  1612. /*
  1613. * Not in cached mode. No need to populate inode with stat.
  1614. * socket syscall returns a fd, so we need instantiate
  1615. */
  1616. inode = v9fs_get_inode(dir->i_sb, mode);
  1617. if (IS_ERR(inode)) {
  1618. err = PTR_ERR(inode);
  1619. goto error;
  1620. }
  1621. dentry->d_op = &v9fs_dentry_operations;
  1622. d_instantiate(dentry, inode);
  1623. }
  1624. error:
  1625. if (fid)
  1626. p9_client_clunk(fid);
  1627. return err;
  1628. }
  1629. static const struct inode_operations v9fs_dir_inode_operations_dotu = {
  1630. .create = v9fs_vfs_create,
  1631. .lookup = v9fs_vfs_lookup,
  1632. .symlink = v9fs_vfs_symlink,
  1633. .link = v9fs_vfs_link,
  1634. .unlink = v9fs_vfs_unlink,
  1635. .mkdir = v9fs_vfs_mkdir,
  1636. .rmdir = v9fs_vfs_rmdir,
  1637. .mknod = v9fs_vfs_mknod_dotl,
  1638. .rename = v9fs_vfs_rename,
  1639. .getattr = v9fs_vfs_getattr,
  1640. .setattr = v9fs_vfs_setattr,
  1641. };
  1642. static const struct inode_operations v9fs_dir_inode_operations_dotl = {
  1643. .create = v9fs_vfs_create_dotl,
  1644. .lookup = v9fs_vfs_lookup,
  1645. .link = v9fs_vfs_link_dotl,
  1646. .symlink = v9fs_vfs_symlink_dotl,
  1647. .unlink = v9fs_vfs_unlink,
  1648. .mkdir = v9fs_vfs_mkdir_dotl,
  1649. .rmdir = v9fs_vfs_rmdir,
  1650. .mknod = v9fs_vfs_mknod_dotl,
  1651. .rename = v9fs_vfs_rename,
  1652. .getattr = v9fs_vfs_getattr_dotl,
  1653. .setattr = v9fs_vfs_setattr_dotl,
  1654. .setxattr = generic_setxattr,
  1655. .getxattr = generic_getxattr,
  1656. .removexattr = generic_removexattr,
  1657. .listxattr = v9fs_listxattr,
  1658. };
  1659. static const struct inode_operations v9fs_dir_inode_operations = {
  1660. .create = v9fs_vfs_create,
  1661. .lookup = v9fs_vfs_lookup,
  1662. .unlink = v9fs_vfs_unlink,
  1663. .mkdir = v9fs_vfs_mkdir,
  1664. .rmdir = v9fs_vfs_rmdir,
  1665. .mknod = v9fs_vfs_mknod,
  1666. .rename = v9fs_vfs_rename,
  1667. .getattr = v9fs_vfs_getattr,
  1668. .setattr = v9fs_vfs_setattr,
  1669. };
  1670. static const struct inode_operations v9fs_file_inode_operations = {
  1671. .getattr = v9fs_vfs_getattr,
  1672. .setattr = v9fs_vfs_setattr,
  1673. };
  1674. static const struct inode_operations v9fs_file_inode_operations_dotl = {
  1675. .getattr = v9fs_vfs_getattr_dotl,
  1676. .setattr = v9fs_vfs_setattr_dotl,
  1677. .setxattr = generic_setxattr,
  1678. .getxattr = generic_getxattr,
  1679. .removexattr = generic_removexattr,
  1680. .listxattr = v9fs_listxattr,
  1681. };
  1682. static const struct inode_operations v9fs_symlink_inode_operations = {
  1683. .readlink = generic_readlink,
  1684. .follow_link = v9fs_vfs_follow_link,
  1685. .put_link = v9fs_vfs_put_link,
  1686. .getattr = v9fs_vfs_getattr,
  1687. .setattr = v9fs_vfs_setattr,
  1688. };
  1689. static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
  1690. .readlink = generic_readlink,
  1691. .follow_link = v9fs_vfs_follow_link,
  1692. .put_link = v9fs_vfs_put_link,
  1693. .getattr = v9fs_vfs_getattr_dotl,
  1694. .setattr = v9fs_vfs_setattr_dotl,
  1695. .setxattr = generic_setxattr,
  1696. .getxattr = generic_getxattr,
  1697. .removexattr = generic_removexattr,
  1698. .listxattr = v9fs_listxattr,
  1699. };