super.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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/fs.h>
  13. #include <linux/slab.h>
  14. #include <linux/vfs.h>
  15. #include <linux/nls.h>
  16. static struct inode *hfsplus_alloc_inode(struct super_block *sb);
  17. static void hfsplus_destroy_inode(struct inode *inode);
  18. #include "hfsplus_fs.h"
  19. struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
  20. {
  21. struct hfs_find_data fd;
  22. struct hfsplus_vh *vhdr;
  23. struct inode *inode;
  24. long err = -EIO;
  25. inode = iget_locked(sb, ino);
  26. if (!inode)
  27. return ERR_PTR(-ENOMEM);
  28. if (!(inode->i_state & I_NEW))
  29. return inode;
  30. INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
  31. mutex_init(&HFSPLUS_I(inode).extents_lock);
  32. HFSPLUS_I(inode).flags = 0;
  33. HFSPLUS_I(inode).rsrc_inode = NULL;
  34. atomic_set(&HFSPLUS_I(inode).opencnt, 0);
  35. if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID) {
  36. read_inode:
  37. hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
  38. err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
  39. if (!err)
  40. err = hfsplus_cat_read_inode(inode, &fd);
  41. hfs_find_exit(&fd);
  42. if (err)
  43. goto bad_inode;
  44. goto done;
  45. }
  46. vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
  47. switch(inode->i_ino) {
  48. case HFSPLUS_ROOT_CNID:
  49. goto read_inode;
  50. case HFSPLUS_EXT_CNID:
  51. hfsplus_inode_read_fork(inode, &vhdr->ext_file);
  52. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  53. break;
  54. case HFSPLUS_CAT_CNID:
  55. hfsplus_inode_read_fork(inode, &vhdr->cat_file);
  56. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  57. break;
  58. case HFSPLUS_ALLOC_CNID:
  59. hfsplus_inode_read_fork(inode, &vhdr->alloc_file);
  60. inode->i_mapping->a_ops = &hfsplus_aops;
  61. break;
  62. case HFSPLUS_START_CNID:
  63. hfsplus_inode_read_fork(inode, &vhdr->start_file);
  64. break;
  65. case HFSPLUS_ATTR_CNID:
  66. hfsplus_inode_read_fork(inode, &vhdr->attr_file);
  67. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  68. break;
  69. default:
  70. goto bad_inode;
  71. }
  72. done:
  73. unlock_new_inode(inode);
  74. return inode;
  75. bad_inode:
  76. iget_failed(inode);
  77. return ERR_PTR(err);
  78. }
  79. static int hfsplus_write_inode(struct inode *inode, int unused)
  80. {
  81. struct hfsplus_vh *vhdr;
  82. int ret = 0;
  83. dprint(DBG_INODE, "hfsplus_write_inode: %lu\n", inode->i_ino);
  84. hfsplus_ext_write_extent(inode);
  85. if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID) {
  86. return hfsplus_cat_write_inode(inode);
  87. }
  88. vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
  89. switch (inode->i_ino) {
  90. case HFSPLUS_ROOT_CNID:
  91. ret = hfsplus_cat_write_inode(inode);
  92. break;
  93. case HFSPLUS_EXT_CNID:
  94. if (vhdr->ext_file.total_size != cpu_to_be64(inode->i_size)) {
  95. HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
  96. inode->i_sb->s_dirt = 1;
  97. }
  98. hfsplus_inode_write_fork(inode, &vhdr->ext_file);
  99. hfs_btree_write(HFSPLUS_SB(inode->i_sb).ext_tree);
  100. break;
  101. case HFSPLUS_CAT_CNID:
  102. if (vhdr->cat_file.total_size != cpu_to_be64(inode->i_size)) {
  103. HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
  104. inode->i_sb->s_dirt = 1;
  105. }
  106. hfsplus_inode_write_fork(inode, &vhdr->cat_file);
  107. hfs_btree_write(HFSPLUS_SB(inode->i_sb).cat_tree);
  108. break;
  109. case HFSPLUS_ALLOC_CNID:
  110. if (vhdr->alloc_file.total_size != cpu_to_be64(inode->i_size)) {
  111. HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
  112. inode->i_sb->s_dirt = 1;
  113. }
  114. hfsplus_inode_write_fork(inode, &vhdr->alloc_file);
  115. break;
  116. case HFSPLUS_START_CNID:
  117. if (vhdr->start_file.total_size != cpu_to_be64(inode->i_size)) {
  118. HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
  119. inode->i_sb->s_dirt = 1;
  120. }
  121. hfsplus_inode_write_fork(inode, &vhdr->start_file);
  122. break;
  123. case HFSPLUS_ATTR_CNID:
  124. if (vhdr->attr_file.total_size != cpu_to_be64(inode->i_size)) {
  125. HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
  126. inode->i_sb->s_dirt = 1;
  127. }
  128. hfsplus_inode_write_fork(inode, &vhdr->attr_file);
  129. hfs_btree_write(HFSPLUS_SB(inode->i_sb).attr_tree);
  130. break;
  131. }
  132. return ret;
  133. }
  134. static void hfsplus_clear_inode(struct inode *inode)
  135. {
  136. dprint(DBG_INODE, "hfsplus_clear_inode: %lu\n", inode->i_ino);
  137. if (HFSPLUS_IS_RSRC(inode)) {
  138. HFSPLUS_I(HFSPLUS_I(inode).rsrc_inode).rsrc_inode = NULL;
  139. iput(HFSPLUS_I(inode).rsrc_inode);
  140. }
  141. }
  142. static void hfsplus_write_super(struct super_block *sb)
  143. {
  144. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
  145. dprint(DBG_SUPER, "hfsplus_write_super\n");
  146. sb->s_dirt = 0;
  147. if (sb->s_flags & MS_RDONLY)
  148. /* warn? */
  149. return;
  150. vhdr->free_blocks = cpu_to_be32(HFSPLUS_SB(sb).free_blocks);
  151. vhdr->next_alloc = cpu_to_be32(HFSPLUS_SB(sb).next_alloc);
  152. vhdr->next_cnid = cpu_to_be32(HFSPLUS_SB(sb).next_cnid);
  153. vhdr->folder_count = cpu_to_be32(HFSPLUS_SB(sb).folder_count);
  154. vhdr->file_count = cpu_to_be32(HFSPLUS_SB(sb).file_count);
  155. mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
  156. if (HFSPLUS_SB(sb).flags & HFSPLUS_SB_WRITEBACKUP) {
  157. if (HFSPLUS_SB(sb).sect_count) {
  158. struct buffer_head *bh;
  159. u32 block, offset;
  160. block = HFSPLUS_SB(sb).blockoffset;
  161. block += (HFSPLUS_SB(sb).sect_count - 2) >> (sb->s_blocksize_bits - 9);
  162. offset = ((HFSPLUS_SB(sb).sect_count - 2) << 9) & (sb->s_blocksize - 1);
  163. printk(KERN_DEBUG "hfs: backup: %u,%u,%u,%u\n", HFSPLUS_SB(sb).blockoffset,
  164. HFSPLUS_SB(sb).sect_count, block, offset);
  165. bh = sb_bread(sb, block);
  166. if (bh) {
  167. vhdr = (struct hfsplus_vh *)(bh->b_data + offset);
  168. if (be16_to_cpu(vhdr->signature) == HFSPLUS_VOLHEAD_SIG) {
  169. memcpy(vhdr, HFSPLUS_SB(sb).s_vhdr, sizeof(*vhdr));
  170. mark_buffer_dirty(bh);
  171. brelse(bh);
  172. } else
  173. printk(KERN_WARNING "hfs: backup not found!\n");
  174. }
  175. }
  176. HFSPLUS_SB(sb).flags &= ~HFSPLUS_SB_WRITEBACKUP;
  177. }
  178. }
  179. static void hfsplus_put_super(struct super_block *sb)
  180. {
  181. dprint(DBG_SUPER, "hfsplus_put_super\n");
  182. if (!sb->s_fs_info)
  183. return;
  184. if (!(sb->s_flags & MS_RDONLY) && HFSPLUS_SB(sb).s_vhdr) {
  185. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
  186. vhdr->modify_date = hfsp_now2mt();
  187. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_UNMNT);
  188. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_INCNSTNT);
  189. mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
  190. sync_dirty_buffer(HFSPLUS_SB(sb).s_vhbh);
  191. }
  192. hfs_btree_close(HFSPLUS_SB(sb).cat_tree);
  193. hfs_btree_close(HFSPLUS_SB(sb).ext_tree);
  194. iput(HFSPLUS_SB(sb).alloc_file);
  195. iput(HFSPLUS_SB(sb).hidden_dir);
  196. brelse(HFSPLUS_SB(sb).s_vhbh);
  197. if (HFSPLUS_SB(sb).nls)
  198. unload_nls(HFSPLUS_SB(sb).nls);
  199. kfree(sb->s_fs_info);
  200. sb->s_fs_info = NULL;
  201. }
  202. static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)
  203. {
  204. struct super_block *sb = dentry->d_sb;
  205. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  206. buf->f_type = HFSPLUS_SUPER_MAGIC;
  207. buf->f_bsize = sb->s_blocksize;
  208. buf->f_blocks = HFSPLUS_SB(sb).total_blocks << HFSPLUS_SB(sb).fs_shift;
  209. buf->f_bfree = HFSPLUS_SB(sb).free_blocks << HFSPLUS_SB(sb).fs_shift;
  210. buf->f_bavail = buf->f_bfree;
  211. buf->f_files = 0xFFFFFFFF;
  212. buf->f_ffree = 0xFFFFFFFF - HFSPLUS_SB(sb).next_cnid;
  213. buf->f_fsid.val[0] = (u32)id;
  214. buf->f_fsid.val[1] = (u32)(id >> 32);
  215. buf->f_namelen = HFSPLUS_MAX_STRLEN;
  216. return 0;
  217. }
  218. static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
  219. {
  220. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  221. return 0;
  222. if (!(*flags & MS_RDONLY)) {
  223. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
  224. struct hfsplus_sb_info sbi;
  225. memset(&sbi, 0, sizeof(struct hfsplus_sb_info));
  226. sbi.nls = HFSPLUS_SB(sb).nls;
  227. if (!hfsplus_parse_options(data, &sbi))
  228. return -EINVAL;
  229. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  230. printk(KERN_WARNING "hfs: filesystem was not cleanly unmounted, "
  231. "running fsck.hfsplus is recommended. leaving read-only.\n");
  232. sb->s_flags |= MS_RDONLY;
  233. *flags |= MS_RDONLY;
  234. } else if (sbi.flags & HFSPLUS_SB_FORCE) {
  235. /* nothing */
  236. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  237. printk(KERN_WARNING "hfs: filesystem is marked locked, leaving read-only.\n");
  238. sb->s_flags |= MS_RDONLY;
  239. *flags |= MS_RDONLY;
  240. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
  241. printk(KERN_WARNING "hfs: filesystem is marked journaled, leaving read-only.\n");
  242. sb->s_flags |= MS_RDONLY;
  243. *flags |= MS_RDONLY;
  244. }
  245. }
  246. return 0;
  247. }
  248. static const struct super_operations hfsplus_sops = {
  249. .alloc_inode = hfsplus_alloc_inode,
  250. .destroy_inode = hfsplus_destroy_inode,
  251. .write_inode = hfsplus_write_inode,
  252. .clear_inode = hfsplus_clear_inode,
  253. .put_super = hfsplus_put_super,
  254. .write_super = hfsplus_write_super,
  255. .statfs = hfsplus_statfs,
  256. .remount_fs = hfsplus_remount,
  257. .show_options = hfsplus_show_options,
  258. };
  259. static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
  260. {
  261. struct hfsplus_vh *vhdr;
  262. struct hfsplus_sb_info *sbi;
  263. hfsplus_cat_entry entry;
  264. struct hfs_find_data fd;
  265. struct inode *root, *inode;
  266. struct qstr str;
  267. struct nls_table *nls = NULL;
  268. int err = -EINVAL;
  269. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  270. if (!sbi)
  271. return -ENOMEM;
  272. sb->s_fs_info = sbi;
  273. INIT_HLIST_HEAD(&sbi->rsrc_inodes);
  274. hfsplus_fill_defaults(sbi);
  275. if (!hfsplus_parse_options(data, sbi)) {
  276. printk(KERN_ERR "hfs: unable to parse mount options\n");
  277. err = -EINVAL;
  278. goto cleanup;
  279. }
  280. /* temporarily use utf8 to correctly find the hidden dir below */
  281. nls = sbi->nls;
  282. sbi->nls = load_nls("utf8");
  283. if (!sbi->nls) {
  284. printk(KERN_ERR "hfs: unable to load nls for utf8\n");
  285. err = -EINVAL;
  286. goto cleanup;
  287. }
  288. /* Grab the volume header */
  289. if (hfsplus_read_wrapper(sb)) {
  290. if (!silent)
  291. printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
  292. err = -EINVAL;
  293. goto cleanup;
  294. }
  295. vhdr = HFSPLUS_SB(sb).s_vhdr;
  296. /* Copy parts of the volume header into the superblock */
  297. sb->s_magic = HFSPLUS_VOLHEAD_SIG;
  298. if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
  299. be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
  300. printk(KERN_ERR "hfs: wrong filesystem version\n");
  301. goto cleanup;
  302. }
  303. HFSPLUS_SB(sb).total_blocks = be32_to_cpu(vhdr->total_blocks);
  304. HFSPLUS_SB(sb).free_blocks = be32_to_cpu(vhdr->free_blocks);
  305. HFSPLUS_SB(sb).next_alloc = be32_to_cpu(vhdr->next_alloc);
  306. HFSPLUS_SB(sb).next_cnid = be32_to_cpu(vhdr->next_cnid);
  307. HFSPLUS_SB(sb).file_count = be32_to_cpu(vhdr->file_count);
  308. HFSPLUS_SB(sb).folder_count = be32_to_cpu(vhdr->folder_count);
  309. HFSPLUS_SB(sb).data_clump_blocks = be32_to_cpu(vhdr->data_clump_sz) >> HFSPLUS_SB(sb).alloc_blksz_shift;
  310. if (!HFSPLUS_SB(sb).data_clump_blocks)
  311. HFSPLUS_SB(sb).data_clump_blocks = 1;
  312. HFSPLUS_SB(sb).rsrc_clump_blocks = be32_to_cpu(vhdr->rsrc_clump_sz) >> HFSPLUS_SB(sb).alloc_blksz_shift;
  313. if (!HFSPLUS_SB(sb).rsrc_clump_blocks)
  314. HFSPLUS_SB(sb).rsrc_clump_blocks = 1;
  315. /* Set up operations so we can load metadata */
  316. sb->s_op = &hfsplus_sops;
  317. sb->s_maxbytes = MAX_LFS_FILESIZE;
  318. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  319. printk(KERN_WARNING "hfs: Filesystem was not cleanly unmounted, "
  320. "running fsck.hfsplus is recommended. mounting read-only.\n");
  321. sb->s_flags |= MS_RDONLY;
  322. } else if (sbi->flags & HFSPLUS_SB_FORCE) {
  323. /* nothing */
  324. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  325. printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
  326. sb->s_flags |= MS_RDONLY;
  327. } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) && !(sb->s_flags & MS_RDONLY)) {
  328. printk(KERN_WARNING "hfs: write access to a journaled filesystem is not supported, "
  329. "use the force option at your own risk, mounting read-only.\n");
  330. sb->s_flags |= MS_RDONLY;
  331. }
  332. sbi->flags &= ~HFSPLUS_SB_FORCE;
  333. /* Load metadata objects (B*Trees) */
  334. HFSPLUS_SB(sb).ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
  335. if (!HFSPLUS_SB(sb).ext_tree) {
  336. printk(KERN_ERR "hfs: failed to load extents file\n");
  337. goto cleanup;
  338. }
  339. HFSPLUS_SB(sb).cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
  340. if (!HFSPLUS_SB(sb).cat_tree) {
  341. printk(KERN_ERR "hfs: failed to load catalog file\n");
  342. goto cleanup;
  343. }
  344. inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
  345. if (IS_ERR(inode)) {
  346. printk(KERN_ERR "hfs: failed to load allocation file\n");
  347. err = PTR_ERR(inode);
  348. goto cleanup;
  349. }
  350. HFSPLUS_SB(sb).alloc_file = inode;
  351. /* Load the root directory */
  352. root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
  353. if (IS_ERR(root)) {
  354. printk(KERN_ERR "hfs: failed to load root directory\n");
  355. err = PTR_ERR(root);
  356. goto cleanup;
  357. }
  358. sb->s_root = d_alloc_root(root);
  359. if (!sb->s_root) {
  360. iput(root);
  361. err = -ENOMEM;
  362. goto cleanup;
  363. }
  364. sb->s_root->d_op = &hfsplus_dentry_operations;
  365. str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
  366. str.name = HFSP_HIDDENDIR_NAME;
  367. hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
  368. hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
  369. if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
  370. hfs_find_exit(&fd);
  371. if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
  372. goto cleanup;
  373. inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
  374. if (IS_ERR(inode)) {
  375. err = PTR_ERR(inode);
  376. goto cleanup;
  377. }
  378. HFSPLUS_SB(sb).hidden_dir = inode;
  379. } else
  380. hfs_find_exit(&fd);
  381. if (sb->s_flags & MS_RDONLY)
  382. goto out;
  383. /* H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
  384. * all three are registered with Apple for our use
  385. */
  386. vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
  387. vhdr->modify_date = hfsp_now2mt();
  388. be32_add_cpu(&vhdr->write_count, 1);
  389. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
  390. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
  391. mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
  392. sync_dirty_buffer(HFSPLUS_SB(sb).s_vhbh);
  393. if (!HFSPLUS_SB(sb).hidden_dir) {
  394. printk(KERN_DEBUG "hfs: create hidden dir...\n");
  395. HFSPLUS_SB(sb).hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
  396. hfsplus_create_cat(HFSPLUS_SB(sb).hidden_dir->i_ino, sb->s_root->d_inode,
  397. &str, HFSPLUS_SB(sb).hidden_dir);
  398. mark_inode_dirty(HFSPLUS_SB(sb).hidden_dir);
  399. }
  400. out:
  401. unload_nls(sbi->nls);
  402. sbi->nls = nls;
  403. return 0;
  404. cleanup:
  405. hfsplus_put_super(sb);
  406. if (nls)
  407. unload_nls(nls);
  408. return err;
  409. }
  410. MODULE_AUTHOR("Brad Boyer");
  411. MODULE_DESCRIPTION("Extended Macintosh Filesystem");
  412. MODULE_LICENSE("GPL");
  413. static struct kmem_cache *hfsplus_inode_cachep;
  414. static struct inode *hfsplus_alloc_inode(struct super_block *sb)
  415. {
  416. struct hfsplus_inode_info *i;
  417. i = kmem_cache_alloc(hfsplus_inode_cachep, GFP_KERNEL);
  418. return i ? &i->vfs_inode : NULL;
  419. }
  420. static void hfsplus_destroy_inode(struct inode *inode)
  421. {
  422. kmem_cache_free(hfsplus_inode_cachep, &HFSPLUS_I(inode));
  423. }
  424. #define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
  425. static int hfsplus_get_sb(struct file_system_type *fs_type,
  426. int flags, const char *dev_name, void *data,
  427. struct vfsmount *mnt)
  428. {
  429. return get_sb_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super,
  430. mnt);
  431. }
  432. static struct file_system_type hfsplus_fs_type = {
  433. .owner = THIS_MODULE,
  434. .name = "hfsplus",
  435. .get_sb = hfsplus_get_sb,
  436. .kill_sb = kill_block_super,
  437. .fs_flags = FS_REQUIRES_DEV,
  438. };
  439. static void hfsplus_init_once(void *p)
  440. {
  441. struct hfsplus_inode_info *i = p;
  442. inode_init_once(&i->vfs_inode);
  443. }
  444. static int __init init_hfsplus_fs(void)
  445. {
  446. int err;
  447. hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
  448. HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
  449. hfsplus_init_once);
  450. if (!hfsplus_inode_cachep)
  451. return -ENOMEM;
  452. err = register_filesystem(&hfsplus_fs_type);
  453. if (err)
  454. kmem_cache_destroy(hfsplus_inode_cachep);
  455. return err;
  456. }
  457. static void __exit exit_hfsplus_fs(void)
  458. {
  459. unregister_filesystem(&hfsplus_fs_type);
  460. kmem_cache_destroy(hfsplus_inode_cachep);
  461. }
  462. module_init(init_hfsplus_fs)
  463. module_exit(exit_hfsplus_fs)