super.c 15 KB

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