inode.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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 "hfsplus_fs.h"
  15. #include "hfsplus_raw.h"
  16. static int hfsplus_readpage(struct file *file, struct page *page)
  17. {
  18. return block_read_full_page(page, hfsplus_get_block);
  19. }
  20. static int hfsplus_writepage(struct page *page, struct writeback_control *wbc)
  21. {
  22. return block_write_full_page(page, hfsplus_get_block, wbc);
  23. }
  24. static int hfsplus_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
  25. {
  26. return cont_prepare_write(page, from, to, hfsplus_get_block,
  27. &HFSPLUS_I(page->mapping->host).phys_size);
  28. }
  29. static sector_t hfsplus_bmap(struct address_space *mapping, sector_t block)
  30. {
  31. return generic_block_bmap(mapping, block, hfsplus_get_block);
  32. }
  33. static int hfsplus_releasepage(struct page *page, gfp_t mask)
  34. {
  35. struct inode *inode = page->mapping->host;
  36. struct super_block *sb = inode->i_sb;
  37. struct hfs_btree *tree;
  38. struct hfs_bnode *node;
  39. u32 nidx;
  40. int i, res = 1;
  41. switch (inode->i_ino) {
  42. case HFSPLUS_EXT_CNID:
  43. tree = HFSPLUS_SB(sb).ext_tree;
  44. break;
  45. case HFSPLUS_CAT_CNID:
  46. tree = HFSPLUS_SB(sb).cat_tree;
  47. break;
  48. case HFSPLUS_ATTR_CNID:
  49. tree = HFSPLUS_SB(sb).attr_tree;
  50. break;
  51. default:
  52. BUG();
  53. return 0;
  54. }
  55. if (tree->node_size >= PAGE_CACHE_SIZE) {
  56. nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT);
  57. spin_lock(&tree->hash_lock);
  58. node = hfs_bnode_findhash(tree, nidx);
  59. if (!node)
  60. ;
  61. else if (atomic_read(&node->refcnt))
  62. res = 0;
  63. if (res && node) {
  64. hfs_bnode_unhash(node);
  65. hfs_bnode_free(node);
  66. }
  67. spin_unlock(&tree->hash_lock);
  68. } else {
  69. nidx = page->index << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  70. i = 1 << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  71. spin_lock(&tree->hash_lock);
  72. do {
  73. node = hfs_bnode_findhash(tree, nidx++);
  74. if (!node)
  75. continue;
  76. if (atomic_read(&node->refcnt)) {
  77. res = 0;
  78. break;
  79. }
  80. hfs_bnode_unhash(node);
  81. hfs_bnode_free(node);
  82. } while (--i && nidx < tree->node_count);
  83. spin_unlock(&tree->hash_lock);
  84. }
  85. return res ? try_to_free_buffers(page) : 0;
  86. }
  87. static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb,
  88. const struct iovec *iov, loff_t offset, unsigned long nr_segs)
  89. {
  90. struct file *file = iocb->ki_filp;
  91. struct inode *inode = file->f_path.dentry->d_inode->i_mapping->host;
  92. return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
  93. offset, nr_segs, hfsplus_get_block, NULL);
  94. }
  95. static int hfsplus_writepages(struct address_space *mapping,
  96. struct writeback_control *wbc)
  97. {
  98. return mpage_writepages(mapping, wbc, hfsplus_get_block);
  99. }
  100. const struct address_space_operations hfsplus_btree_aops = {
  101. .readpage = hfsplus_readpage,
  102. .writepage = hfsplus_writepage,
  103. .sync_page = block_sync_page,
  104. .prepare_write = hfsplus_prepare_write,
  105. .commit_write = generic_commit_write,
  106. .bmap = hfsplus_bmap,
  107. .releasepage = hfsplus_releasepage,
  108. };
  109. const struct address_space_operations hfsplus_aops = {
  110. .readpage = hfsplus_readpage,
  111. .writepage = hfsplus_writepage,
  112. .sync_page = block_sync_page,
  113. .prepare_write = hfsplus_prepare_write,
  114. .commit_write = generic_commit_write,
  115. .bmap = hfsplus_bmap,
  116. .direct_IO = hfsplus_direct_IO,
  117. .writepages = hfsplus_writepages,
  118. };
  119. static struct dentry *hfsplus_file_lookup(struct inode *dir, struct dentry *dentry,
  120. struct nameidata *nd)
  121. {
  122. struct hfs_find_data fd;
  123. struct super_block *sb = dir->i_sb;
  124. struct inode *inode = NULL;
  125. int err;
  126. if (HFSPLUS_IS_RSRC(dir) || strcmp(dentry->d_name.name, "rsrc"))
  127. goto out;
  128. inode = HFSPLUS_I(dir).rsrc_inode;
  129. if (inode)
  130. goto out;
  131. inode = new_inode(sb);
  132. if (!inode)
  133. return ERR_PTR(-ENOMEM);
  134. inode->i_ino = dir->i_ino;
  135. INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
  136. init_MUTEX(&HFSPLUS_I(inode).extents_lock);
  137. HFSPLUS_I(inode).flags = HFSPLUS_FLG_RSRC;
  138. hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
  139. err = hfsplus_find_cat(sb, dir->i_ino, &fd);
  140. if (!err)
  141. err = hfsplus_cat_read_inode(inode, &fd);
  142. hfs_find_exit(&fd);
  143. if (err) {
  144. iput(inode);
  145. return ERR_PTR(err);
  146. }
  147. HFSPLUS_I(inode).rsrc_inode = dir;
  148. HFSPLUS_I(dir).rsrc_inode = inode;
  149. igrab(dir);
  150. hlist_add_head(&inode->i_hash, &HFSPLUS_SB(sb).rsrc_inodes);
  151. mark_inode_dirty(inode);
  152. out:
  153. d_add(dentry, inode);
  154. return NULL;
  155. }
  156. static void hfsplus_get_perms(struct inode *inode, struct hfsplus_perm *perms, int dir)
  157. {
  158. struct super_block *sb = inode->i_sb;
  159. u16 mode;
  160. mode = be16_to_cpu(perms->mode);
  161. inode->i_uid = be32_to_cpu(perms->owner);
  162. if (!inode->i_uid && !mode)
  163. inode->i_uid = HFSPLUS_SB(sb).uid;
  164. inode->i_gid = be32_to_cpu(perms->group);
  165. if (!inode->i_gid && !mode)
  166. inode->i_gid = HFSPLUS_SB(sb).gid;
  167. if (dir) {
  168. mode = mode ? (mode & S_IALLUGO) :
  169. (S_IRWXUGO & ~(HFSPLUS_SB(sb).umask));
  170. mode |= S_IFDIR;
  171. } else if (!mode)
  172. mode = S_IFREG | ((S_IRUGO|S_IWUGO) &
  173. ~(HFSPLUS_SB(sb).umask));
  174. inode->i_mode = mode;
  175. HFSPLUS_I(inode).rootflags = perms->rootflags;
  176. HFSPLUS_I(inode).userflags = perms->userflags;
  177. if (perms->rootflags & HFSPLUS_FLG_IMMUTABLE)
  178. inode->i_flags |= S_IMMUTABLE;
  179. else
  180. inode->i_flags &= ~S_IMMUTABLE;
  181. if (perms->rootflags & HFSPLUS_FLG_APPEND)
  182. inode->i_flags |= S_APPEND;
  183. else
  184. inode->i_flags &= ~S_APPEND;
  185. }
  186. static void hfsplus_set_perms(struct inode *inode, struct hfsplus_perm *perms)
  187. {
  188. if (inode->i_flags & S_IMMUTABLE)
  189. perms->rootflags |= HFSPLUS_FLG_IMMUTABLE;
  190. else
  191. perms->rootflags &= ~HFSPLUS_FLG_IMMUTABLE;
  192. if (inode->i_flags & S_APPEND)
  193. perms->rootflags |= HFSPLUS_FLG_APPEND;
  194. else
  195. perms->rootflags &= ~HFSPLUS_FLG_APPEND;
  196. perms->userflags = HFSPLUS_I(inode).userflags;
  197. perms->mode = cpu_to_be16(inode->i_mode);
  198. perms->owner = cpu_to_be32(inode->i_uid);
  199. perms->group = cpu_to_be32(inode->i_gid);
  200. perms->dev = cpu_to_be32(HFSPLUS_I(inode).dev);
  201. }
  202. static int hfsplus_permission(struct inode *inode, int mask, struct nameidata *nd)
  203. {
  204. /* MAY_EXEC is also used for lookup, if no x bit is set allow lookup,
  205. * open_exec has the same test, so it's still not executable, if a x bit
  206. * is set fall back to standard permission check.
  207. */
  208. if (S_ISREG(inode->i_mode) && mask & MAY_EXEC && !(inode->i_mode & 0111))
  209. return 0;
  210. return generic_permission(inode, mask, NULL);
  211. }
  212. static int hfsplus_file_open(struct inode *inode, struct file *file)
  213. {
  214. if (HFSPLUS_IS_RSRC(inode))
  215. inode = HFSPLUS_I(inode).rsrc_inode;
  216. if (atomic_read(&file->f_count) != 1)
  217. return 0;
  218. atomic_inc(&HFSPLUS_I(inode).opencnt);
  219. return 0;
  220. }
  221. static int hfsplus_file_release(struct inode *inode, struct file *file)
  222. {
  223. struct super_block *sb = inode->i_sb;
  224. if (HFSPLUS_IS_RSRC(inode))
  225. inode = HFSPLUS_I(inode).rsrc_inode;
  226. if (atomic_read(&file->f_count) != 0)
  227. return 0;
  228. if (atomic_dec_and_test(&HFSPLUS_I(inode).opencnt)) {
  229. mutex_lock(&inode->i_mutex);
  230. hfsplus_file_truncate(inode);
  231. if (inode->i_flags & S_DEAD) {
  232. hfsplus_delete_cat(inode->i_ino, HFSPLUS_SB(sb).hidden_dir, NULL);
  233. hfsplus_delete_inode(inode);
  234. }
  235. mutex_unlock(&inode->i_mutex);
  236. }
  237. return 0;
  238. }
  239. extern const struct inode_operations hfsplus_dir_inode_operations;
  240. extern struct file_operations hfsplus_dir_operations;
  241. static const struct inode_operations hfsplus_file_inode_operations = {
  242. .lookup = hfsplus_file_lookup,
  243. .truncate = hfsplus_file_truncate,
  244. .permission = hfsplus_permission,
  245. .setxattr = hfsplus_setxattr,
  246. .getxattr = hfsplus_getxattr,
  247. .listxattr = hfsplus_listxattr,
  248. };
  249. static const struct file_operations hfsplus_file_operations = {
  250. .llseek = generic_file_llseek,
  251. .read = do_sync_read,
  252. .aio_read = generic_file_aio_read,
  253. .write = do_sync_write,
  254. .aio_write = generic_file_aio_write,
  255. .mmap = generic_file_mmap,
  256. .sendfile = generic_file_sendfile,
  257. .fsync = file_fsync,
  258. .open = hfsplus_file_open,
  259. .release = hfsplus_file_release,
  260. .ioctl = hfsplus_ioctl,
  261. };
  262. struct inode *hfsplus_new_inode(struct super_block *sb, int mode)
  263. {
  264. struct inode *inode = new_inode(sb);
  265. if (!inode)
  266. return NULL;
  267. inode->i_ino = HFSPLUS_SB(sb).next_cnid++;
  268. inode->i_mode = mode;
  269. inode->i_uid = current->fsuid;
  270. inode->i_gid = current->fsgid;
  271. inode->i_nlink = 1;
  272. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
  273. INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
  274. init_MUTEX(&HFSPLUS_I(inode).extents_lock);
  275. atomic_set(&HFSPLUS_I(inode).opencnt, 0);
  276. HFSPLUS_I(inode).flags = 0;
  277. memset(HFSPLUS_I(inode).first_extents, 0, sizeof(hfsplus_extent_rec));
  278. memset(HFSPLUS_I(inode).cached_extents, 0, sizeof(hfsplus_extent_rec));
  279. HFSPLUS_I(inode).alloc_blocks = 0;
  280. HFSPLUS_I(inode).first_blocks = 0;
  281. HFSPLUS_I(inode).cached_start = 0;
  282. HFSPLUS_I(inode).cached_blocks = 0;
  283. HFSPLUS_I(inode).phys_size = 0;
  284. HFSPLUS_I(inode).fs_blocks = 0;
  285. HFSPLUS_I(inode).rsrc_inode = NULL;
  286. if (S_ISDIR(inode->i_mode)) {
  287. inode->i_size = 2;
  288. HFSPLUS_SB(sb).folder_count++;
  289. inode->i_op = &hfsplus_dir_inode_operations;
  290. inode->i_fop = &hfsplus_dir_operations;
  291. } else if (S_ISREG(inode->i_mode)) {
  292. HFSPLUS_SB(sb).file_count++;
  293. inode->i_op = &hfsplus_file_inode_operations;
  294. inode->i_fop = &hfsplus_file_operations;
  295. inode->i_mapping->a_ops = &hfsplus_aops;
  296. HFSPLUS_I(inode).clump_blocks = HFSPLUS_SB(sb).data_clump_blocks;
  297. } else if (S_ISLNK(inode->i_mode)) {
  298. HFSPLUS_SB(sb).file_count++;
  299. inode->i_op = &page_symlink_inode_operations;
  300. inode->i_mapping->a_ops = &hfsplus_aops;
  301. HFSPLUS_I(inode).clump_blocks = 1;
  302. } else
  303. HFSPLUS_SB(sb).file_count++;
  304. insert_inode_hash(inode);
  305. mark_inode_dirty(inode);
  306. sb->s_dirt = 1;
  307. return inode;
  308. }
  309. void hfsplus_delete_inode(struct inode *inode)
  310. {
  311. struct super_block *sb = inode->i_sb;
  312. if (S_ISDIR(inode->i_mode)) {
  313. HFSPLUS_SB(sb).folder_count--;
  314. sb->s_dirt = 1;
  315. return;
  316. }
  317. HFSPLUS_SB(sb).file_count--;
  318. if (S_ISREG(inode->i_mode)) {
  319. if (!inode->i_nlink) {
  320. inode->i_size = 0;
  321. hfsplus_file_truncate(inode);
  322. }
  323. } else if (S_ISLNK(inode->i_mode)) {
  324. inode->i_size = 0;
  325. hfsplus_file_truncate(inode);
  326. }
  327. sb->s_dirt = 1;
  328. }
  329. void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  330. {
  331. struct super_block *sb = inode->i_sb;
  332. u32 count;
  333. int i;
  334. memcpy(&HFSPLUS_I(inode).first_extents, &fork->extents,
  335. sizeof(hfsplus_extent_rec));
  336. for (count = 0, i = 0; i < 8; i++)
  337. count += be32_to_cpu(fork->extents[i].block_count);
  338. HFSPLUS_I(inode).first_blocks = count;
  339. memset(HFSPLUS_I(inode).cached_extents, 0, sizeof(hfsplus_extent_rec));
  340. HFSPLUS_I(inode).cached_start = 0;
  341. HFSPLUS_I(inode).cached_blocks = 0;
  342. HFSPLUS_I(inode).alloc_blocks = be32_to_cpu(fork->total_blocks);
  343. inode->i_size = HFSPLUS_I(inode).phys_size = be64_to_cpu(fork->total_size);
  344. HFSPLUS_I(inode).fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  345. inode_set_bytes(inode, HFSPLUS_I(inode).fs_blocks << sb->s_blocksize_bits);
  346. HFSPLUS_I(inode).clump_blocks = be32_to_cpu(fork->clump_size) >> HFSPLUS_SB(sb).alloc_blksz_shift;
  347. if (!HFSPLUS_I(inode).clump_blocks)
  348. HFSPLUS_I(inode).clump_blocks = HFSPLUS_IS_RSRC(inode) ? HFSPLUS_SB(sb).rsrc_clump_blocks :
  349. HFSPLUS_SB(sb).data_clump_blocks;
  350. }
  351. void hfsplus_inode_write_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
  352. {
  353. memcpy(&fork->extents, &HFSPLUS_I(inode).first_extents,
  354. sizeof(hfsplus_extent_rec));
  355. fork->total_size = cpu_to_be64(inode->i_size);
  356. fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode).alloc_blocks);
  357. }
  358. int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
  359. {
  360. hfsplus_cat_entry entry;
  361. int res = 0;
  362. u16 type;
  363. type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
  364. HFSPLUS_I(inode).dev = 0;
  365. if (type == HFSPLUS_FOLDER) {
  366. struct hfsplus_cat_folder *folder = &entry.folder;
  367. if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
  368. /* panic? */;
  369. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  370. sizeof(struct hfsplus_cat_folder));
  371. hfsplus_get_perms(inode, &folder->permissions, 1);
  372. inode->i_nlink = 1;
  373. inode->i_size = 2 + be32_to_cpu(folder->valence);
  374. inode->i_atime = hfsp_mt2ut(folder->access_date);
  375. inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
  376. inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
  377. HFSPLUS_I(inode).create_date = folder->create_date;
  378. HFSPLUS_I(inode).fs_blocks = 0;
  379. inode->i_op = &hfsplus_dir_inode_operations;
  380. inode->i_fop = &hfsplus_dir_operations;
  381. } else if (type == HFSPLUS_FILE) {
  382. struct hfsplus_cat_file *file = &entry.file;
  383. if (fd->entrylength < sizeof(struct hfsplus_cat_file))
  384. /* panic? */;
  385. hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
  386. sizeof(struct hfsplus_cat_file));
  387. hfsplus_inode_read_fork(inode, HFSPLUS_IS_DATA(inode) ?
  388. &file->data_fork : &file->rsrc_fork);
  389. hfsplus_get_perms(inode, &file->permissions, 0);
  390. inode->i_nlink = 1;
  391. if (S_ISREG(inode->i_mode)) {
  392. if (file->permissions.dev)
  393. inode->i_nlink = be32_to_cpu(file->permissions.dev);
  394. inode->i_op = &hfsplus_file_inode_operations;
  395. inode->i_fop = &hfsplus_file_operations;
  396. inode->i_mapping->a_ops = &hfsplus_aops;
  397. } else if (S_ISLNK(inode->i_mode)) {
  398. inode->i_op = &page_symlink_inode_operations;
  399. inode->i_mapping->a_ops = &hfsplus_aops;
  400. } else {
  401. init_special_inode(inode, inode->i_mode,
  402. be32_to_cpu(file->permissions.dev));
  403. }
  404. inode->i_atime = hfsp_mt2ut(file->access_date);
  405. inode->i_mtime = hfsp_mt2ut(file->content_mod_date);
  406. inode->i_ctime = hfsp_mt2ut(file->attribute_mod_date);
  407. HFSPLUS_I(inode).create_date = file->create_date;
  408. } else {
  409. printk(KERN_ERR "hfs: bad catalog entry used to create inode\n");
  410. res = -EIO;
  411. }
  412. return res;
  413. }
  414. int hfsplus_cat_write_inode(struct inode *inode)
  415. {
  416. struct inode *main_inode = inode;
  417. struct hfs_find_data fd;
  418. hfsplus_cat_entry entry;
  419. if (HFSPLUS_IS_RSRC(inode))
  420. main_inode = HFSPLUS_I(inode).rsrc_inode;
  421. if (!main_inode->i_nlink)
  422. return 0;
  423. if (hfs_find_init(HFSPLUS_SB(main_inode->i_sb).cat_tree, &fd))
  424. /* panic? */
  425. return -EIO;
  426. if (hfsplus_find_cat(main_inode->i_sb, main_inode->i_ino, &fd))
  427. /* panic? */
  428. goto out;
  429. if (S_ISDIR(main_inode->i_mode)) {
  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. /* simple node checks? */
  436. hfsplus_set_perms(inode, &folder->permissions);
  437. folder->access_date = hfsp_ut2mt(inode->i_atime);
  438. folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  439. folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  440. folder->valence = cpu_to_be32(inode->i_size - 2);
  441. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  442. sizeof(struct hfsplus_cat_folder));
  443. } else if (HFSPLUS_IS_RSRC(inode)) {
  444. struct hfsplus_cat_file *file = &entry.file;
  445. hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
  446. sizeof(struct hfsplus_cat_file));
  447. hfsplus_inode_write_fork(inode, &file->rsrc_fork);
  448. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  449. sizeof(struct hfsplus_cat_file));
  450. } else {
  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_write_fork(inode, &file->data_fork);
  457. if (S_ISREG(inode->i_mode))
  458. HFSPLUS_I(inode).dev = inode->i_nlink;
  459. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  460. HFSPLUS_I(inode).dev = kdev_t_to_nr(inode->i_rdev);
  461. hfsplus_set_perms(inode, &file->permissions);
  462. if ((file->permissions.rootflags | file->permissions.userflags) & HFSPLUS_FLG_IMMUTABLE)
  463. file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
  464. else
  465. file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
  466. file->access_date = hfsp_ut2mt(inode->i_atime);
  467. file->content_mod_date = hfsp_ut2mt(inode->i_mtime);
  468. file->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
  469. hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
  470. sizeof(struct hfsplus_cat_file));
  471. }
  472. out:
  473. hfs_find_exit(&fd);
  474. return 0;
  475. }