inode.c 17 KB

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