inode.c 59 KB

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