inode.c 59 KB

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