inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/hfsplus/inode.c
  4. *
  5. * Copyright (C) 2001
  6. * Brad Boyer (flar@allandria.com)
  7. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  8. *
  9. * Inode handling routines
  10. */
  11. #include <linux/blkdev.h>
  12. #include <linux/mm.h>
  13. #include <linux/fs.h>
  14. #include <linux/pagemap.h>
  15. #include <linux/mpage.h>
  16. #include <linux/sched.h>
  17. #include <linux/cred.h>
  18. #include <linux/uio.h>
  19. #include "hfsplus_fs.h"
  20. #include "hfsplus_raw.h"
  21. #include "xattr.h"
  22. static int hfsplus_readpage(struct file *file, struct page *page)
  23. {
  24. return block_read_full_page(page, hfsplus_get_block);
  25. }
  26. static int hfsplus_writepage(struct page *page, struct writeback_control *wbc)
  27. {
  28. return block_write_full_page(page, hfsplus_get_block, wbc);
  29. }
  30. static void hfsplus_write_failed(struct address_space *mapping, loff_t to)
  31. {
  32. struct inode *inode = mapping->host;
  33. if (to > inode->i_size) {
  34. truncate_pagecache(inode, inode->i_size);
  35. hfsplus_file_truncate(inode);
  36. }
  37. }
  38. static int hfsplus_write_begin(struct file *file, struct address_space *mapping,
  39. loff_t pos, unsigned len, unsigned flags,
  40. struct page **pagep, void **fsdata)
  41. {
  42. int ret;
  43. *pagep = NULL;
  44. ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  45. hfsplus_get_block,
  46. &HFSPLUS_I(mapping->host)->phys_size);
  47. if (unlikely(ret))
  48. hfsplus_write_failed(mapping, pos + len);
  49. return ret;
  50. }
  51. static sector_t hfsplus_bmap(struct address_space *mapping, sector_t block)
  52. {
  53. return generic_block_bmap(mapping, block, hfsplus_get_block);
  54. }
  55. static int hfsplus_releasepage(struct page *page, gfp_t mask)
  56. {
  57. struct inode *inode = page->mapping->host;
  58. struct super_block *sb = inode->i_sb;
  59. struct hfs_btree *tree;
  60. struct hfs_bnode *node;
  61. u32 nidx;
  62. int i, res = 1;
  63. switch (inode->i_ino) {
  64. case HFSPLUS_EXT_CNID:
  65. tree = HFSPLUS_SB(sb)->ext_tree;
  66. break;
  67. case HFSPLUS_CAT_CNID:
  68. tree = HFSPLUS_SB(sb)->cat_tree;
  69. break;
  70. case HFSPLUS_ATTR_CNID:
  71. tree = HFSPLUS_SB(sb)->attr_tree;
  72. break;
  73. default:
  74. BUG();
  75. return 0;
  76. }
  77. if (!tree)
  78. return 0;
  79. if (tree->node_size >= PAGE_SIZE) {
  80. nidx = page->index >>
  81. (tree->node_size_shift - PAGE_SHIFT);
  82. spin_lock(&tree->hash_lock);
  83. node = hfs_bnode_findhash(tree, nidx);
  84. if (!node)
  85. ;
  86. else if (atomic_read(&node->refcnt))
  87. res = 0;
  88. if (res && node) {
  89. hfs_bnode_unhash(node);
  90. hfs_bnode_free(node);
  91. }
  92. spin_unlock(&tree->hash_lock);
  93. } else {
  94. nidx = page->index <<
  95. (PAGE_SHIFT - tree->node_size_shift);
  96. i = 1 << (PAGE_SHIFT - tree->node_size_shift);
  97. spin_lock(&tree->hash_lock);
  98. do {
  99. node = hfs_bnode_findhash(tree, nidx++);
  100. if (!node)
  101. continue;
  102. if (atomic_read(&node->refcnt)) {
  103. res = 0;
  104. break;
  105. }
  106. hfs_bnode_unhash(node);
  107. hfs_bnode_free(node);
  108. } while (--i && nidx < tree->node_count);
  109. spin_unlock(&tree->hash_lock);
  110. }
  111. return res ? try_to_free_buffers(page) : 0;
  112. }
  113. static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
  114. {
  115. struct file *file = iocb->ki_filp;
  116. struct address_space *mapping = file->f_mapping;
  117. struct inode *inode = mapping->host;
  118. size_t count = iov_iter_count(iter);
  119. ssize_t ret;
  120. ret = blockdev_direct_IO(iocb, inode, iter, 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 = iocb->ki_pos + 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. inode_lock(inode);
  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. inode_unlock(inode);
  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 = setattr_prepare(dentry, 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. inode->i_mtime = inode->i_ctime = current_time(inode);
  232. }
  233. setattr_copy(inode, attr);
  234. mark_inode_dirty(inode);
  235. return 0;
  236. }
  237. int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
  238. int datasync)
  239. {
  240. struct inode *inode = file->f_mapping->host;
  241. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  242. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  243. int error = 0, error2;
  244. error = file_write_and_wait_range(file, start, end);
  245. if (error)
  246. return error;
  247. inode_lock(inode);
  248. /*
  249. * Sync inode metadata into the catalog and extent trees.
  250. */
  251. sync_inode_metadata(inode, 1);
  252. /*
  253. * And explicitly write out the btrees.
  254. */
  255. if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags))
  256. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  257. if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags)) {
  258. error2 =
  259. filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  260. if (!error)
  261. error = error2;
  262. }
  263. if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags)) {
  264. if (sbi->attr_tree) {
  265. error2 =
  266. filemap_write_and_wait(
  267. sbi->attr_tree->inode->i_mapping);
  268. if (!error)
  269. error = error2;
  270. } else {
  271. pr_err("sync non-existent attributes tree\n");
  272. }
  273. }
  274. if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) {
  275. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  276. if (!error)
  277. error = error2;
  278. }
  279. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  280. blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
  281. inode_unlock(inode);
  282. return error;
  283. }
  284. static const struct inode_operations hfsplus_file_inode_operations = {
  285. .setattr = hfsplus_setattr,
  286. .listxattr = hfsplus_listxattr,
  287. };
  288. static const struct file_operations hfsplus_file_operations = {
  289. .llseek = generic_file_llseek,
  290. .read_iter = generic_file_read_iter,
  291. .write_iter = generic_file_write_iter,
  292. .mmap = generic_file_mmap,
  293. .splice_read = generic_file_splice_read,
  294. .fsync = hfsplus_file_fsync,
  295. .open = hfsplus_file_open,
  296. .release = hfsplus_file_release,
  297. .unlocked_ioctl = hfsplus_ioctl,
  298. };
  299. struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
  300. umode_t mode)
  301. {
  302. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  303. struct inode *inode = new_inode(sb);
  304. struct hfsplus_inode_info *hip;
  305. if (!inode)
  306. return NULL;
  307. inode->i_ino = sbi->next_cnid++;
  308. inode_init_owner(inode, dir, mode);
  309. set_nlink(inode, 1);
  310. inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
  311. hip = HFSPLUS_I(inode);
  312. INIT_LIST_HEAD(&hip->open_dir_list);
  313. spin_lock_init(&hip->open_dir_lock);
  314. mutex_init(&hip->extents_lock);
  315. atomic_set(&hip->opencnt, 0);
  316. hip->extent_state = 0;
  317. hip->flags = 0;
  318. hip->userflags = 0;
  319. hip->subfolders = 0;
  320. memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
  321. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  322. hip->alloc_blocks = 0;
  323. hip->first_blocks = 0;
  324. hip->cached_start = 0;
  325. hip->cached_blocks = 0;
  326. hip->phys_size = 0;
  327. hip->fs_blocks = 0;
  328. hip->rsrc_inode = NULL;
  329. if (S_ISDIR(inode->i_mode)) {
  330. inode->i_size = 2;
  331. sbi->folder_count++;
  332. inode->i_op = &hfsplus_dir_inode_operations;
  333. inode->i_fop = &hfsplus_dir_operations;
  334. } else if (S_ISREG(inode->i_mode)) {
  335. sbi->file_count++;
  336. inode->i_op = &hfsplus_file_inode_operations;
  337. inode->i_fop = &hfsplus_file_operations;
  338. inode->i_mapping->a_ops = &hfsplus_aops;
  339. hip->clump_blocks = sbi->data_clump_blocks;
  340. } else if (S_ISLNK(inode->i_mode)) {
  341. sbi->file_count++;
  342. inode->i_op = &page_symlink_inode_operations;
  343. inode_nohighmem(inode);
  344. inode->i_mapping->a_ops = &hfsplus_aops;
  345. hip->clump_blocks = 1;
  346. } else
  347. sbi->file_count++;
  348. insert_inode_hash(inode);
  349. mark_inode_dirty(inode);
  350. hfsplus_mark_mdb_dirty(sb);
  351. return inode;
  352. }
  353. void hfsplus_delete_inode(struct inode *inode)
  354. {
  355. struct super_block *sb = inode->i_sb;
  356. if (S_ISDIR(inode->i_mode)) {
  357. HFSPLUS_SB(sb)->folder_count--;
  358. hfsplus_mark_mdb_dirty(sb);
  359. return;
  360. }
  361. HFSPLUS_SB(sb)->file_count--;
  362. if (S_ISREG(inode->i_mode)) {
  363. if (!inode->i_nlink) {
  364. inode->i_size = 0;
  365. hfsplus_file_truncate(inode);
  366. }
  367. } else if (S_ISLNK(inode->i_mode)) {
  368. inode->i_size = 0;
  369. hfsplus_file_truncate(inode);
  370. }
  371. hfsplus_mark_mdb_dirty(sb);
  372. }
  373. void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  374. {
  375. struct super_block *sb = inode->i_sb;
  376. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  377. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  378. u32 count;
  379. int i;
  380. memcpy(&hip->first_extents, &fork->extents, sizeof(hfsplus_extent_rec));
  381. for (count = 0, i = 0; i < 8; i++)
  382. count += be32_to_cpu(fork->extents[i].block_count);
  383. hip->first_blocks = count;
  384. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  385. hip->cached_start = 0;
  386. hip->cached_blocks = 0;
  387. hip->alloc_blocks = be32_to_cpu(fork->total_blocks);
  388. hip->phys_size = inode->i_size = be64_to_cpu(fork->total_size);
  389. hip->fs_blocks =
  390. (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  391. inode_set_bytes(inode, hip->fs_blocks << sb->s_blocksize_bits);
  392. hip->clump_blocks =
  393. be32_to_cpu(fork->clump_size) >> sbi->alloc_blksz_shift;
  394. if (!hip->clump_blocks) {
  395. hip->clump_blocks = HFSPLUS_IS_RSRC(inode) ?
  396. sbi->rsrc_clump_blocks :
  397. sbi->data_clump_blocks;
  398. }
  399. }
  400. void hfsplus_inode_write_fork(struct inode *inode,
  401. struct hfsplus_fork_raw *fork)
  402. {
  403. memcpy(&fork->extents, &HFSPLUS_I(inode)->first_extents,
  404. sizeof(hfsplus_extent_rec));
  405. fork->total_size = cpu_to_be64(inode->i_size);
  406. fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
  407. }
  408. int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
  409. {
  410. hfsplus_cat_entry entry;
  411. int res = 0;
  412. u16 type;
  413. type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
  414. HFSPLUS_I(inode)->linkid = 0;
  415. if (type == HFSPLUS_FOLDER) {
  416. struct hfsplus_cat_folder *folder = &entry.folder;
  417. if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
  418. /* panic? */;
  419. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  420. sizeof(struct hfsplus_cat_folder));
  421. hfsplus_get_perms(inode, &folder->permissions, 1);
  422. set_nlink(inode, 1);
  423. inode->i_size = 2 + be32_to_cpu(folder->valence);
  424. inode->i_atime = timespec_to_timespec64(hfsp_mt2ut(folder->access_date));
  425. inode->i_mtime = timespec_to_timespec64(hfsp_mt2ut(folder->content_mod_date));
  426. inode->i_ctime = timespec_to_timespec64(hfsp_mt2ut(folder->attribute_mod_date));
  427. HFSPLUS_I(inode)->create_date = folder->create_date;
  428. HFSPLUS_I(inode)->fs_blocks = 0;
  429. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  430. HFSPLUS_I(inode)->subfolders =
  431. be32_to_cpu(folder->subfolders);
  432. }
  433. inode->i_op = &hfsplus_dir_inode_operations;
  434. inode->i_fop = &hfsplus_dir_operations;
  435. } else if (type == HFSPLUS_FILE) {
  436. struct hfsplus_cat_file *file = &entry.file;
  437. if (fd->entrylength < sizeof(struct hfsplus_cat_file))
  438. /* panic? */;
  439. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  440. sizeof(struct hfsplus_cat_file));
  441. hfsplus_inode_read_fork(inode, HFSPLUS_IS_RSRC(inode) ?
  442. &file->rsrc_fork : &file->data_fork);
  443. hfsplus_get_perms(inode, &file->permissions, 0);
  444. set_nlink(inode, 1);
  445. if (S_ISREG(inode->i_mode)) {
  446. if (file->permissions.dev)
  447. set_nlink(inode,
  448. be32_to_cpu(file->permissions.dev));
  449. inode->i_op = &hfsplus_file_inode_operations;
  450. inode->i_fop = &hfsplus_file_operations;
  451. inode->i_mapping->a_ops = &hfsplus_aops;
  452. } else if (S_ISLNK(inode->i_mode)) {
  453. inode->i_op = &page_symlink_inode_operations;
  454. inode_nohighmem(inode);
  455. inode->i_mapping->a_ops = &hfsplus_aops;
  456. } else {
  457. init_special_inode(inode, inode->i_mode,
  458. be32_to_cpu(file->permissions.dev));
  459. }
  460. inode->i_atime = timespec_to_timespec64(hfsp_mt2ut(file->access_date));
  461. inode->i_mtime = timespec_to_timespec64(hfsp_mt2ut(file->content_mod_date));
  462. inode->i_ctime = timespec_to_timespec64(hfsp_mt2ut(file->attribute_mod_date));
  463. HFSPLUS_I(inode)->create_date = file->create_date;
  464. } else {
  465. pr_err("bad catalog entry used to create inode\n");
  466. res = -EIO;
  467. }
  468. return res;
  469. }
  470. int hfsplus_cat_write_inode(struct inode *inode)
  471. {
  472. struct inode *main_inode = inode;
  473. struct hfs_find_data fd;
  474. hfsplus_cat_entry entry;
  475. if (HFSPLUS_IS_RSRC(inode))
  476. main_inode = HFSPLUS_I(inode)->rsrc_inode;
  477. if (!main_inode->i_nlink)
  478. return 0;
  479. if (hfs_find_init(HFSPLUS_SB(main_inode->i_sb)->cat_tree, &fd))
  480. /* panic? */
  481. return -EIO;
  482. if (hfsplus_find_cat(main_inode->i_sb, main_inode->i_ino, &fd))
  483. /* panic? */
  484. goto out;
  485. if (S_ISDIR(main_inode->i_mode)) {
  486. struct hfsplus_cat_folder *folder = &entry.folder;
  487. if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
  488. /* panic? */;
  489. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  490. sizeof(struct hfsplus_cat_folder));
  491. /* simple node checks? */
  492. hfsplus_cat_set_perms(inode, &folder->permissions);
  493. folder->access_date = hfsp_ut2mt(inode->i_atime);
  494. folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  495. folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  496. folder->valence = cpu_to_be32(inode->i_size - 2);
  497. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  498. folder->subfolders =
  499. cpu_to_be32(HFSPLUS_I(inode)->subfolders);
  500. }
  501. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  502. sizeof(struct hfsplus_cat_folder));
  503. } else if (HFSPLUS_IS_RSRC(inode)) {
  504. struct hfsplus_cat_file *file = &entry.file;
  505. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  506. sizeof(struct hfsplus_cat_file));
  507. hfsplus_inode_write_fork(inode, &file->rsrc_fork);
  508. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  509. sizeof(struct hfsplus_cat_file));
  510. } else {
  511. struct hfsplus_cat_file *file = &entry.file;
  512. if (fd.entrylength < sizeof(struct hfsplus_cat_file))
  513. /* panic? */;
  514. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  515. sizeof(struct hfsplus_cat_file));
  516. hfsplus_inode_write_fork(inode, &file->data_fork);
  517. hfsplus_cat_set_perms(inode, &file->permissions);
  518. if (HFSPLUS_FLG_IMMUTABLE &
  519. (file->permissions.rootflags |
  520. file->permissions.userflags))
  521. file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
  522. else
  523. file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
  524. file->access_date = hfsp_ut2mt(inode->i_atime);
  525. file->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  526. file->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  527. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  528. sizeof(struct hfsplus_cat_file));
  529. }
  530. set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
  531. out:
  532. hfs_find_exit(&fd);
  533. return 0;
  534. }