inode.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  1. /*
  2. * fs/cifs/inode.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2010
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published
  9. * by the Free Software Foundation; either version 2.1 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  15. * the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/fs.h>
  22. #include <linux/stat.h>
  23. #include <linux/slab.h>
  24. #include <linux/pagemap.h>
  25. #include <asm/div64.h>
  26. #include "cifsfs.h"
  27. #include "cifspdu.h"
  28. #include "cifsglob.h"
  29. #include "cifsproto.h"
  30. #include "cifs_debug.h"
  31. #include "cifs_fs_sb.h"
  32. #include "fscache.h"
  33. static void cifs_set_ops(struct inode *inode)
  34. {
  35. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  36. switch (inode->i_mode & S_IFMT) {
  37. case S_IFREG:
  38. inode->i_op = &cifs_file_inode_ops;
  39. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
  40. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  41. inode->i_fop = &cifs_file_direct_nobrl_ops;
  42. else
  43. inode->i_fop = &cifs_file_direct_ops;
  44. } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) {
  45. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  46. inode->i_fop = &cifs_file_strict_nobrl_ops;
  47. else
  48. inode->i_fop = &cifs_file_strict_ops;
  49. } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  50. inode->i_fop = &cifs_file_nobrl_ops;
  51. else { /* not direct, send byte range locks */
  52. inode->i_fop = &cifs_file_ops;
  53. }
  54. /* check if server can support readpages */
  55. if (cifs_sb_master_tcon(cifs_sb)->ses->server->maxBuf <
  56. PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
  57. inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
  58. else
  59. inode->i_data.a_ops = &cifs_addr_ops;
  60. break;
  61. case S_IFDIR:
  62. #ifdef CONFIG_CIFS_DFS_UPCALL
  63. if (IS_AUTOMOUNT(inode)) {
  64. inode->i_op = &cifs_dfs_referral_inode_operations;
  65. } else {
  66. #else /* NO DFS support, treat as a directory */
  67. {
  68. #endif
  69. inode->i_op = &cifs_dir_inode_ops;
  70. inode->i_fop = &cifs_dir_ops;
  71. }
  72. break;
  73. case S_IFLNK:
  74. inode->i_op = &cifs_symlink_inode_ops;
  75. break;
  76. default:
  77. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  78. break;
  79. }
  80. }
  81. /* check inode attributes against fattr. If they don't match, tag the
  82. * inode for cache invalidation
  83. */
  84. static void
  85. cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr)
  86. {
  87. struct cifsInodeInfo *cifs_i = CIFS_I(inode);
  88. cFYI(1, "%s: revalidating inode %llu", __func__, cifs_i->uniqueid);
  89. if (inode->i_state & I_NEW) {
  90. cFYI(1, "%s: inode %llu is new", __func__, cifs_i->uniqueid);
  91. return;
  92. }
  93. /* don't bother with revalidation if we have an oplock */
  94. if (cifs_i->clientCanCacheRead) {
  95. cFYI(1, "%s: inode %llu is oplocked", __func__,
  96. cifs_i->uniqueid);
  97. return;
  98. }
  99. /* revalidate if mtime or size have changed */
  100. if (timespec_equal(&inode->i_mtime, &fattr->cf_mtime) &&
  101. cifs_i->server_eof == fattr->cf_eof) {
  102. cFYI(1, "%s: inode %llu is unchanged", __func__,
  103. cifs_i->uniqueid);
  104. return;
  105. }
  106. cFYI(1, "%s: invalidating inode %llu mapping", __func__,
  107. cifs_i->uniqueid);
  108. cifs_i->invalid_mapping = true;
  109. }
  110. /* populate an inode with info from a cifs_fattr struct */
  111. void
  112. cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
  113. {
  114. struct cifsInodeInfo *cifs_i = CIFS_I(inode);
  115. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  116. unsigned long oldtime = cifs_i->time;
  117. cifs_revalidate_cache(inode, fattr);
  118. inode->i_atime = fattr->cf_atime;
  119. inode->i_mtime = fattr->cf_mtime;
  120. inode->i_ctime = fattr->cf_ctime;
  121. inode->i_rdev = fattr->cf_rdev;
  122. inode->i_nlink = fattr->cf_nlink;
  123. inode->i_uid = fattr->cf_uid;
  124. inode->i_gid = fattr->cf_gid;
  125. /* if dynperm is set, don't clobber existing mode */
  126. if (inode->i_state & I_NEW ||
  127. !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM))
  128. inode->i_mode = fattr->cf_mode;
  129. cifs_i->cifsAttrs = fattr->cf_cifsattrs;
  130. if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
  131. cifs_i->time = 0;
  132. else
  133. cifs_i->time = jiffies;
  134. cFYI(1, "inode 0x%p old_time=%ld new_time=%ld", inode,
  135. oldtime, cifs_i->time);
  136. cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING;
  137. cifs_i->server_eof = fattr->cf_eof;
  138. /*
  139. * Can't safely change the file size here if the client is writing to
  140. * it due to potential races.
  141. */
  142. spin_lock(&inode->i_lock);
  143. if (is_size_safe_to_change(cifs_i, fattr->cf_eof)) {
  144. i_size_write(inode, fattr->cf_eof);
  145. /*
  146. * i_blocks is not related to (i_size / i_blksize),
  147. * but instead 512 byte (2**9) size is required for
  148. * calculating num blocks.
  149. */
  150. inode->i_blocks = (512 - 1 + fattr->cf_bytes) >> 9;
  151. }
  152. spin_unlock(&inode->i_lock);
  153. if (fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL)
  154. inode->i_flags |= S_AUTOMOUNT;
  155. cifs_set_ops(inode);
  156. }
  157. void
  158. cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr)
  159. {
  160. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  161. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
  162. return;
  163. fattr->cf_uniqueid = iunique(sb, ROOT_I);
  164. }
  165. /* Fill a cifs_fattr struct with info from FILE_UNIX_BASIC_INFO. */
  166. void
  167. cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info,
  168. struct cifs_sb_info *cifs_sb)
  169. {
  170. memset(fattr, 0, sizeof(*fattr));
  171. fattr->cf_uniqueid = le64_to_cpu(info->UniqueId);
  172. fattr->cf_bytes = le64_to_cpu(info->NumOfBytes);
  173. fattr->cf_eof = le64_to_cpu(info->EndOfFile);
  174. fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
  175. fattr->cf_mtime = cifs_NTtimeToUnix(info->LastModificationTime);
  176. fattr->cf_ctime = cifs_NTtimeToUnix(info->LastStatusChange);
  177. fattr->cf_mode = le64_to_cpu(info->Permissions);
  178. /*
  179. * Since we set the inode type below we need to mask off
  180. * to avoid strange results if bits set above.
  181. */
  182. fattr->cf_mode &= ~S_IFMT;
  183. switch (le32_to_cpu(info->Type)) {
  184. case UNIX_FILE:
  185. fattr->cf_mode |= S_IFREG;
  186. fattr->cf_dtype = DT_REG;
  187. break;
  188. case UNIX_SYMLINK:
  189. fattr->cf_mode |= S_IFLNK;
  190. fattr->cf_dtype = DT_LNK;
  191. break;
  192. case UNIX_DIR:
  193. fattr->cf_mode |= S_IFDIR;
  194. fattr->cf_dtype = DT_DIR;
  195. break;
  196. case UNIX_CHARDEV:
  197. fattr->cf_mode |= S_IFCHR;
  198. fattr->cf_dtype = DT_CHR;
  199. fattr->cf_rdev = MKDEV(le64_to_cpu(info->DevMajor),
  200. le64_to_cpu(info->DevMinor) & MINORMASK);
  201. break;
  202. case UNIX_BLOCKDEV:
  203. fattr->cf_mode |= S_IFBLK;
  204. fattr->cf_dtype = DT_BLK;
  205. fattr->cf_rdev = MKDEV(le64_to_cpu(info->DevMajor),
  206. le64_to_cpu(info->DevMinor) & MINORMASK);
  207. break;
  208. case UNIX_FIFO:
  209. fattr->cf_mode |= S_IFIFO;
  210. fattr->cf_dtype = DT_FIFO;
  211. break;
  212. case UNIX_SOCKET:
  213. fattr->cf_mode |= S_IFSOCK;
  214. fattr->cf_dtype = DT_SOCK;
  215. break;
  216. default:
  217. /* safest to call it a file if we do not know */
  218. fattr->cf_mode |= S_IFREG;
  219. fattr->cf_dtype = DT_REG;
  220. cFYI(1, "unknown type %d", le32_to_cpu(info->Type));
  221. break;
  222. }
  223. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
  224. fattr->cf_uid = cifs_sb->mnt_uid;
  225. else
  226. fattr->cf_uid = le64_to_cpu(info->Uid);
  227. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
  228. fattr->cf_gid = cifs_sb->mnt_gid;
  229. else
  230. fattr->cf_gid = le64_to_cpu(info->Gid);
  231. fattr->cf_nlink = le64_to_cpu(info->Nlinks);
  232. }
  233. /*
  234. * Fill a cifs_fattr struct with fake inode info.
  235. *
  236. * Needed to setup cifs_fattr data for the directory which is the
  237. * junction to the new submount (ie to setup the fake directory
  238. * which represents a DFS referral).
  239. */
  240. static void
  241. cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb)
  242. {
  243. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  244. cFYI(1, "creating fake fattr for DFS referral");
  245. memset(fattr, 0, sizeof(*fattr));
  246. fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU;
  247. fattr->cf_uid = cifs_sb->mnt_uid;
  248. fattr->cf_gid = cifs_sb->mnt_gid;
  249. fattr->cf_atime = CURRENT_TIME;
  250. fattr->cf_ctime = CURRENT_TIME;
  251. fattr->cf_mtime = CURRENT_TIME;
  252. fattr->cf_nlink = 2;
  253. fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL;
  254. }
  255. int cifs_get_file_info_unix(struct file *filp)
  256. {
  257. int rc;
  258. int xid;
  259. FILE_UNIX_BASIC_INFO find_data;
  260. struct cifs_fattr fattr;
  261. struct inode *inode = filp->f_path.dentry->d_inode;
  262. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  263. struct cifsFileInfo *cfile = filp->private_data;
  264. struct cifsTconInfo *tcon = tlink_tcon(cfile->tlink);
  265. xid = GetXid();
  266. rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->netfid, &find_data);
  267. if (!rc) {
  268. cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb);
  269. } else if (rc == -EREMOTE) {
  270. cifs_create_dfs_fattr(&fattr, inode->i_sb);
  271. rc = 0;
  272. }
  273. cifs_fattr_to_inode(inode, &fattr);
  274. FreeXid(xid);
  275. return rc;
  276. }
  277. int cifs_get_inode_info_unix(struct inode **pinode,
  278. const unsigned char *full_path,
  279. struct super_block *sb, int xid)
  280. {
  281. int rc;
  282. FILE_UNIX_BASIC_INFO find_data;
  283. struct cifs_fattr fattr;
  284. struct cifsTconInfo *tcon;
  285. struct tcon_link *tlink;
  286. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  287. cFYI(1, "Getting info on %s", full_path);
  288. tlink = cifs_sb_tlink(cifs_sb);
  289. if (IS_ERR(tlink))
  290. return PTR_ERR(tlink);
  291. tcon = tlink_tcon(tlink);
  292. /* could have done a find first instead but this returns more info */
  293. rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data,
  294. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  295. CIFS_MOUNT_MAP_SPECIAL_CHR);
  296. cifs_put_tlink(tlink);
  297. if (!rc) {
  298. cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb);
  299. } else if (rc == -EREMOTE) {
  300. cifs_create_dfs_fattr(&fattr, sb);
  301. rc = 0;
  302. } else {
  303. return rc;
  304. }
  305. /* check for Minshall+French symlinks */
  306. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {
  307. int tmprc = CIFSCheckMFSymlink(&fattr, full_path, cifs_sb, xid);
  308. if (tmprc)
  309. cFYI(1, "CIFSCheckMFSymlink: %d", tmprc);
  310. }
  311. if (*pinode == NULL) {
  312. /* get new inode */
  313. cifs_fill_uniqueid(sb, &fattr);
  314. *pinode = cifs_iget(sb, &fattr);
  315. if (!*pinode)
  316. rc = -ENOMEM;
  317. } else {
  318. /* we already have inode, update it */
  319. cifs_fattr_to_inode(*pinode, &fattr);
  320. }
  321. return rc;
  322. }
  323. static int
  324. cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
  325. struct cifs_sb_info *cifs_sb, int xid)
  326. {
  327. int rc;
  328. int oplock = 0;
  329. __u16 netfid;
  330. struct tcon_link *tlink;
  331. struct cifsTconInfo *tcon;
  332. char buf[24];
  333. unsigned int bytes_read;
  334. char *pbuf;
  335. pbuf = buf;
  336. fattr->cf_mode &= ~S_IFMT;
  337. if (fattr->cf_eof == 0) {
  338. fattr->cf_mode |= S_IFIFO;
  339. fattr->cf_dtype = DT_FIFO;
  340. return 0;
  341. } else if (fattr->cf_eof < 8) {
  342. fattr->cf_mode |= S_IFREG;
  343. fattr->cf_dtype = DT_REG;
  344. return -EINVAL; /* EOPNOTSUPP? */
  345. }
  346. tlink = cifs_sb_tlink(cifs_sb);
  347. if (IS_ERR(tlink))
  348. return PTR_ERR(tlink);
  349. tcon = tlink_tcon(tlink);
  350. rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, GENERIC_READ,
  351. CREATE_NOT_DIR, &netfid, &oplock, NULL,
  352. cifs_sb->local_nls,
  353. cifs_sb->mnt_cifs_flags &
  354. CIFS_MOUNT_MAP_SPECIAL_CHR);
  355. if (rc == 0) {
  356. int buf_type = CIFS_NO_BUFFER;
  357. /* Read header */
  358. rc = CIFSSMBRead(xid, tcon, netfid,
  359. 24 /* length */, 0 /* offset */,
  360. &bytes_read, &pbuf, &buf_type);
  361. if ((rc == 0) && (bytes_read >= 8)) {
  362. if (memcmp("IntxBLK", pbuf, 8) == 0) {
  363. cFYI(1, "Block device");
  364. fattr->cf_mode |= S_IFBLK;
  365. fattr->cf_dtype = DT_BLK;
  366. if (bytes_read == 24) {
  367. /* we have enough to decode dev num */
  368. __u64 mjr; /* major */
  369. __u64 mnr; /* minor */
  370. mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
  371. mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
  372. fattr->cf_rdev = MKDEV(mjr, mnr);
  373. }
  374. } else if (memcmp("IntxCHR", pbuf, 8) == 0) {
  375. cFYI(1, "Char device");
  376. fattr->cf_mode |= S_IFCHR;
  377. fattr->cf_dtype = DT_CHR;
  378. if (bytes_read == 24) {
  379. /* we have enough to decode dev num */
  380. __u64 mjr; /* major */
  381. __u64 mnr; /* minor */
  382. mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
  383. mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
  384. fattr->cf_rdev = MKDEV(mjr, mnr);
  385. }
  386. } else if (memcmp("IntxLNK", pbuf, 7) == 0) {
  387. cFYI(1, "Symlink");
  388. fattr->cf_mode |= S_IFLNK;
  389. fattr->cf_dtype = DT_LNK;
  390. } else {
  391. fattr->cf_mode |= S_IFREG; /* file? */
  392. fattr->cf_dtype = DT_REG;
  393. rc = -EOPNOTSUPP;
  394. }
  395. } else {
  396. fattr->cf_mode |= S_IFREG; /* then it is a file */
  397. fattr->cf_dtype = DT_REG;
  398. rc = -EOPNOTSUPP; /* or some unknown SFU type */
  399. }
  400. CIFSSMBClose(xid, tcon, netfid);
  401. }
  402. cifs_put_tlink(tlink);
  403. return rc;
  404. }
  405. #define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */
  406. /*
  407. * Fetch mode bits as provided by SFU.
  408. *
  409. * FIXME: Doesn't this clobber the type bit we got from cifs_sfu_type ?
  410. */
  411. static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
  412. struct cifs_sb_info *cifs_sb, int xid)
  413. {
  414. #ifdef CONFIG_CIFS_XATTR
  415. ssize_t rc;
  416. char ea_value[4];
  417. __u32 mode;
  418. struct tcon_link *tlink;
  419. struct cifsTconInfo *tcon;
  420. tlink = cifs_sb_tlink(cifs_sb);
  421. if (IS_ERR(tlink))
  422. return PTR_ERR(tlink);
  423. tcon = tlink_tcon(tlink);
  424. rc = CIFSSMBQAllEAs(xid, tcon, path, "SETFILEBITS",
  425. ea_value, 4 /* size of buf */, cifs_sb->local_nls,
  426. cifs_sb->mnt_cifs_flags &
  427. CIFS_MOUNT_MAP_SPECIAL_CHR);
  428. cifs_put_tlink(tlink);
  429. if (rc < 0)
  430. return (int)rc;
  431. else if (rc > 3) {
  432. mode = le32_to_cpu(*((__le32 *)ea_value));
  433. fattr->cf_mode &= ~SFBITS_MASK;
  434. cFYI(1, "special bits 0%o org mode 0%o", mode,
  435. fattr->cf_mode);
  436. fattr->cf_mode = (mode & SFBITS_MASK) | fattr->cf_mode;
  437. cFYI(1, "special mode bits 0%o", mode);
  438. }
  439. return 0;
  440. #else
  441. return -EOPNOTSUPP;
  442. #endif
  443. }
  444. /* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
  445. static void
  446. cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
  447. struct cifs_sb_info *cifs_sb, bool adjust_tz)
  448. {
  449. struct cifsTconInfo *tcon = cifs_sb_master_tcon(cifs_sb);
  450. memset(fattr, 0, sizeof(*fattr));
  451. fattr->cf_cifsattrs = le32_to_cpu(info->Attributes);
  452. if (info->DeletePending)
  453. fattr->cf_flags |= CIFS_FATTR_DELETE_PENDING;
  454. if (info->LastAccessTime)
  455. fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
  456. else
  457. fattr->cf_atime = CURRENT_TIME;
  458. fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
  459. fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
  460. if (adjust_tz) {
  461. fattr->cf_ctime.tv_sec += tcon->ses->server->timeAdj;
  462. fattr->cf_mtime.tv_sec += tcon->ses->server->timeAdj;
  463. }
  464. fattr->cf_eof = le64_to_cpu(info->EndOfFile);
  465. fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
  466. fattr->cf_createtime = le64_to_cpu(info->CreationTime);
  467. if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
  468. fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
  469. fattr->cf_dtype = DT_DIR;
  470. } else {
  471. fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
  472. fattr->cf_dtype = DT_REG;
  473. /* clear write bits if ATTR_READONLY is set */
  474. if (fattr->cf_cifsattrs & ATTR_READONLY)
  475. fattr->cf_mode &= ~(S_IWUGO);
  476. }
  477. fattr->cf_nlink = le32_to_cpu(info->NumberOfLinks);
  478. fattr->cf_uid = cifs_sb->mnt_uid;
  479. fattr->cf_gid = cifs_sb->mnt_gid;
  480. }
  481. int cifs_get_file_info(struct file *filp)
  482. {
  483. int rc;
  484. int xid;
  485. FILE_ALL_INFO find_data;
  486. struct cifs_fattr fattr;
  487. struct inode *inode = filp->f_path.dentry->d_inode;
  488. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  489. struct cifsFileInfo *cfile = filp->private_data;
  490. struct cifsTconInfo *tcon = tlink_tcon(cfile->tlink);
  491. xid = GetXid();
  492. rc = CIFSSMBQFileInfo(xid, tcon, cfile->netfid, &find_data);
  493. if (rc == -EOPNOTSUPP || rc == -EINVAL) {
  494. /*
  495. * FIXME: legacy server -- fall back to path-based call?
  496. * for now, just skip revalidating and mark inode for
  497. * immediate reval.
  498. */
  499. rc = 0;
  500. CIFS_I(inode)->time = 0;
  501. goto cgfi_exit;
  502. } else if (rc == -EREMOTE) {
  503. cifs_create_dfs_fattr(&fattr, inode->i_sb);
  504. rc = 0;
  505. } else if (rc)
  506. goto cgfi_exit;
  507. /*
  508. * don't bother with SFU junk here -- just mark inode as needing
  509. * revalidation.
  510. */
  511. cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false);
  512. fattr.cf_uniqueid = CIFS_I(inode)->uniqueid;
  513. fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
  514. cifs_fattr_to_inode(inode, &fattr);
  515. cgfi_exit:
  516. FreeXid(xid);
  517. return rc;
  518. }
  519. int cifs_get_inode_info(struct inode **pinode,
  520. const unsigned char *full_path, FILE_ALL_INFO *pfindData,
  521. struct super_block *sb, int xid, const __u16 *pfid)
  522. {
  523. int rc = 0, tmprc;
  524. struct cifsTconInfo *pTcon;
  525. struct tcon_link *tlink;
  526. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  527. char *buf = NULL;
  528. bool adjustTZ = false;
  529. struct cifs_fattr fattr;
  530. tlink = cifs_sb_tlink(cifs_sb);
  531. if (IS_ERR(tlink))
  532. return PTR_ERR(tlink);
  533. pTcon = tlink_tcon(tlink);
  534. cFYI(1, "Getting info on %s", full_path);
  535. if ((pfindData == NULL) && (*pinode != NULL)) {
  536. if (CIFS_I(*pinode)->clientCanCacheRead) {
  537. cFYI(1, "No need to revalidate cached inode sizes");
  538. goto cgii_exit;
  539. }
  540. }
  541. /* if file info not passed in then get it from server */
  542. if (pfindData == NULL) {
  543. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  544. if (buf == NULL) {
  545. rc = -ENOMEM;
  546. goto cgii_exit;
  547. }
  548. pfindData = (FILE_ALL_INFO *)buf;
  549. /* could do find first instead but this returns more info */
  550. rc = CIFSSMBQPathInfo(xid, pTcon, full_path, pfindData,
  551. 0 /* not legacy */,
  552. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  553. CIFS_MOUNT_MAP_SPECIAL_CHR);
  554. /* BB optimize code so we do not make the above call
  555. when server claims no NT SMB support and the above call
  556. failed at least once - set flag in tcon or mount */
  557. if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
  558. rc = SMBQueryInformation(xid, pTcon, full_path,
  559. pfindData, cifs_sb->local_nls,
  560. cifs_sb->mnt_cifs_flags &
  561. CIFS_MOUNT_MAP_SPECIAL_CHR);
  562. adjustTZ = true;
  563. }
  564. }
  565. if (!rc) {
  566. cifs_all_info_to_fattr(&fattr, (FILE_ALL_INFO *) pfindData,
  567. cifs_sb, adjustTZ);
  568. } else if (rc == -EREMOTE) {
  569. cifs_create_dfs_fattr(&fattr, sb);
  570. rc = 0;
  571. } else {
  572. goto cgii_exit;
  573. }
  574. /*
  575. * If an inode wasn't passed in, then get the inode number
  576. *
  577. * Is an i_ino of zero legal? Can we use that to check if the server
  578. * supports returning inode numbers? Are there other sanity checks we
  579. * can use to ensure that the server is really filling in that field?
  580. *
  581. * We can not use the IndexNumber field by default from Windows or
  582. * Samba (in ALL_INFO buf) but we can request it explicitly. The SNIA
  583. * CIFS spec claims that this value is unique within the scope of a
  584. * share, and the windows docs hint that it's actually unique
  585. * per-machine.
  586. *
  587. * There may be higher info levels that work but are there Windows
  588. * server or network appliances for which IndexNumber field is not
  589. * guaranteed unique?
  590. */
  591. if (*pinode == NULL) {
  592. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
  593. int rc1 = 0;
  594. rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
  595. full_path, &fattr.cf_uniqueid,
  596. cifs_sb->local_nls,
  597. cifs_sb->mnt_cifs_flags &
  598. CIFS_MOUNT_MAP_SPECIAL_CHR);
  599. if (rc1 || !fattr.cf_uniqueid) {
  600. cFYI(1, "GetSrvInodeNum rc %d", rc1);
  601. fattr.cf_uniqueid = iunique(sb, ROOT_I);
  602. cifs_autodisable_serverino(cifs_sb);
  603. }
  604. } else {
  605. fattr.cf_uniqueid = iunique(sb, ROOT_I);
  606. }
  607. } else {
  608. fattr.cf_uniqueid = CIFS_I(*pinode)->uniqueid;
  609. }
  610. /* query for SFU type info if supported and needed */
  611. if (fattr.cf_cifsattrs & ATTR_SYSTEM &&
  612. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
  613. tmprc = cifs_sfu_type(&fattr, full_path, cifs_sb, xid);
  614. if (tmprc)
  615. cFYI(1, "cifs_sfu_type failed: %d", tmprc);
  616. }
  617. #ifdef CONFIG_CIFS_ACL
  618. /* fill in 0777 bits from ACL */
  619. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
  620. rc = cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path,
  621. pfid);
  622. if (rc) {
  623. cFYI(1, "%s: Getting ACL failed with error: %d",
  624. __func__, rc);
  625. goto cgii_exit;
  626. }
  627. }
  628. #endif /* CONFIG_CIFS_ACL */
  629. /* fill in remaining high mode bits e.g. SUID, VTX */
  630. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
  631. cifs_sfu_mode(&fattr, full_path, cifs_sb, xid);
  632. /* check for Minshall+French symlinks */
  633. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {
  634. tmprc = CIFSCheckMFSymlink(&fattr, full_path, cifs_sb, xid);
  635. if (tmprc)
  636. cFYI(1, "CIFSCheckMFSymlink: %d", tmprc);
  637. }
  638. if (!*pinode) {
  639. *pinode = cifs_iget(sb, &fattr);
  640. if (!*pinode)
  641. rc = -ENOMEM;
  642. } else {
  643. cifs_fattr_to_inode(*pinode, &fattr);
  644. }
  645. cgii_exit:
  646. kfree(buf);
  647. cifs_put_tlink(tlink);
  648. return rc;
  649. }
  650. static const struct inode_operations cifs_ipc_inode_ops = {
  651. .lookup = cifs_lookup,
  652. };
  653. char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb,
  654. struct cifsTconInfo *tcon)
  655. {
  656. int pplen = cifs_sb->prepathlen;
  657. int dfsplen;
  658. char *full_path = NULL;
  659. /* if no prefix path, simply set path to the root of share to "" */
  660. if (pplen == 0) {
  661. full_path = kmalloc(1, GFP_KERNEL);
  662. if (full_path)
  663. full_path[0] = 0;
  664. return full_path;
  665. }
  666. if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
  667. dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
  668. else
  669. dfsplen = 0;
  670. full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
  671. if (full_path == NULL)
  672. return full_path;
  673. if (dfsplen) {
  674. strncpy(full_path, tcon->treeName, dfsplen);
  675. /* switch slash direction in prepath depending on whether
  676. * windows or posix style path names
  677. */
  678. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
  679. int i;
  680. for (i = 0; i < dfsplen; i++) {
  681. if (full_path[i] == '\\')
  682. full_path[i] = '/';
  683. }
  684. }
  685. }
  686. strncpy(full_path + dfsplen, cifs_sb->prepath, pplen);
  687. full_path[dfsplen + pplen] = 0; /* add trailing null */
  688. return full_path;
  689. }
  690. static int
  691. cifs_find_inode(struct inode *inode, void *opaque)
  692. {
  693. struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
  694. /* don't match inode with different uniqueid */
  695. if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
  696. return 0;
  697. /* use createtime like an i_generation field */
  698. if (CIFS_I(inode)->createtime != fattr->cf_createtime)
  699. return 0;
  700. /* don't match inode of different type */
  701. if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
  702. return 0;
  703. /* if it's not a directory or has no dentries, then flag it */
  704. if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry))
  705. fattr->cf_flags |= CIFS_FATTR_INO_COLLISION;
  706. return 1;
  707. }
  708. static int
  709. cifs_init_inode(struct inode *inode, void *opaque)
  710. {
  711. struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
  712. CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
  713. CIFS_I(inode)->createtime = fattr->cf_createtime;
  714. return 0;
  715. }
  716. /*
  717. * walk dentry list for an inode and report whether it has aliases that
  718. * are hashed. We use this to determine if a directory inode can actually
  719. * be used.
  720. */
  721. static bool
  722. inode_has_hashed_dentries(struct inode *inode)
  723. {
  724. struct dentry *dentry;
  725. spin_lock(&inode->i_lock);
  726. list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
  727. if (!d_unhashed(dentry) || IS_ROOT(dentry)) {
  728. spin_unlock(&inode->i_lock);
  729. return true;
  730. }
  731. }
  732. spin_unlock(&inode->i_lock);
  733. return false;
  734. }
  735. /* Given fattrs, get a corresponding inode */
  736. struct inode *
  737. cifs_iget(struct super_block *sb, struct cifs_fattr *fattr)
  738. {
  739. unsigned long hash;
  740. struct inode *inode;
  741. retry_iget5_locked:
  742. cFYI(1, "looking for uniqueid=%llu", fattr->cf_uniqueid);
  743. /* hash down to 32-bits on 32-bit arch */
  744. hash = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid);
  745. inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr);
  746. if (inode) {
  747. /* was there a potentially problematic inode collision? */
  748. if (fattr->cf_flags & CIFS_FATTR_INO_COLLISION) {
  749. fattr->cf_flags &= ~CIFS_FATTR_INO_COLLISION;
  750. if (inode_has_hashed_dentries(inode)) {
  751. cifs_autodisable_serverino(CIFS_SB(sb));
  752. iput(inode);
  753. fattr->cf_uniqueid = iunique(sb, ROOT_I);
  754. goto retry_iget5_locked;
  755. }
  756. }
  757. cifs_fattr_to_inode(inode, fattr);
  758. if (sb->s_flags & MS_NOATIME)
  759. inode->i_flags |= S_NOATIME | S_NOCMTIME;
  760. if (inode->i_state & I_NEW) {
  761. inode->i_ino = hash;
  762. if (S_ISREG(inode->i_mode))
  763. inode->i_data.backing_dev_info = sb->s_bdi;
  764. #ifdef CONFIG_CIFS_FSCACHE
  765. /* initialize per-inode cache cookie pointer */
  766. CIFS_I(inode)->fscache = NULL;
  767. #endif
  768. unlock_new_inode(inode);
  769. }
  770. }
  771. return inode;
  772. }
  773. /* gets root inode */
  774. struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
  775. {
  776. int xid;
  777. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  778. struct inode *inode = NULL;
  779. long rc;
  780. char *full_path;
  781. struct cifsTconInfo *tcon = cifs_sb_master_tcon(cifs_sb);
  782. full_path = cifs_build_path_to_root(cifs_sb, tcon);
  783. if (full_path == NULL)
  784. return ERR_PTR(-ENOMEM);
  785. xid = GetXid();
  786. if (tcon->unix_ext)
  787. rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
  788. else
  789. rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
  790. xid, NULL);
  791. if (!inode) {
  792. inode = ERR_PTR(rc);
  793. goto out;
  794. }
  795. #ifdef CONFIG_CIFS_FSCACHE
  796. /* populate tcon->resource_id */
  797. tcon->resource_id = CIFS_I(inode)->uniqueid;
  798. #endif
  799. if (rc && tcon->ipc) {
  800. cFYI(1, "ipc connection - fake read inode");
  801. inode->i_mode |= S_IFDIR;
  802. inode->i_nlink = 2;
  803. inode->i_op = &cifs_ipc_inode_ops;
  804. inode->i_fop = &simple_dir_operations;
  805. inode->i_uid = cifs_sb->mnt_uid;
  806. inode->i_gid = cifs_sb->mnt_gid;
  807. } else if (rc) {
  808. iget_failed(inode);
  809. inode = ERR_PTR(rc);
  810. }
  811. out:
  812. kfree(full_path);
  813. /* can not call macro FreeXid here since in a void func
  814. * TODO: This is no longer true
  815. */
  816. _FreeXid(xid);
  817. return inode;
  818. }
  819. static int
  820. cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid,
  821. char *full_path, __u32 dosattr)
  822. {
  823. int rc;
  824. int oplock = 0;
  825. __u16 netfid;
  826. __u32 netpid;
  827. bool set_time = false;
  828. struct cifsFileInfo *open_file;
  829. struct cifsInodeInfo *cifsInode = CIFS_I(inode);
  830. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  831. struct tcon_link *tlink = NULL;
  832. struct cifsTconInfo *pTcon;
  833. FILE_BASIC_INFO info_buf;
  834. if (attrs == NULL)
  835. return -EINVAL;
  836. if (attrs->ia_valid & ATTR_ATIME) {
  837. set_time = true;
  838. info_buf.LastAccessTime =
  839. cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
  840. } else
  841. info_buf.LastAccessTime = 0;
  842. if (attrs->ia_valid & ATTR_MTIME) {
  843. set_time = true;
  844. info_buf.LastWriteTime =
  845. cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
  846. } else
  847. info_buf.LastWriteTime = 0;
  848. /*
  849. * Samba throws this field away, but windows may actually use it.
  850. * Do not set ctime unless other time stamps are changed explicitly
  851. * (i.e. by utimes()) since we would then have a mix of client and
  852. * server times.
  853. */
  854. if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
  855. cFYI(1, "CIFS - CTIME changed");
  856. info_buf.ChangeTime =
  857. cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
  858. } else
  859. info_buf.ChangeTime = 0;
  860. info_buf.CreationTime = 0; /* don't change */
  861. info_buf.Attributes = cpu_to_le32(dosattr);
  862. /*
  863. * If the file is already open for write, just use that fileid
  864. */
  865. open_file = find_writable_file(cifsInode, true);
  866. if (open_file) {
  867. netfid = open_file->netfid;
  868. netpid = open_file->pid;
  869. pTcon = tlink_tcon(open_file->tlink);
  870. goto set_via_filehandle;
  871. }
  872. tlink = cifs_sb_tlink(cifs_sb);
  873. if (IS_ERR(tlink)) {
  874. rc = PTR_ERR(tlink);
  875. tlink = NULL;
  876. goto out;
  877. }
  878. pTcon = tlink_tcon(tlink);
  879. /*
  880. * NT4 apparently returns success on this call, but it doesn't
  881. * really work.
  882. */
  883. if (!(pTcon->ses->flags & CIFS_SES_NT4)) {
  884. rc = CIFSSMBSetPathInfo(xid, pTcon, full_path,
  885. &info_buf, cifs_sb->local_nls,
  886. cifs_sb->mnt_cifs_flags &
  887. CIFS_MOUNT_MAP_SPECIAL_CHR);
  888. if (rc == 0) {
  889. cifsInode->cifsAttrs = dosattr;
  890. goto out;
  891. } else if (rc != -EOPNOTSUPP && rc != -EINVAL)
  892. goto out;
  893. }
  894. cFYI(1, "calling SetFileInfo since SetPathInfo for "
  895. "times not supported by this server");
  896. rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
  897. SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
  898. CREATE_NOT_DIR, &netfid, &oplock,
  899. NULL, cifs_sb->local_nls,
  900. cifs_sb->mnt_cifs_flags &
  901. CIFS_MOUNT_MAP_SPECIAL_CHR);
  902. if (rc != 0) {
  903. if (rc == -EIO)
  904. rc = -EINVAL;
  905. goto out;
  906. }
  907. netpid = current->tgid;
  908. set_via_filehandle:
  909. rc = CIFSSMBSetFileInfo(xid, pTcon, &info_buf, netfid, netpid);
  910. if (!rc)
  911. cifsInode->cifsAttrs = dosattr;
  912. if (open_file == NULL)
  913. CIFSSMBClose(xid, pTcon, netfid);
  914. else
  915. cifsFileInfo_put(open_file);
  916. out:
  917. if (tlink != NULL)
  918. cifs_put_tlink(tlink);
  919. return rc;
  920. }
  921. /*
  922. * open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
  923. * and rename it to a random name that hopefully won't conflict with
  924. * anything else.
  925. */
  926. static int
  927. cifs_rename_pending_delete(char *full_path, struct dentry *dentry, int xid)
  928. {
  929. int oplock = 0;
  930. int rc;
  931. __u16 netfid;
  932. struct inode *inode = dentry->d_inode;
  933. struct cifsInodeInfo *cifsInode = CIFS_I(inode);
  934. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  935. struct tcon_link *tlink;
  936. struct cifsTconInfo *tcon;
  937. __u32 dosattr, origattr;
  938. FILE_BASIC_INFO *info_buf = NULL;
  939. tlink = cifs_sb_tlink(cifs_sb);
  940. if (IS_ERR(tlink))
  941. return PTR_ERR(tlink);
  942. tcon = tlink_tcon(tlink);
  943. rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN,
  944. DELETE|FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR,
  945. &netfid, &oplock, NULL, cifs_sb->local_nls,
  946. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  947. if (rc != 0)
  948. goto out;
  949. origattr = cifsInode->cifsAttrs;
  950. if (origattr == 0)
  951. origattr |= ATTR_NORMAL;
  952. dosattr = origattr & ~ATTR_READONLY;
  953. if (dosattr == 0)
  954. dosattr |= ATTR_NORMAL;
  955. dosattr |= ATTR_HIDDEN;
  956. /* set ATTR_HIDDEN and clear ATTR_READONLY, but only if needed */
  957. if (dosattr != origattr) {
  958. info_buf = kzalloc(sizeof(*info_buf), GFP_KERNEL);
  959. if (info_buf == NULL) {
  960. rc = -ENOMEM;
  961. goto out_close;
  962. }
  963. info_buf->Attributes = cpu_to_le32(dosattr);
  964. rc = CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid,
  965. current->tgid);
  966. /* although we would like to mark the file hidden
  967. if that fails we will still try to rename it */
  968. if (rc != 0)
  969. cifsInode->cifsAttrs = dosattr;
  970. else
  971. dosattr = origattr; /* since not able to change them */
  972. }
  973. /* rename the file */
  974. rc = CIFSSMBRenameOpenFile(xid, tcon, netfid, NULL, cifs_sb->local_nls,
  975. cifs_sb->mnt_cifs_flags &
  976. CIFS_MOUNT_MAP_SPECIAL_CHR);
  977. if (rc != 0) {
  978. rc = -ETXTBSY;
  979. goto undo_setattr;
  980. }
  981. /* try to set DELETE_ON_CLOSE */
  982. if (!cifsInode->delete_pending) {
  983. rc = CIFSSMBSetFileDisposition(xid, tcon, true, netfid,
  984. current->tgid);
  985. /*
  986. * some samba versions return -ENOENT when we try to set the
  987. * file disposition here. Likely a samba bug, but work around
  988. * it for now. This means that some cifsXXX files may hang
  989. * around after they shouldn't.
  990. *
  991. * BB: remove this hack after more servers have the fix
  992. */
  993. if (rc == -ENOENT)
  994. rc = 0;
  995. else if (rc != 0) {
  996. rc = -ETXTBSY;
  997. goto undo_rename;
  998. }
  999. cifsInode->delete_pending = true;
  1000. }
  1001. out_close:
  1002. CIFSSMBClose(xid, tcon, netfid);
  1003. out:
  1004. kfree(info_buf);
  1005. cifs_put_tlink(tlink);
  1006. return rc;
  1007. /*
  1008. * reset everything back to the original state. Don't bother
  1009. * dealing with errors here since we can't do anything about
  1010. * them anyway.
  1011. */
  1012. undo_rename:
  1013. CIFSSMBRenameOpenFile(xid, tcon, netfid, dentry->d_name.name,
  1014. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  1015. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1016. undo_setattr:
  1017. if (dosattr != origattr) {
  1018. info_buf->Attributes = cpu_to_le32(origattr);
  1019. if (!CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid,
  1020. current->tgid))
  1021. cifsInode->cifsAttrs = origattr;
  1022. }
  1023. goto out_close;
  1024. }
  1025. /*
  1026. * If dentry->d_inode is null (usually meaning the cached dentry
  1027. * is a negative dentry) then we would attempt a standard SMB delete, but
  1028. * if that fails we can not attempt the fall back mechanisms on EACCESS
  1029. * but will return the EACCESS to the caller. Note that the VFS does not call
  1030. * unlink on negative dentries currently.
  1031. */
  1032. int cifs_unlink(struct inode *dir, struct dentry *dentry)
  1033. {
  1034. int rc = 0;
  1035. int xid;
  1036. char *full_path = NULL;
  1037. struct inode *inode = dentry->d_inode;
  1038. struct cifsInodeInfo *cifs_inode;
  1039. struct super_block *sb = dir->i_sb;
  1040. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  1041. struct tcon_link *tlink;
  1042. struct cifsTconInfo *tcon;
  1043. struct iattr *attrs = NULL;
  1044. __u32 dosattr = 0, origattr = 0;
  1045. cFYI(1, "cifs_unlink, dir=0x%p, dentry=0x%p", dir, dentry);
  1046. tlink = cifs_sb_tlink(cifs_sb);
  1047. if (IS_ERR(tlink))
  1048. return PTR_ERR(tlink);
  1049. tcon = tlink_tcon(tlink);
  1050. xid = GetXid();
  1051. /* Unlink can be called from rename so we can not take the
  1052. * sb->s_vfs_rename_mutex here */
  1053. full_path = build_path_from_dentry(dentry);
  1054. if (full_path == NULL) {
  1055. rc = -ENOMEM;
  1056. goto unlink_out;
  1057. }
  1058. if ((tcon->ses->capabilities & CAP_UNIX) &&
  1059. (CIFS_UNIX_POSIX_PATH_OPS_CAP &
  1060. le64_to_cpu(tcon->fsUnixInfo.Capability))) {
  1061. rc = CIFSPOSIXDelFile(xid, tcon, full_path,
  1062. SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls,
  1063. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  1064. cFYI(1, "posix del rc %d", rc);
  1065. if ((rc == 0) || (rc == -ENOENT))
  1066. goto psx_del_no_retry;
  1067. }
  1068. retry_std_delete:
  1069. rc = CIFSSMBDelFile(xid, tcon, full_path, cifs_sb->local_nls,
  1070. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  1071. psx_del_no_retry:
  1072. if (!rc) {
  1073. if (inode)
  1074. drop_nlink(inode);
  1075. } else if (rc == -ENOENT) {
  1076. d_drop(dentry);
  1077. } else if (rc == -ETXTBSY) {
  1078. rc = cifs_rename_pending_delete(full_path, dentry, xid);
  1079. if (rc == 0)
  1080. drop_nlink(inode);
  1081. } else if ((rc == -EACCES) && (dosattr == 0) && inode) {
  1082. attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
  1083. if (attrs == NULL) {
  1084. rc = -ENOMEM;
  1085. goto out_reval;
  1086. }
  1087. /* try to reset dos attributes */
  1088. cifs_inode = CIFS_I(inode);
  1089. origattr = cifs_inode->cifsAttrs;
  1090. if (origattr == 0)
  1091. origattr |= ATTR_NORMAL;
  1092. dosattr = origattr & ~ATTR_READONLY;
  1093. if (dosattr == 0)
  1094. dosattr |= ATTR_NORMAL;
  1095. dosattr |= ATTR_HIDDEN;
  1096. rc = cifs_set_file_info(inode, attrs, xid, full_path, dosattr);
  1097. if (rc != 0)
  1098. goto out_reval;
  1099. goto retry_std_delete;
  1100. }
  1101. /* undo the setattr if we errored out and it's needed */
  1102. if (rc != 0 && dosattr != 0)
  1103. cifs_set_file_info(inode, attrs, xid, full_path, origattr);
  1104. out_reval:
  1105. if (inode) {
  1106. cifs_inode = CIFS_I(inode);
  1107. cifs_inode->time = 0; /* will force revalidate to get info
  1108. when needed */
  1109. inode->i_ctime = current_fs_time(sb);
  1110. }
  1111. dir->i_ctime = dir->i_mtime = current_fs_time(sb);
  1112. cifs_inode = CIFS_I(dir);
  1113. CIFS_I(dir)->time = 0; /* force revalidate of dir as well */
  1114. unlink_out:
  1115. kfree(full_path);
  1116. kfree(attrs);
  1117. FreeXid(xid);
  1118. cifs_put_tlink(tlink);
  1119. return rc;
  1120. }
  1121. int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
  1122. {
  1123. int rc = 0, tmprc;
  1124. int xid;
  1125. struct cifs_sb_info *cifs_sb;
  1126. struct tcon_link *tlink;
  1127. struct cifsTconInfo *pTcon;
  1128. char *full_path = NULL;
  1129. struct inode *newinode = NULL;
  1130. struct cifs_fattr fattr;
  1131. cFYI(1, "In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode);
  1132. cifs_sb = CIFS_SB(inode->i_sb);
  1133. tlink = cifs_sb_tlink(cifs_sb);
  1134. if (IS_ERR(tlink))
  1135. return PTR_ERR(tlink);
  1136. pTcon = tlink_tcon(tlink);
  1137. xid = GetXid();
  1138. full_path = build_path_from_dentry(direntry);
  1139. if (full_path == NULL) {
  1140. rc = -ENOMEM;
  1141. goto mkdir_out;
  1142. }
  1143. if ((pTcon->ses->capabilities & CAP_UNIX) &&
  1144. (CIFS_UNIX_POSIX_PATH_OPS_CAP &
  1145. le64_to_cpu(pTcon->fsUnixInfo.Capability))) {
  1146. u32 oplock = 0;
  1147. FILE_UNIX_BASIC_INFO *pInfo =
  1148. kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
  1149. if (pInfo == NULL) {
  1150. rc = -ENOMEM;
  1151. goto mkdir_out;
  1152. }
  1153. mode &= ~current_umask();
  1154. rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT,
  1155. mode, NULL /* netfid */, pInfo, &oplock,
  1156. full_path, cifs_sb->local_nls,
  1157. cifs_sb->mnt_cifs_flags &
  1158. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1159. if (rc == -EOPNOTSUPP) {
  1160. kfree(pInfo);
  1161. goto mkdir_retry_old;
  1162. } else if (rc) {
  1163. cFYI(1, "posix mkdir returned 0x%x", rc);
  1164. d_drop(direntry);
  1165. } else {
  1166. if (pInfo->Type == cpu_to_le32(-1)) {
  1167. /* no return info, go query for it */
  1168. kfree(pInfo);
  1169. goto mkdir_get_info;
  1170. }
  1171. /*BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if need
  1172. to set uid/gid */
  1173. inc_nlink(inode);
  1174. cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb);
  1175. cifs_fill_uniqueid(inode->i_sb, &fattr);
  1176. newinode = cifs_iget(inode->i_sb, &fattr);
  1177. if (!newinode) {
  1178. kfree(pInfo);
  1179. goto mkdir_get_info;
  1180. }
  1181. d_instantiate(direntry, newinode);
  1182. #ifdef CONFIG_CIFS_DEBUG2
  1183. cFYI(1, "instantiated dentry %p %s to inode %p",
  1184. direntry, direntry->d_name.name, newinode);
  1185. if (newinode->i_nlink != 2)
  1186. cFYI(1, "unexpected number of links %d",
  1187. newinode->i_nlink);
  1188. #endif
  1189. }
  1190. kfree(pInfo);
  1191. goto mkdir_out;
  1192. }
  1193. mkdir_retry_old:
  1194. /* BB add setting the equivalent of mode via CreateX w/ACLs */
  1195. rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
  1196. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  1197. if (rc) {
  1198. cFYI(1, "cifs_mkdir returned 0x%x", rc);
  1199. d_drop(direntry);
  1200. } else {
  1201. mkdir_get_info:
  1202. inc_nlink(inode);
  1203. if (pTcon->unix_ext)
  1204. rc = cifs_get_inode_info_unix(&newinode, full_path,
  1205. inode->i_sb, xid);
  1206. else
  1207. rc = cifs_get_inode_info(&newinode, full_path, NULL,
  1208. inode->i_sb, xid, NULL);
  1209. d_instantiate(direntry, newinode);
  1210. /* setting nlink not necessary except in cases where we
  1211. * failed to get it from the server or was set bogus */
  1212. if ((direntry->d_inode) && (direntry->d_inode->i_nlink < 2))
  1213. direntry->d_inode->i_nlink = 2;
  1214. mode &= ~current_umask();
  1215. /* must turn on setgid bit if parent dir has it */
  1216. if (inode->i_mode & S_ISGID)
  1217. mode |= S_ISGID;
  1218. if (pTcon->unix_ext) {
  1219. struct cifs_unix_set_info_args args = {
  1220. .mode = mode,
  1221. .ctime = NO_CHANGE_64,
  1222. .atime = NO_CHANGE_64,
  1223. .mtime = NO_CHANGE_64,
  1224. .device = 0,
  1225. };
  1226. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  1227. args.uid = (__u64)current_fsuid();
  1228. if (inode->i_mode & S_ISGID)
  1229. args.gid = (__u64)inode->i_gid;
  1230. else
  1231. args.gid = (__u64)current_fsgid();
  1232. } else {
  1233. args.uid = NO_CHANGE_64;
  1234. args.gid = NO_CHANGE_64;
  1235. }
  1236. CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, &args,
  1237. cifs_sb->local_nls,
  1238. cifs_sb->mnt_cifs_flags &
  1239. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1240. } else {
  1241. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
  1242. (mode & S_IWUGO) == 0) {
  1243. FILE_BASIC_INFO pInfo;
  1244. struct cifsInodeInfo *cifsInode;
  1245. u32 dosattrs;
  1246. memset(&pInfo, 0, sizeof(pInfo));
  1247. cifsInode = CIFS_I(newinode);
  1248. dosattrs = cifsInode->cifsAttrs|ATTR_READONLY;
  1249. pInfo.Attributes = cpu_to_le32(dosattrs);
  1250. tmprc = CIFSSMBSetPathInfo(xid, pTcon,
  1251. full_path, &pInfo,
  1252. cifs_sb->local_nls,
  1253. cifs_sb->mnt_cifs_flags &
  1254. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1255. if (tmprc == 0)
  1256. cifsInode->cifsAttrs = dosattrs;
  1257. }
  1258. if (direntry->d_inode) {
  1259. if (cifs_sb->mnt_cifs_flags &
  1260. CIFS_MOUNT_DYNPERM)
  1261. direntry->d_inode->i_mode =
  1262. (mode | S_IFDIR);
  1263. if (cifs_sb->mnt_cifs_flags &
  1264. CIFS_MOUNT_SET_UID) {
  1265. direntry->d_inode->i_uid =
  1266. current_fsuid();
  1267. if (inode->i_mode & S_ISGID)
  1268. direntry->d_inode->i_gid =
  1269. inode->i_gid;
  1270. else
  1271. direntry->d_inode->i_gid =
  1272. current_fsgid();
  1273. }
  1274. }
  1275. }
  1276. }
  1277. mkdir_out:
  1278. kfree(full_path);
  1279. FreeXid(xid);
  1280. cifs_put_tlink(tlink);
  1281. return rc;
  1282. }
  1283. int cifs_rmdir(struct inode *inode, struct dentry *direntry)
  1284. {
  1285. int rc = 0;
  1286. int xid;
  1287. struct cifs_sb_info *cifs_sb;
  1288. struct tcon_link *tlink;
  1289. struct cifsTconInfo *pTcon;
  1290. char *full_path = NULL;
  1291. struct cifsInodeInfo *cifsInode;
  1292. cFYI(1, "cifs_rmdir, inode = 0x%p", inode);
  1293. xid = GetXid();
  1294. full_path = build_path_from_dentry(direntry);
  1295. if (full_path == NULL) {
  1296. rc = -ENOMEM;
  1297. goto rmdir_exit;
  1298. }
  1299. cifs_sb = CIFS_SB(inode->i_sb);
  1300. tlink = cifs_sb_tlink(cifs_sb);
  1301. if (IS_ERR(tlink)) {
  1302. rc = PTR_ERR(tlink);
  1303. goto rmdir_exit;
  1304. }
  1305. pTcon = tlink_tcon(tlink);
  1306. rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
  1307. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  1308. cifs_put_tlink(tlink);
  1309. if (!rc) {
  1310. drop_nlink(inode);
  1311. spin_lock(&direntry->d_inode->i_lock);
  1312. i_size_write(direntry->d_inode, 0);
  1313. clear_nlink(direntry->d_inode);
  1314. spin_unlock(&direntry->d_inode->i_lock);
  1315. }
  1316. cifsInode = CIFS_I(direntry->d_inode);
  1317. cifsInode->time = 0; /* force revalidate to go get info when
  1318. needed */
  1319. cifsInode = CIFS_I(inode);
  1320. cifsInode->time = 0; /* force revalidate to get parent dir info
  1321. since cached search results now invalid */
  1322. direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
  1323. current_fs_time(inode->i_sb);
  1324. rmdir_exit:
  1325. kfree(full_path);
  1326. FreeXid(xid);
  1327. return rc;
  1328. }
  1329. static int
  1330. cifs_do_rename(int xid, struct dentry *from_dentry, const char *fromPath,
  1331. struct dentry *to_dentry, const char *toPath)
  1332. {
  1333. struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb);
  1334. struct tcon_link *tlink;
  1335. struct cifsTconInfo *pTcon;
  1336. __u16 srcfid;
  1337. int oplock, rc;
  1338. tlink = cifs_sb_tlink(cifs_sb);
  1339. if (IS_ERR(tlink))
  1340. return PTR_ERR(tlink);
  1341. pTcon = tlink_tcon(tlink);
  1342. /* try path-based rename first */
  1343. rc = CIFSSMBRename(xid, pTcon, fromPath, toPath, cifs_sb->local_nls,
  1344. cifs_sb->mnt_cifs_flags &
  1345. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1346. /*
  1347. * don't bother with rename by filehandle unless file is busy and
  1348. * source Note that cross directory moves do not work with
  1349. * rename by filehandle to various Windows servers.
  1350. */
  1351. if (rc == 0 || rc != -ETXTBSY)
  1352. goto do_rename_exit;
  1353. /* open-file renames don't work across directories */
  1354. if (to_dentry->d_parent != from_dentry->d_parent)
  1355. goto do_rename_exit;
  1356. /* open the file to be renamed -- we need DELETE perms */
  1357. rc = CIFSSMBOpen(xid, pTcon, fromPath, FILE_OPEN, DELETE,
  1358. CREATE_NOT_DIR, &srcfid, &oplock, NULL,
  1359. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  1360. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1361. if (rc == 0) {
  1362. rc = CIFSSMBRenameOpenFile(xid, pTcon, srcfid,
  1363. (const char *) to_dentry->d_name.name,
  1364. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  1365. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1366. CIFSSMBClose(xid, pTcon, srcfid);
  1367. }
  1368. do_rename_exit:
  1369. cifs_put_tlink(tlink);
  1370. return rc;
  1371. }
  1372. int cifs_rename(struct inode *source_dir, struct dentry *source_dentry,
  1373. struct inode *target_dir, struct dentry *target_dentry)
  1374. {
  1375. char *fromName = NULL;
  1376. char *toName = NULL;
  1377. struct cifs_sb_info *cifs_sb;
  1378. struct tcon_link *tlink;
  1379. struct cifsTconInfo *tcon;
  1380. FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
  1381. FILE_UNIX_BASIC_INFO *info_buf_target;
  1382. int xid, rc, tmprc;
  1383. cifs_sb = CIFS_SB(source_dir->i_sb);
  1384. tlink = cifs_sb_tlink(cifs_sb);
  1385. if (IS_ERR(tlink))
  1386. return PTR_ERR(tlink);
  1387. tcon = tlink_tcon(tlink);
  1388. xid = GetXid();
  1389. /*
  1390. * we already have the rename sem so we do not need to
  1391. * grab it again here to protect the path integrity
  1392. */
  1393. fromName = build_path_from_dentry(source_dentry);
  1394. if (fromName == NULL) {
  1395. rc = -ENOMEM;
  1396. goto cifs_rename_exit;
  1397. }
  1398. toName = build_path_from_dentry(target_dentry);
  1399. if (toName == NULL) {
  1400. rc = -ENOMEM;
  1401. goto cifs_rename_exit;
  1402. }
  1403. rc = cifs_do_rename(xid, source_dentry, fromName,
  1404. target_dentry, toName);
  1405. if (rc == -EEXIST && tcon->unix_ext) {
  1406. /*
  1407. * Are src and dst hardlinks of same inode? We can
  1408. * only tell with unix extensions enabled
  1409. */
  1410. info_buf_source =
  1411. kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO),
  1412. GFP_KERNEL);
  1413. if (info_buf_source == NULL) {
  1414. rc = -ENOMEM;
  1415. goto cifs_rename_exit;
  1416. }
  1417. info_buf_target = info_buf_source + 1;
  1418. tmprc = CIFSSMBUnixQPathInfo(xid, tcon, fromName,
  1419. info_buf_source,
  1420. cifs_sb->local_nls,
  1421. cifs_sb->mnt_cifs_flags &
  1422. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1423. if (tmprc != 0)
  1424. goto unlink_target;
  1425. tmprc = CIFSSMBUnixQPathInfo(xid, tcon, toName,
  1426. info_buf_target,
  1427. cifs_sb->local_nls,
  1428. cifs_sb->mnt_cifs_flags &
  1429. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1430. if (tmprc == 0 && (info_buf_source->UniqueId ==
  1431. info_buf_target->UniqueId)) {
  1432. /* same file, POSIX says that this is a noop */
  1433. rc = 0;
  1434. goto cifs_rename_exit;
  1435. }
  1436. } /* else ... BB we could add the same check for Windows by
  1437. checking the UniqueId via FILE_INTERNAL_INFO */
  1438. unlink_target:
  1439. /* Try unlinking the target dentry if it's not negative */
  1440. if (target_dentry->d_inode && (rc == -EACCES || rc == -EEXIST)) {
  1441. tmprc = cifs_unlink(target_dir, target_dentry);
  1442. if (tmprc)
  1443. goto cifs_rename_exit;
  1444. rc = cifs_do_rename(xid, source_dentry, fromName,
  1445. target_dentry, toName);
  1446. }
  1447. cifs_rename_exit:
  1448. kfree(info_buf_source);
  1449. kfree(fromName);
  1450. kfree(toName);
  1451. FreeXid(xid);
  1452. cifs_put_tlink(tlink);
  1453. return rc;
  1454. }
  1455. static bool
  1456. cifs_inode_needs_reval(struct inode *inode)
  1457. {
  1458. struct cifsInodeInfo *cifs_i = CIFS_I(inode);
  1459. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1460. if (cifs_i->clientCanCacheRead)
  1461. return false;
  1462. if (!lookupCacheEnabled)
  1463. return true;
  1464. if (cifs_i->time == 0)
  1465. return true;
  1466. if (!time_in_range(jiffies, cifs_i->time,
  1467. cifs_i->time + cifs_sb->actimeo))
  1468. return true;
  1469. /* hardlinked files w/ noserverino get "special" treatment */
  1470. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) &&
  1471. S_ISREG(inode->i_mode) && inode->i_nlink != 1)
  1472. return true;
  1473. return false;
  1474. }
  1475. /*
  1476. * Zap the cache. Called when invalid_mapping flag is set.
  1477. */
  1478. void
  1479. cifs_invalidate_mapping(struct inode *inode)
  1480. {
  1481. int rc;
  1482. struct cifsInodeInfo *cifs_i = CIFS_I(inode);
  1483. cifs_i->invalid_mapping = false;
  1484. /* write back any cached data */
  1485. if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
  1486. rc = filemap_write_and_wait(inode->i_mapping);
  1487. mapping_set_error(inode->i_mapping, rc);
  1488. }
  1489. invalidate_remote_inode(inode);
  1490. cifs_fscache_reset_inode_cookie(inode);
  1491. }
  1492. int cifs_revalidate_file(struct file *filp)
  1493. {
  1494. int rc = 0;
  1495. struct inode *inode = filp->f_path.dentry->d_inode;
  1496. struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data;
  1497. if (!cifs_inode_needs_reval(inode))
  1498. goto check_inval;
  1499. if (tlink_tcon(cfile->tlink)->unix_ext)
  1500. rc = cifs_get_file_info_unix(filp);
  1501. else
  1502. rc = cifs_get_file_info(filp);
  1503. check_inval:
  1504. if (CIFS_I(inode)->invalid_mapping)
  1505. cifs_invalidate_mapping(inode);
  1506. return rc;
  1507. }
  1508. /* revalidate a dentry's inode attributes */
  1509. int cifs_revalidate_dentry(struct dentry *dentry)
  1510. {
  1511. int xid;
  1512. int rc = 0;
  1513. char *full_path = NULL;
  1514. struct inode *inode = dentry->d_inode;
  1515. struct super_block *sb = dentry->d_sb;
  1516. if (inode == NULL)
  1517. return -ENOENT;
  1518. xid = GetXid();
  1519. if (!cifs_inode_needs_reval(inode))
  1520. goto check_inval;
  1521. /* can not safely grab the rename sem here if rename calls revalidate
  1522. since that would deadlock */
  1523. full_path = build_path_from_dentry(dentry);
  1524. if (full_path == NULL) {
  1525. rc = -ENOMEM;
  1526. goto check_inval;
  1527. }
  1528. cFYI(1, "Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
  1529. "jiffies %ld", full_path, inode, inode->i_count.counter,
  1530. dentry, dentry->d_time, jiffies);
  1531. if (cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext)
  1532. rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
  1533. else
  1534. rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
  1535. xid, NULL);
  1536. check_inval:
  1537. if (CIFS_I(inode)->invalid_mapping)
  1538. cifs_invalidate_mapping(inode);
  1539. kfree(full_path);
  1540. FreeXid(xid);
  1541. return rc;
  1542. }
  1543. int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1544. struct kstat *stat)
  1545. {
  1546. struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
  1547. struct cifsTconInfo *tcon = cifs_sb_master_tcon(cifs_sb);
  1548. int err = cifs_revalidate_dentry(dentry);
  1549. if (!err) {
  1550. generic_fillattr(dentry->d_inode, stat);
  1551. stat->blksize = CIFS_MAX_MSGSIZE;
  1552. stat->ino = CIFS_I(dentry->d_inode)->uniqueid;
  1553. /*
  1554. * If on a multiuser mount without unix extensions, and the
  1555. * admin hasn't overridden them, set the ownership to the
  1556. * fsuid/fsgid of the current process.
  1557. */
  1558. if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) &&
  1559. !tcon->unix_ext) {
  1560. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID))
  1561. stat->uid = current_fsuid();
  1562. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID))
  1563. stat->gid = current_fsgid();
  1564. }
  1565. }
  1566. return err;
  1567. }
  1568. static int cifs_truncate_page(struct address_space *mapping, loff_t from)
  1569. {
  1570. pgoff_t index = from >> PAGE_CACHE_SHIFT;
  1571. unsigned offset = from & (PAGE_CACHE_SIZE - 1);
  1572. struct page *page;
  1573. int rc = 0;
  1574. page = grab_cache_page(mapping, index);
  1575. if (!page)
  1576. return -ENOMEM;
  1577. zero_user_segment(page, offset, PAGE_CACHE_SIZE);
  1578. unlock_page(page);
  1579. page_cache_release(page);
  1580. return rc;
  1581. }
  1582. static void cifs_setsize(struct inode *inode, loff_t offset)
  1583. {
  1584. loff_t oldsize;
  1585. spin_lock(&inode->i_lock);
  1586. oldsize = inode->i_size;
  1587. i_size_write(inode, offset);
  1588. spin_unlock(&inode->i_lock);
  1589. truncate_pagecache(inode, oldsize, offset);
  1590. }
  1591. static int
  1592. cifs_set_file_size(struct inode *inode, struct iattr *attrs,
  1593. int xid, char *full_path)
  1594. {
  1595. int rc;
  1596. struct cifsFileInfo *open_file;
  1597. struct cifsInodeInfo *cifsInode = CIFS_I(inode);
  1598. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1599. struct tcon_link *tlink = NULL;
  1600. struct cifsTconInfo *pTcon = NULL;
  1601. /*
  1602. * To avoid spurious oplock breaks from server, in the case of
  1603. * inodes that we already have open, avoid doing path based
  1604. * setting of file size if we can do it by handle.
  1605. * This keeps our caching token (oplock) and avoids timeouts
  1606. * when the local oplock break takes longer to flush
  1607. * writebehind data than the SMB timeout for the SetPathInfo
  1608. * request would allow
  1609. */
  1610. open_file = find_writable_file(cifsInode, true);
  1611. if (open_file) {
  1612. __u16 nfid = open_file->netfid;
  1613. __u32 npid = open_file->pid;
  1614. pTcon = tlink_tcon(open_file->tlink);
  1615. rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid,
  1616. npid, false);
  1617. cifsFileInfo_put(open_file);
  1618. cFYI(1, "SetFSize for attrs rc = %d", rc);
  1619. if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
  1620. unsigned int bytes_written;
  1621. rc = CIFSSMBWrite(xid, pTcon, nfid, 0, attrs->ia_size,
  1622. &bytes_written, NULL, NULL, 1);
  1623. cFYI(1, "Wrt seteof rc %d", rc);
  1624. }
  1625. } else
  1626. rc = -EINVAL;
  1627. if (rc != 0) {
  1628. if (pTcon == NULL) {
  1629. tlink = cifs_sb_tlink(cifs_sb);
  1630. if (IS_ERR(tlink))
  1631. return PTR_ERR(tlink);
  1632. pTcon = tlink_tcon(tlink);
  1633. }
  1634. /* Set file size by pathname rather than by handle
  1635. either because no valid, writeable file handle for
  1636. it was found or because there was an error setting
  1637. it by handle */
  1638. rc = CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size,
  1639. false, cifs_sb->local_nls,
  1640. cifs_sb->mnt_cifs_flags &
  1641. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1642. cFYI(1, "SetEOF by path (setattrs) rc = %d", rc);
  1643. if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
  1644. __u16 netfid;
  1645. int oplock = 0;
  1646. rc = SMBLegacyOpen(xid, pTcon, full_path,
  1647. FILE_OPEN, GENERIC_WRITE,
  1648. CREATE_NOT_DIR, &netfid, &oplock, NULL,
  1649. cifs_sb->local_nls,
  1650. cifs_sb->mnt_cifs_flags &
  1651. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1652. if (rc == 0) {
  1653. unsigned int bytes_written;
  1654. rc = CIFSSMBWrite(xid, pTcon, netfid, 0,
  1655. attrs->ia_size,
  1656. &bytes_written, NULL,
  1657. NULL, 1);
  1658. cFYI(1, "wrt seteof rc %d", rc);
  1659. CIFSSMBClose(xid, pTcon, netfid);
  1660. }
  1661. }
  1662. if (tlink)
  1663. cifs_put_tlink(tlink);
  1664. }
  1665. if (rc == 0) {
  1666. cifsInode->server_eof = attrs->ia_size;
  1667. cifs_setsize(inode, attrs->ia_size);
  1668. cifs_truncate_page(inode->i_mapping, inode->i_size);
  1669. }
  1670. return rc;
  1671. }
  1672. static int
  1673. cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
  1674. {
  1675. int rc;
  1676. int xid;
  1677. char *full_path = NULL;
  1678. struct inode *inode = direntry->d_inode;
  1679. struct cifsInodeInfo *cifsInode = CIFS_I(inode);
  1680. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1681. struct tcon_link *tlink;
  1682. struct cifsTconInfo *pTcon;
  1683. struct cifs_unix_set_info_args *args = NULL;
  1684. struct cifsFileInfo *open_file;
  1685. cFYI(1, "setattr_unix on file %s attrs->ia_valid=0x%x",
  1686. direntry->d_name.name, attrs->ia_valid);
  1687. xid = GetXid();
  1688. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
  1689. attrs->ia_valid |= ATTR_FORCE;
  1690. rc = inode_change_ok(inode, attrs);
  1691. if (rc < 0)
  1692. goto out;
  1693. full_path = build_path_from_dentry(direntry);
  1694. if (full_path == NULL) {
  1695. rc = -ENOMEM;
  1696. goto out;
  1697. }
  1698. /*
  1699. * Attempt to flush data before changing attributes. We need to do
  1700. * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the
  1701. * ownership or mode then we may also need to do this. Here, we take
  1702. * the safe way out and just do the flush on all setattr requests. If
  1703. * the flush returns error, store it to report later and continue.
  1704. *
  1705. * BB: This should be smarter. Why bother flushing pages that
  1706. * will be truncated anyway? Also, should we error out here if
  1707. * the flush returns error?
  1708. */
  1709. rc = filemap_write_and_wait(inode->i_mapping);
  1710. mapping_set_error(inode->i_mapping, rc);
  1711. rc = 0;
  1712. if (attrs->ia_valid & ATTR_SIZE) {
  1713. rc = cifs_set_file_size(inode, attrs, xid, full_path);
  1714. if (rc != 0)
  1715. goto out;
  1716. }
  1717. /* skip mode change if it's just for clearing setuid/setgid */
  1718. if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
  1719. attrs->ia_valid &= ~ATTR_MODE;
  1720. args = kmalloc(sizeof(*args), GFP_KERNEL);
  1721. if (args == NULL) {
  1722. rc = -ENOMEM;
  1723. goto out;
  1724. }
  1725. /* set up the struct */
  1726. if (attrs->ia_valid & ATTR_MODE)
  1727. args->mode = attrs->ia_mode;
  1728. else
  1729. args->mode = NO_CHANGE_64;
  1730. if (attrs->ia_valid & ATTR_UID)
  1731. args->uid = attrs->ia_uid;
  1732. else
  1733. args->uid = NO_CHANGE_64;
  1734. if (attrs->ia_valid & ATTR_GID)
  1735. args->gid = attrs->ia_gid;
  1736. else
  1737. args->gid = NO_CHANGE_64;
  1738. if (attrs->ia_valid & ATTR_ATIME)
  1739. args->atime = cifs_UnixTimeToNT(attrs->ia_atime);
  1740. else
  1741. args->atime = NO_CHANGE_64;
  1742. if (attrs->ia_valid & ATTR_MTIME)
  1743. args->mtime = cifs_UnixTimeToNT(attrs->ia_mtime);
  1744. else
  1745. args->mtime = NO_CHANGE_64;
  1746. if (attrs->ia_valid & ATTR_CTIME)
  1747. args->ctime = cifs_UnixTimeToNT(attrs->ia_ctime);
  1748. else
  1749. args->ctime = NO_CHANGE_64;
  1750. args->device = 0;
  1751. open_file = find_writable_file(cifsInode, true);
  1752. if (open_file) {
  1753. u16 nfid = open_file->netfid;
  1754. u32 npid = open_file->pid;
  1755. pTcon = tlink_tcon(open_file->tlink);
  1756. rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid);
  1757. cifsFileInfo_put(open_file);
  1758. } else {
  1759. tlink = cifs_sb_tlink(cifs_sb);
  1760. if (IS_ERR(tlink)) {
  1761. rc = PTR_ERR(tlink);
  1762. goto out;
  1763. }
  1764. pTcon = tlink_tcon(tlink);
  1765. rc = CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, args,
  1766. cifs_sb->local_nls,
  1767. cifs_sb->mnt_cifs_flags &
  1768. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1769. cifs_put_tlink(tlink);
  1770. }
  1771. if (rc)
  1772. goto out;
  1773. if ((attrs->ia_valid & ATTR_SIZE) &&
  1774. attrs->ia_size != i_size_read(inode))
  1775. truncate_setsize(inode, attrs->ia_size);
  1776. setattr_copy(inode, attrs);
  1777. mark_inode_dirty(inode);
  1778. /* force revalidate when any of these times are set since some
  1779. of the fs types (eg ext3, fat) do not have fine enough
  1780. time granularity to match protocol, and we do not have a
  1781. a way (yet) to query the server fs's time granularity (and
  1782. whether it rounds times down).
  1783. */
  1784. if (attrs->ia_valid & (ATTR_MTIME | ATTR_CTIME))
  1785. cifsInode->time = 0;
  1786. out:
  1787. kfree(args);
  1788. kfree(full_path);
  1789. FreeXid(xid);
  1790. return rc;
  1791. }
  1792. static int
  1793. cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
  1794. {
  1795. int xid;
  1796. struct inode *inode = direntry->d_inode;
  1797. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1798. struct cifsInodeInfo *cifsInode = CIFS_I(inode);
  1799. char *full_path = NULL;
  1800. int rc = -EACCES;
  1801. __u32 dosattr = 0;
  1802. __u64 mode = NO_CHANGE_64;
  1803. xid = GetXid();
  1804. cFYI(1, "setattr on file %s attrs->iavalid 0x%x",
  1805. direntry->d_name.name, attrs->ia_valid);
  1806. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
  1807. attrs->ia_valid |= ATTR_FORCE;
  1808. rc = inode_change_ok(inode, attrs);
  1809. if (rc < 0) {
  1810. FreeXid(xid);
  1811. return rc;
  1812. }
  1813. full_path = build_path_from_dentry(direntry);
  1814. if (full_path == NULL) {
  1815. rc = -ENOMEM;
  1816. FreeXid(xid);
  1817. return rc;
  1818. }
  1819. /*
  1820. * Attempt to flush data before changing attributes. We need to do
  1821. * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the
  1822. * ownership or mode then we may also need to do this. Here, we take
  1823. * the safe way out and just do the flush on all setattr requests. If
  1824. * the flush returns error, store it to report later and continue.
  1825. *
  1826. * BB: This should be smarter. Why bother flushing pages that
  1827. * will be truncated anyway? Also, should we error out here if
  1828. * the flush returns error?
  1829. */
  1830. rc = filemap_write_and_wait(inode->i_mapping);
  1831. mapping_set_error(inode->i_mapping, rc);
  1832. rc = 0;
  1833. if (attrs->ia_valid & ATTR_SIZE) {
  1834. rc = cifs_set_file_size(inode, attrs, xid, full_path);
  1835. if (rc != 0)
  1836. goto cifs_setattr_exit;
  1837. }
  1838. /*
  1839. * Without unix extensions we can't send ownership changes to the
  1840. * server, so silently ignore them. This is consistent with how
  1841. * local DOS/Windows filesystems behave (VFAT, NTFS, etc). With
  1842. * CIFSACL support + proper Windows to Unix idmapping, we may be
  1843. * able to support this in the future.
  1844. */
  1845. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID))
  1846. attrs->ia_valid &= ~(ATTR_UID | ATTR_GID);
  1847. /* skip mode change if it's just for clearing setuid/setgid */
  1848. if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
  1849. attrs->ia_valid &= ~ATTR_MODE;
  1850. if (attrs->ia_valid & ATTR_MODE) {
  1851. cFYI(1, "Mode changed to 0%o", attrs->ia_mode);
  1852. mode = attrs->ia_mode;
  1853. }
  1854. if (attrs->ia_valid & ATTR_MODE) {
  1855. rc = 0;
  1856. #ifdef CONFIG_CIFS_ACL
  1857. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
  1858. rc = mode_to_cifs_acl(inode, full_path, mode);
  1859. if (rc) {
  1860. cFYI(1, "%s: Setting ACL failed with error: %d",
  1861. __func__, rc);
  1862. goto cifs_setattr_exit;
  1863. }
  1864. } else
  1865. #endif /* CONFIG_CIFS_ACL */
  1866. if (((mode & S_IWUGO) == 0) &&
  1867. (cifsInode->cifsAttrs & ATTR_READONLY) == 0) {
  1868. dosattr = cifsInode->cifsAttrs | ATTR_READONLY;
  1869. /* fix up mode if we're not using dynperm */
  1870. if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) == 0)
  1871. attrs->ia_mode = inode->i_mode & ~S_IWUGO;
  1872. } else if ((mode & S_IWUGO) &&
  1873. (cifsInode->cifsAttrs & ATTR_READONLY)) {
  1874. dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY;
  1875. /* Attributes of 0 are ignored */
  1876. if (dosattr == 0)
  1877. dosattr |= ATTR_NORMAL;
  1878. /* reset local inode permissions to normal */
  1879. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)) {
  1880. attrs->ia_mode &= ~(S_IALLUGO);
  1881. if (S_ISDIR(inode->i_mode))
  1882. attrs->ia_mode |=
  1883. cifs_sb->mnt_dir_mode;
  1884. else
  1885. attrs->ia_mode |=
  1886. cifs_sb->mnt_file_mode;
  1887. }
  1888. } else if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)) {
  1889. /* ignore mode change - ATTR_READONLY hasn't changed */
  1890. attrs->ia_valid &= ~ATTR_MODE;
  1891. }
  1892. }
  1893. if (attrs->ia_valid & (ATTR_MTIME|ATTR_ATIME|ATTR_CTIME) ||
  1894. ((attrs->ia_valid & ATTR_MODE) && dosattr)) {
  1895. rc = cifs_set_file_info(inode, attrs, xid, full_path, dosattr);
  1896. /* BB: check for rc = -EOPNOTSUPP and switch to legacy mode */
  1897. /* Even if error on time set, no sense failing the call if
  1898. the server would set the time to a reasonable value anyway,
  1899. and this check ensures that we are not being called from
  1900. sys_utimes in which case we ought to fail the call back to
  1901. the user when the server rejects the call */
  1902. if ((rc) && (attrs->ia_valid &
  1903. (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE)))
  1904. rc = 0;
  1905. }
  1906. /* do not need local check to inode_check_ok since the server does
  1907. that */
  1908. if (rc)
  1909. goto cifs_setattr_exit;
  1910. if ((attrs->ia_valid & ATTR_SIZE) &&
  1911. attrs->ia_size != i_size_read(inode))
  1912. truncate_setsize(inode, attrs->ia_size);
  1913. setattr_copy(inode, attrs);
  1914. mark_inode_dirty(inode);
  1915. cifs_setattr_exit:
  1916. kfree(full_path);
  1917. FreeXid(xid);
  1918. return rc;
  1919. }
  1920. int
  1921. cifs_setattr(struct dentry *direntry, struct iattr *attrs)
  1922. {
  1923. struct inode *inode = direntry->d_inode;
  1924. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1925. struct cifsTconInfo *pTcon = cifs_sb_master_tcon(cifs_sb);
  1926. if (pTcon->unix_ext)
  1927. return cifs_setattr_unix(direntry, attrs);
  1928. return cifs_setattr_nounix(direntry, attrs);
  1929. /* BB: add cifs_setattr_legacy for really old servers */
  1930. }
  1931. #if 0
  1932. void cifs_delete_inode(struct inode *inode)
  1933. {
  1934. cFYI(1, "In cifs_delete_inode, inode = 0x%p", inode);
  1935. /* may have to add back in if and when safe distributed caching of
  1936. directories added e.g. via FindNotify */
  1937. }
  1938. #endif