super.c 15 KB

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