inode.c 34 KB

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