inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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 "hfsplus_fs.h"
  17. #include "hfsplus_raw.h"
  18. static int hfsplus_readpage(struct file *file, struct page *page)
  19. {
  20. return block_read_full_page(page, hfsplus_get_block);
  21. }
  22. static int hfsplus_writepage(struct page *page, struct writeback_control *wbc)
  23. {
  24. return block_write_full_page(page, hfsplus_get_block, wbc);
  25. }
  26. static int hfsplus_write_begin(struct file *file, struct address_space *mapping,
  27. loff_t pos, unsigned len, unsigned flags,
  28. struct page **pagep, void **fsdata)
  29. {
  30. int ret;
  31. *pagep = NULL;
  32. ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  33. hfsplus_get_block,
  34. &HFSPLUS_I(mapping->host)->phys_size);
  35. if (unlikely(ret)) {
  36. loff_t isize = mapping->host->i_size;
  37. if (pos + len > isize)
  38. vmtruncate(mapping->host, isize);
  39. }
  40. return ret;
  41. }
  42. static sector_t hfsplus_bmap(struct address_space *mapping, sector_t block)
  43. {
  44. return generic_block_bmap(mapping, block, hfsplus_get_block);
  45. }
  46. static int hfsplus_releasepage(struct page *page, gfp_t mask)
  47. {
  48. struct inode *inode = page->mapping->host;
  49. struct super_block *sb = inode->i_sb;
  50. struct hfs_btree *tree;
  51. struct hfs_bnode *node;
  52. u32 nidx;
  53. int i, res = 1;
  54. switch (inode->i_ino) {
  55. case HFSPLUS_EXT_CNID:
  56. tree = HFSPLUS_SB(sb)->ext_tree;
  57. break;
  58. case HFSPLUS_CAT_CNID:
  59. tree = HFSPLUS_SB(sb)->cat_tree;
  60. break;
  61. case HFSPLUS_ATTR_CNID:
  62. tree = HFSPLUS_SB(sb)->attr_tree;
  63. break;
  64. default:
  65. BUG();
  66. return 0;
  67. }
  68. if (!tree)
  69. return 0;
  70. if (tree->node_size >= PAGE_CACHE_SIZE) {
  71. nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT);
  72. spin_lock(&tree->hash_lock);
  73. node = hfs_bnode_findhash(tree, nidx);
  74. if (!node)
  75. ;
  76. else if (atomic_read(&node->refcnt))
  77. res = 0;
  78. if (res && node) {
  79. hfs_bnode_unhash(node);
  80. hfs_bnode_free(node);
  81. }
  82. spin_unlock(&tree->hash_lock);
  83. } else {
  84. nidx = page->index << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  85. i = 1 << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  86. spin_lock(&tree->hash_lock);
  87. do {
  88. node = hfs_bnode_findhash(tree, nidx++);
  89. if (!node)
  90. continue;
  91. if (atomic_read(&node->refcnt)) {
  92. res = 0;
  93. break;
  94. }
  95. hfs_bnode_unhash(node);
  96. hfs_bnode_free(node);
  97. } while (--i && nidx < tree->node_count);
  98. spin_unlock(&tree->hash_lock);
  99. }
  100. return res ? try_to_free_buffers(page) : 0;
  101. }
  102. static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb,
  103. const struct iovec *iov, loff_t offset, unsigned long nr_segs)
  104. {
  105. struct file *file = iocb->ki_filp;
  106. struct inode *inode = file->f_path.dentry->d_inode->i_mapping->host;
  107. ssize_t ret;
  108. ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
  109. offset, nr_segs, hfsplus_get_block, NULL);
  110. /*
  111. * In case of error extending write may have instantiated a few
  112. * blocks outside i_size. Trim these off again.
  113. */
  114. if (unlikely((rw & WRITE) && ret < 0)) {
  115. loff_t isize = i_size_read(inode);
  116. loff_t end = offset + iov_length(iov, nr_segs);
  117. if (end > isize)
  118. vmtruncate(inode, isize);
  119. }
  120. return ret;
  121. }
  122. static int hfsplus_writepages(struct address_space *mapping,
  123. struct writeback_control *wbc)
  124. {
  125. return mpage_writepages(mapping, wbc, hfsplus_get_block);
  126. }
  127. const struct address_space_operations hfsplus_btree_aops = {
  128. .readpage = hfsplus_readpage,
  129. .writepage = hfsplus_writepage,
  130. .sync_page = block_sync_page,
  131. .write_begin = hfsplus_write_begin,
  132. .write_end = generic_write_end,
  133. .bmap = hfsplus_bmap,
  134. .releasepage = hfsplus_releasepage,
  135. };
  136. const struct address_space_operations hfsplus_aops = {
  137. .readpage = hfsplus_readpage,
  138. .writepage = hfsplus_writepage,
  139. .sync_page = block_sync_page,
  140. .write_begin = hfsplus_write_begin,
  141. .write_end = generic_write_end,
  142. .bmap = hfsplus_bmap,
  143. .direct_IO = hfsplus_direct_IO,
  144. .writepages = hfsplus_writepages,
  145. };
  146. const struct dentry_operations hfsplus_dentry_operations = {
  147. .d_hash = hfsplus_hash_dentry,
  148. .d_compare = hfsplus_compare_dentry,
  149. };
  150. static struct dentry *hfsplus_file_lookup(struct inode *dir, struct dentry *dentry,
  151. struct nameidata *nd)
  152. {
  153. struct hfs_find_data fd;
  154. struct super_block *sb = dir->i_sb;
  155. struct inode *inode = NULL;
  156. struct hfsplus_inode_info *hip;
  157. int err;
  158. if (HFSPLUS_IS_RSRC(dir) || strcmp(dentry->d_name.name, "rsrc"))
  159. goto out;
  160. inode = HFSPLUS_I(dir)->rsrc_inode;
  161. if (inode)
  162. goto out;
  163. inode = new_inode(sb);
  164. if (!inode)
  165. return ERR_PTR(-ENOMEM);
  166. hip = HFSPLUS_I(inode);
  167. inode->i_ino = dir->i_ino;
  168. INIT_LIST_HEAD(&hip->open_dir_list);
  169. mutex_init(&hip->extents_lock);
  170. hip->extent_state = 0;
  171. hip->flags = 0;
  172. set_bit(HFSPLUS_I_RSRC, &hip->flags);
  173. hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
  174. err = hfsplus_find_cat(sb, dir->i_ino, &fd);
  175. if (!err)
  176. err = hfsplus_cat_read_inode(inode, &fd);
  177. hfs_find_exit(&fd);
  178. if (err) {
  179. iput(inode);
  180. return ERR_PTR(err);
  181. }
  182. hip->rsrc_inode = dir;
  183. HFSPLUS_I(dir)->rsrc_inode = inode;
  184. igrab(dir);
  185. /*
  186. * __mark_inode_dirty expects inodes to be hashed. Since we don't
  187. * want resource fork inodes in the regular inode space, we make them
  188. * appear hashed, but do not put on any lists. hlist_del()
  189. * will work fine and require no locking.
  190. */
  191. hlist_add_fake(&inode->i_hash);
  192. mark_inode_dirty(inode);
  193. out:
  194. d_add(dentry, inode);
  195. return NULL;
  196. }
  197. static void hfsplus_get_perms(struct inode *inode, struct hfsplus_perm *perms, int dir)
  198. {
  199. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  200. u16 mode;
  201. mode = be16_to_cpu(perms->mode);
  202. inode->i_uid = be32_to_cpu(perms->owner);
  203. if (!inode->i_uid && !mode)
  204. inode->i_uid = sbi->uid;
  205. inode->i_gid = be32_to_cpu(perms->group);
  206. if (!inode->i_gid && !mode)
  207. inode->i_gid = sbi->gid;
  208. if (dir) {
  209. mode = mode ? (mode & S_IALLUGO) : (S_IRWXUGO & ~(sbi->umask));
  210. mode |= S_IFDIR;
  211. } else if (!mode)
  212. mode = S_IFREG | ((S_IRUGO|S_IWUGO) & ~(sbi->umask));
  213. inode->i_mode = mode;
  214. HFSPLUS_I(inode)->userflags = perms->userflags;
  215. if (perms->rootflags & HFSPLUS_FLG_IMMUTABLE)
  216. inode->i_flags |= S_IMMUTABLE;
  217. else
  218. inode->i_flags &= ~S_IMMUTABLE;
  219. if (perms->rootflags & HFSPLUS_FLG_APPEND)
  220. inode->i_flags |= S_APPEND;
  221. else
  222. inode->i_flags &= ~S_APPEND;
  223. }
  224. static int hfsplus_file_open(struct inode *inode, struct file *file)
  225. {
  226. if (HFSPLUS_IS_RSRC(inode))
  227. inode = HFSPLUS_I(inode)->rsrc_inode;
  228. if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
  229. return -EOVERFLOW;
  230. atomic_inc(&HFSPLUS_I(inode)->opencnt);
  231. return 0;
  232. }
  233. static int hfsplus_file_release(struct inode *inode, struct file *file)
  234. {
  235. struct super_block *sb = inode->i_sb;
  236. if (HFSPLUS_IS_RSRC(inode))
  237. inode = HFSPLUS_I(inode)->rsrc_inode;
  238. if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
  239. mutex_lock(&inode->i_mutex);
  240. hfsplus_file_truncate(inode);
  241. if (inode->i_flags & S_DEAD) {
  242. hfsplus_delete_cat(inode->i_ino,
  243. HFSPLUS_SB(sb)->hidden_dir, NULL);
  244. hfsplus_delete_inode(inode);
  245. }
  246. mutex_unlock(&inode->i_mutex);
  247. }
  248. return 0;
  249. }
  250. static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
  251. {
  252. struct inode *inode = dentry->d_inode;
  253. int error;
  254. error = inode_change_ok(inode, attr);
  255. if (error)
  256. return error;
  257. if ((attr->ia_valid & ATTR_SIZE) &&
  258. attr->ia_size != i_size_read(inode)) {
  259. error = vmtruncate(inode, attr->ia_size);
  260. if (error)
  261. return error;
  262. }
  263. setattr_copy(inode, attr);
  264. mark_inode_dirty(inode);
  265. return 0;
  266. }
  267. int hfsplus_file_fsync(struct file *file, int datasync)
  268. {
  269. struct inode *inode = file->f_mapping->host;
  270. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  271. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  272. int error = 0, error2;
  273. /*
  274. * Sync inode metadata into the catalog and extent trees.
  275. */
  276. sync_inode_metadata(inode, 1);
  277. /*
  278. * And explicitly write out the btrees.
  279. */
  280. if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags))
  281. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  282. if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags)) {
  283. error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  284. if (!error)
  285. error = error2;
  286. }
  287. if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags)) {
  288. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  289. if (!error)
  290. error = error2;
  291. }
  292. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  293. blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
  294. return error;
  295. }
  296. static const struct inode_operations hfsplus_file_inode_operations = {
  297. .lookup = hfsplus_file_lookup,
  298. .truncate = hfsplus_file_truncate,
  299. .setattr = hfsplus_setattr,
  300. .setxattr = hfsplus_setxattr,
  301. .getxattr = hfsplus_getxattr,
  302. .listxattr = hfsplus_listxattr,
  303. };
  304. static const struct file_operations hfsplus_file_operations = {
  305. .llseek = generic_file_llseek,
  306. .read = do_sync_read,
  307. .aio_read = generic_file_aio_read,
  308. .write = do_sync_write,
  309. .aio_write = generic_file_aio_write,
  310. .mmap = generic_file_mmap,
  311. .splice_read = generic_file_splice_read,
  312. .fsync = hfsplus_file_fsync,
  313. .open = hfsplus_file_open,
  314. .release = hfsplus_file_release,
  315. .unlocked_ioctl = hfsplus_ioctl,
  316. };
  317. struct inode *hfsplus_new_inode(struct super_block *sb, int mode)
  318. {
  319. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  320. struct inode *inode = new_inode(sb);
  321. struct hfsplus_inode_info *hip;
  322. if (!inode)
  323. return NULL;
  324. inode->i_ino = sbi->next_cnid++;
  325. inode->i_mode = mode;
  326. inode->i_uid = current_fsuid();
  327. inode->i_gid = current_fsgid();
  328. inode->i_nlink = 1;
  329. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
  330. hip = HFSPLUS_I(inode);
  331. INIT_LIST_HEAD(&hip->open_dir_list);
  332. mutex_init(&hip->extents_lock);
  333. atomic_set(&hip->opencnt, 0);
  334. hip->extent_state = 0;
  335. hip->flags = 0;
  336. memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
  337. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  338. hip->alloc_blocks = 0;
  339. hip->first_blocks = 0;
  340. hip->cached_start = 0;
  341. hip->cached_blocks = 0;
  342. hip->phys_size = 0;
  343. hip->fs_blocks = 0;
  344. hip->rsrc_inode = NULL;
  345. if (S_ISDIR(inode->i_mode)) {
  346. inode->i_size = 2;
  347. sbi->folder_count++;
  348. inode->i_op = &hfsplus_dir_inode_operations;
  349. inode->i_fop = &hfsplus_dir_operations;
  350. } else if (S_ISREG(inode->i_mode)) {
  351. sbi->file_count++;
  352. inode->i_op = &hfsplus_file_inode_operations;
  353. inode->i_fop = &hfsplus_file_operations;
  354. inode->i_mapping->a_ops = &hfsplus_aops;
  355. hip->clump_blocks = sbi->data_clump_blocks;
  356. } else if (S_ISLNK(inode->i_mode)) {
  357. sbi->file_count++;
  358. inode->i_op = &page_symlink_inode_operations;
  359. inode->i_mapping->a_ops = &hfsplus_aops;
  360. hip->clump_blocks = 1;
  361. } else
  362. sbi->file_count++;
  363. insert_inode_hash(inode);
  364. mark_inode_dirty(inode);
  365. sb->s_dirt = 1;
  366. return inode;
  367. }
  368. void hfsplus_delete_inode(struct inode *inode)
  369. {
  370. struct super_block *sb = inode->i_sb;
  371. if (S_ISDIR(inode->i_mode)) {
  372. HFSPLUS_SB(sb)->folder_count--;
  373. sb->s_dirt = 1;
  374. return;
  375. }
  376. HFSPLUS_SB(sb)->file_count--;
  377. if (S_ISREG(inode->i_mode)) {
  378. if (!inode->i_nlink) {
  379. inode->i_size = 0;
  380. hfsplus_file_truncate(inode);
  381. }
  382. } else if (S_ISLNK(inode->i_mode)) {
  383. inode->i_size = 0;
  384. hfsplus_file_truncate(inode);
  385. }
  386. sb->s_dirt = 1;
  387. }
  388. void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  389. {
  390. struct super_block *sb = inode->i_sb;
  391. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  392. struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
  393. u32 count;
  394. int i;
  395. memcpy(&hip->first_extents, &fork->extents, sizeof(hfsplus_extent_rec));
  396. for (count = 0, i = 0; i < 8; i++)
  397. count += be32_to_cpu(fork->extents[i].block_count);
  398. hip->first_blocks = count;
  399. memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
  400. hip->cached_start = 0;
  401. hip->cached_blocks = 0;
  402. hip->alloc_blocks = be32_to_cpu(fork->total_blocks);
  403. hip->phys_size = inode->i_size = be64_to_cpu(fork->total_size);
  404. hip->fs_blocks =
  405. (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  406. inode_set_bytes(inode, hip->fs_blocks << sb->s_blocksize_bits);
  407. hip->clump_blocks =
  408. be32_to_cpu(fork->clump_size) >> sbi->alloc_blksz_shift;
  409. if (!hip->clump_blocks) {
  410. hip->clump_blocks = HFSPLUS_IS_RSRC(inode) ?
  411. sbi->rsrc_clump_blocks :
  412. sbi->data_clump_blocks;
  413. }
  414. }
  415. void hfsplus_inode_write_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  416. {
  417. memcpy(&fork->extents, &HFSPLUS_I(inode)->first_extents,
  418. sizeof(hfsplus_extent_rec));
  419. fork->total_size = cpu_to_be64(inode->i_size);
  420. fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
  421. }
  422. int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
  423. {
  424. hfsplus_cat_entry entry;
  425. int res = 0;
  426. u16 type;
  427. type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
  428. HFSPLUS_I(inode)->linkid = 0;
  429. if (type == HFSPLUS_FOLDER) {
  430. struct hfsplus_cat_folder *folder = &entry.folder;
  431. if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
  432. /* panic? */;
  433. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  434. sizeof(struct hfsplus_cat_folder));
  435. hfsplus_get_perms(inode, &folder->permissions, 1);
  436. inode->i_nlink = 1;
  437. inode->i_size = 2 + be32_to_cpu(folder->valence);
  438. inode->i_atime = hfsp_mt2ut(folder->access_date);
  439. inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
  440. inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
  441. HFSPLUS_I(inode)->create_date = folder->create_date;
  442. HFSPLUS_I(inode)->fs_blocks = 0;
  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. inode->i_nlink = 1;
  455. if (S_ISREG(inode->i_mode)) {
  456. if (file->permissions.dev)
  457. inode->i_nlink = be32_to_cpu(file->permissions.dev);
  458. inode->i_op = &hfsplus_file_inode_operations;
  459. inode->i_fop = &hfsplus_file_operations;
  460. inode->i_mapping->a_ops = &hfsplus_aops;
  461. } else if (S_ISLNK(inode->i_mode)) {
  462. inode->i_op = &page_symlink_inode_operations;
  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. printk(KERN_ERR "hfs: 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. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  506. sizeof(struct hfsplus_cat_folder));
  507. } else if (HFSPLUS_IS_RSRC(inode)) {
  508. struct hfsplus_cat_file *file = &entry.file;
  509. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  510. sizeof(struct hfsplus_cat_file));
  511. hfsplus_inode_write_fork(inode, &file->rsrc_fork);
  512. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  513. sizeof(struct hfsplus_cat_file));
  514. } else {
  515. struct hfsplus_cat_file *file = &entry.file;
  516. if (fd.entrylength < sizeof(struct hfsplus_cat_file))
  517. /* panic? */;
  518. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  519. sizeof(struct hfsplus_cat_file));
  520. hfsplus_inode_write_fork(inode, &file->data_fork);
  521. hfsplus_cat_set_perms(inode, &file->permissions);
  522. if ((file->permissions.rootflags | file->permissions.userflags) & HFSPLUS_FLG_IMMUTABLE)
  523. file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
  524. else
  525. file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
  526. file->access_date = hfsp_ut2mt(inode->i_atime);
  527. file->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  528. file->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  529. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  530. sizeof(struct hfsplus_cat_file));
  531. }
  532. set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
  533. out:
  534. hfs_find_exit(&fd);
  535. return 0;
  536. }