inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * linux/fs/hfsplus/inode.c
  3. *
  4. * Copyright (C) 2001
  5. * Brad Boyer (flar@allandria.com)
  6. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  7. *
  8. * Inode handling routines
  9. */
  10. #include <linux/blkdev.h>
  11. #include <linux/mm.h>
  12. #include <linux/fs.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/mpage.h>
  15. #include <linux/sched.h>
  16. #include <linux/uio.h>
  17. #include "hfsplus_fs.h"
  18. #include "hfsplus_raw.h"
  19. #include "xattr.h"
  20. #include "acl.h"
  21. static int hfsplus_readpage(struct file *file, struct page *page)
  22. {
  23. return block_read_full_page(page, hfsplus_get_block);
  24. }
  25. static int hfsplus_writepage(struct page *page, struct writeback_control *wbc)
  26. {
  27. return block_write_full_page(page, hfsplus_get_block, wbc);
  28. }
  29. static void hfsplus_write_failed(struct address_space *mapping, loff_t to)
  30. {
  31. struct inode *inode = mapping->host;
  32. if (to > inode->i_size) {
  33. truncate_pagecache(inode, inode->i_size);
  34. hfsplus_file_truncate(inode);
  35. }
  36. }
  37. static int hfsplus_write_begin(struct file *file, struct address_space *mapping,
  38. loff_t pos, unsigned len, unsigned flags,
  39. struct page **pagep, void **fsdata)
  40. {
  41. int ret;
  42. *pagep = NULL;
  43. ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  44. hfsplus_get_block,
  45. &HFSPLUS_I(mapping->host)->phys_size);
  46. if (unlikely(ret))
  47. hfsplus_write_failed(mapping, pos + len);
  48. return ret;
  49. }
  50. static sector_t hfsplus_bmap(struct address_space *mapping, sector_t block)
  51. {
  52. return generic_block_bmap(mapping, block, hfsplus_get_block);
  53. }
  54. static int hfsplus_releasepage(struct page *page, gfp_t mask)
  55. {
  56. struct inode *inode = page->mapping->host;
  57. struct super_block *sb = inode->i_sb;
  58. struct hfs_btree *tree;
  59. struct hfs_bnode *node;
  60. u32 nidx;
  61. int i, res = 1;
  62. switch (inode->i_ino) {
  63. case HFSPLUS_EXT_CNID:
  64. tree = HFSPLUS_SB(sb)->ext_tree;
  65. break;
  66. case HFSPLUS_CAT_CNID:
  67. tree = HFSPLUS_SB(sb)->cat_tree;
  68. break;
  69. case HFSPLUS_ATTR_CNID:
  70. tree = HFSPLUS_SB(sb)->attr_tree;
  71. break;
  72. default:
  73. BUG();
  74. return 0;
  75. }
  76. if (!tree)
  77. return 0;
  78. if (tree->node_size >= PAGE_CACHE_SIZE) {
  79. nidx = page->index >>
  80. (tree->node_size_shift - PAGE_CACHE_SHIFT);
  81. spin_lock(&tree->hash_lock);
  82. node = hfs_bnode_findhash(tree, nidx);
  83. if (!node)
  84. ;
  85. else if (atomic_read(&node->refcnt))
  86. res = 0;
  87. if (res && node) {
  88. hfs_bnode_unhash(node);
  89. hfs_bnode_free(node);
  90. }
  91. spin_unlock(&tree->hash_lock);
  92. } else {
  93. nidx = page->index <<
  94. (PAGE_CACHE_SHIFT - tree->node_size_shift);
  95. i = 1 << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  96. spin_lock(&tree->hash_lock);
  97. do {
  98. node = hfs_bnode_findhash(tree, nidx++);
  99. if (!node)
  100. continue;
  101. if (atomic_read(&node->refcnt)) {
  102. res = 0;
  103. break;
  104. }
  105. hfs_bnode_unhash(node);
  106. hfs_bnode_free(node);
  107. } while (--i && nidx < tree->node_count);
  108. spin_unlock(&tree->hash_lock);
  109. }
  110. return res ? try_to_free_buffers(page) : 0;
  111. }
  112. static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
  113. loff_t offset)
  114. {
  115. struct file *file = iocb->ki_filp;
  116. struct address_space *mapping = file->f_mapping;
  117. struct inode *inode = file_inode(file)->i_mapping->host;
  118. size_t count = iov_iter_count(iter);
  119. ssize_t ret;
  120. ret = blockdev_direct_IO(iocb, inode, iter, offset, hfsplus_get_block);
  121. /*
  122. * In case of error extending write may have instantiated a few
  123. * blocks outside i_size. Trim these off again.
  124. */
  125. if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
  126. loff_t isize = i_size_read(inode);
  127. loff_t end = offset + count;
  128. if (end > isize)
  129. hfsplus_write_failed(mapping, end);
  130. }
  131. return ret;
  132. }
  133. static int hfsplus_writepages(struct address_space *mapping,
  134. struct writeback_control *wbc)
  135. {
  136. return mpage_writepages(mapping, wbc, hfsplus_get_block);
  137. }
  138. const struct address_space_operations hfsplus_btree_aops = {
  139. .readpage = hfsplus_readpage,
  140. .writepage = hfsplus_writepage,
  141. .write_begin = hfsplus_write_begin,
  142. .write_end = generic_write_end,
  143. .bmap = hfsplus_bmap,
  144. .releasepage = hfsplus_releasepage,
  145. };
  146. const struct address_space_operations hfsplus_aops = {
  147. .readpage = hfsplus_readpage,
  148. .writepage = hfsplus_writepage,
  149. .write_begin = hfsplus_write_begin,
  150. .write_end = generic_write_end,
  151. .bmap = hfsplus_bmap,
  152. .direct_IO = hfsplus_direct_IO,
  153. .writepages = hfsplus_writepages,
  154. };
  155. const struct dentry_operations hfsplus_dentry_operations = {
  156. .d_hash = hfsplus_hash_dentry,
  157. .d_compare = hfsplus_compare_dentry,
  158. };
  159. static void hfsplus_get_perms(struct inode *inode,
  160. struct hfsplus_perm *perms, int dir)
  161. {
  162. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  163. u16 mode;
  164. mode = be16_to_cpu(perms->mode);
  165. i_uid_write(inode, be32_to_cpu(perms->owner));
  166. if (!i_uid_read(inode) && !mode)
  167. inode->i_uid = sbi->uid;
  168. i_gid_write(inode, be32_to_cpu(perms->group));
  169. if (!i_gid_read(inode) && !mode)
  170. inode->i_gid = sbi->gid;
  171. if (dir) {
  172. mode = mode ? (mode & S_IALLUGO) : (S_IRWXUGO & ~(sbi->umask));
  173. mode |= S_IFDIR;
  174. } else if (!mode)
  175. mode = S_IFREG | ((S_IRUGO|S_IWUGO) & ~(sbi->umask));
  176. inode->i_mode = mode;
  177. HFSPLUS_I(inode)->userflags = perms->userflags;
  178. if (perms->rootflags & HFSPLUS_FLG_IMMUTABLE)
  179. inode->i_flags |= S_IMMUTABLE;
  180. else
  181. inode->i_flags &= ~S_IMMUTABLE;
  182. if (perms->rootflags & HFSPLUS_FLG_APPEND)
  183. inode->i_flags |= S_APPEND;
  184. else
  185. inode->i_flags &= ~S_APPEND;
  186. }
  187. static int hfsplus_file_open(struct inode *inode, struct file *file)
  188. {
  189. if (HFSPLUS_IS_RSRC(inode))
  190. inode = HFSPLUS_I(inode)->rsrc_inode;
  191. if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
  192. return -EOVERFLOW;
  193. atomic_inc(&HFSPLUS_I(inode)->opencnt);
  194. return 0;
  195. }
  196. static int hfsplus_file_release(struct inode *inode, struct file *file)
  197. {
  198. struct super_block *sb = inode->i_sb;
  199. if (HFSPLUS_IS_RSRC(inode))
  200. inode = HFSPLUS_I(inode)->rsrc_inode;
  201. if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
  202. mutex_lock(&inode->i_mutex);
  203. hfsplus_file_truncate(inode);
  204. if (inode->i_flags & S_DEAD) {
  205. hfsplus_delete_cat(inode->i_ino,
  206. HFSPLUS_SB(sb)->hidden_dir, NULL);
  207. hfsplus_delete_inode(inode);
  208. }
  209. mutex_unlock(&inode->i_mutex);
  210. }
  211. return 0;
  212. }
  213. static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
  214. {
  215. struct inode *inode = d_inode(dentry);
  216. int error;
  217. error = inode_change_ok(inode, attr);
  218. if (error)
  219. return error;
  220. if ((attr->ia_valid & ATTR_SIZE) &&
  221. attr->ia_size != i_size_read(inode)) {
  222. inode_dio_wait(inode);
  223. if (attr->ia_size > inode->i_size) {
  224. error = generic_cont_expand_simple(inode,
  225. attr->ia_size);
  226. if (error)
  227. return error;
  228. }
  229. truncate_setsize(inode, attr->ia_size);
  230. hfsplus_file_truncate(inode);
  231. }
  232. setattr_copy(inode, attr);
  233. mark_inode_dirty(inode);
  234. if (attr->ia_valid & ATTR_MODE) {
  235. error = posix_acl_chmod(inode, inode->i_mode);
  236. if (unlikely(error))
  237. return error;
  238. }
  239. return 0;
  240. }
  241. int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
  242. int datasync)
  243. {
  244. struct inode *inode = file->f_mapping->host;
  245. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  246. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  247. int error = 0, error2;
  248. error = filemap_write_and_wait_range(inode->i_mapping, start, end);
  249. if (error)
  250. return error;
  251. mutex_lock(&inode->i_mutex);
  252. /*
  253. * Sync inode metadata into the catalog and extent trees.
  254. */
  255. sync_inode_metadata(inode, 1);
  256. /*
  257. * And explicitly write out the btrees.
  258. */
  259. if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags))
  260. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  261. if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags)) {
  262. error2 =
  263. filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  264. if (!error)
  265. error = error2;
  266. }
  267. if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags)) {
  268. if (sbi->attr_tree) {
  269. error2 =
  270. filemap_write_and_wait(
  271. sbi->attr_tree->inode->i_mapping);
  272. if (!error)
  273. error = error2;
  274. } else {
  275. pr_err("sync non-existent attributes tree\n");
  276. }
  277. }
  278. if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) {
  279. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  280. if (!error)
  281. error = error2;
  282. }
  283. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  284. blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
  285. mutex_unlock(&inode->i_mutex);
  286. return error;
  287. }
  288. static const struct inode_operations hfsplus_file_inode_operations = {
  289. .setattr = hfsplus_setattr,
  290. .setxattr = generic_setxattr,
  291. .getxattr = generic_getxattr,
  292. .listxattr = hfsplus_listxattr,
  293. .removexattr = generic_removexattr,
  294. #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
  295. .get_acl = hfsplus_get_posix_acl,
  296. .set_acl = hfsplus_set_posix_acl,
  297. #endif
  298. };
  299. static const struct file_operations hfsplus_file_operations = {
  300. .llseek = generic_file_llseek,
  301. .read_iter = generic_file_read_iter,
  302. .write_iter = generic_file_write_iter,
  303. .mmap = generic_file_mmap,
  304. .splice_read = generic_file_splice_read,
  305. .fsync = hfsplus_file_fsync,
  306. .open = hfsplus_file_open,
  307. .release = hfsplus_file_release,
  308. .unlocked_ioctl = hfsplus_ioctl,
  309. };
  310. struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode)
  311. {
  312. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  313. struct inode *inode = new_inode(sb);
  314. struct hfsplus_inode_info *hip;
  315. if (!inode)
  316. return NULL;
  317. inode->i_ino = sbi->next_cnid++;
  318. inode->i_mode = mode;
  319. inode->i_uid = current_fsuid();
  320. inode->i_gid = current_fsgid();
  321. set_nlink(inode, 1);
  322. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
  323. hip = HFSPLUS_I(inode);
  324. INIT_LIST_HEAD(&hip->open_dir_list);
  325. mutex_init(&hip->extents_lock);
  326. atomic_set(&hip->opencnt, 0);
  327. hip->extent_state = 0;
  328. hip->flags = 0;
  329. hip->userflags = 0;
  330. hip->subfolders = 0;
  331. memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
  332. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  333. hip->alloc_blocks = 0;
  334. hip->first_blocks = 0;
  335. hip->cached_start = 0;
  336. hip->cached_blocks = 0;
  337. hip->phys_size = 0;
  338. hip->fs_blocks = 0;
  339. hip->rsrc_inode = NULL;
  340. if (S_ISDIR(inode->i_mode)) {
  341. inode->i_size = 2;
  342. sbi->folder_count++;
  343. inode->i_op = &hfsplus_dir_inode_operations;
  344. inode->i_fop = &hfsplus_dir_operations;
  345. } else if (S_ISREG(inode->i_mode)) {
  346. sbi->file_count++;
  347. inode->i_op = &hfsplus_file_inode_operations;
  348. inode->i_fop = &hfsplus_file_operations;
  349. inode->i_mapping->a_ops = &hfsplus_aops;
  350. hip->clump_blocks = sbi->data_clump_blocks;
  351. } else if (S_ISLNK(inode->i_mode)) {
  352. sbi->file_count++;
  353. inode->i_op = &page_symlink_inode_operations;
  354. inode->i_mapping->a_ops = &hfsplus_aops;
  355. hip->clump_blocks = 1;
  356. } else
  357. sbi->file_count++;
  358. insert_inode_hash(inode);
  359. mark_inode_dirty(inode);
  360. hfsplus_mark_mdb_dirty(sb);
  361. return inode;
  362. }
  363. void hfsplus_delete_inode(struct inode *inode)
  364. {
  365. struct super_block *sb = inode->i_sb;
  366. if (S_ISDIR(inode->i_mode)) {
  367. HFSPLUS_SB(sb)->folder_count--;
  368. hfsplus_mark_mdb_dirty(sb);
  369. return;
  370. }
  371. HFSPLUS_SB(sb)->file_count--;
  372. if (S_ISREG(inode->i_mode)) {
  373. if (!inode->i_nlink) {
  374. inode->i_size = 0;
  375. hfsplus_file_truncate(inode);
  376. }
  377. } else if (S_ISLNK(inode->i_mode)) {
  378. inode->i_size = 0;
  379. hfsplus_file_truncate(inode);
  380. }
  381. hfsplus_mark_mdb_dirty(sb);
  382. }
  383. void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  384. {
  385. struct super_block *sb = inode->i_sb;
  386. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  387. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  388. u32 count;
  389. int i;
  390. memcpy(&hip->first_extents, &fork->extents, sizeof(hfsplus_extent_rec));
  391. for (count = 0, i = 0; i < 8; i++)
  392. count += be32_to_cpu(fork->extents[i].block_count);
  393. hip->first_blocks = count;
  394. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  395. hip->cached_start = 0;
  396. hip->cached_blocks = 0;
  397. hip->alloc_blocks = be32_to_cpu(fork->total_blocks);
  398. hip->phys_size = inode->i_size = be64_to_cpu(fork->total_size);
  399. hip->fs_blocks =
  400. (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  401. inode_set_bytes(inode, hip->fs_blocks << sb->s_blocksize_bits);
  402. hip->clump_blocks =
  403. be32_to_cpu(fork->clump_size) >> sbi->alloc_blksz_shift;
  404. if (!hip->clump_blocks) {
  405. hip->clump_blocks = HFSPLUS_IS_RSRC(inode) ?
  406. sbi->rsrc_clump_blocks :
  407. sbi->data_clump_blocks;
  408. }
  409. }
  410. void hfsplus_inode_write_fork(struct inode *inode,
  411. struct hfsplus_fork_raw *fork)
  412. {
  413. memcpy(&fork->extents, &HFSPLUS_I(inode)->first_extents,
  414. sizeof(hfsplus_extent_rec));
  415. fork->total_size = cpu_to_be64(inode->i_size);
  416. fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
  417. }
  418. int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
  419. {
  420. hfsplus_cat_entry entry;
  421. int res = 0;
  422. u16 type;
  423. type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
  424. HFSPLUS_I(inode)->linkid = 0;
  425. if (type == HFSPLUS_FOLDER) {
  426. struct hfsplus_cat_folder *folder = &entry.folder;
  427. if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
  428. /* panic? */;
  429. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  430. sizeof(struct hfsplus_cat_folder));
  431. hfsplus_get_perms(inode, &folder->permissions, 1);
  432. set_nlink(inode, 1);
  433. inode->i_size = 2 + be32_to_cpu(folder->valence);
  434. inode->i_atime = hfsp_mt2ut(folder->access_date);
  435. inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
  436. inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
  437. HFSPLUS_I(inode)->create_date = folder->create_date;
  438. HFSPLUS_I(inode)->fs_blocks = 0;
  439. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  440. HFSPLUS_I(inode)->subfolders =
  441. be32_to_cpu(folder->subfolders);
  442. }
  443. inode->i_op = &hfsplus_dir_inode_operations;
  444. inode->i_fop = &hfsplus_dir_operations;
  445. } else if (type == HFSPLUS_FILE) {
  446. struct hfsplus_cat_file *file = &entry.file;
  447. if (fd->entrylength < sizeof(struct hfsplus_cat_file))
  448. /* panic? */;
  449. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  450. sizeof(struct hfsplus_cat_file));
  451. hfsplus_inode_read_fork(inode, HFSPLUS_IS_RSRC(inode) ?
  452. &file->rsrc_fork : &file->data_fork);
  453. hfsplus_get_perms(inode, &file->permissions, 0);
  454. set_nlink(inode, 1);
  455. if (S_ISREG(inode->i_mode)) {
  456. if (file->permissions.dev)
  457. set_nlink(inode,
  458. be32_to_cpu(file->permissions.dev));
  459. inode->i_op = &hfsplus_file_inode_operations;
  460. inode->i_fop = &hfsplus_file_operations;
  461. inode->i_mapping->a_ops = &hfsplus_aops;
  462. } else if (S_ISLNK(inode->i_mode)) {
  463. inode->i_op = &page_symlink_inode_operations;
  464. inode->i_mapping->a_ops = &hfsplus_aops;
  465. } else {
  466. init_special_inode(inode, inode->i_mode,
  467. be32_to_cpu(file->permissions.dev));
  468. }
  469. inode->i_atime = hfsp_mt2ut(file->access_date);
  470. inode->i_mtime = hfsp_mt2ut(file->content_mod_date);
  471. inode->i_ctime = hfsp_mt2ut(file->attribute_mod_date);
  472. HFSPLUS_I(inode)->create_date = file->create_date;
  473. } else {
  474. pr_err("bad catalog entry used to create inode\n");
  475. res = -EIO;
  476. }
  477. return res;
  478. }
  479. int hfsplus_cat_write_inode(struct inode *inode)
  480. {
  481. struct inode *main_inode = inode;
  482. struct hfs_find_data fd;
  483. hfsplus_cat_entry entry;
  484. if (HFSPLUS_IS_RSRC(inode))
  485. main_inode = HFSPLUS_I(inode)->rsrc_inode;
  486. if (!main_inode->i_nlink)
  487. return 0;
  488. if (hfs_find_init(HFSPLUS_SB(main_inode->i_sb)->cat_tree, &fd))
  489. /* panic? */
  490. return -EIO;
  491. if (hfsplus_find_cat(main_inode->i_sb, main_inode->i_ino, &fd))
  492. /* panic? */
  493. goto out;
  494. if (S_ISDIR(main_inode->i_mode)) {
  495. struct hfsplus_cat_folder *folder = &entry.folder;
  496. if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
  497. /* panic? */;
  498. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  499. sizeof(struct hfsplus_cat_folder));
  500. /* simple node checks? */
  501. hfsplus_cat_set_perms(inode, &folder->permissions);
  502. folder->access_date = hfsp_ut2mt(inode->i_atime);
  503. folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  504. folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  505. folder->valence = cpu_to_be32(inode->i_size - 2);
  506. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  507. folder->subfolders =
  508. cpu_to_be32(HFSPLUS_I(inode)->subfolders);
  509. }
  510. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  511. sizeof(struct hfsplus_cat_folder));
  512. } else if (HFSPLUS_IS_RSRC(inode)) {
  513. struct hfsplus_cat_file *file = &entry.file;
  514. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  515. sizeof(struct hfsplus_cat_file));
  516. hfsplus_inode_write_fork(inode, &file->rsrc_fork);
  517. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  518. sizeof(struct hfsplus_cat_file));
  519. } else {
  520. struct hfsplus_cat_file *file = &entry.file;
  521. if (fd.entrylength < sizeof(struct hfsplus_cat_file))
  522. /* panic? */;
  523. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  524. sizeof(struct hfsplus_cat_file));
  525. hfsplus_inode_write_fork(inode, &file->data_fork);
  526. hfsplus_cat_set_perms(inode, &file->permissions);
  527. if (HFSPLUS_FLG_IMMUTABLE &
  528. (file->permissions.rootflags |
  529. file->permissions.userflags))
  530. file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
  531. else
  532. file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
  533. file->access_date = hfsp_ut2mt(inode->i_atime);
  534. file->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  535. file->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  536. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  537. sizeof(struct hfsplus_cat_file));
  538. }
  539. set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
  540. out:
  541. hfs_find_exit(&fd);
  542. return 0;
  543. }