inode.c 59 KB

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