dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Directory operations for Coda filesystem
  3. * Original version: (C) 1996 P. Braam and M. Callahan
  4. * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
  5. *
  6. * Carnegie Mellon encourages users to contribute improvements to
  7. * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
  8. */
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/time.h>
  12. #include <linux/fs.h>
  13. #include <linux/file.h>
  14. #include <linux/stat.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/smp_lock.h>
  18. #include <asm/uaccess.h>
  19. #include <linux/coda.h>
  20. #include <linux/coda_linux.h>
  21. #include <linux/coda_psdev.h>
  22. #include <linux/coda_fs_i.h>
  23. #include <linux/coda_cache.h>
  24. #include <linux/coda_proc.h>
  25. #include "coda_int.h"
  26. /* dir inode-ops */
  27. static int coda_create(struct inode *dir, struct dentry *new, int mode, struct nameidata *nd);
  28. static struct dentry *coda_lookup(struct inode *dir, struct dentry *target, struct nameidata *nd);
  29. static int coda_link(struct dentry *old_dentry, struct inode *dir_inode,
  30. struct dentry *entry);
  31. static int coda_unlink(struct inode *dir_inode, struct dentry *entry);
  32. static int coda_symlink(struct inode *dir_inode, struct dentry *entry,
  33. const char *symname);
  34. static int coda_mkdir(struct inode *dir_inode, struct dentry *entry, int mode);
  35. static int coda_rmdir(struct inode *dir_inode, struct dentry *entry);
  36. static int coda_rename(struct inode *old_inode, struct dentry *old_dentry,
  37. struct inode *new_inode, struct dentry *new_dentry);
  38. /* dir file-ops */
  39. static int coda_readdir(struct file *file, void *dirent, filldir_t filldir);
  40. /* dentry ops */
  41. static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd);
  42. static int coda_dentry_delete(struct dentry *);
  43. /* support routines */
  44. static int coda_venus_readdir(struct file *filp, filldir_t filldir,
  45. void *dirent, struct dentry *dir);
  46. /* same as fs/bad_inode.c */
  47. static int coda_return_EIO(void)
  48. {
  49. return -EIO;
  50. }
  51. #define CODA_EIO_ERROR ((void *) (coda_return_EIO))
  52. static struct dentry_operations coda_dentry_operations =
  53. {
  54. .d_revalidate = coda_dentry_revalidate,
  55. .d_delete = coda_dentry_delete,
  56. };
  57. const struct inode_operations coda_dir_inode_operations =
  58. {
  59. .create = coda_create,
  60. .lookup = coda_lookup,
  61. .link = coda_link,
  62. .unlink = coda_unlink,
  63. .symlink = coda_symlink,
  64. .mkdir = coda_mkdir,
  65. .rmdir = coda_rmdir,
  66. .mknod = CODA_EIO_ERROR,
  67. .rename = coda_rename,
  68. .permission = coda_permission,
  69. .getattr = coda_getattr,
  70. .setattr = coda_setattr,
  71. };
  72. const struct file_operations coda_dir_operations = {
  73. .llseek = generic_file_llseek,
  74. .read = generic_read_dir,
  75. .readdir = coda_readdir,
  76. .open = coda_open,
  77. .flush = coda_flush,
  78. .release = coda_release,
  79. .fsync = coda_fsync,
  80. };
  81. /* inode operations for directories */
  82. /* access routines: lookup, readlink, permission */
  83. static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, struct nameidata *nd)
  84. {
  85. struct inode *res_inode = NULL;
  86. struct CodaFid resfid = { { 0, } };
  87. int dropme = 0; /* to indicate entry should not be cached */
  88. int type = 0;
  89. int error = 0;
  90. const char *name = entry->d_name.name;
  91. size_t length = entry->d_name.len;
  92. if ( length > CODA_MAXNAMLEN ) {
  93. printk("name too long: lookup, %s (%*s)\n",
  94. coda_i2s(dir), (int)length, name);
  95. return ERR_PTR(-ENAMETOOLONG);
  96. }
  97. lock_kernel();
  98. /* control object, create inode on the fly */
  99. if (coda_isroot(dir) && coda_iscontrol(name, length)) {
  100. error = coda_cnode_makectl(&res_inode, dir->i_sb);
  101. dropme = 1;
  102. goto exit;
  103. }
  104. error = venus_lookup(dir->i_sb, coda_i2f(dir),
  105. (const char *)name, length, &type, &resfid);
  106. res_inode = NULL;
  107. if (!error) {
  108. if (type & CODA_NOCACHE) {
  109. type &= (~CODA_NOCACHE);
  110. dropme = 1;
  111. }
  112. error = coda_cnode_make(&res_inode, &resfid, dir->i_sb);
  113. if (error) {
  114. unlock_kernel();
  115. return ERR_PTR(error);
  116. }
  117. } else if (error != -ENOENT) {
  118. unlock_kernel();
  119. return ERR_PTR(error);
  120. }
  121. exit:
  122. entry->d_time = 0;
  123. entry->d_op = &coda_dentry_operations;
  124. d_add(entry, res_inode);
  125. if ( dropme ) {
  126. d_drop(entry);
  127. coda_flag_inode(res_inode, C_VATTR);
  128. }
  129. unlock_kernel();
  130. return NULL;
  131. }
  132. int coda_permission(struct inode *inode, int mask, struct nameidata *nd)
  133. {
  134. int error = 0;
  135. if (!mask)
  136. return 0;
  137. lock_kernel();
  138. coda_vfs_stat.permission++;
  139. if (coda_cache_check(inode, mask))
  140. goto out;
  141. error = venus_access(inode->i_sb, coda_i2f(inode), mask);
  142. if (!error)
  143. coda_cache_enter(inode, mask);
  144. out:
  145. unlock_kernel();
  146. return error;
  147. }
  148. static inline void coda_dir_update_mtime(struct inode *dir)
  149. {
  150. #ifdef REQUERY_VENUS_FOR_MTIME
  151. /* invalidate the directory cnode's attributes so we refetch the
  152. * attributes from venus next time the inode is referenced */
  153. coda_flag_inode(dir, C_VATTR);
  154. #else
  155. /* optimistically we can also act as if our nose bleeds. The
  156. * granularity of the mtime is coarse anyways so we might actually be
  157. * right most of the time. Note: we only do this for directories. */
  158. dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
  159. #endif
  160. }
  161. /* we have to wrap inc_nlink/drop_nlink because sometimes userspace uses a
  162. * trick to fool GNU find's optimizations. If we can't be sure of the link
  163. * (because of volume mount points) we set i_nlink to 1 which forces find
  164. * to consider every child as a possible directory. We should also never
  165. * see an increment or decrement for deleted directories where i_nlink == 0 */
  166. static inline void coda_dir_inc_nlink(struct inode *dir)
  167. {
  168. if (dir->i_nlink >= 2)
  169. inc_nlink(dir);
  170. }
  171. static inline void coda_dir_drop_nlink(struct inode *dir)
  172. {
  173. if (dir->i_nlink > 2)
  174. drop_nlink(dir);
  175. }
  176. /* creation routines: create, mknod, mkdir, link, symlink */
  177. static int coda_create(struct inode *dir, struct dentry *de, int mode, struct nameidata *nd)
  178. {
  179. int error=0;
  180. const char *name=de->d_name.name;
  181. int length=de->d_name.len;
  182. struct inode *inode;
  183. struct CodaFid newfid;
  184. struct coda_vattr attrs;
  185. lock_kernel();
  186. coda_vfs_stat.create++;
  187. if (coda_isroot(dir) && coda_iscontrol(name, length)) {
  188. unlock_kernel();
  189. return -EPERM;
  190. }
  191. error = venus_create(dir->i_sb, coda_i2f(dir), name, length,
  192. 0, mode, &newfid, &attrs);
  193. if ( error ) {
  194. unlock_kernel();
  195. d_drop(de);
  196. return error;
  197. }
  198. inode = coda_iget(dir->i_sb, &newfid, &attrs);
  199. if ( IS_ERR(inode) ) {
  200. unlock_kernel();
  201. d_drop(de);
  202. return PTR_ERR(inode);
  203. }
  204. /* invalidate the directory cnode's attributes */
  205. coda_dir_update_mtime(dir);
  206. unlock_kernel();
  207. d_instantiate(de, inode);
  208. return 0;
  209. }
  210. static int coda_mkdir(struct inode *dir, struct dentry *de, int mode)
  211. {
  212. struct inode *inode;
  213. struct coda_vattr attrs;
  214. const char *name = de->d_name.name;
  215. int len = de->d_name.len;
  216. int error;
  217. struct CodaFid newfid;
  218. lock_kernel();
  219. coda_vfs_stat.mkdir++;
  220. if (coda_isroot(dir) && coda_iscontrol(name, len)) {
  221. unlock_kernel();
  222. return -EPERM;
  223. }
  224. attrs.va_mode = mode;
  225. error = venus_mkdir(dir->i_sb, coda_i2f(dir),
  226. name, len, &newfid, &attrs);
  227. if ( error ) {
  228. unlock_kernel();
  229. d_drop(de);
  230. return error;
  231. }
  232. inode = coda_iget(dir->i_sb, &newfid, &attrs);
  233. if ( IS_ERR(inode) ) {
  234. unlock_kernel();
  235. d_drop(de);
  236. return PTR_ERR(inode);
  237. }
  238. /* invalidate the directory cnode's attributes */
  239. coda_dir_inc_nlink(dir);
  240. coda_dir_update_mtime(dir);
  241. unlock_kernel();
  242. d_instantiate(de, inode);
  243. return 0;
  244. }
  245. /* try to make de an entry in dir_inodde linked to source_de */
  246. static int coda_link(struct dentry *source_de, struct inode *dir_inode,
  247. struct dentry *de)
  248. {
  249. struct inode *inode = source_de->d_inode;
  250. const char * name = de->d_name.name;
  251. int len = de->d_name.len;
  252. int error;
  253. lock_kernel();
  254. coda_vfs_stat.link++;
  255. if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) {
  256. unlock_kernel();
  257. return -EPERM;
  258. }
  259. error = venus_link(dir_inode->i_sb, coda_i2f(inode),
  260. coda_i2f(dir_inode), (const char *)name, len);
  261. if (error) {
  262. d_drop(de);
  263. goto out;
  264. }
  265. coda_dir_update_mtime(dir_inode);
  266. atomic_inc(&inode->i_count);
  267. d_instantiate(de, inode);
  268. inc_nlink(inode);
  269. out:
  270. unlock_kernel();
  271. return(error);
  272. }
  273. static int coda_symlink(struct inode *dir_inode, struct dentry *de,
  274. const char *symname)
  275. {
  276. const char *name = de->d_name.name;
  277. int len = de->d_name.len;
  278. int symlen;
  279. int error=0;
  280. lock_kernel();
  281. coda_vfs_stat.symlink++;
  282. if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) {
  283. unlock_kernel();
  284. return -EPERM;
  285. }
  286. symlen = strlen(symname);
  287. if ( symlen > CODA_MAXPATHLEN ) {
  288. unlock_kernel();
  289. return -ENAMETOOLONG;
  290. }
  291. /*
  292. * This entry is now negative. Since we do not create
  293. * an inode for the entry we have to drop it.
  294. */
  295. d_drop(de);
  296. error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len,
  297. symname, symlen);
  298. /* mtime is no good anymore */
  299. if ( !error )
  300. coda_dir_update_mtime(dir_inode);
  301. unlock_kernel();
  302. return error;
  303. }
  304. /* destruction routines: unlink, rmdir */
  305. int coda_unlink(struct inode *dir, struct dentry *de)
  306. {
  307. int error;
  308. const char *name = de->d_name.name;
  309. int len = de->d_name.len;
  310. lock_kernel();
  311. coda_vfs_stat.unlink++;
  312. error = venus_remove(dir->i_sb, coda_i2f(dir), name, len);
  313. if ( error ) {
  314. unlock_kernel();
  315. return error;
  316. }
  317. coda_dir_update_mtime(dir);
  318. drop_nlink(de->d_inode);
  319. unlock_kernel();
  320. return 0;
  321. }
  322. int coda_rmdir(struct inode *dir, struct dentry *de)
  323. {
  324. const char *name = de->d_name.name;
  325. int len = de->d_name.len;
  326. int error;
  327. lock_kernel();
  328. coda_vfs_stat.rmdir++;
  329. error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len);
  330. if (!error) {
  331. /* VFS may delete the child */
  332. if (de->d_inode)
  333. de->d_inode->i_nlink = 0;
  334. /* fix the link count of the parent */
  335. coda_dir_drop_nlink(dir);
  336. coda_dir_update_mtime(dir);
  337. }
  338. unlock_kernel();
  339. return error;
  340. }
  341. /* rename */
  342. static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
  343. struct inode *new_dir, struct dentry *new_dentry)
  344. {
  345. const char *old_name = old_dentry->d_name.name;
  346. const char *new_name = new_dentry->d_name.name;
  347. int old_length = old_dentry->d_name.len;
  348. int new_length = new_dentry->d_name.len;
  349. int error;
  350. lock_kernel();
  351. coda_vfs_stat.rename++;
  352. error = venus_rename(old_dir->i_sb, coda_i2f(old_dir),
  353. coda_i2f(new_dir), old_length, new_length,
  354. (const char *) old_name, (const char *)new_name);
  355. if ( !error ) {
  356. if ( new_dentry->d_inode ) {
  357. if ( S_ISDIR(new_dentry->d_inode->i_mode) ) {
  358. coda_dir_drop_nlink(old_dir);
  359. coda_dir_inc_nlink(new_dir);
  360. }
  361. coda_dir_update_mtime(old_dir);
  362. coda_dir_update_mtime(new_dir);
  363. coda_flag_inode(new_dentry->d_inode, C_VATTR);
  364. } else {
  365. coda_flag_inode(old_dir, C_VATTR);
  366. coda_flag_inode(new_dir, C_VATTR);
  367. }
  368. }
  369. unlock_kernel();
  370. return error;
  371. }
  372. /* file operations for directories */
  373. int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir)
  374. {
  375. struct dentry *coda_dentry = coda_file->f_path.dentry;
  376. struct coda_file_info *cfi;
  377. struct file *host_file;
  378. struct inode *host_inode;
  379. int ret;
  380. cfi = CODA_FTOC(coda_file);
  381. BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
  382. host_file = cfi->cfi_container;
  383. coda_vfs_stat.readdir++;
  384. host_inode = host_file->f_path.dentry->d_inode;
  385. mutex_lock(&host_inode->i_mutex);
  386. host_file->f_pos = coda_file->f_pos;
  387. if (!host_file->f_op->readdir) {
  388. /* Venus: we must read Venus dirents from the file */
  389. ret = coda_venus_readdir(host_file, filldir, dirent, coda_dentry);
  390. } else {
  391. /* potemkin case: we were handed a directory inode. */
  392. /* Yuk, we can't call vfs_readdir because we are already
  393. * holding the inode semaphore. */
  394. ret = -ENOTDIR;
  395. if (!host_file->f_op || !host_file->f_op->readdir)
  396. goto out;
  397. ret = -ENOENT;
  398. if (!IS_DEADDIR(host_inode)) {
  399. ret = host_file->f_op->readdir(host_file, dirent, filldir);
  400. file_accessed(host_file);
  401. }
  402. }
  403. out:
  404. coda_file->f_pos = host_file->f_pos;
  405. mutex_unlock(&host_inode->i_mutex);
  406. return ret;
  407. }
  408. static inline unsigned int CDT2DT(unsigned char cdt)
  409. {
  410. unsigned int dt;
  411. switch(cdt) {
  412. case CDT_UNKNOWN: dt = DT_UNKNOWN; break;
  413. case CDT_FIFO: dt = DT_FIFO; break;
  414. case CDT_CHR: dt = DT_CHR; break;
  415. case CDT_DIR: dt = DT_DIR; break;
  416. case CDT_BLK: dt = DT_BLK; break;
  417. case CDT_REG: dt = DT_REG; break;
  418. case CDT_LNK: dt = DT_LNK; break;
  419. case CDT_SOCK: dt = DT_SOCK; break;
  420. case CDT_WHT: dt = DT_WHT; break;
  421. default: dt = DT_UNKNOWN; break;
  422. }
  423. return dt;
  424. }
  425. /* support routines */
  426. static int coda_venus_readdir(struct file *filp, filldir_t filldir,
  427. void *dirent, struct dentry *dir)
  428. {
  429. int result = 0; /* # of entries returned */
  430. struct venus_dirent *vdir;
  431. unsigned long vdir_size =
  432. (unsigned long)(&((struct venus_dirent *)0)->d_name);
  433. unsigned int type;
  434. struct qstr name;
  435. ino_t ino;
  436. int ret, i;
  437. vdir = kmalloc(sizeof(*vdir), GFP_KERNEL);
  438. if (!vdir) return -ENOMEM;
  439. i = filp->f_pos;
  440. switch(i) {
  441. case 0:
  442. ret = filldir(dirent, ".", 1, 0, dir->d_inode->i_ino, DT_DIR);
  443. if (ret < 0) break;
  444. result++;
  445. filp->f_pos++;
  446. /* fallthrough */
  447. case 1:
  448. ret = filldir(dirent, "..", 2, 1, dir->d_parent->d_inode->i_ino, DT_DIR);
  449. if (ret < 0) break;
  450. result++;
  451. filp->f_pos++;
  452. /* fallthrough */
  453. default:
  454. while (1) {
  455. /* read entries from the directory file */
  456. ret = kernel_read(filp, filp->f_pos - 2, (char *)vdir,
  457. sizeof(*vdir));
  458. if (ret < 0) {
  459. printk("coda_venus_readdir: read dir failed %d\n", ret);
  460. break;
  461. }
  462. if (ret == 0) break; /* end of directory file reached */
  463. /* catch truncated reads */
  464. if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) {
  465. printk("coda_venus_readdir: short read: %ld\n",
  466. filp->f_path.dentry->d_inode->i_ino);
  467. ret = -EBADF;
  468. break;
  469. }
  470. /* validate whether the directory file actually makes sense */
  471. if (vdir->d_reclen < vdir_size + vdir->d_namlen) {
  472. printk("coda_venus_readdir: Invalid dir: %ld\n",
  473. filp->f_path.dentry->d_inode->i_ino);
  474. ret = -EBADF;
  475. break;
  476. }
  477. name.len = vdir->d_namlen;
  478. name.name = vdir->d_name;
  479. /* Make sure we skip '.' and '..', we already got those */
  480. if (name.name[0] == '.' && (name.len == 1 ||
  481. (vdir->d_name[1] == '.' && name.len == 2)))
  482. vdir->d_fileno = name.len = 0;
  483. /* skip null entries */
  484. if (vdir->d_fileno && name.len) {
  485. /* try to look up this entry in the dcache, that way
  486. * userspace doesn't have to worry about breaking
  487. * getcwd by having mismatched inode numbers for
  488. * internal volume mountpoints. */
  489. ino = find_inode_number(dir, &name);
  490. if (!ino) ino = vdir->d_fileno;
  491. type = CDT2DT(vdir->d_type);
  492. ret = filldir(dirent, name.name, name.len, filp->f_pos,
  493. ino, type);
  494. /* failure means no space for filling in this round */
  495. if (ret < 0) break;
  496. result++;
  497. }
  498. /* we'll always have progress because d_reclen is unsigned and
  499. * we've already established it is non-zero. */
  500. filp->f_pos += vdir->d_reclen;
  501. }
  502. }
  503. kfree(vdir);
  504. return result ? result : ret;
  505. }
  506. /* called when a cache lookup succeeds */
  507. static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd)
  508. {
  509. struct inode *inode = de->d_inode;
  510. struct coda_inode_info *cii;
  511. if (!inode)
  512. return 1;
  513. lock_kernel();
  514. if (coda_isroot(inode))
  515. goto out;
  516. if (is_bad_inode(inode))
  517. goto bad;
  518. cii = ITOC(de->d_inode);
  519. if (!(cii->c_flags & (C_PURGE | C_FLUSH)))
  520. goto out;
  521. shrink_dcache_parent(de);
  522. /* propagate for a flush */
  523. if (cii->c_flags & C_FLUSH)
  524. coda_flag_inode_children(inode, C_FLUSH);
  525. if (atomic_read(&de->d_count) > 1)
  526. /* pretend it's valid, but don't change the flags */
  527. goto out;
  528. /* clear the flags. */
  529. cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
  530. bad:
  531. unlock_kernel();
  532. return 0;
  533. out:
  534. unlock_kernel();
  535. return 1;
  536. }
  537. /*
  538. * This is the callback from dput() when d_count is going to 0.
  539. * We use this to unhash dentries with bad inodes.
  540. */
  541. static int coda_dentry_delete(struct dentry * dentry)
  542. {
  543. int flags;
  544. if (!dentry->d_inode)
  545. return 0;
  546. flags = (ITOC(dentry->d_inode)->c_flags) & C_PURGE;
  547. if (is_bad_inode(dentry->d_inode) || flags) {
  548. return 1;
  549. }
  550. return 0;
  551. }
  552. /*
  553. * This is called when we want to check if the inode has
  554. * changed on the server. Coda makes this easy since the
  555. * cache manager Venus issues a downcall to the kernel when this
  556. * happens
  557. */
  558. int coda_revalidate_inode(struct dentry *dentry)
  559. {
  560. struct coda_vattr attr;
  561. int error = 0;
  562. int old_mode;
  563. ino_t old_ino;
  564. struct inode *inode = dentry->d_inode;
  565. struct coda_inode_info *cii = ITOC(inode);
  566. lock_kernel();
  567. if ( !cii->c_flags )
  568. goto ok;
  569. if (cii->c_flags & (C_VATTR | C_PURGE | C_FLUSH)) {
  570. error = venus_getattr(inode->i_sb, &(cii->c_fid), &attr);
  571. if ( error )
  572. goto return_bad;
  573. /* this inode may be lost if:
  574. - it's ino changed
  575. - type changes must be permitted for repair and
  576. missing mount points.
  577. */
  578. old_mode = inode->i_mode;
  579. old_ino = inode->i_ino;
  580. coda_vattr_to_iattr(inode, &attr);
  581. if ((old_mode & S_IFMT) != (inode->i_mode & S_IFMT)) {
  582. printk("Coda: inode %ld, fid %s changed type!\n",
  583. inode->i_ino, coda_f2s(&(cii->c_fid)));
  584. }
  585. /* the following can happen when a local fid is replaced
  586. with a global one, here we lose and declare the inode bad */
  587. if (inode->i_ino != old_ino)
  588. goto return_bad;
  589. coda_flag_inode_children(inode, C_FLUSH);
  590. cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
  591. }
  592. ok:
  593. unlock_kernel();
  594. return 0;
  595. return_bad:
  596. unlock_kernel();
  597. return -EIO;
  598. }