inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * linux/fs/hfs/inode.c
  3. *
  4. * Copyright (C) 1995-1997 Paul H. Hargrove
  5. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  6. * This file may be distributed under the terms of the GNU General Public License.
  7. *
  8. * This file contains inode-related functions which do not depend on
  9. * which scheme is being used to represent forks.
  10. *
  11. * Based on the minix file system code, (C) 1991, 1992 by Linus Torvalds
  12. */
  13. #include <linux/pagemap.h>
  14. #include <linux/mpage.h>
  15. #include "hfs_fs.h"
  16. #include "btree.h"
  17. static struct file_operations hfs_file_operations;
  18. static struct inode_operations hfs_file_inode_operations;
  19. /*================ Variable-like macros ================*/
  20. #define HFS_VALID_MODE_BITS (S_IFREG | S_IFDIR | S_IRWXUGO)
  21. static int hfs_writepage(struct page *page, struct writeback_control *wbc)
  22. {
  23. return block_write_full_page(page, hfs_get_block, wbc);
  24. }
  25. static int hfs_readpage(struct file *file, struct page *page)
  26. {
  27. return block_read_full_page(page, hfs_get_block);
  28. }
  29. static int hfs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
  30. {
  31. return cont_prepare_write(page, from, to, hfs_get_block,
  32. &HFS_I(page->mapping->host)->phys_size);
  33. }
  34. static sector_t hfs_bmap(struct address_space *mapping, sector_t block)
  35. {
  36. return generic_block_bmap(mapping, block, hfs_get_block);
  37. }
  38. static int hfs_releasepage(struct page *page, gfp_t mask)
  39. {
  40. struct inode *inode = page->mapping->host;
  41. struct super_block *sb = inode->i_sb;
  42. struct hfs_btree *tree;
  43. struct hfs_bnode *node;
  44. u32 nidx;
  45. int i, res = 1;
  46. switch (inode->i_ino) {
  47. case HFS_EXT_CNID:
  48. tree = HFS_SB(sb)->ext_tree;
  49. break;
  50. case HFS_CAT_CNID:
  51. tree = HFS_SB(sb)->cat_tree;
  52. break;
  53. default:
  54. BUG();
  55. return 0;
  56. }
  57. if (tree->node_size >= PAGE_CACHE_SIZE) {
  58. nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT);
  59. spin_lock(&tree->hash_lock);
  60. node = hfs_bnode_findhash(tree, nidx);
  61. if (!node)
  62. ;
  63. else if (atomic_read(&node->refcnt))
  64. res = 0;
  65. if (res && node) {
  66. hfs_bnode_unhash(node);
  67. hfs_bnode_free(node);
  68. }
  69. spin_unlock(&tree->hash_lock);
  70. } else {
  71. nidx = page->index << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  72. i = 1 << (PAGE_CACHE_SHIFT - tree->node_size_shift);
  73. spin_lock(&tree->hash_lock);
  74. do {
  75. node = hfs_bnode_findhash(tree, nidx++);
  76. if (!node)
  77. continue;
  78. if (atomic_read(&node->refcnt)) {
  79. res = 0;
  80. break;
  81. }
  82. hfs_bnode_unhash(node);
  83. hfs_bnode_free(node);
  84. } while (--i && nidx < tree->node_count);
  85. spin_unlock(&tree->hash_lock);
  86. }
  87. return res ? try_to_free_buffers(page) : 0;
  88. }
  89. static int hfs_get_blocks(struct inode *inode, sector_t iblock, unsigned long max_blocks,
  90. struct buffer_head *bh_result, int create)
  91. {
  92. int ret;
  93. ret = hfs_get_block(inode, iblock, bh_result, create);
  94. if (!ret)
  95. bh_result->b_size = (1 << inode->i_blkbits);
  96. return ret;
  97. }
  98. static ssize_t hfs_direct_IO(int rw, struct kiocb *iocb,
  99. const struct iovec *iov, loff_t offset, unsigned long nr_segs)
  100. {
  101. struct file *file = iocb->ki_filp;
  102. struct inode *inode = file->f_dentry->d_inode->i_mapping->host;
  103. return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
  104. offset, nr_segs, hfs_get_blocks, NULL);
  105. }
  106. static int hfs_writepages(struct address_space *mapping,
  107. struct writeback_control *wbc)
  108. {
  109. return mpage_writepages(mapping, wbc, hfs_get_block);
  110. }
  111. struct address_space_operations hfs_btree_aops = {
  112. .readpage = hfs_readpage,
  113. .writepage = hfs_writepage,
  114. .sync_page = block_sync_page,
  115. .prepare_write = hfs_prepare_write,
  116. .commit_write = generic_commit_write,
  117. .bmap = hfs_bmap,
  118. .releasepage = hfs_releasepage,
  119. };
  120. struct address_space_operations hfs_aops = {
  121. .readpage = hfs_readpage,
  122. .writepage = hfs_writepage,
  123. .sync_page = block_sync_page,
  124. .prepare_write = hfs_prepare_write,
  125. .commit_write = generic_commit_write,
  126. .bmap = hfs_bmap,
  127. .direct_IO = hfs_direct_IO,
  128. .writepages = hfs_writepages,
  129. };
  130. /*
  131. * hfs_new_inode
  132. */
  133. struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, int mode)
  134. {
  135. struct super_block *sb = dir->i_sb;
  136. struct inode *inode = new_inode(sb);
  137. if (!inode)
  138. return NULL;
  139. init_MUTEX(&HFS_I(inode)->extents_lock);
  140. INIT_LIST_HEAD(&HFS_I(inode)->open_dir_list);
  141. hfs_cat_build_key(sb, (btree_key *)&HFS_I(inode)->cat_key, dir->i_ino, name);
  142. inode->i_ino = HFS_SB(sb)->next_id++;
  143. inode->i_mode = mode;
  144. inode->i_uid = current->fsuid;
  145. inode->i_gid = current->fsgid;
  146. inode->i_nlink = 1;
  147. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
  148. inode->i_blksize = HFS_SB(sb)->alloc_blksz;
  149. HFS_I(inode)->flags = 0;
  150. HFS_I(inode)->rsrc_inode = NULL;
  151. HFS_I(inode)->fs_blocks = 0;
  152. if (S_ISDIR(mode)) {
  153. inode->i_size = 2;
  154. HFS_SB(sb)->folder_count++;
  155. if (dir->i_ino == HFS_ROOT_CNID)
  156. HFS_SB(sb)->root_dirs++;
  157. inode->i_op = &hfs_dir_inode_operations;
  158. inode->i_fop = &hfs_dir_operations;
  159. inode->i_mode |= S_IRWXUGO;
  160. inode->i_mode &= ~HFS_SB(inode->i_sb)->s_dir_umask;
  161. } else if (S_ISREG(mode)) {
  162. HFS_I(inode)->clump_blocks = HFS_SB(sb)->clumpablks;
  163. HFS_SB(sb)->file_count++;
  164. if (dir->i_ino == HFS_ROOT_CNID)
  165. HFS_SB(sb)->root_files++;
  166. inode->i_op = &hfs_file_inode_operations;
  167. inode->i_fop = &hfs_file_operations;
  168. inode->i_mapping->a_ops = &hfs_aops;
  169. inode->i_mode |= S_IRUGO|S_IXUGO;
  170. if (mode & S_IWUSR)
  171. inode->i_mode |= S_IWUGO;
  172. inode->i_mode &= ~HFS_SB(inode->i_sb)->s_file_umask;
  173. HFS_I(inode)->phys_size = 0;
  174. HFS_I(inode)->alloc_blocks = 0;
  175. HFS_I(inode)->first_blocks = 0;
  176. HFS_I(inode)->cached_start = 0;
  177. HFS_I(inode)->cached_blocks = 0;
  178. memset(HFS_I(inode)->first_extents, 0, sizeof(hfs_extent_rec));
  179. memset(HFS_I(inode)->cached_extents, 0, sizeof(hfs_extent_rec));
  180. }
  181. insert_inode_hash(inode);
  182. mark_inode_dirty(inode);
  183. set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags);
  184. sb->s_dirt = 1;
  185. return inode;
  186. }
  187. void hfs_delete_inode(struct inode *inode)
  188. {
  189. struct super_block *sb = inode->i_sb;
  190. dprint(DBG_INODE, "delete_inode: %lu\n", inode->i_ino);
  191. if (S_ISDIR(inode->i_mode)) {
  192. HFS_SB(sb)->folder_count--;
  193. if (HFS_I(inode)->cat_key.ParID == cpu_to_be32(HFS_ROOT_CNID))
  194. HFS_SB(sb)->root_dirs--;
  195. set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags);
  196. sb->s_dirt = 1;
  197. return;
  198. }
  199. HFS_SB(sb)->file_count--;
  200. if (HFS_I(inode)->cat_key.ParID == cpu_to_be32(HFS_ROOT_CNID))
  201. HFS_SB(sb)->root_files--;
  202. if (S_ISREG(inode->i_mode)) {
  203. if (!inode->i_nlink) {
  204. inode->i_size = 0;
  205. hfs_file_truncate(inode);
  206. }
  207. }
  208. set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags);
  209. sb->s_dirt = 1;
  210. }
  211. void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
  212. __be32 __log_size, __be32 phys_size, u32 clump_size)
  213. {
  214. struct super_block *sb = inode->i_sb;
  215. u32 log_size = be32_to_cpu(__log_size);
  216. u16 count;
  217. int i;
  218. memcpy(HFS_I(inode)->first_extents, ext, sizeof(hfs_extent_rec));
  219. for (count = 0, i = 0; i < 3; i++)
  220. count += be16_to_cpu(ext[i].count);
  221. HFS_I(inode)->first_blocks = count;
  222. inode->i_size = HFS_I(inode)->phys_size = log_size;
  223. HFS_I(inode)->fs_blocks = (log_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  224. inode_set_bytes(inode, HFS_I(inode)->fs_blocks << sb->s_blocksize_bits);
  225. HFS_I(inode)->alloc_blocks = be32_to_cpu(phys_size) /
  226. HFS_SB(sb)->alloc_blksz;
  227. HFS_I(inode)->clump_blocks = clump_size / HFS_SB(sb)->alloc_blksz;
  228. if (!HFS_I(inode)->clump_blocks)
  229. HFS_I(inode)->clump_blocks = HFS_SB(sb)->clumpablks;
  230. }
  231. struct hfs_iget_data {
  232. struct hfs_cat_key *key;
  233. hfs_cat_rec *rec;
  234. };
  235. static int hfs_test_inode(struct inode *inode, void *data)
  236. {
  237. struct hfs_iget_data *idata = data;
  238. hfs_cat_rec *rec;
  239. rec = idata->rec;
  240. switch (rec->type) {
  241. case HFS_CDR_DIR:
  242. return inode->i_ino == be32_to_cpu(rec->dir.DirID);
  243. case HFS_CDR_FIL:
  244. return inode->i_ino == be32_to_cpu(rec->file.FlNum);
  245. default:
  246. BUG();
  247. return 1;
  248. }
  249. }
  250. /*
  251. * hfs_read_inode
  252. */
  253. static int hfs_read_inode(struct inode *inode, void *data)
  254. {
  255. struct hfs_iget_data *idata = data;
  256. struct hfs_sb_info *hsb = HFS_SB(inode->i_sb);
  257. hfs_cat_rec *rec;
  258. HFS_I(inode)->flags = 0;
  259. HFS_I(inode)->rsrc_inode = NULL;
  260. init_MUTEX(&HFS_I(inode)->extents_lock);
  261. INIT_LIST_HEAD(&HFS_I(inode)->open_dir_list);
  262. /* Initialize the inode */
  263. inode->i_uid = hsb->s_uid;
  264. inode->i_gid = hsb->s_gid;
  265. inode->i_nlink = 1;
  266. inode->i_blksize = HFS_SB(inode->i_sb)->alloc_blksz;
  267. if (idata->key)
  268. HFS_I(inode)->cat_key = *idata->key;
  269. else
  270. HFS_I(inode)->flags |= HFS_FLG_RSRC;
  271. HFS_I(inode)->tz_secondswest = sys_tz.tz_minuteswest * 60;
  272. rec = idata->rec;
  273. switch (rec->type) {
  274. case HFS_CDR_FIL:
  275. if (!HFS_IS_RSRC(inode)) {
  276. hfs_inode_read_fork(inode, rec->file.ExtRec, rec->file.LgLen,
  277. rec->file.PyLen, be16_to_cpu(rec->file.ClpSize));
  278. } else {
  279. hfs_inode_read_fork(inode, rec->file.RExtRec, rec->file.RLgLen,
  280. rec->file.RPyLen, be16_to_cpu(rec->file.ClpSize));
  281. }
  282. inode->i_ino = be32_to_cpu(rec->file.FlNum);
  283. inode->i_mode = S_IRUGO | S_IXUGO;
  284. if (!(rec->file.Flags & HFS_FIL_LOCK))
  285. inode->i_mode |= S_IWUGO;
  286. inode->i_mode &= ~hsb->s_file_umask;
  287. inode->i_mode |= S_IFREG;
  288. inode->i_ctime = inode->i_atime = inode->i_mtime =
  289. hfs_m_to_utime(rec->file.MdDat);
  290. inode->i_op = &hfs_file_inode_operations;
  291. inode->i_fop = &hfs_file_operations;
  292. inode->i_mapping->a_ops = &hfs_aops;
  293. break;
  294. case HFS_CDR_DIR:
  295. inode->i_ino = be32_to_cpu(rec->dir.DirID);
  296. inode->i_size = be16_to_cpu(rec->dir.Val) + 2;
  297. HFS_I(inode)->fs_blocks = 0;
  298. inode->i_mode = S_IFDIR | (S_IRWXUGO & ~hsb->s_dir_umask);
  299. inode->i_ctime = inode->i_atime = inode->i_mtime =
  300. hfs_m_to_utime(rec->dir.MdDat);
  301. inode->i_op = &hfs_dir_inode_operations;
  302. inode->i_fop = &hfs_dir_operations;
  303. break;
  304. default:
  305. make_bad_inode(inode);
  306. }
  307. return 0;
  308. }
  309. /*
  310. * __hfs_iget()
  311. *
  312. * Given the MDB for a HFS filesystem, a 'key' and an 'entry' in
  313. * the catalog B-tree and the 'type' of the desired file return the
  314. * inode for that file/directory or NULL. Note that 'type' indicates
  315. * whether we want the actual file or directory, or the corresponding
  316. * metadata (AppleDouble header file or CAP metadata file).
  317. */
  318. struct inode *hfs_iget(struct super_block *sb, struct hfs_cat_key *key, hfs_cat_rec *rec)
  319. {
  320. struct hfs_iget_data data = { key, rec };
  321. struct inode *inode;
  322. u32 cnid;
  323. switch (rec->type) {
  324. case HFS_CDR_DIR:
  325. cnid = be32_to_cpu(rec->dir.DirID);
  326. break;
  327. case HFS_CDR_FIL:
  328. cnid = be32_to_cpu(rec->file.FlNum);
  329. break;
  330. default:
  331. return NULL;
  332. }
  333. inode = iget5_locked(sb, cnid, hfs_test_inode, hfs_read_inode, &data);
  334. if (inode && (inode->i_state & I_NEW))
  335. unlock_new_inode(inode);
  336. return inode;
  337. }
  338. void hfs_inode_write_fork(struct inode *inode, struct hfs_extent *ext,
  339. __be32 *log_size, __be32 *phys_size)
  340. {
  341. memcpy(ext, HFS_I(inode)->first_extents, sizeof(hfs_extent_rec));
  342. if (log_size)
  343. *log_size = cpu_to_be32(inode->i_size);
  344. if (phys_size)
  345. *phys_size = cpu_to_be32(HFS_I(inode)->alloc_blocks *
  346. HFS_SB(inode->i_sb)->alloc_blksz);
  347. }
  348. int hfs_write_inode(struct inode *inode, int unused)
  349. {
  350. struct inode *main_inode = inode;
  351. struct hfs_find_data fd;
  352. hfs_cat_rec rec;
  353. dprint(DBG_INODE, "hfs_write_inode: %lu\n", inode->i_ino);
  354. hfs_ext_write_extent(inode);
  355. if (inode->i_ino < HFS_FIRSTUSER_CNID) {
  356. switch (inode->i_ino) {
  357. case HFS_ROOT_CNID:
  358. break;
  359. case HFS_EXT_CNID:
  360. hfs_btree_write(HFS_SB(inode->i_sb)->ext_tree);
  361. return 0;
  362. case HFS_CAT_CNID:
  363. hfs_btree_write(HFS_SB(inode->i_sb)->cat_tree);
  364. return 0;
  365. default:
  366. BUG();
  367. return -EIO;
  368. }
  369. }
  370. if (HFS_IS_RSRC(inode))
  371. main_inode = HFS_I(inode)->rsrc_inode;
  372. if (!main_inode->i_nlink)
  373. return 0;
  374. if (hfs_find_init(HFS_SB(main_inode->i_sb)->cat_tree, &fd))
  375. /* panic? */
  376. return -EIO;
  377. fd.search_key->cat = HFS_I(main_inode)->cat_key;
  378. if (hfs_brec_find(&fd))
  379. /* panic? */
  380. goto out;
  381. if (S_ISDIR(main_inode->i_mode)) {
  382. if (fd.entrylength < sizeof(struct hfs_cat_dir))
  383. /* panic? */;
  384. hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
  385. sizeof(struct hfs_cat_dir));
  386. if (rec.type != HFS_CDR_DIR ||
  387. be32_to_cpu(rec.dir.DirID) != inode->i_ino) {
  388. }
  389. rec.dir.MdDat = hfs_u_to_mtime(inode->i_mtime);
  390. rec.dir.Val = cpu_to_be16(inode->i_size - 2);
  391. hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
  392. sizeof(struct hfs_cat_dir));
  393. } else if (HFS_IS_RSRC(inode)) {
  394. hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
  395. sizeof(struct hfs_cat_file));
  396. hfs_inode_write_fork(inode, rec.file.RExtRec,
  397. &rec.file.RLgLen, &rec.file.RPyLen);
  398. hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
  399. sizeof(struct hfs_cat_file));
  400. } else {
  401. if (fd.entrylength < sizeof(struct hfs_cat_file))
  402. /* panic? */;
  403. hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
  404. sizeof(struct hfs_cat_file));
  405. if (rec.type != HFS_CDR_FIL ||
  406. be32_to_cpu(rec.file.FlNum) != inode->i_ino) {
  407. }
  408. if (inode->i_mode & S_IWUSR)
  409. rec.file.Flags &= ~HFS_FIL_LOCK;
  410. else
  411. rec.file.Flags |= HFS_FIL_LOCK;
  412. hfs_inode_write_fork(inode, rec.file.ExtRec, &rec.file.LgLen, &rec.file.PyLen);
  413. rec.file.MdDat = hfs_u_to_mtime(inode->i_mtime);
  414. hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
  415. sizeof(struct hfs_cat_file));
  416. }
  417. out:
  418. hfs_find_exit(&fd);
  419. return 0;
  420. }
  421. static struct dentry *hfs_file_lookup(struct inode *dir, struct dentry *dentry,
  422. struct nameidata *nd)
  423. {
  424. struct inode *inode = NULL;
  425. hfs_cat_rec rec;
  426. struct hfs_find_data fd;
  427. int res;
  428. if (HFS_IS_RSRC(dir) || strcmp(dentry->d_name.name, "rsrc"))
  429. goto out;
  430. inode = HFS_I(dir)->rsrc_inode;
  431. if (inode)
  432. goto out;
  433. inode = new_inode(dir->i_sb);
  434. if (!inode)
  435. return ERR_PTR(-ENOMEM);
  436. hfs_find_init(HFS_SB(dir->i_sb)->cat_tree, &fd);
  437. fd.search_key->cat = HFS_I(dir)->cat_key;
  438. res = hfs_brec_read(&fd, &rec, sizeof(rec));
  439. if (!res) {
  440. struct hfs_iget_data idata = { NULL, &rec };
  441. hfs_read_inode(inode, &idata);
  442. }
  443. hfs_find_exit(&fd);
  444. if (res) {
  445. iput(inode);
  446. return ERR_PTR(res);
  447. }
  448. HFS_I(inode)->rsrc_inode = dir;
  449. HFS_I(dir)->rsrc_inode = inode;
  450. igrab(dir);
  451. hlist_add_head(&inode->i_hash, &HFS_SB(dir->i_sb)->rsrc_inodes);
  452. mark_inode_dirty(inode);
  453. out:
  454. d_add(dentry, inode);
  455. return NULL;
  456. }
  457. void hfs_clear_inode(struct inode *inode)
  458. {
  459. if (HFS_IS_RSRC(inode) && HFS_I(inode)->rsrc_inode) {
  460. HFS_I(HFS_I(inode)->rsrc_inode)->rsrc_inode = NULL;
  461. iput(HFS_I(inode)->rsrc_inode);
  462. }
  463. }
  464. static int hfs_permission(struct inode *inode, int mask,
  465. struct nameidata *nd)
  466. {
  467. if (S_ISREG(inode->i_mode) && mask & MAY_EXEC)
  468. return 0;
  469. return generic_permission(inode, mask, NULL);
  470. }
  471. static int hfs_file_open(struct inode *inode, struct file *file)
  472. {
  473. if (HFS_IS_RSRC(inode))
  474. inode = HFS_I(inode)->rsrc_inode;
  475. if (atomic_read(&file->f_count) != 1)
  476. return 0;
  477. atomic_inc(&HFS_I(inode)->opencnt);
  478. return 0;
  479. }
  480. static int hfs_file_release(struct inode *inode, struct file *file)
  481. {
  482. //struct super_block *sb = inode->i_sb;
  483. if (HFS_IS_RSRC(inode))
  484. inode = HFS_I(inode)->rsrc_inode;
  485. if (atomic_read(&file->f_count) != 0)
  486. return 0;
  487. if (atomic_dec_and_test(&HFS_I(inode)->opencnt)) {
  488. mutex_lock(&inode->i_mutex);
  489. hfs_file_truncate(inode);
  490. //if (inode->i_flags & S_DEAD) {
  491. // hfs_delete_cat(inode->i_ino, HFSPLUS_SB(sb).hidden_dir, NULL);
  492. // hfs_delete_inode(inode);
  493. //}
  494. mutex_unlock(&inode->i_mutex);
  495. }
  496. return 0;
  497. }
  498. /*
  499. * hfs_notify_change()
  500. *
  501. * Based very closely on fs/msdos/inode.c by Werner Almesberger
  502. *
  503. * This is the notify_change() field in the super_operations structure
  504. * for HFS file systems. The purpose is to take that changes made to
  505. * an inode and apply then in a filesystem-dependent manner. In this
  506. * case the process has a few of tasks to do:
  507. * 1) prevent changes to the i_uid and i_gid fields.
  508. * 2) map file permissions to the closest allowable permissions
  509. * 3) Since multiple Linux files can share the same on-disk inode under
  510. * HFS (for instance the data and resource forks of a file) a change
  511. * to permissions must be applied to all other in-core inodes which
  512. * correspond to the same HFS file.
  513. */
  514. int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)
  515. {
  516. struct inode *inode = dentry->d_inode;
  517. struct hfs_sb_info *hsb = HFS_SB(inode->i_sb);
  518. int error;
  519. error = inode_change_ok(inode, attr); /* basic permission checks */
  520. if (error)
  521. return error;
  522. /* no uig/gid changes and limit which mode bits can be set */
  523. if (((attr->ia_valid & ATTR_UID) &&
  524. (attr->ia_uid != hsb->s_uid)) ||
  525. ((attr->ia_valid & ATTR_GID) &&
  526. (attr->ia_gid != hsb->s_gid)) ||
  527. ((attr->ia_valid & ATTR_MODE) &&
  528. ((S_ISDIR(inode->i_mode) &&
  529. (attr->ia_mode != inode->i_mode)) ||
  530. (attr->ia_mode & ~HFS_VALID_MODE_BITS)))) {
  531. return hsb->s_quiet ? 0 : error;
  532. }
  533. if (attr->ia_valid & ATTR_MODE) {
  534. /* Only the 'w' bits can ever change and only all together. */
  535. if (attr->ia_mode & S_IWUSR)
  536. attr->ia_mode = inode->i_mode | S_IWUGO;
  537. else
  538. attr->ia_mode = inode->i_mode & ~S_IWUGO;
  539. attr->ia_mode &= S_ISDIR(inode->i_mode) ? ~hsb->s_dir_umask: ~hsb->s_file_umask;
  540. }
  541. error = inode_setattr(inode, attr);
  542. if (error)
  543. return error;
  544. return 0;
  545. }
  546. static struct file_operations hfs_file_operations = {
  547. .llseek = generic_file_llseek,
  548. .read = generic_file_read,
  549. .write = generic_file_write,
  550. .mmap = generic_file_mmap,
  551. .sendfile = generic_file_sendfile,
  552. .fsync = file_fsync,
  553. .open = hfs_file_open,
  554. .release = hfs_file_release,
  555. };
  556. static struct inode_operations hfs_file_inode_operations = {
  557. .lookup = hfs_file_lookup,
  558. .truncate = hfs_file_truncate,
  559. .setattr = hfs_inode_setattr,
  560. .permission = hfs_permission,
  561. .setxattr = hfs_setxattr,
  562. .getxattr = hfs_getxattr,
  563. .listxattr = hfs_listxattr,
  564. };