inode.c 17 KB

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