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_SIZE) {
  79. nidx = page->index >>
  80. (tree->node_size_shift - PAGE_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_SHIFT - tree->node_size_shift);
  95. i = 1 << (PAGE_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. {
  114. struct file *file = iocb->ki_filp;
  115. struct address_space *mapping = file->f_mapping;
  116. struct inode *inode = mapping->host;
  117. size_t count = iov_iter_count(iter);
  118. ssize_t ret;
  119. ret = blockdev_direct_IO(iocb, inode, iter, hfsplus_get_block);
  120. /*
  121. * In case of error extending write may have instantiated a few
  122. * blocks outside i_size. Trim these off again.
  123. */
  124. if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
  125. loff_t isize = i_size_read(inode);
  126. loff_t end = iocb->ki_pos + count;
  127. if (end > isize)
  128. hfsplus_write_failed(mapping, end);
  129. }
  130. return ret;
  131. }
  132. static int hfsplus_writepages(struct address_space *mapping,
  133. struct writeback_control *wbc)
  134. {
  135. return mpage_writepages(mapping, wbc, hfsplus_get_block);
  136. }
  137. const struct address_space_operations hfsplus_btree_aops = {
  138. .readpage = hfsplus_readpage,
  139. .writepage = hfsplus_writepage,
  140. .write_begin = hfsplus_write_begin,
  141. .write_end = generic_write_end,
  142. .bmap = hfsplus_bmap,
  143. .releasepage = hfsplus_releasepage,
  144. };
  145. const struct address_space_operations hfsplus_aops = {
  146. .readpage = hfsplus_readpage,
  147. .writepage = hfsplus_writepage,
  148. .write_begin = hfsplus_write_begin,
  149. .write_end = generic_write_end,
  150. .bmap = hfsplus_bmap,
  151. .direct_IO = hfsplus_direct_IO,
  152. .writepages = hfsplus_writepages,
  153. };
  154. const struct dentry_operations hfsplus_dentry_operations = {
  155. .d_hash = hfsplus_hash_dentry,
  156. .d_compare = hfsplus_compare_dentry,
  157. };
  158. static void hfsplus_get_perms(struct inode *inode,
  159. struct hfsplus_perm *perms, int dir)
  160. {
  161. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  162. u16 mode;
  163. mode = be16_to_cpu(perms->mode);
  164. i_uid_write(inode, be32_to_cpu(perms->owner));
  165. if (!i_uid_read(inode) && !mode)
  166. inode->i_uid = sbi->uid;
  167. i_gid_write(inode, be32_to_cpu(perms->group));
  168. if (!i_gid_read(inode) && !mode)
  169. inode->i_gid = sbi->gid;
  170. if (dir) {
  171. mode = mode ? (mode & S_IALLUGO) : (S_IRWXUGO & ~(sbi->umask));
  172. mode |= S_IFDIR;
  173. } else if (!mode)
  174. mode = S_IFREG | ((S_IRUGO|S_IWUGO) & ~(sbi->umask));
  175. inode->i_mode = mode;
  176. HFSPLUS_I(inode)->userflags = perms->userflags;
  177. if (perms->rootflags & HFSPLUS_FLG_IMMUTABLE)
  178. inode->i_flags |= S_IMMUTABLE;
  179. else
  180. inode->i_flags &= ~S_IMMUTABLE;
  181. if (perms->rootflags & HFSPLUS_FLG_APPEND)
  182. inode->i_flags |= S_APPEND;
  183. else
  184. inode->i_flags &= ~S_APPEND;
  185. }
  186. static int hfsplus_file_open(struct inode *inode, struct file *file)
  187. {
  188. if (HFSPLUS_IS_RSRC(inode))
  189. inode = HFSPLUS_I(inode)->rsrc_inode;
  190. if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
  191. return -EOVERFLOW;
  192. atomic_inc(&HFSPLUS_I(inode)->opencnt);
  193. return 0;
  194. }
  195. static int hfsplus_file_release(struct inode *inode, struct file *file)
  196. {
  197. struct super_block *sb = inode->i_sb;
  198. if (HFSPLUS_IS_RSRC(inode))
  199. inode = HFSPLUS_I(inode)->rsrc_inode;
  200. if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
  201. inode_lock(inode);
  202. hfsplus_file_truncate(inode);
  203. if (inode->i_flags & S_DEAD) {
  204. hfsplus_delete_cat(inode->i_ino,
  205. HFSPLUS_SB(sb)->hidden_dir, NULL);
  206. hfsplus_delete_inode(inode);
  207. }
  208. inode_unlock(inode);
  209. }
  210. return 0;
  211. }
  212. static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
  213. {
  214. struct inode *inode = d_inode(dentry);
  215. int error;
  216. error = setattr_prepare(dentry, attr);
  217. if (error)
  218. return error;
  219. if ((attr->ia_valid & ATTR_SIZE) &&
  220. attr->ia_size != i_size_read(inode)) {
  221. inode_dio_wait(inode);
  222. if (attr->ia_size > inode->i_size) {
  223. error = generic_cont_expand_simple(inode,
  224. attr->ia_size);
  225. if (error)
  226. return error;
  227. }
  228. truncate_setsize(inode, attr->ia_size);
  229. hfsplus_file_truncate(inode);
  230. }
  231. setattr_copy(inode, attr);
  232. mark_inode_dirty(inode);
  233. if (attr->ia_valid & ATTR_MODE) {
  234. error = posix_acl_chmod(inode, inode->i_mode);
  235. if (unlikely(error))
  236. return error;
  237. }
  238. return 0;
  239. }
  240. int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
  241. int datasync)
  242. {
  243. struct inode *inode = file->f_mapping->host;
  244. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  245. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  246. int error = 0, error2;
  247. error = filemap_write_and_wait_range(inode->i_mapping, start, end);
  248. if (error)
  249. return error;
  250. inode_lock(inode);
  251. /*
  252. * Sync inode metadata into the catalog and extent trees.
  253. */
  254. sync_inode_metadata(inode, 1);
  255. /*
  256. * And explicitly write out the btrees.
  257. */
  258. if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags))
  259. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  260. if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags)) {
  261. error2 =
  262. filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  263. if (!error)
  264. error = error2;
  265. }
  266. if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags)) {
  267. if (sbi->attr_tree) {
  268. error2 =
  269. filemap_write_and_wait(
  270. sbi->attr_tree->inode->i_mapping);
  271. if (!error)
  272. error = error2;
  273. } else {
  274. pr_err("sync non-existent attributes tree\n");
  275. }
  276. }
  277. if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) {
  278. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  279. if (!error)
  280. error = error2;
  281. }
  282. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  283. blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
  284. inode_unlock(inode);
  285. return error;
  286. }
  287. static const struct inode_operations hfsplus_file_inode_operations = {
  288. .setattr = hfsplus_setattr,
  289. .listxattr = hfsplus_listxattr,
  290. #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
  291. .get_acl = hfsplus_get_posix_acl,
  292. .set_acl = hfsplus_set_posix_acl,
  293. #endif
  294. };
  295. static const struct file_operations hfsplus_file_operations = {
  296. .llseek = generic_file_llseek,
  297. .read_iter = generic_file_read_iter,
  298. .write_iter = generic_file_write_iter,
  299. .mmap = generic_file_mmap,
  300. .splice_read = generic_file_splice_read,
  301. .fsync = hfsplus_file_fsync,
  302. .open = hfsplus_file_open,
  303. .release = hfsplus_file_release,
  304. .unlocked_ioctl = hfsplus_ioctl,
  305. };
  306. struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode)
  307. {
  308. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  309. struct inode *inode = new_inode(sb);
  310. struct hfsplus_inode_info *hip;
  311. if (!inode)
  312. return NULL;
  313. inode->i_ino = sbi->next_cnid++;
  314. inode->i_mode = mode;
  315. inode->i_uid = current_fsuid();
  316. inode->i_gid = current_fsgid();
  317. set_nlink(inode, 1);
  318. inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
  319. hip = HFSPLUS_I(inode);
  320. INIT_LIST_HEAD(&hip->open_dir_list);
  321. spin_lock_init(&hip->open_dir_lock);
  322. mutex_init(&hip->extents_lock);
  323. atomic_set(&hip->opencnt, 0);
  324. hip->extent_state = 0;
  325. hip->flags = 0;
  326. hip->userflags = 0;
  327. hip->subfolders = 0;
  328. memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
  329. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  330. hip->alloc_blocks = 0;
  331. hip->first_blocks = 0;
  332. hip->cached_start = 0;
  333. hip->cached_blocks = 0;
  334. hip->phys_size = 0;
  335. hip->fs_blocks = 0;
  336. hip->rsrc_inode = NULL;
  337. if (S_ISDIR(inode->i_mode)) {
  338. inode->i_size = 2;
  339. sbi->folder_count++;
  340. inode->i_op = &hfsplus_dir_inode_operations;
  341. inode->i_fop = &hfsplus_dir_operations;
  342. } else if (S_ISREG(inode->i_mode)) {
  343. sbi->file_count++;
  344. inode->i_op = &hfsplus_file_inode_operations;
  345. inode->i_fop = &hfsplus_file_operations;
  346. inode->i_mapping->a_ops = &hfsplus_aops;
  347. hip->clump_blocks = sbi->data_clump_blocks;
  348. } else if (S_ISLNK(inode->i_mode)) {
  349. sbi->file_count++;
  350. inode->i_op = &page_symlink_inode_operations;
  351. inode_nohighmem(inode);
  352. inode->i_mapping->a_ops = &hfsplus_aops;
  353. hip->clump_blocks = 1;
  354. } else
  355. sbi->file_count++;
  356. insert_inode_hash(inode);
  357. mark_inode_dirty(inode);
  358. hfsplus_mark_mdb_dirty(sb);
  359. return inode;
  360. }
  361. void hfsplus_delete_inode(struct inode *inode)
  362. {
  363. struct super_block *sb = inode->i_sb;
  364. if (S_ISDIR(inode->i_mode)) {
  365. HFSPLUS_SB(sb)->folder_count--;
  366. hfsplus_mark_mdb_dirty(sb);
  367. return;
  368. }
  369. HFSPLUS_SB(sb)->file_count--;
  370. if (S_ISREG(inode->i_mode)) {
  371. if (!inode->i_nlink) {
  372. inode->i_size = 0;
  373. hfsplus_file_truncate(inode);
  374. }
  375. } else if (S_ISLNK(inode->i_mode)) {
  376. inode->i_size = 0;
  377. hfsplus_file_truncate(inode);
  378. }
  379. hfsplus_mark_mdb_dirty(sb);
  380. }
  381. void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  382. {
  383. struct super_block *sb = inode->i_sb;
  384. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  385. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  386. u32 count;
  387. int i;
  388. memcpy(&hip->first_extents, &fork->extents, sizeof(hfsplus_extent_rec));
  389. for (count = 0, i = 0; i < 8; i++)
  390. count += be32_to_cpu(fork->extents[i].block_count);
  391. hip->first_blocks = count;
  392. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  393. hip->cached_start = 0;
  394. hip->cached_blocks = 0;
  395. hip->alloc_blocks = be32_to_cpu(fork->total_blocks);
  396. hip->phys_size = inode->i_size = be64_to_cpu(fork->total_size);
  397. hip->fs_blocks =
  398. (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  399. inode_set_bytes(inode, hip->fs_blocks << sb->s_blocksize_bits);
  400. hip->clump_blocks =
  401. be32_to_cpu(fork->clump_size) >> sbi->alloc_blksz_shift;
  402. if (!hip->clump_blocks) {
  403. hip->clump_blocks = HFSPLUS_IS_RSRC(inode) ?
  404. sbi->rsrc_clump_blocks :
  405. sbi->data_clump_blocks;
  406. }
  407. }
  408. void hfsplus_inode_write_fork(struct inode *inode,
  409. struct hfsplus_fork_raw *fork)
  410. {
  411. memcpy(&fork->extents, &HFSPLUS_I(inode)->first_extents,
  412. sizeof(hfsplus_extent_rec));
  413. fork->total_size = cpu_to_be64(inode->i_size);
  414. fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
  415. }
  416. int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
  417. {
  418. hfsplus_cat_entry entry;
  419. int res = 0;
  420. u16 type;
  421. type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
  422. HFSPLUS_I(inode)->linkid = 0;
  423. if (type == HFSPLUS_FOLDER) {
  424. struct hfsplus_cat_folder *folder = &entry.folder;
  425. if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
  426. /* panic? */;
  427. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  428. sizeof(struct hfsplus_cat_folder));
  429. hfsplus_get_perms(inode, &folder->permissions, 1);
  430. set_nlink(inode, 1);
  431. inode->i_size = 2 + be32_to_cpu(folder->valence);
  432. inode->i_atime = hfsp_mt2ut(folder->access_date);
  433. inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
  434. inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
  435. HFSPLUS_I(inode)->create_date = folder->create_date;
  436. HFSPLUS_I(inode)->fs_blocks = 0;
  437. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  438. HFSPLUS_I(inode)->subfolders =
  439. be32_to_cpu(folder->subfolders);
  440. }
  441. inode->i_op = &hfsplus_dir_inode_operations;
  442. inode->i_fop = &hfsplus_dir_operations;
  443. } else if (type == HFSPLUS_FILE) {
  444. struct hfsplus_cat_file *file = &entry.file;
  445. if (fd->entrylength < sizeof(struct hfsplus_cat_file))
  446. /* panic? */;
  447. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  448. sizeof(struct hfsplus_cat_file));
  449. hfsplus_inode_read_fork(inode, HFSPLUS_IS_RSRC(inode) ?
  450. &file->rsrc_fork : &file->data_fork);
  451. hfsplus_get_perms(inode, &file->permissions, 0);
  452. set_nlink(inode, 1);
  453. if (S_ISREG(inode->i_mode)) {
  454. if (file->permissions.dev)
  455. set_nlink(inode,
  456. be32_to_cpu(file->permissions.dev));
  457. inode->i_op = &hfsplus_file_inode_operations;
  458. inode->i_fop = &hfsplus_file_operations;
  459. inode->i_mapping->a_ops = &hfsplus_aops;
  460. } else if (S_ISLNK(inode->i_mode)) {
  461. inode->i_op = &page_symlink_inode_operations;
  462. inode_nohighmem(inode);
  463. inode->i_mapping->a_ops = &hfsplus_aops;
  464. } else {
  465. init_special_inode(inode, inode->i_mode,
  466. be32_to_cpu(file->permissions.dev));
  467. }
  468. inode->i_atime = hfsp_mt2ut(file->access_date);
  469. inode->i_mtime = hfsp_mt2ut(file->content_mod_date);
  470. inode->i_ctime = hfsp_mt2ut(file->attribute_mod_date);
  471. HFSPLUS_I(inode)->create_date = file->create_date;
  472. } else {
  473. pr_err("bad catalog entry used to create inode\n");
  474. res = -EIO;
  475. }
  476. return res;
  477. }
  478. int hfsplus_cat_write_inode(struct inode *inode)
  479. {
  480. struct inode *main_inode = inode;
  481. struct hfs_find_data fd;
  482. hfsplus_cat_entry entry;
  483. if (HFSPLUS_IS_RSRC(inode))
  484. main_inode = HFSPLUS_I(inode)->rsrc_inode;
  485. if (!main_inode->i_nlink)
  486. return 0;
  487. if (hfs_find_init(HFSPLUS_SB(main_inode->i_sb)->cat_tree, &fd))
  488. /* panic? */
  489. return -EIO;
  490. if (hfsplus_find_cat(main_inode->i_sb, main_inode->i_ino, &fd))
  491. /* panic? */
  492. goto out;
  493. if (S_ISDIR(main_inode->i_mode)) {
  494. struct hfsplus_cat_folder *folder = &entry.folder;
  495. if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
  496. /* panic? */;
  497. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  498. sizeof(struct hfsplus_cat_folder));
  499. /* simple node checks? */
  500. hfsplus_cat_set_perms(inode, &folder->permissions);
  501. folder->access_date = hfsp_ut2mt(inode->i_atime);
  502. folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  503. folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  504. folder->valence = cpu_to_be32(inode->i_size - 2);
  505. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  506. folder->subfolders =
  507. cpu_to_be32(HFSPLUS_I(inode)->subfolders);
  508. }
  509. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  510. sizeof(struct hfsplus_cat_folder));
  511. } else if (HFSPLUS_IS_RSRC(inode)) {
  512. struct hfsplus_cat_file *file = &entry.file;
  513. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  514. sizeof(struct hfsplus_cat_file));
  515. hfsplus_inode_write_fork(inode, &file->rsrc_fork);
  516. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  517. sizeof(struct hfsplus_cat_file));
  518. } else {
  519. struct hfsplus_cat_file *file = &entry.file;
  520. if (fd.entrylength < sizeof(struct hfsplus_cat_file))
  521. /* panic? */;
  522. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  523. sizeof(struct hfsplus_cat_file));
  524. hfsplus_inode_write_fork(inode, &file->data_fork);
  525. hfsplus_cat_set_perms(inode, &file->permissions);
  526. if (HFSPLUS_FLG_IMMUTABLE &
  527. (file->permissions.rootflags |
  528. file->permissions.userflags))
  529. file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
  530. else
  531. file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
  532. file->access_date = hfsp_ut2mt(inode->i_atime);
  533. file->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  534. file->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  535. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  536. sizeof(struct hfsplus_cat_file));
  537. }
  538. set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
  539. out:
  540. hfs_find_exit(&fd);
  541. return 0;
  542. }