super.c 15 KB

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