inode.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. /*
  2. * fs/cifs/inode.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2005
  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/buffer_head.h>
  23. #include <linux/stat.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. int cifs_get_inode_info_unix(struct inode **pinode,
  33. const unsigned char *search_path, struct super_block *sb, int xid)
  34. {
  35. int rc = 0;
  36. FILE_UNIX_BASIC_INFO findData;
  37. struct cifsTconInfo *pTcon;
  38. struct inode *inode;
  39. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  40. char *tmp_path;
  41. pTcon = cifs_sb->tcon;
  42. cFYI(1, (" Getting info on %s ", search_path));
  43. /* could have done a find first instead but this returns more info */
  44. rc = CIFSSMBUnixQPathInfo(xid, pTcon, search_path, &findData,
  45. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  46. CIFS_MOUNT_MAP_SPECIAL_CHR);
  47. /* dump_mem("\nUnixQPathInfo return data", &findData,
  48. sizeof(findData)); */
  49. if (rc) {
  50. if (rc == -EREMOTE) {
  51. tmp_path =
  52. kmalloc(strnlen(pTcon->treeName,
  53. MAX_TREE_SIZE + 1) +
  54. strnlen(search_path, MAX_PATHCONF) + 1,
  55. GFP_KERNEL);
  56. if (tmp_path == NULL) {
  57. return -ENOMEM;
  58. }
  59. /* have to skip first of the double backslash of
  60. UNC name */
  61. strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
  62. strncat(tmp_path, search_path, MAX_PATHCONF);
  63. rc = connect_to_dfs_path(xid, pTcon->ses,
  64. /* treename + */ tmp_path,
  65. cifs_sb->local_nls,
  66. cifs_sb->mnt_cifs_flags &
  67. CIFS_MOUNT_MAP_SPECIAL_CHR);
  68. kfree(tmp_path);
  69. /* BB fix up inode etc. */
  70. } else if (rc) {
  71. return rc;
  72. }
  73. } else {
  74. struct cifsInodeInfo *cifsInfo;
  75. __u32 type = le32_to_cpu(findData.Type);
  76. __u64 num_of_bytes = le64_to_cpu(findData.NumOfBytes);
  77. __u64 end_of_file = le64_to_cpu(findData.EndOfFile);
  78. /* get new inode */
  79. if (*pinode == NULL) {
  80. *pinode = new_inode(sb);
  81. if (*pinode == NULL)
  82. return -ENOMEM;
  83. /* Is an i_ino of zero legal? */
  84. /* Are there sanity checks we can use to ensure that
  85. the server is really filling in that field? */
  86. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
  87. (*pinode)->i_ino =
  88. (unsigned long)findData.UniqueId;
  89. } /* note ino incremented to unique num in new_inode */
  90. insert_inode_hash(*pinode);
  91. }
  92. inode = *pinode;
  93. cifsInfo = CIFS_I(inode);
  94. cFYI(1, (" Old time %ld ", cifsInfo->time));
  95. cifsInfo->time = jiffies;
  96. cFYI(1, (" New time %ld ", cifsInfo->time));
  97. /* this is ok to set on every inode revalidate */
  98. atomic_set(&cifsInfo->inUse,1);
  99. inode->i_atime =
  100. cifs_NTtimeToUnix(le64_to_cpu(findData.LastAccessTime));
  101. inode->i_mtime =
  102. cifs_NTtimeToUnix(le64_to_cpu
  103. (findData.LastModificationTime));
  104. inode->i_ctime =
  105. cifs_NTtimeToUnix(le64_to_cpu(findData.LastStatusChange));
  106. inode->i_mode = le64_to_cpu(findData.Permissions);
  107. if (type == UNIX_FILE) {
  108. inode->i_mode |= S_IFREG;
  109. } else if (type == UNIX_SYMLINK) {
  110. inode->i_mode |= S_IFLNK;
  111. } else if (type == UNIX_DIR) {
  112. inode->i_mode |= S_IFDIR;
  113. } else if (type == UNIX_CHARDEV) {
  114. inode->i_mode |= S_IFCHR;
  115. inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
  116. le64_to_cpu(findData.DevMinor) & MINORMASK);
  117. } else if (type == UNIX_BLOCKDEV) {
  118. inode->i_mode |= S_IFBLK;
  119. inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
  120. le64_to_cpu(findData.DevMinor) & MINORMASK);
  121. } else if (type == UNIX_FIFO) {
  122. inode->i_mode |= S_IFIFO;
  123. } else if (type == UNIX_SOCKET) {
  124. inode->i_mode |= S_IFSOCK;
  125. }
  126. inode->i_uid = le64_to_cpu(findData.Uid);
  127. inode->i_gid = le64_to_cpu(findData.Gid);
  128. inode->i_nlink = le64_to_cpu(findData.Nlinks);
  129. if (is_size_safe_to_change(cifsInfo)) {
  130. /* can not safely change the file size here if the
  131. client is writing to it due to potential races */
  132. i_size_write(inode, end_of_file);
  133. /* blksize needs to be multiple of two. So safer to default to
  134. blksize and blkbits set in superblock so 2**blkbits and blksize
  135. will match rather than setting to:
  136. (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
  137. /* This seems incredibly stupid but it turns out that i_blocks
  138. is not related to (i_size / i_blksize), instead 512 byte size
  139. is required for calculating num blocks */
  140. /* 512 bytes (2**9) is the fake blocksize that must be used */
  141. /* for this calculation */
  142. inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
  143. }
  144. if (num_of_bytes < end_of_file)
  145. cFYI(1, ("allocation size less than end of file "));
  146. cFYI(1,
  147. ("Size %ld and blocks %ld",
  148. (unsigned long) inode->i_size, inode->i_blocks));
  149. if (S_ISREG(inode->i_mode)) {
  150. cFYI(1, (" File inode "));
  151. inode->i_op = &cifs_file_inode_ops;
  152. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
  153. inode->i_fop = &cifs_file_direct_ops;
  154. else
  155. inode->i_fop = &cifs_file_ops;
  156. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  157. inode->i_fop->lock = NULL;
  158. inode->i_data.a_ops = &cifs_addr_ops;
  159. /* check if server can support readpages */
  160. if(pTcon->ses->server->maxBuf <
  161. 4096 + MAX_CIFS_HDR_SIZE)
  162. inode->i_data.a_ops->readpages = NULL;
  163. } else if (S_ISDIR(inode->i_mode)) {
  164. cFYI(1, (" Directory inode"));
  165. inode->i_op = &cifs_dir_inode_ops;
  166. inode->i_fop = &cifs_dir_ops;
  167. } else if (S_ISLNK(inode->i_mode)) {
  168. cFYI(1, (" Symbolic Link inode "));
  169. inode->i_op = &cifs_symlink_inode_ops;
  170. /* tmp_inode->i_fop = */ /* do not need to set to anything */
  171. } else {
  172. cFYI(1, (" Init special inode "));
  173. init_special_inode(inode, inode->i_mode,
  174. inode->i_rdev);
  175. }
  176. }
  177. return rc;
  178. }
  179. int cifs_get_inode_info(struct inode **pinode,
  180. const unsigned char *search_path, FILE_ALL_INFO *pfindData,
  181. struct super_block *sb, int xid)
  182. {
  183. int rc = 0;
  184. struct cifsTconInfo *pTcon;
  185. struct inode *inode;
  186. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  187. char *tmp_path;
  188. char *buf = NULL;
  189. pTcon = cifs_sb->tcon;
  190. cFYI(1,("Getting info on %s ", search_path));
  191. if ((pfindData == NULL) && (*pinode != NULL)) {
  192. if (CIFS_I(*pinode)->clientCanCacheRead) {
  193. cFYI(1,("No need to revalidate cached inode sizes"));
  194. return rc;
  195. }
  196. }
  197. /* if file info not passed in then get it from server */
  198. if (pfindData == NULL) {
  199. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  200. if (buf == NULL)
  201. return -ENOMEM;
  202. pfindData = (FILE_ALL_INFO *)buf;
  203. /* could do find first instead but this returns more info */
  204. rc = CIFSSMBQPathInfo(xid, pTcon, search_path, pfindData,
  205. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  206. CIFS_MOUNT_MAP_SPECIAL_CHR);
  207. /* BB optimize code so we do not make the above call
  208. when server claims no NT SMB support and the above call
  209. failed at least once - set flag in tcon or mount */
  210. if((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
  211. rc = SMBQueryInformation(xid, pTcon, search_path,
  212. pfindData, cifs_sb->local_nls,
  213. cifs_sb->mnt_cifs_flags &
  214. CIFS_MOUNT_MAP_SPECIAL_CHR);
  215. }
  216. }
  217. /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
  218. if (rc) {
  219. if (rc == -EREMOTE) {
  220. tmp_path =
  221. kmalloc(strnlen
  222. (pTcon->treeName,
  223. MAX_TREE_SIZE + 1) +
  224. strnlen(search_path, MAX_PATHCONF) + 1,
  225. GFP_KERNEL);
  226. if (tmp_path == NULL) {
  227. kfree(buf);
  228. return -ENOMEM;
  229. }
  230. strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
  231. strncat(tmp_path, search_path, MAX_PATHCONF);
  232. rc = connect_to_dfs_path(xid, pTcon->ses,
  233. /* treename + */ tmp_path,
  234. cifs_sb->local_nls,
  235. cifs_sb->mnt_cifs_flags &
  236. CIFS_MOUNT_MAP_SPECIAL_CHR);
  237. kfree(tmp_path);
  238. /* BB fix up inode etc. */
  239. } else if (rc) {
  240. kfree(buf);
  241. return rc;
  242. }
  243. } else {
  244. struct cifsInodeInfo *cifsInfo;
  245. __u32 attr = le32_to_cpu(pfindData->Attributes);
  246. /* get new inode */
  247. if (*pinode == NULL) {
  248. *pinode = new_inode(sb);
  249. if (*pinode == NULL)
  250. return -ENOMEM;
  251. /* Is an i_ino of zero legal? Can we use that to check
  252. if the server supports returning inode numbers? Are
  253. there other sanity checks we can use to ensure that
  254. the server is really filling in that field? */
  255. /* We can not use the IndexNumber field by default from
  256. Windows or Samba (in ALL_INFO buf) but we can request
  257. it explicitly. It may not be unique presumably if
  258. the server has multiple devices mounted under one
  259. share */
  260. /* There may be higher info levels that work but are
  261. there Windows server or network appliances for which
  262. IndexNumber field is not guaranteed unique? */
  263. #ifdef CONFIG_CIFS_EXPERIMENTAL
  264. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM){
  265. int rc1 = 0;
  266. __u64 inode_num;
  267. rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
  268. search_path, &inode_num,
  269. cifs_sb->local_nls,
  270. cifs_sb->mnt_cifs_flags &
  271. CIFS_MOUNT_MAP_SPECIAL_CHR);
  272. if (rc1) {
  273. cFYI(1,("GetSrvInodeNum rc %d", rc1));
  274. /* BB EOPNOSUPP disable SERVER_INUM? */
  275. } else /* do we need cast or hash to ino? */
  276. (*pinode)->i_ino = inode_num;
  277. } /* else ino incremented to unique num in new_inode*/
  278. #endif /* CIFS_EXPERIMENTAL */
  279. insert_inode_hash(*pinode);
  280. }
  281. inode = *pinode;
  282. cifsInfo = CIFS_I(inode);
  283. cifsInfo->cifsAttrs = attr;
  284. cFYI(1, (" Old time %ld ", cifsInfo->time));
  285. cifsInfo->time = jiffies;
  286. cFYI(1, (" New time %ld ", cifsInfo->time));
  287. /* blksize needs to be multiple of two. So safer to default to
  288. blksize and blkbits set in superblock so 2**blkbits and blksize
  289. will match rather than setting to:
  290. (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
  291. /* Linux can not store file creation time unfortunately so we ignore it */
  292. inode->i_atime =
  293. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime));
  294. inode->i_mtime =
  295. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
  296. inode->i_ctime =
  297. cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
  298. cFYI(0, (" Attributes came in as 0x%x ", attr));
  299. /* set default mode. will override for dirs below */
  300. if (atomic_read(&cifsInfo->inUse) == 0)
  301. /* new inode, can safely set these fields */
  302. inode->i_mode = cifs_sb->mnt_file_mode;
  303. /* if (attr & ATTR_REPARSE) */
  304. /* We no longer handle these as symlinks because we could not
  305. follow them due to the absolute path with drive letter */
  306. if (attr & ATTR_DIRECTORY) {
  307. /* override default perms since we do not do byte range locking
  308. on dirs */
  309. inode->i_mode = cifs_sb->mnt_dir_mode;
  310. inode->i_mode |= S_IFDIR;
  311. } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
  312. (cifsInfo->cifsAttrs & ATTR_SYSTEM) &&
  313. /* No need to le64 convert size of zero */
  314. (pfindData->EndOfFile == 0)) {
  315. inode->i_mode = cifs_sb->mnt_file_mode;
  316. inode->i_mode |= S_IFIFO;
  317. /* BB Finish for SFU style symlinks and devies */
  318. /* } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
  319. (cifsInfo->cifsAttrs & ATTR_SYSTEM) && ) */
  320. } else {
  321. inode->i_mode |= S_IFREG;
  322. /* treat the dos attribute of read-only as read-only
  323. mode e.g. 555 */
  324. if (cifsInfo->cifsAttrs & ATTR_READONLY)
  325. inode->i_mode &= ~(S_IWUGO);
  326. /* BB add code here -
  327. validate if device or weird share or device type? */
  328. }
  329. if (is_size_safe_to_change(cifsInfo)) {
  330. /* can not safely change the file size here if the
  331. client is writing to it due to potential races */
  332. i_size_write(inode,le64_to_cpu(pfindData->EndOfFile));
  333. /* 512 bytes (2**9) is the fake blocksize that must be
  334. used for this calculation */
  335. inode->i_blocks = (512 - 1 + le64_to_cpu(
  336. pfindData->AllocationSize)) >> 9;
  337. }
  338. inode->i_nlink = le32_to_cpu(pfindData->NumberOfLinks);
  339. /* BB fill in uid and gid here? with help from winbind?
  340. or retrieve from NTFS stream extended attribute */
  341. if (atomic_read(&cifsInfo->inUse) == 0) {
  342. inode->i_uid = cifs_sb->mnt_uid;
  343. inode->i_gid = cifs_sb->mnt_gid;
  344. /* set so we do not keep refreshing these fields with
  345. bad data after user has changed them in memory */
  346. atomic_set(&cifsInfo->inUse,1);
  347. }
  348. if (S_ISREG(inode->i_mode)) {
  349. cFYI(1, (" File inode "));
  350. inode->i_op = &cifs_file_inode_ops;
  351. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
  352. inode->i_fop = &cifs_file_direct_ops;
  353. else
  354. inode->i_fop = &cifs_file_ops;
  355. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  356. inode->i_fop->lock = NULL;
  357. inode->i_data.a_ops = &cifs_addr_ops;
  358. if(pTcon->ses->server->maxBuf <
  359. 4096 + MAX_CIFS_HDR_SIZE)
  360. inode->i_data.a_ops->readpages = NULL;
  361. } else if (S_ISDIR(inode->i_mode)) {
  362. cFYI(1, (" Directory inode "));
  363. inode->i_op = &cifs_dir_inode_ops;
  364. inode->i_fop = &cifs_dir_ops;
  365. } else if (S_ISLNK(inode->i_mode)) {
  366. cFYI(1, (" Symbolic Link inode "));
  367. inode->i_op = &cifs_symlink_inode_ops;
  368. } else {
  369. init_special_inode(inode, inode->i_mode,
  370. inode->i_rdev);
  371. }
  372. }
  373. kfree(buf);
  374. return rc;
  375. }
  376. /* gets root inode */
  377. void cifs_read_inode(struct inode *inode)
  378. {
  379. int xid;
  380. struct cifs_sb_info *cifs_sb;
  381. cifs_sb = CIFS_SB(inode->i_sb);
  382. xid = GetXid();
  383. if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
  384. cifs_get_inode_info_unix(&inode, "", inode->i_sb,xid);
  385. else
  386. cifs_get_inode_info(&inode, "", NULL, inode->i_sb,xid);
  387. /* can not call macro FreeXid here since in a void func */
  388. _FreeXid(xid);
  389. }
  390. int cifs_unlink(struct inode *inode, struct dentry *direntry)
  391. {
  392. int rc = 0;
  393. int xid;
  394. struct cifs_sb_info *cifs_sb;
  395. struct cifsTconInfo *pTcon;
  396. char *full_path = NULL;
  397. struct cifsInodeInfo *cifsInode;
  398. FILE_BASIC_INFO *pinfo_buf;
  399. cFYI(1, (" cifs_unlink, inode = 0x%p with ", inode));
  400. xid = GetXid();
  401. cifs_sb = CIFS_SB(inode->i_sb);
  402. pTcon = cifs_sb->tcon;
  403. /* Unlink can be called from rename so we can not grab the sem here
  404. since we deadlock otherwise */
  405. /* down(&direntry->d_sb->s_vfs_rename_sem);*/
  406. full_path = build_path_from_dentry(direntry);
  407. /* up(&direntry->d_sb->s_vfs_rename_sem);*/
  408. if (full_path == NULL) {
  409. FreeXid(xid);
  410. return -ENOMEM;
  411. }
  412. rc = CIFSSMBDelFile(xid, pTcon, full_path, cifs_sb->local_nls,
  413. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  414. if (!rc) {
  415. if (direntry->d_inode)
  416. direntry->d_inode->i_nlink--;
  417. } else if (rc == -ENOENT) {
  418. d_drop(direntry);
  419. } else if (rc == -ETXTBSY) {
  420. int oplock = FALSE;
  421. __u16 netfid;
  422. rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, DELETE,
  423. CREATE_NOT_DIR | CREATE_DELETE_ON_CLOSE,
  424. &netfid, &oplock, NULL, cifs_sb->local_nls,
  425. cifs_sb->mnt_cifs_flags &
  426. CIFS_MOUNT_MAP_SPECIAL_CHR);
  427. if (rc==0) {
  428. CIFSSMBRenameOpenFile(xid, pTcon, netfid, NULL,
  429. cifs_sb->local_nls,
  430. cifs_sb->mnt_cifs_flags &
  431. CIFS_MOUNT_MAP_SPECIAL_CHR);
  432. CIFSSMBClose(xid, pTcon, netfid);
  433. if (direntry->d_inode)
  434. direntry->d_inode->i_nlink--;
  435. }
  436. } else if (rc == -EACCES) {
  437. /* try only if r/o attribute set in local lookup data? */
  438. pinfo_buf = kmalloc(sizeof(FILE_BASIC_INFO), GFP_KERNEL);
  439. if (pinfo_buf) {
  440. memset(pinfo_buf, 0, sizeof(FILE_BASIC_INFO));
  441. /* ATTRS set to normal clears r/o bit */
  442. pinfo_buf->Attributes = cpu_to_le32(ATTR_NORMAL);
  443. if (!(pTcon->ses->flags & CIFS_SES_NT4))
  444. rc = CIFSSMBSetTimes(xid, pTcon, full_path,
  445. pinfo_buf,
  446. cifs_sb->local_nls,
  447. cifs_sb->mnt_cifs_flags &
  448. CIFS_MOUNT_MAP_SPECIAL_CHR);
  449. else
  450. rc = -EOPNOTSUPP;
  451. if (rc == -EOPNOTSUPP) {
  452. int oplock = FALSE;
  453. __u16 netfid;
  454. /* rc = CIFSSMBSetAttrLegacy(xid, pTcon,
  455. full_path,
  456. (__u16)ATTR_NORMAL,
  457. cifs_sb->local_nls);
  458. For some strange reason it seems that NT4 eats the
  459. old setattr call without actually setting the
  460. attributes so on to the third attempted workaround
  461. */
  462. /* BB could scan to see if we already have it open
  463. and pass in pid of opener to function */
  464. rc = CIFSSMBOpen(xid, pTcon, full_path,
  465. FILE_OPEN, SYNCHRONIZE |
  466. FILE_WRITE_ATTRIBUTES, 0,
  467. &netfid, &oplock, NULL,
  468. cifs_sb->local_nls,
  469. cifs_sb->mnt_cifs_flags &
  470. CIFS_MOUNT_MAP_SPECIAL_CHR);
  471. if (rc==0) {
  472. rc = CIFSSMBSetFileTimes(xid, pTcon,
  473. pinfo_buf,
  474. netfid);
  475. CIFSSMBClose(xid, pTcon, netfid);
  476. }
  477. }
  478. kfree(pinfo_buf);
  479. }
  480. if (rc==0) {
  481. rc = CIFSSMBDelFile(xid, pTcon, full_path,
  482. cifs_sb->local_nls,
  483. cifs_sb->mnt_cifs_flags &
  484. CIFS_MOUNT_MAP_SPECIAL_CHR);
  485. if (!rc) {
  486. if (direntry->d_inode)
  487. direntry->d_inode->i_nlink--;
  488. } else if (rc == -ETXTBSY) {
  489. int oplock = FALSE;
  490. __u16 netfid;
  491. rc = CIFSSMBOpen(xid, pTcon, full_path,
  492. FILE_OPEN, DELETE,
  493. CREATE_NOT_DIR |
  494. CREATE_DELETE_ON_CLOSE,
  495. &netfid, &oplock, NULL,
  496. cifs_sb->local_nls,
  497. cifs_sb->mnt_cifs_flags &
  498. CIFS_MOUNT_MAP_SPECIAL_CHR);
  499. if (rc==0) {
  500. CIFSSMBRenameOpenFile(xid, pTcon,
  501. netfid, NULL,
  502. cifs_sb->local_nls,
  503. cifs_sb->mnt_cifs_flags &
  504. CIFS_MOUNT_MAP_SPECIAL_CHR);
  505. CIFSSMBClose(xid, pTcon, netfid);
  506. if (direntry->d_inode)
  507. direntry->d_inode->i_nlink--;
  508. }
  509. /* BB if rc = -ETXTBUSY goto the rename logic BB */
  510. }
  511. }
  512. }
  513. if (direntry->d_inode) {
  514. cifsInode = CIFS_I(direntry->d_inode);
  515. cifsInode->time = 0; /* will force revalidate to get info
  516. when needed */
  517. direntry->d_inode->i_ctime = current_fs_time(inode->i_sb);
  518. }
  519. inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);
  520. cifsInode = CIFS_I(inode);
  521. cifsInode->time = 0; /* force revalidate of dir as well */
  522. kfree(full_path);
  523. FreeXid(xid);
  524. return rc;
  525. }
  526. int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
  527. {
  528. int rc = 0;
  529. int xid;
  530. struct cifs_sb_info *cifs_sb;
  531. struct cifsTconInfo *pTcon;
  532. char *full_path = NULL;
  533. struct inode *newinode = NULL;
  534. cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p ", mode, inode));
  535. xid = GetXid();
  536. cifs_sb = CIFS_SB(inode->i_sb);
  537. pTcon = cifs_sb->tcon;
  538. down(&inode->i_sb->s_vfs_rename_sem);
  539. full_path = build_path_from_dentry(direntry);
  540. up(&inode->i_sb->s_vfs_rename_sem);
  541. if (full_path == NULL) {
  542. FreeXid(xid);
  543. return -ENOMEM;
  544. }
  545. /* BB add setting the equivalent of mode via CreateX w/ACLs */
  546. rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
  547. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  548. if (rc) {
  549. cFYI(1, ("cifs_mkdir returned 0x%x ", rc));
  550. d_drop(direntry);
  551. } else {
  552. inode->i_nlink++;
  553. if (pTcon->ses->capabilities & CAP_UNIX)
  554. rc = cifs_get_inode_info_unix(&newinode, full_path,
  555. inode->i_sb,xid);
  556. else
  557. rc = cifs_get_inode_info(&newinode, full_path, NULL,
  558. inode->i_sb,xid);
  559. if (pTcon->nocase)
  560. direntry->d_op = &cifs_ci_dentry_ops;
  561. else
  562. direntry->d_op = &cifs_dentry_ops;
  563. d_instantiate(direntry, newinode);
  564. if (direntry->d_inode)
  565. direntry->d_inode->i_nlink = 2;
  566. if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
  567. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  568. CIFSSMBUnixSetPerms(xid, pTcon, full_path,
  569. mode,
  570. (__u64)current->euid,
  571. (__u64)current->egid,
  572. 0 /* dev_t */,
  573. cifs_sb->local_nls,
  574. cifs_sb->mnt_cifs_flags &
  575. CIFS_MOUNT_MAP_SPECIAL_CHR);
  576. } else {
  577. CIFSSMBUnixSetPerms(xid, pTcon, full_path,
  578. mode, (__u64)-1,
  579. (__u64)-1, 0 /* dev_t */,
  580. cifs_sb->local_nls,
  581. cifs_sb->mnt_cifs_flags &
  582. CIFS_MOUNT_MAP_SPECIAL_CHR);
  583. }
  584. else {
  585. /* BB to be implemented via Windows secrty descriptors
  586. eg CIFSSMBWinSetPerms(xid, pTcon, full_path, mode,
  587. -1, -1, local_nls); */
  588. }
  589. }
  590. kfree(full_path);
  591. FreeXid(xid);
  592. return rc;
  593. }
  594. int cifs_rmdir(struct inode *inode, struct dentry *direntry)
  595. {
  596. int rc = 0;
  597. int xid;
  598. struct cifs_sb_info *cifs_sb;
  599. struct cifsTconInfo *pTcon;
  600. char *full_path = NULL;
  601. struct cifsInodeInfo *cifsInode;
  602. cFYI(1, (" cifs_rmdir, inode = 0x%p with ", inode));
  603. xid = GetXid();
  604. cifs_sb = CIFS_SB(inode->i_sb);
  605. pTcon = cifs_sb->tcon;
  606. down(&inode->i_sb->s_vfs_rename_sem);
  607. full_path = build_path_from_dentry(direntry);
  608. up(&inode->i_sb->s_vfs_rename_sem);
  609. if (full_path == NULL) {
  610. FreeXid(xid);
  611. return -ENOMEM;
  612. }
  613. rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
  614. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  615. if (!rc) {
  616. inode->i_nlink--;
  617. i_size_write(direntry->d_inode,0);
  618. direntry->d_inode->i_nlink = 0;
  619. }
  620. cifsInode = CIFS_I(direntry->d_inode);
  621. cifsInode->time = 0; /* force revalidate to go get info when
  622. needed */
  623. direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
  624. current_fs_time(inode->i_sb);
  625. kfree(full_path);
  626. FreeXid(xid);
  627. return rc;
  628. }
  629. int cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
  630. struct inode *target_inode, struct dentry *target_direntry)
  631. {
  632. char *fromName;
  633. char *toName;
  634. struct cifs_sb_info *cifs_sb_source;
  635. struct cifs_sb_info *cifs_sb_target;
  636. struct cifsTconInfo *pTcon;
  637. int xid;
  638. int rc = 0;
  639. xid = GetXid();
  640. cifs_sb_target = CIFS_SB(target_inode->i_sb);
  641. cifs_sb_source = CIFS_SB(source_inode->i_sb);
  642. pTcon = cifs_sb_source->tcon;
  643. if (pTcon != cifs_sb_target->tcon) {
  644. FreeXid(xid);
  645. return -EXDEV; /* BB actually could be allowed if same server,
  646. but different share.
  647. Might eventually add support for this */
  648. }
  649. /* we already have the rename sem so we do not need to grab it again
  650. here to protect the path integrity */
  651. fromName = build_path_from_dentry(source_direntry);
  652. toName = build_path_from_dentry(target_direntry);
  653. if ((fromName == NULL) || (toName == NULL)) {
  654. rc = -ENOMEM;
  655. goto cifs_rename_exit;
  656. }
  657. rc = CIFSSMBRename(xid, pTcon, fromName, toName,
  658. cifs_sb_source->local_nls,
  659. cifs_sb_source->mnt_cifs_flags &
  660. CIFS_MOUNT_MAP_SPECIAL_CHR);
  661. if (rc == -EEXIST) {
  662. /* check if they are the same file because rename of hardlinked
  663. files is a noop */
  664. FILE_UNIX_BASIC_INFO *info_buf_source;
  665. FILE_UNIX_BASIC_INFO *info_buf_target;
  666. info_buf_source =
  667. kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
  668. if (info_buf_source != NULL) {
  669. info_buf_target = info_buf_source + 1;
  670. rc = CIFSSMBUnixQPathInfo(xid, pTcon, fromName,
  671. info_buf_source, cifs_sb_source->local_nls,
  672. cifs_sb_source->mnt_cifs_flags &
  673. CIFS_MOUNT_MAP_SPECIAL_CHR);
  674. if (rc == 0) {
  675. rc = CIFSSMBUnixQPathInfo(xid, pTcon, toName,
  676. info_buf_target,
  677. cifs_sb_target->local_nls,
  678. /* remap based on source sb */
  679. cifs_sb_source->mnt_cifs_flags &
  680. CIFS_MOUNT_MAP_SPECIAL_CHR);
  681. }
  682. if ((rc == 0) &&
  683. (info_buf_source->UniqueId ==
  684. info_buf_target->UniqueId)) {
  685. /* do not rename since the files are hardlinked which
  686. is a noop */
  687. } else {
  688. /* we either can not tell the files are hardlinked
  689. (as with Windows servers) or files are not
  690. hardlinked so delete the target manually before
  691. renaming to follow POSIX rather than Windows
  692. semantics */
  693. cifs_unlink(target_inode, target_direntry);
  694. rc = CIFSSMBRename(xid, pTcon, fromName,
  695. toName,
  696. cifs_sb_source->local_nls,
  697. cifs_sb_source->mnt_cifs_flags
  698. & CIFS_MOUNT_MAP_SPECIAL_CHR);
  699. }
  700. kfree(info_buf_source);
  701. } /* if we can not get memory just leave rc as EEXIST */
  702. }
  703. if (rc) {
  704. cFYI(1, ("rename rc %d", rc));
  705. }
  706. if ((rc == -EIO) || (rc == -EEXIST)) {
  707. int oplock = FALSE;
  708. __u16 netfid;
  709. /* BB FIXME Is Generic Read correct for rename? */
  710. /* if renaming directory - we should not say CREATE_NOT_DIR,
  711. need to test renaming open directory, also GENERIC_READ
  712. might not right be right access to request */
  713. rc = CIFSSMBOpen(xid, pTcon, fromName, FILE_OPEN, GENERIC_READ,
  714. CREATE_NOT_DIR, &netfid, &oplock, NULL,
  715. cifs_sb_source->local_nls,
  716. cifs_sb_source->mnt_cifs_flags &
  717. CIFS_MOUNT_MAP_SPECIAL_CHR);
  718. if (rc==0) {
  719. CIFSSMBRenameOpenFile(xid, pTcon, netfid, toName,
  720. cifs_sb_source->local_nls,
  721. cifs_sb_source->mnt_cifs_flags &
  722. CIFS_MOUNT_MAP_SPECIAL_CHR);
  723. CIFSSMBClose(xid, pTcon, netfid);
  724. }
  725. }
  726. cifs_rename_exit:
  727. kfree(fromName);
  728. kfree(toName);
  729. FreeXid(xid);
  730. return rc;
  731. }
  732. int cifs_revalidate(struct dentry *direntry)
  733. {
  734. int xid;
  735. int rc = 0;
  736. char *full_path;
  737. struct cifs_sb_info *cifs_sb;
  738. struct cifsInodeInfo *cifsInode;
  739. loff_t local_size;
  740. struct timespec local_mtime;
  741. int invalidate_inode = FALSE;
  742. if (direntry->d_inode == NULL)
  743. return -ENOENT;
  744. cifsInode = CIFS_I(direntry->d_inode);
  745. if (cifsInode == NULL)
  746. return -ENOENT;
  747. /* no sense revalidating inode info on file that no one can write */
  748. if (CIFS_I(direntry->d_inode)->clientCanCacheRead)
  749. return rc;
  750. xid = GetXid();
  751. cifs_sb = CIFS_SB(direntry->d_sb);
  752. /* can not safely grab the rename sem here if rename calls revalidate
  753. since that would deadlock */
  754. full_path = build_path_from_dentry(direntry);
  755. if (full_path == NULL) {
  756. FreeXid(xid);
  757. return -ENOMEM;
  758. }
  759. cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
  760. "jiffies %ld", full_path, direntry->d_inode,
  761. direntry->d_inode->i_count.counter, direntry,
  762. direntry->d_time, jiffies));
  763. if (cifsInode->time == 0) {
  764. /* was set to zero previously to force revalidate */
  765. } else if (time_before(jiffies, cifsInode->time + HZ) &&
  766. lookupCacheEnabled) {
  767. if ((S_ISREG(direntry->d_inode->i_mode) == 0) ||
  768. (direntry->d_inode->i_nlink == 1)) {
  769. kfree(full_path);
  770. FreeXid(xid);
  771. return rc;
  772. } else {
  773. cFYI(1, ("Have to revalidate file due to hardlinks"));
  774. }
  775. }
  776. /* save mtime and size */
  777. local_mtime = direntry->d_inode->i_mtime;
  778. local_size = direntry->d_inode->i_size;
  779. if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
  780. rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path,
  781. direntry->d_sb,xid);
  782. if (rc) {
  783. cFYI(1, ("error on getting revalidate info %d", rc));
  784. /* if (rc != -ENOENT)
  785. rc = 0; */ /* BB should we cache info on
  786. certain errors? */
  787. }
  788. } else {
  789. rc = cifs_get_inode_info(&direntry->d_inode, full_path, NULL,
  790. direntry->d_sb,xid);
  791. if (rc) {
  792. cFYI(1, ("error on getting revalidate info %d", rc));
  793. /* if (rc != -ENOENT)
  794. rc = 0; */ /* BB should we cache info on
  795. certain errors? */
  796. }
  797. }
  798. /* should we remap certain errors, access denied?, to zero */
  799. /* if not oplocked, we invalidate inode pages if mtime or file size
  800. had changed on server */
  801. if (timespec_equal(&local_mtime,&direntry->d_inode->i_mtime) &&
  802. (local_size == direntry->d_inode->i_size)) {
  803. cFYI(1, ("cifs_revalidate - inode unchanged"));
  804. } else {
  805. /* file may have changed on server */
  806. if (cifsInode->clientCanCacheRead) {
  807. /* no need to invalidate inode pages since we were the
  808. only ones who could have modified the file and the
  809. server copy is staler than ours */
  810. } else {
  811. invalidate_inode = TRUE;
  812. }
  813. }
  814. /* can not grab this sem since kernel filesys locking documentation
  815. indicates i_sem may be taken by the kernel on lookup and rename
  816. which could deadlock if we grab the i_sem here as well */
  817. /* down(&direntry->d_inode->i_sem);*/
  818. /* need to write out dirty pages here */
  819. if (direntry->d_inode->i_mapping) {
  820. /* do we need to lock inode until after invalidate completes
  821. below? */
  822. filemap_fdatawrite(direntry->d_inode->i_mapping);
  823. }
  824. if (invalidate_inode) {
  825. if (direntry->d_inode->i_mapping)
  826. filemap_fdatawait(direntry->d_inode->i_mapping);
  827. /* may eventually have to do this for open files too */
  828. if (list_empty(&(cifsInode->openFileList))) {
  829. /* Has changed on server - flush read ahead pages */
  830. cFYI(1, ("Invalidating read ahead data on "
  831. "closed file"));
  832. invalidate_remote_inode(direntry->d_inode);
  833. }
  834. }
  835. /* up(&direntry->d_inode->i_sem); */
  836. kfree(full_path);
  837. FreeXid(xid);
  838. return rc;
  839. }
  840. int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  841. struct kstat *stat)
  842. {
  843. int err = cifs_revalidate(dentry);
  844. if (!err)
  845. generic_fillattr(dentry->d_inode, stat);
  846. return err;
  847. }
  848. static int cifs_truncate_page(struct address_space *mapping, loff_t from)
  849. {
  850. pgoff_t index = from >> PAGE_CACHE_SHIFT;
  851. unsigned offset = from & (PAGE_CACHE_SIZE - 1);
  852. struct page *page;
  853. char *kaddr;
  854. int rc = 0;
  855. page = grab_cache_page(mapping, index);
  856. if (!page)
  857. return -ENOMEM;
  858. kaddr = kmap_atomic(page, KM_USER0);
  859. memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
  860. flush_dcache_page(page);
  861. kunmap_atomic(kaddr, KM_USER0);
  862. unlock_page(page);
  863. page_cache_release(page);
  864. return rc;
  865. }
  866. int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
  867. {
  868. int xid;
  869. struct cifs_sb_info *cifs_sb;
  870. struct cifsTconInfo *pTcon;
  871. char *full_path = NULL;
  872. int rc = -EACCES;
  873. struct cifsFileInfo *open_file = NULL;
  874. FILE_BASIC_INFO time_buf;
  875. int set_time = FALSE;
  876. __u64 mode = 0xFFFFFFFFFFFFFFFFULL;
  877. __u64 uid = 0xFFFFFFFFFFFFFFFFULL;
  878. __u64 gid = 0xFFFFFFFFFFFFFFFFULL;
  879. struct cifsInodeInfo *cifsInode;
  880. xid = GetXid();
  881. cFYI(1, (" In cifs_setattr, name = %s attrs->iavalid 0x%x ",
  882. direntry->d_name.name, attrs->ia_valid));
  883. cifs_sb = CIFS_SB(direntry->d_inode->i_sb);
  884. pTcon = cifs_sb->tcon;
  885. down(&direntry->d_sb->s_vfs_rename_sem);
  886. full_path = build_path_from_dentry(direntry);
  887. up(&direntry->d_sb->s_vfs_rename_sem);
  888. if (full_path == NULL) {
  889. FreeXid(xid);
  890. return -ENOMEM;
  891. }
  892. cifsInode = CIFS_I(direntry->d_inode);
  893. /* BB check if we need to refresh inode from server now ? BB */
  894. /* need to flush data before changing file size on server */
  895. filemap_fdatawrite(direntry->d_inode->i_mapping);
  896. filemap_fdatawait(direntry->d_inode->i_mapping);
  897. if (attrs->ia_valid & ATTR_SIZE) {
  898. /* To avoid spurious oplock breaks from server, in the case of
  899. inodes that we already have open, avoid doing path based
  900. setting of file size if we can do it by handle.
  901. This keeps our caching token (oplock) and avoids timeouts
  902. when the local oplock break takes longer to flush
  903. writebehind data than the SMB timeout for the SetPathInfo
  904. request would allow */
  905. open_file = find_writable_file(cifsInode);
  906. if (open_file) {
  907. __u16 nfid = open_file->netfid;
  908. __u32 npid = open_file->pid;
  909. rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size,
  910. nfid, npid, FALSE);
  911. atomic_dec(&open_file->wrtPending);
  912. cFYI(1,("SetFSize for attrs rc = %d", rc));
  913. if(rc == -EINVAL) {
  914. int bytes_written;
  915. rc = CIFSSMBWrite(xid, pTcon,
  916. nfid, 0, attrs->ia_size,
  917. &bytes_written, NULL, NULL,
  918. 1 /* 45 seconds */);
  919. cFYI(1,("Wrt seteof rc %d", rc));
  920. }
  921. }
  922. if (rc != 0) {
  923. /* Set file size by pathname rather than by handle
  924. either because no valid, writeable file handle for
  925. it was found or because there was an error setting
  926. it by handle */
  927. rc = CIFSSMBSetEOF(xid, pTcon, full_path,
  928. attrs->ia_size, FALSE,
  929. cifs_sb->local_nls,
  930. cifs_sb->mnt_cifs_flags &
  931. CIFS_MOUNT_MAP_SPECIAL_CHR);
  932. cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc));
  933. if(rc == -EINVAL) {
  934. __u16 netfid;
  935. int oplock = FALSE;
  936. rc = SMBLegacyOpen(xid, pTcon, full_path,
  937. FILE_OPEN,
  938. SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
  939. CREATE_NOT_DIR, &netfid, &oplock,
  940. NULL, cifs_sb->local_nls,
  941. cifs_sb->mnt_cifs_flags &
  942. CIFS_MOUNT_MAP_SPECIAL_CHR);
  943. if (rc==0) {
  944. int bytes_written;
  945. rc = CIFSSMBWrite(xid, pTcon,
  946. netfid, 0,
  947. attrs->ia_size,
  948. &bytes_written, NULL,
  949. NULL, 1 /* 45 sec */);
  950. cFYI(1,("wrt seteof rc %d",rc));
  951. CIFSSMBClose(xid, pTcon, netfid);
  952. }
  953. }
  954. }
  955. /* Server is ok setting allocation size implicitly - no need
  956. to call:
  957. CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE,
  958. cifs_sb->local_nls);
  959. */
  960. if (rc == 0) {
  961. rc = vmtruncate(direntry->d_inode, attrs->ia_size);
  962. cifs_truncate_page(direntry->d_inode->i_mapping,
  963. direntry->d_inode->i_size);
  964. } else
  965. goto cifs_setattr_exit;
  966. }
  967. if (attrs->ia_valid & ATTR_UID) {
  968. cFYI(1, ("UID changed to %d", attrs->ia_uid));
  969. uid = attrs->ia_uid;
  970. }
  971. if (attrs->ia_valid & ATTR_GID) {
  972. cFYI(1, ("GID changed to %d", attrs->ia_gid));
  973. gid = attrs->ia_gid;
  974. }
  975. time_buf.Attributes = 0;
  976. if (attrs->ia_valid & ATTR_MODE) {
  977. cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode));
  978. mode = attrs->ia_mode;
  979. }
  980. if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX)
  981. && (attrs->ia_valid & (ATTR_MODE | ATTR_GID | ATTR_UID)))
  982. rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, uid, gid,
  983. 0 /* dev_t */, cifs_sb->local_nls,
  984. cifs_sb->mnt_cifs_flags &
  985. CIFS_MOUNT_MAP_SPECIAL_CHR);
  986. else if (attrs->ia_valid & ATTR_MODE) {
  987. if ((mode & S_IWUGO) == 0) /* not writeable */ {
  988. if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0)
  989. time_buf.Attributes =
  990. cpu_to_le32(cifsInode->cifsAttrs |
  991. ATTR_READONLY);
  992. } else if ((mode & S_IWUGO) == S_IWUGO) {
  993. if (cifsInode->cifsAttrs & ATTR_READONLY)
  994. time_buf.Attributes =
  995. cpu_to_le32(cifsInode->cifsAttrs &
  996. (~ATTR_READONLY));
  997. }
  998. /* BB to be implemented -
  999. via Windows security descriptors or streams */
  1000. /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, uid, gid,
  1001. cifs_sb->local_nls); */
  1002. }
  1003. if (attrs->ia_valid & ATTR_ATIME) {
  1004. set_time = TRUE;
  1005. time_buf.LastAccessTime =
  1006. cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
  1007. } else
  1008. time_buf.LastAccessTime = 0;
  1009. if (attrs->ia_valid & ATTR_MTIME) {
  1010. set_time = TRUE;
  1011. time_buf.LastWriteTime =
  1012. cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
  1013. } else
  1014. time_buf.LastWriteTime = 0;
  1015. /* Do not set ctime explicitly unless other time
  1016. stamps are changed explicitly (i.e. by utime()
  1017. since we would then have a mix of client and
  1018. server times */
  1019. if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
  1020. set_time = TRUE;
  1021. /* Although Samba throws this field away
  1022. it may be useful to Windows - but we do
  1023. not want to set ctime unless some other
  1024. timestamp is changing */
  1025. cFYI(1, ("CIFS - CTIME changed "));
  1026. time_buf.ChangeTime =
  1027. cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
  1028. } else
  1029. time_buf.ChangeTime = 0;
  1030. if (set_time || time_buf.Attributes) {
  1031. time_buf.CreationTime = 0; /* do not change */
  1032. /* In the future we should experiment - try setting timestamps
  1033. via Handle (SetFileInfo) instead of by path */
  1034. if (!(pTcon->ses->flags & CIFS_SES_NT4))
  1035. rc = CIFSSMBSetTimes(xid, pTcon, full_path, &time_buf,
  1036. cifs_sb->local_nls,
  1037. cifs_sb->mnt_cifs_flags &
  1038. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1039. else
  1040. rc = -EOPNOTSUPP;
  1041. if (rc == -EOPNOTSUPP) {
  1042. int oplock = FALSE;
  1043. __u16 netfid;
  1044. cFYI(1, ("calling SetFileInfo since SetPathInfo for "
  1045. "times not supported by this server"));
  1046. /* BB we could scan to see if we already have it open
  1047. and pass in pid of opener to function */
  1048. rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
  1049. SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
  1050. CREATE_NOT_DIR, &netfid, &oplock,
  1051. NULL, cifs_sb->local_nls,
  1052. cifs_sb->mnt_cifs_flags &
  1053. CIFS_MOUNT_MAP_SPECIAL_CHR);
  1054. if (rc==0) {
  1055. rc = CIFSSMBSetFileTimes(xid, pTcon, &time_buf,
  1056. netfid);
  1057. CIFSSMBClose(xid, pTcon, netfid);
  1058. } else {
  1059. /* BB For even older servers we could convert time_buf
  1060. into old DOS style which uses two second
  1061. granularity */
  1062. /* rc = CIFSSMBSetTimesLegacy(xid, pTcon, full_path,
  1063. &time_buf, cifs_sb->local_nls); */
  1064. }
  1065. }
  1066. /* Even if error on time set, no sense failing the call if
  1067. the server would set the time to a reasonable value anyway,
  1068. and this check ensures that we are not being called from
  1069. sys_utimes in which case we ought to fail the call back to
  1070. the user when the server rejects the call */
  1071. if((rc) && (attrs->ia_valid &&
  1072. (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE)))
  1073. rc = 0;
  1074. }
  1075. /* do not need local check to inode_check_ok since the server does
  1076. that */
  1077. if (!rc)
  1078. rc = inode_setattr(direntry->d_inode, attrs);
  1079. cifs_setattr_exit:
  1080. kfree(full_path);
  1081. FreeXid(xid);
  1082. return rc;
  1083. }
  1084. void cifs_delete_inode(struct inode *inode)
  1085. {
  1086. cFYI(1, ("In cifs_delete_inode, inode = 0x%p ", inode));
  1087. /* may have to add back in if and when safe distributed caching of
  1088. directories added e.g. via FindNotify */
  1089. }