inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. const struct iovec *iov, loff_t offset, unsigned long nr_segs)
  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. ssize_t ret;
  119. ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs,
  120. 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((rw & WRITE) && ret < 0)) {
  126. loff_t isize = i_size_read(inode);
  127. loff_t end = offset + iov_length(iov, nr_segs);
  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 = dentry->d_inode;
  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. truncate_setsize(inode, attr->ia_size);
  224. hfsplus_file_truncate(inode);
  225. }
  226. setattr_copy(inode, attr);
  227. mark_inode_dirty(inode);
  228. if (attr->ia_valid & ATTR_MODE) {
  229. error = posix_acl_chmod(inode, inode->i_mode);
  230. if (unlikely(error))
  231. return error;
  232. }
  233. return 0;
  234. }
  235. int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
  236. int datasync)
  237. {
  238. struct inode *inode = file->f_mapping->host;
  239. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  240. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  241. int error = 0, error2;
  242. error = filemap_write_and_wait_range(inode->i_mapping, start, end);
  243. if (error)
  244. return error;
  245. mutex_lock(&inode->i_mutex);
  246. /*
  247. * Sync inode metadata into the catalog and extent trees.
  248. */
  249. sync_inode_metadata(inode, 1);
  250. /*
  251. * And explicitly write out the btrees.
  252. */
  253. if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags))
  254. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  255. if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags)) {
  256. error2 =
  257. filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  258. if (!error)
  259. error = error2;
  260. }
  261. if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags)) {
  262. if (sbi->attr_tree) {
  263. error2 =
  264. filemap_write_and_wait(
  265. sbi->attr_tree->inode->i_mapping);
  266. if (!error)
  267. error = error2;
  268. } else {
  269. pr_err("sync non-existent attributes tree\n");
  270. }
  271. }
  272. if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) {
  273. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  274. if (!error)
  275. error = error2;
  276. }
  277. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  278. blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
  279. mutex_unlock(&inode->i_mutex);
  280. return error;
  281. }
  282. static const struct inode_operations hfsplus_file_inode_operations = {
  283. .setattr = hfsplus_setattr,
  284. .setxattr = generic_setxattr,
  285. .getxattr = generic_getxattr,
  286. .listxattr = hfsplus_listxattr,
  287. .removexattr = generic_removexattr,
  288. #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
  289. .get_acl = hfsplus_get_posix_acl,
  290. .set_acl = hfsplus_set_posix_acl,
  291. #endif
  292. };
  293. static const struct file_operations hfsplus_file_operations = {
  294. .llseek = generic_file_llseek,
  295. .read = do_sync_read,
  296. .aio_read = generic_file_aio_read,
  297. .write = do_sync_write,
  298. .aio_write = generic_file_aio_write,
  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_SEC;
  319. hip = HFSPLUS_I(inode);
  320. INIT_LIST_HEAD(&hip->open_dir_list);
  321. mutex_init(&hip->extents_lock);
  322. atomic_set(&hip->opencnt, 0);
  323. hip->extent_state = 0;
  324. hip->flags = 0;
  325. hip->userflags = 0;
  326. hip->subfolders = 0;
  327. memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
  328. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  329. hip->alloc_blocks = 0;
  330. hip->first_blocks = 0;
  331. hip->cached_start = 0;
  332. hip->cached_blocks = 0;
  333. hip->phys_size = 0;
  334. hip->fs_blocks = 0;
  335. hip->rsrc_inode = NULL;
  336. if (S_ISDIR(inode->i_mode)) {
  337. inode->i_size = 2;
  338. sbi->folder_count++;
  339. inode->i_op = &hfsplus_dir_inode_operations;
  340. inode->i_fop = &hfsplus_dir_operations;
  341. } else if (S_ISREG(inode->i_mode)) {
  342. sbi->file_count++;
  343. inode->i_op = &hfsplus_file_inode_operations;
  344. inode->i_fop = &hfsplus_file_operations;
  345. inode->i_mapping->a_ops = &hfsplus_aops;
  346. hip->clump_blocks = sbi->data_clump_blocks;
  347. } else if (S_ISLNK(inode->i_mode)) {
  348. sbi->file_count++;
  349. inode->i_op = &page_symlink_inode_operations;
  350. inode->i_mapping->a_ops = &hfsplus_aops;
  351. hip->clump_blocks = 1;
  352. } else
  353. sbi->file_count++;
  354. insert_inode_hash(inode);
  355. mark_inode_dirty(inode);
  356. hfsplus_mark_mdb_dirty(sb);
  357. return inode;
  358. }
  359. void hfsplus_delete_inode(struct inode *inode)
  360. {
  361. struct super_block *sb = inode->i_sb;
  362. if (S_ISDIR(inode->i_mode)) {
  363. HFSPLUS_SB(sb)->folder_count--;
  364. hfsplus_mark_mdb_dirty(sb);
  365. return;
  366. }
  367. HFSPLUS_SB(sb)->file_count--;
  368. if (S_ISREG(inode->i_mode)) {
  369. if (!inode->i_nlink) {
  370. inode->i_size = 0;
  371. hfsplus_file_truncate(inode);
  372. }
  373. } else if (S_ISLNK(inode->i_mode)) {
  374. inode->i_size = 0;
  375. hfsplus_file_truncate(inode);
  376. }
  377. hfsplus_mark_mdb_dirty(sb);
  378. }
  379. void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  380. {
  381. struct super_block *sb = inode->i_sb;
  382. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  383. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  384. u32 count;
  385. int i;
  386. memcpy(&hip->first_extents, &fork->extents, sizeof(hfsplus_extent_rec));
  387. for (count = 0, i = 0; i < 8; i++)
  388. count += be32_to_cpu(fork->extents[i].block_count);
  389. hip->first_blocks = count;
  390. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  391. hip->cached_start = 0;
  392. hip->cached_blocks = 0;
  393. hip->alloc_blocks = be32_to_cpu(fork->total_blocks);
  394. hip->phys_size = inode->i_size = be64_to_cpu(fork->total_size);
  395. hip->fs_blocks =
  396. (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  397. inode_set_bytes(inode, hip->fs_blocks << sb->s_blocksize_bits);
  398. hip->clump_blocks =
  399. be32_to_cpu(fork->clump_size) >> sbi->alloc_blksz_shift;
  400. if (!hip->clump_blocks) {
  401. hip->clump_blocks = HFSPLUS_IS_RSRC(inode) ?
  402. sbi->rsrc_clump_blocks :
  403. sbi->data_clump_blocks;
  404. }
  405. }
  406. void hfsplus_inode_write_fork(struct inode *inode,
  407. struct hfsplus_fork_raw *fork)
  408. {
  409. memcpy(&fork->extents, &HFSPLUS_I(inode)->first_extents,
  410. sizeof(hfsplus_extent_rec));
  411. fork->total_size = cpu_to_be64(inode->i_size);
  412. fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
  413. }
  414. int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
  415. {
  416. hfsplus_cat_entry entry;
  417. int res = 0;
  418. u16 type;
  419. type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
  420. HFSPLUS_I(inode)->linkid = 0;
  421. if (type == HFSPLUS_FOLDER) {
  422. struct hfsplus_cat_folder *folder = &entry.folder;
  423. if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
  424. /* panic? */;
  425. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  426. sizeof(struct hfsplus_cat_folder));
  427. hfsplus_get_perms(inode, &folder->permissions, 1);
  428. set_nlink(inode, 1);
  429. inode->i_size = 2 + be32_to_cpu(folder->valence);
  430. inode->i_atime = hfsp_mt2ut(folder->access_date);
  431. inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
  432. inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
  433. HFSPLUS_I(inode)->create_date = folder->create_date;
  434. HFSPLUS_I(inode)->fs_blocks = 0;
  435. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  436. HFSPLUS_I(inode)->subfolders =
  437. be32_to_cpu(folder->subfolders);
  438. }
  439. inode->i_op = &hfsplus_dir_inode_operations;
  440. inode->i_fop = &hfsplus_dir_operations;
  441. } else if (type == HFSPLUS_FILE) {
  442. struct hfsplus_cat_file *file = &entry.file;
  443. if (fd->entrylength < sizeof(struct hfsplus_cat_file))
  444. /* panic? */;
  445. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  446. sizeof(struct hfsplus_cat_file));
  447. hfsplus_inode_read_fork(inode, HFSPLUS_IS_RSRC(inode) ?
  448. &file->rsrc_fork : &file->data_fork);
  449. hfsplus_get_perms(inode, &file->permissions, 0);
  450. set_nlink(inode, 1);
  451. if (S_ISREG(inode->i_mode)) {
  452. if (file->permissions.dev)
  453. set_nlink(inode,
  454. be32_to_cpu(file->permissions.dev));
  455. inode->i_op = &hfsplus_file_inode_operations;
  456. inode->i_fop = &hfsplus_file_operations;
  457. inode->i_mapping->a_ops = &hfsplus_aops;
  458. } else if (S_ISLNK(inode->i_mode)) {
  459. inode->i_op = &page_symlink_inode_operations;
  460. inode->i_mapping->a_ops = &hfsplus_aops;
  461. } else {
  462. init_special_inode(inode, inode->i_mode,
  463. be32_to_cpu(file->permissions.dev));
  464. }
  465. inode->i_atime = hfsp_mt2ut(file->access_date);
  466. inode->i_mtime = hfsp_mt2ut(file->content_mod_date);
  467. inode->i_ctime = hfsp_mt2ut(file->attribute_mod_date);
  468. HFSPLUS_I(inode)->create_date = file->create_date;
  469. } else {
  470. pr_err("bad catalog entry used to create inode\n");
  471. res = -EIO;
  472. }
  473. return res;
  474. }
  475. int hfsplus_cat_write_inode(struct inode *inode)
  476. {
  477. struct inode *main_inode = inode;
  478. struct hfs_find_data fd;
  479. hfsplus_cat_entry entry;
  480. if (HFSPLUS_IS_RSRC(inode))
  481. main_inode = HFSPLUS_I(inode)->rsrc_inode;
  482. if (!main_inode->i_nlink)
  483. return 0;
  484. if (hfs_find_init(HFSPLUS_SB(main_inode->i_sb)->cat_tree, &fd))
  485. /* panic? */
  486. return -EIO;
  487. if (hfsplus_find_cat(main_inode->i_sb, main_inode->i_ino, &fd))
  488. /* panic? */
  489. goto out;
  490. if (S_ISDIR(main_inode->i_mode)) {
  491. struct hfsplus_cat_folder *folder = &entry.folder;
  492. if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
  493. /* panic? */;
  494. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  495. sizeof(struct hfsplus_cat_folder));
  496. /* simple node checks? */
  497. hfsplus_cat_set_perms(inode, &folder->permissions);
  498. folder->access_date = hfsp_ut2mt(inode->i_atime);
  499. folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  500. folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  501. folder->valence = cpu_to_be32(inode->i_size - 2);
  502. if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
  503. folder->subfolders =
  504. cpu_to_be32(HFSPLUS_I(inode)->subfolders);
  505. }
  506. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  507. sizeof(struct hfsplus_cat_folder));
  508. } else if (HFSPLUS_IS_RSRC(inode)) {
  509. struct hfsplus_cat_file *file = &entry.file;
  510. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  511. sizeof(struct hfsplus_cat_file));
  512. hfsplus_inode_write_fork(inode, &file->rsrc_fork);
  513. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  514. sizeof(struct hfsplus_cat_file));
  515. } else {
  516. struct hfsplus_cat_file *file = &entry.file;
  517. if (fd.entrylength < sizeof(struct hfsplus_cat_file))
  518. /* panic? */;
  519. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  520. sizeof(struct hfsplus_cat_file));
  521. hfsplus_inode_write_fork(inode, &file->data_fork);
  522. hfsplus_cat_set_perms(inode, &file->permissions);
  523. if (HFSPLUS_FLG_IMMUTABLE &
  524. (file->permissions.rootflags |
  525. file->permissions.userflags))
  526. file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
  527. else
  528. file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
  529. file->access_date = hfsp_ut2mt(inode->i_atime);
  530. file->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  531. file->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  532. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  533. sizeof(struct hfsplus_cat_file));
  534. }
  535. set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
  536. out:
  537. hfs_find_exit(&fd);
  538. return 0;
  539. }