inode.c 59 KB

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