super.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /*
  2. * linux/fs/hfsplus/super.c
  3. *
  4. * Copyright (C) 2001
  5. * Brad Boyer (flar@allandria.com)
  6. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  7. *
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/fs.h>
  14. #include <linux/slab.h>
  15. #include <linux/vfs.h>
  16. #include <linux/nls.h>
  17. static struct inode *hfsplus_alloc_inode(struct super_block *sb);
  18. static void hfsplus_destroy_inode(struct inode *inode);
  19. #include "hfsplus_fs.h"
  20. static int hfsplus_system_read_inode(struct inode *inode)
  21. {
  22. struct hfsplus_vh *vhdr = HFSPLUS_SB(inode->i_sb)->s_vhdr;
  23. switch (inode->i_ino) {
  24. case HFSPLUS_EXT_CNID:
  25. hfsplus_inode_read_fork(inode, &vhdr->ext_file);
  26. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  27. break;
  28. case HFSPLUS_CAT_CNID:
  29. hfsplus_inode_read_fork(inode, &vhdr->cat_file);
  30. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  31. break;
  32. case HFSPLUS_ALLOC_CNID:
  33. hfsplus_inode_read_fork(inode, &vhdr->alloc_file);
  34. inode->i_mapping->a_ops = &hfsplus_aops;
  35. break;
  36. case HFSPLUS_START_CNID:
  37. hfsplus_inode_read_fork(inode, &vhdr->start_file);
  38. break;
  39. case HFSPLUS_ATTR_CNID:
  40. hfsplus_inode_read_fork(inode, &vhdr->attr_file);
  41. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  42. break;
  43. default:
  44. return -EIO;
  45. }
  46. return 0;
  47. }
  48. struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
  49. {
  50. struct hfs_find_data fd;
  51. struct inode *inode;
  52. int err;
  53. inode = iget_locked(sb, ino);
  54. if (!inode)
  55. return ERR_PTR(-ENOMEM);
  56. if (!(inode->i_state & I_NEW))
  57. return inode;
  58. INIT_LIST_HEAD(&HFSPLUS_I(inode)->open_dir_list);
  59. mutex_init(&HFSPLUS_I(inode)->extents_lock);
  60. HFSPLUS_I(inode)->flags = 0;
  61. HFSPLUS_I(inode)->extent_state = 0;
  62. HFSPLUS_I(inode)->rsrc_inode = NULL;
  63. atomic_set(&HFSPLUS_I(inode)->opencnt, 0);
  64. if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID ||
  65. inode->i_ino == HFSPLUS_ROOT_CNID) {
  66. err = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
  67. if (!err) {
  68. err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
  69. if (!err)
  70. err = hfsplus_cat_read_inode(inode, &fd);
  71. hfs_find_exit(&fd);
  72. }
  73. } else {
  74. err = hfsplus_system_read_inode(inode);
  75. }
  76. if (err) {
  77. iget_failed(inode);
  78. return ERR_PTR(err);
  79. }
  80. unlock_new_inode(inode);
  81. return inode;
  82. }
  83. static int hfsplus_system_write_inode(struct inode *inode)
  84. {
  85. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  86. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  87. struct hfsplus_fork_raw *fork;
  88. struct hfs_btree *tree = NULL;
  89. switch (inode->i_ino) {
  90. case HFSPLUS_EXT_CNID:
  91. fork = &vhdr->ext_file;
  92. tree = sbi->ext_tree;
  93. break;
  94. case HFSPLUS_CAT_CNID:
  95. fork = &vhdr->cat_file;
  96. tree = sbi->cat_tree;
  97. break;
  98. case HFSPLUS_ALLOC_CNID:
  99. fork = &vhdr->alloc_file;
  100. break;
  101. case HFSPLUS_START_CNID:
  102. fork = &vhdr->start_file;
  103. break;
  104. case HFSPLUS_ATTR_CNID:
  105. fork = &vhdr->attr_file;
  106. tree = sbi->attr_tree;
  107. default:
  108. return -EIO;
  109. }
  110. if (fork->total_size != cpu_to_be64(inode->i_size)) {
  111. set_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags);
  112. inode->i_sb->s_dirt = 1;
  113. }
  114. hfsplus_inode_write_fork(inode, fork);
  115. if (tree)
  116. hfs_btree_write(tree);
  117. return 0;
  118. }
  119. static int hfsplus_write_inode(struct inode *inode,
  120. struct writeback_control *wbc)
  121. {
  122. int err;
  123. dprint(DBG_INODE, "hfsplus_write_inode: %lu\n", inode->i_ino);
  124. err = hfsplus_ext_write_extent(inode);
  125. if (err)
  126. return err;
  127. if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID ||
  128. inode->i_ino == HFSPLUS_ROOT_CNID)
  129. return hfsplus_cat_write_inode(inode);
  130. else
  131. return hfsplus_system_write_inode(inode);
  132. }
  133. static void hfsplus_evict_inode(struct inode *inode)
  134. {
  135. dprint(DBG_INODE, "hfsplus_evict_inode: %lu\n", inode->i_ino);
  136. truncate_inode_pages(&inode->i_data, 0);
  137. end_writeback(inode);
  138. if (HFSPLUS_IS_RSRC(inode)) {
  139. HFSPLUS_I(HFSPLUS_I(inode)->rsrc_inode)->rsrc_inode = NULL;
  140. iput(HFSPLUS_I(inode)->rsrc_inode);
  141. }
  142. }
  143. int hfsplus_sync_fs(struct super_block *sb, int wait)
  144. {
  145. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  146. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  147. int write_backup = 0;
  148. int error, error2;
  149. if (!wait)
  150. return 0;
  151. dprint(DBG_SUPER, "hfsplus_write_super\n");
  152. sb->s_dirt = 0;
  153. /*
  154. * Explicitly write out the special metadata inodes.
  155. *
  156. * While these special inodes are marked as hashed and written
  157. * out peridocically by the flusher threads we redirty them
  158. * during writeout of normal inodes, and thus the life lock
  159. * prevents us from getting the latest state to disk.
  160. */
  161. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  162. error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  163. if (!error)
  164. error = error2;
  165. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  166. if (!error)
  167. error = error2;
  168. mutex_lock(&sbi->vh_mutex);
  169. mutex_lock(&sbi->alloc_mutex);
  170. vhdr->free_blocks = cpu_to_be32(sbi->free_blocks);
  171. vhdr->next_cnid = cpu_to_be32(sbi->next_cnid);
  172. vhdr->folder_count = cpu_to_be32(sbi->folder_count);
  173. vhdr->file_count = cpu_to_be32(sbi->file_count);
  174. if (test_and_clear_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags)) {
  175. memcpy(sbi->s_backup_vhdr, sbi->s_vhdr, sizeof(*sbi->s_vhdr));
  176. write_backup = 1;
  177. }
  178. error2 = hfsplus_submit_bio(sb,
  179. sbi->part_start + HFSPLUS_VOLHEAD_SECTOR,
  180. sbi->s_vhdr_buf, NULL, WRITE_SYNC);
  181. if (!error)
  182. error = error2;
  183. if (!write_backup)
  184. goto out;
  185. error2 = hfsplus_submit_bio(sb,
  186. sbi->part_start + sbi->sect_count - 2,
  187. sbi->s_backup_vhdr_buf, NULL, WRITE_SYNC);
  188. if (!error)
  189. error2 = error;
  190. out:
  191. mutex_unlock(&sbi->alloc_mutex);
  192. mutex_unlock(&sbi->vh_mutex);
  193. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  194. blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
  195. return error;
  196. }
  197. static void hfsplus_write_super(struct super_block *sb)
  198. {
  199. if (!(sb->s_flags & MS_RDONLY))
  200. hfsplus_sync_fs(sb, 1);
  201. else
  202. sb->s_dirt = 0;
  203. }
  204. static void hfsplus_put_super(struct super_block *sb)
  205. {
  206. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  207. dprint(DBG_SUPER, "hfsplus_put_super\n");
  208. if (!sb->s_fs_info)
  209. return;
  210. if (!(sb->s_flags & MS_RDONLY) && sbi->s_vhdr) {
  211. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  212. vhdr->modify_date = hfsp_now2mt();
  213. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_UNMNT);
  214. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_INCNSTNT);
  215. hfsplus_sync_fs(sb, 1);
  216. }
  217. hfs_btree_close(sbi->cat_tree);
  218. hfs_btree_close(sbi->ext_tree);
  219. iput(sbi->alloc_file);
  220. iput(sbi->hidden_dir);
  221. kfree(sbi->s_vhdr_buf);
  222. kfree(sbi->s_backup_vhdr_buf);
  223. unload_nls(sbi->nls);
  224. kfree(sb->s_fs_info);
  225. sb->s_fs_info = NULL;
  226. }
  227. static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)
  228. {
  229. struct super_block *sb = dentry->d_sb;
  230. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  231. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  232. buf->f_type = HFSPLUS_SUPER_MAGIC;
  233. buf->f_bsize = sb->s_blocksize;
  234. buf->f_blocks = sbi->total_blocks << sbi->fs_shift;
  235. buf->f_bfree = sbi->free_blocks << sbi->fs_shift;
  236. buf->f_bavail = buf->f_bfree;
  237. buf->f_files = 0xFFFFFFFF;
  238. buf->f_ffree = 0xFFFFFFFF - sbi->next_cnid;
  239. buf->f_fsid.val[0] = (u32)id;
  240. buf->f_fsid.val[1] = (u32)(id >> 32);
  241. buf->f_namelen = HFSPLUS_MAX_STRLEN;
  242. return 0;
  243. }
  244. static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
  245. {
  246. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  247. return 0;
  248. if (!(*flags & MS_RDONLY)) {
  249. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb)->s_vhdr;
  250. int force = 0;
  251. if (!hfsplus_parse_options_remount(data, &force))
  252. return -EINVAL;
  253. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  254. printk(KERN_WARNING "hfs: filesystem was "
  255. "not cleanly unmounted, "
  256. "running fsck.hfsplus is recommended. "
  257. "leaving read-only.\n");
  258. sb->s_flags |= MS_RDONLY;
  259. *flags |= MS_RDONLY;
  260. } else if (force) {
  261. /* nothing */
  262. } else if (vhdr->attributes &
  263. cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  264. printk(KERN_WARNING "hfs: filesystem is marked locked, "
  265. "leaving read-only.\n");
  266. sb->s_flags |= MS_RDONLY;
  267. *flags |= MS_RDONLY;
  268. } else if (vhdr->attributes &
  269. cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
  270. printk(KERN_WARNING "hfs: filesystem is "
  271. "marked journaled, "
  272. "leaving read-only.\n");
  273. sb->s_flags |= MS_RDONLY;
  274. *flags |= MS_RDONLY;
  275. }
  276. }
  277. return 0;
  278. }
  279. static const struct super_operations hfsplus_sops = {
  280. .alloc_inode = hfsplus_alloc_inode,
  281. .destroy_inode = hfsplus_destroy_inode,
  282. .write_inode = hfsplus_write_inode,
  283. .evict_inode = hfsplus_evict_inode,
  284. .put_super = hfsplus_put_super,
  285. .write_super = hfsplus_write_super,
  286. .sync_fs = hfsplus_sync_fs,
  287. .statfs = hfsplus_statfs,
  288. .remount_fs = hfsplus_remount,
  289. .show_options = hfsplus_show_options,
  290. };
  291. static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
  292. {
  293. struct hfsplus_vh *vhdr;
  294. struct hfsplus_sb_info *sbi;
  295. hfsplus_cat_entry entry;
  296. struct hfs_find_data fd;
  297. struct inode *root, *inode;
  298. struct qstr str;
  299. struct nls_table *nls = NULL;
  300. u64 last_fs_block, last_fs_page;
  301. int err;
  302. err = -EINVAL;
  303. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  304. if (!sbi)
  305. goto out;
  306. sb->s_fs_info = sbi;
  307. mutex_init(&sbi->alloc_mutex);
  308. mutex_init(&sbi->vh_mutex);
  309. hfsplus_fill_defaults(sbi);
  310. err = -EINVAL;
  311. if (!hfsplus_parse_options(data, sbi)) {
  312. printk(KERN_ERR "hfs: unable to parse mount options\n");
  313. goto out_unload_nls;
  314. }
  315. /* temporarily use utf8 to correctly find the hidden dir below */
  316. nls = sbi->nls;
  317. sbi->nls = load_nls("utf8");
  318. if (!sbi->nls) {
  319. printk(KERN_ERR "hfs: unable to load nls for utf8\n");
  320. goto out_unload_nls;
  321. }
  322. /* Grab the volume header */
  323. if (hfsplus_read_wrapper(sb)) {
  324. if (!silent)
  325. printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
  326. goto out_unload_nls;
  327. }
  328. vhdr = sbi->s_vhdr;
  329. /* Copy parts of the volume header into the superblock */
  330. sb->s_magic = HFSPLUS_VOLHEAD_SIG;
  331. if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
  332. be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
  333. printk(KERN_ERR "hfs: wrong filesystem version\n");
  334. goto out_free_vhdr;
  335. }
  336. sbi->total_blocks = be32_to_cpu(vhdr->total_blocks);
  337. sbi->free_blocks = be32_to_cpu(vhdr->free_blocks);
  338. sbi->next_cnid = be32_to_cpu(vhdr->next_cnid);
  339. sbi->file_count = be32_to_cpu(vhdr->file_count);
  340. sbi->folder_count = be32_to_cpu(vhdr->folder_count);
  341. sbi->data_clump_blocks =
  342. be32_to_cpu(vhdr->data_clump_sz) >> sbi->alloc_blksz_shift;
  343. if (!sbi->data_clump_blocks)
  344. sbi->data_clump_blocks = 1;
  345. sbi->rsrc_clump_blocks =
  346. be32_to_cpu(vhdr->rsrc_clump_sz) >> sbi->alloc_blksz_shift;
  347. if (!sbi->rsrc_clump_blocks)
  348. sbi->rsrc_clump_blocks = 1;
  349. err = -EFBIG;
  350. last_fs_block = sbi->total_blocks - 1;
  351. last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
  352. PAGE_CACHE_SHIFT;
  353. if ((last_fs_block > (sector_t)(~0ULL) >> (sbi->alloc_blksz_shift - 9)) ||
  354. (last_fs_page > (pgoff_t)(~0ULL))) {
  355. printk(KERN_ERR "hfs: filesystem size too large.\n");
  356. goto out_free_vhdr;
  357. }
  358. /* Set up operations so we can load metadata */
  359. sb->s_op = &hfsplus_sops;
  360. sb->s_maxbytes = MAX_LFS_FILESIZE;
  361. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  362. printk(KERN_WARNING "hfs: Filesystem was "
  363. "not cleanly unmounted, "
  364. "running fsck.hfsplus is recommended. "
  365. "mounting read-only.\n");
  366. sb->s_flags |= MS_RDONLY;
  367. } else if (test_and_clear_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
  368. /* nothing */
  369. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  370. printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
  371. sb->s_flags |= MS_RDONLY;
  372. } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
  373. !(sb->s_flags & MS_RDONLY)) {
  374. printk(KERN_WARNING "hfs: write access to "
  375. "a journaled filesystem is not supported, "
  376. "use the force option at your own risk, "
  377. "mounting read-only.\n");
  378. sb->s_flags |= MS_RDONLY;
  379. }
  380. err = -EINVAL;
  381. /* Load metadata objects (B*Trees) */
  382. sbi->ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
  383. if (!sbi->ext_tree) {
  384. printk(KERN_ERR "hfs: failed to load extents file\n");
  385. goto out_free_vhdr;
  386. }
  387. sbi->cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
  388. if (!sbi->cat_tree) {
  389. printk(KERN_ERR "hfs: failed to load catalog file\n");
  390. goto out_close_ext_tree;
  391. }
  392. inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
  393. if (IS_ERR(inode)) {
  394. printk(KERN_ERR "hfs: failed to load allocation file\n");
  395. err = PTR_ERR(inode);
  396. goto out_close_cat_tree;
  397. }
  398. sbi->alloc_file = inode;
  399. /* Load the root directory */
  400. root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
  401. if (IS_ERR(root)) {
  402. printk(KERN_ERR "hfs: failed to load root directory\n");
  403. err = PTR_ERR(root);
  404. goto out_put_alloc_file;
  405. }
  406. str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
  407. str.name = HFSP_HIDDENDIR_NAME;
  408. err = hfs_find_init(sbi->cat_tree, &fd);
  409. if (err)
  410. goto out_put_root;
  411. hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
  412. if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
  413. hfs_find_exit(&fd);
  414. if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
  415. goto out_put_root;
  416. inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
  417. if (IS_ERR(inode)) {
  418. err = PTR_ERR(inode);
  419. goto out_put_root;
  420. }
  421. sbi->hidden_dir = inode;
  422. } else
  423. hfs_find_exit(&fd);
  424. if (!(sb->s_flags & MS_RDONLY)) {
  425. /*
  426. * H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
  427. * all three are registered with Apple for our use
  428. */
  429. vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
  430. vhdr->modify_date = hfsp_now2mt();
  431. be32_add_cpu(&vhdr->write_count, 1);
  432. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
  433. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
  434. hfsplus_sync_fs(sb, 1);
  435. if (!sbi->hidden_dir) {
  436. mutex_lock(&sbi->vh_mutex);
  437. sbi->hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
  438. hfsplus_create_cat(sbi->hidden_dir->i_ino, root, &str,
  439. sbi->hidden_dir);
  440. mutex_unlock(&sbi->vh_mutex);
  441. hfsplus_mark_inode_dirty(sbi->hidden_dir,
  442. HFSPLUS_I_CAT_DIRTY);
  443. }
  444. }
  445. sb->s_d_op = &hfsplus_dentry_operations;
  446. sb->s_root = d_alloc_root(root);
  447. if (!sb->s_root) {
  448. err = -ENOMEM;
  449. goto out_put_hidden_dir;
  450. }
  451. unload_nls(sbi->nls);
  452. sbi->nls = nls;
  453. return 0;
  454. out_put_hidden_dir:
  455. iput(sbi->hidden_dir);
  456. out_put_root:
  457. iput(root);
  458. out_put_alloc_file:
  459. iput(sbi->alloc_file);
  460. out_close_cat_tree:
  461. hfs_btree_close(sbi->cat_tree);
  462. out_close_ext_tree:
  463. hfs_btree_close(sbi->ext_tree);
  464. out_free_vhdr:
  465. kfree(sbi->s_vhdr_buf);
  466. kfree(sbi->s_backup_vhdr_buf);
  467. out_unload_nls:
  468. unload_nls(sbi->nls);
  469. unload_nls(nls);
  470. kfree(sbi);
  471. out:
  472. return err;
  473. }
  474. MODULE_AUTHOR("Brad Boyer");
  475. MODULE_DESCRIPTION("Extended Macintosh Filesystem");
  476. MODULE_LICENSE("GPL");
  477. static struct kmem_cache *hfsplus_inode_cachep;
  478. static struct inode *hfsplus_alloc_inode(struct super_block *sb)
  479. {
  480. struct hfsplus_inode_info *i;
  481. i = kmem_cache_alloc(hfsplus_inode_cachep, GFP_KERNEL);
  482. return i ? &i->vfs_inode : NULL;
  483. }
  484. static void hfsplus_i_callback(struct rcu_head *head)
  485. {
  486. struct inode *inode = container_of(head, struct inode, i_rcu);
  487. INIT_LIST_HEAD(&inode->i_dentry);
  488. kmem_cache_free(hfsplus_inode_cachep, HFSPLUS_I(inode));
  489. }
  490. static void hfsplus_destroy_inode(struct inode *inode)
  491. {
  492. call_rcu(&inode->i_rcu, hfsplus_i_callback);
  493. }
  494. #define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
  495. static struct dentry *hfsplus_mount(struct file_system_type *fs_type,
  496. int flags, const char *dev_name, void *data)
  497. {
  498. return mount_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
  499. }
  500. static struct file_system_type hfsplus_fs_type = {
  501. .owner = THIS_MODULE,
  502. .name = "hfsplus",
  503. .mount = hfsplus_mount,
  504. .kill_sb = kill_block_super,
  505. .fs_flags = FS_REQUIRES_DEV,
  506. };
  507. static void hfsplus_init_once(void *p)
  508. {
  509. struct hfsplus_inode_info *i = p;
  510. inode_init_once(&i->vfs_inode);
  511. }
  512. static int __init init_hfsplus_fs(void)
  513. {
  514. int err;
  515. hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
  516. HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
  517. hfsplus_init_once);
  518. if (!hfsplus_inode_cachep)
  519. return -ENOMEM;
  520. err = register_filesystem(&hfsplus_fs_type);
  521. if (err)
  522. kmem_cache_destroy(hfsplus_inode_cachep);
  523. return err;
  524. }
  525. static void __exit exit_hfsplus_fs(void)
  526. {
  527. unregister_filesystem(&hfsplus_fs_type);
  528. kmem_cache_destroy(hfsplus_inode_cachep);
  529. }
  530. module_init(init_hfsplus_fs)
  531. module_exit(exit_hfsplus_fs)