inode.c 17 KB

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