super.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. sync_filesystem(sb);
  247. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  248. return 0;
  249. if (!(*flags & MS_RDONLY)) {
  250. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb)->s_vhdr;
  251. int force = 0;
  252. if (!hfsplus_parse_options_remount(data, &force))
  253. return -EINVAL;
  254. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  255. printk(KERN_WARNING "hfs: filesystem was "
  256. "not cleanly unmounted, "
  257. "running fsck.hfsplus is recommended. "
  258. "leaving read-only.\n");
  259. sb->s_flags |= MS_RDONLY;
  260. *flags |= MS_RDONLY;
  261. } else if (force) {
  262. /* nothing */
  263. } else if (vhdr->attributes &
  264. cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  265. printk(KERN_WARNING "hfs: filesystem is marked locked, "
  266. "leaving read-only.\n");
  267. sb->s_flags |= MS_RDONLY;
  268. *flags |= MS_RDONLY;
  269. } else if (vhdr->attributes &
  270. cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
  271. printk(KERN_WARNING "hfs: filesystem is "
  272. "marked journaled, "
  273. "leaving read-only.\n");
  274. sb->s_flags |= MS_RDONLY;
  275. *flags |= MS_RDONLY;
  276. }
  277. }
  278. return 0;
  279. }
  280. static const struct super_operations hfsplus_sops = {
  281. .alloc_inode = hfsplus_alloc_inode,
  282. .destroy_inode = hfsplus_destroy_inode,
  283. .write_inode = hfsplus_write_inode,
  284. .evict_inode = hfsplus_evict_inode,
  285. .put_super = hfsplus_put_super,
  286. .write_super = hfsplus_write_super,
  287. .sync_fs = hfsplus_sync_fs,
  288. .statfs = hfsplus_statfs,
  289. .remount_fs = hfsplus_remount,
  290. .show_options = hfsplus_show_options,
  291. };
  292. static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
  293. {
  294. struct hfsplus_vh *vhdr;
  295. struct hfsplus_sb_info *sbi;
  296. hfsplus_cat_entry entry;
  297. struct hfs_find_data fd;
  298. struct inode *root, *inode;
  299. struct qstr str;
  300. struct nls_table *nls = NULL;
  301. u64 last_fs_block, last_fs_page;
  302. int err;
  303. err = -EINVAL;
  304. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  305. if (!sbi)
  306. goto out;
  307. sb->s_fs_info = sbi;
  308. mutex_init(&sbi->alloc_mutex);
  309. mutex_init(&sbi->vh_mutex);
  310. hfsplus_fill_defaults(sbi);
  311. err = -EINVAL;
  312. if (!hfsplus_parse_options(data, sbi)) {
  313. printk(KERN_ERR "hfs: unable to parse mount options\n");
  314. goto out_unload_nls;
  315. }
  316. /* temporarily use utf8 to correctly find the hidden dir below */
  317. nls = sbi->nls;
  318. sbi->nls = load_nls("utf8");
  319. if (!sbi->nls) {
  320. printk(KERN_ERR "hfs: unable to load nls for utf8\n");
  321. goto out_unload_nls;
  322. }
  323. /* Grab the volume header */
  324. if (hfsplus_read_wrapper(sb)) {
  325. if (!silent)
  326. printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
  327. goto out_unload_nls;
  328. }
  329. vhdr = sbi->s_vhdr;
  330. /* Copy parts of the volume header into the superblock */
  331. sb->s_magic = HFSPLUS_VOLHEAD_SIG;
  332. if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
  333. be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
  334. printk(KERN_ERR "hfs: wrong filesystem version\n");
  335. goto out_free_vhdr;
  336. }
  337. sbi->total_blocks = be32_to_cpu(vhdr->total_blocks);
  338. sbi->free_blocks = be32_to_cpu(vhdr->free_blocks);
  339. sbi->next_cnid = be32_to_cpu(vhdr->next_cnid);
  340. sbi->file_count = be32_to_cpu(vhdr->file_count);
  341. sbi->folder_count = be32_to_cpu(vhdr->folder_count);
  342. sbi->data_clump_blocks =
  343. be32_to_cpu(vhdr->data_clump_sz) >> sbi->alloc_blksz_shift;
  344. if (!sbi->data_clump_blocks)
  345. sbi->data_clump_blocks = 1;
  346. sbi->rsrc_clump_blocks =
  347. be32_to_cpu(vhdr->rsrc_clump_sz) >> sbi->alloc_blksz_shift;
  348. if (!sbi->rsrc_clump_blocks)
  349. sbi->rsrc_clump_blocks = 1;
  350. err = -EFBIG;
  351. last_fs_block = sbi->total_blocks - 1;
  352. last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
  353. PAGE_CACHE_SHIFT;
  354. if ((last_fs_block > (sector_t)(~0ULL) >> (sbi->alloc_blksz_shift - 9)) ||
  355. (last_fs_page > (pgoff_t)(~0ULL))) {
  356. printk(KERN_ERR "hfs: filesystem size too large.\n");
  357. goto out_free_vhdr;
  358. }
  359. /* Set up operations so we can load metadata */
  360. sb->s_op = &hfsplus_sops;
  361. sb->s_maxbytes = MAX_LFS_FILESIZE;
  362. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  363. printk(KERN_WARNING "hfs: Filesystem was "
  364. "not cleanly unmounted, "
  365. "running fsck.hfsplus is recommended. "
  366. "mounting read-only.\n");
  367. sb->s_flags |= MS_RDONLY;
  368. } else if (test_and_clear_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
  369. /* nothing */
  370. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  371. printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
  372. sb->s_flags |= MS_RDONLY;
  373. } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
  374. !(sb->s_flags & MS_RDONLY)) {
  375. printk(KERN_WARNING "hfs: write access to "
  376. "a journaled filesystem is not supported, "
  377. "use the force option at your own risk, "
  378. "mounting read-only.\n");
  379. sb->s_flags |= MS_RDONLY;
  380. }
  381. err = -EINVAL;
  382. /* Load metadata objects (B*Trees) */
  383. sbi->ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
  384. if (!sbi->ext_tree) {
  385. printk(KERN_ERR "hfs: failed to load extents file\n");
  386. goto out_free_vhdr;
  387. }
  388. sbi->cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
  389. if (!sbi->cat_tree) {
  390. printk(KERN_ERR "hfs: failed to load catalog file\n");
  391. goto out_close_ext_tree;
  392. }
  393. inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
  394. if (IS_ERR(inode)) {
  395. printk(KERN_ERR "hfs: failed to load allocation file\n");
  396. err = PTR_ERR(inode);
  397. goto out_close_cat_tree;
  398. }
  399. sbi->alloc_file = inode;
  400. /* Load the root directory */
  401. root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
  402. if (IS_ERR(root)) {
  403. printk(KERN_ERR "hfs: failed to load root directory\n");
  404. err = PTR_ERR(root);
  405. goto out_put_alloc_file;
  406. }
  407. sb->s_d_op = &hfsplus_dentry_operations;
  408. sb->s_root = d_make_root(root);
  409. if (!sb->s_root) {
  410. err = -ENOMEM;
  411. goto out_put_alloc_file;
  412. }
  413. str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
  414. str.name = HFSP_HIDDENDIR_NAME;
  415. err = hfs_find_init(sbi->cat_tree, &fd);
  416. if (err)
  417. goto out_put_root;
  418. hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
  419. if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
  420. hfs_find_exit(&fd);
  421. if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
  422. goto out_put_root;
  423. inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
  424. if (IS_ERR(inode)) {
  425. err = PTR_ERR(inode);
  426. goto out_put_root;
  427. }
  428. sbi->hidden_dir = inode;
  429. } else
  430. hfs_find_exit(&fd);
  431. if (!(sb->s_flags & MS_RDONLY)) {
  432. /*
  433. * H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
  434. * all three are registered with Apple for our use
  435. */
  436. vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
  437. vhdr->modify_date = hfsp_now2mt();
  438. be32_add_cpu(&vhdr->write_count, 1);
  439. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
  440. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
  441. hfsplus_sync_fs(sb, 1);
  442. if (!sbi->hidden_dir) {
  443. mutex_lock(&sbi->vh_mutex);
  444. sbi->hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
  445. if (!sbi->hidden_dir) {
  446. mutex_unlock(&sbi->vh_mutex);
  447. err = -ENOMEM;
  448. goto out_put_root;
  449. }
  450. err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root,
  451. &str, sbi->hidden_dir);
  452. mutex_unlock(&sbi->vh_mutex);
  453. if (err)
  454. goto out_put_hidden_dir;
  455. hfsplus_mark_inode_dirty(sbi->hidden_dir,
  456. HFSPLUS_I_CAT_DIRTY);
  457. }
  458. }
  459. unload_nls(sbi->nls);
  460. sbi->nls = nls;
  461. return 0;
  462. out_put_hidden_dir:
  463. iput(sbi->hidden_dir);
  464. out_put_root:
  465. dput(sb->s_root);
  466. sb->s_root = NULL;
  467. out_put_alloc_file:
  468. iput(sbi->alloc_file);
  469. out_close_cat_tree:
  470. hfs_btree_close(sbi->cat_tree);
  471. out_close_ext_tree:
  472. hfs_btree_close(sbi->ext_tree);
  473. out_free_vhdr:
  474. kfree(sbi->s_vhdr_buf);
  475. kfree(sbi->s_backup_vhdr_buf);
  476. out_unload_nls:
  477. unload_nls(sbi->nls);
  478. unload_nls(nls);
  479. kfree(sbi);
  480. out:
  481. return err;
  482. }
  483. MODULE_AUTHOR("Brad Boyer");
  484. MODULE_DESCRIPTION("Extended Macintosh Filesystem");
  485. MODULE_LICENSE("GPL");
  486. static struct kmem_cache *hfsplus_inode_cachep;
  487. static struct inode *hfsplus_alloc_inode(struct super_block *sb)
  488. {
  489. struct hfsplus_inode_info *i;
  490. i = kmem_cache_alloc(hfsplus_inode_cachep, GFP_KERNEL);
  491. return i ? &i->vfs_inode : NULL;
  492. }
  493. static void hfsplus_i_callback(struct rcu_head *head)
  494. {
  495. struct inode *inode = container_of(head, struct inode, i_rcu);
  496. kmem_cache_free(hfsplus_inode_cachep, HFSPLUS_I(inode));
  497. }
  498. static void hfsplus_destroy_inode(struct inode *inode)
  499. {
  500. call_rcu(&inode->i_rcu, hfsplus_i_callback);
  501. }
  502. #define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
  503. static struct dentry *hfsplus_mount(struct file_system_type *fs_type,
  504. int flags, const char *dev_name, void *data)
  505. {
  506. return mount_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
  507. }
  508. static struct file_system_type hfsplus_fs_type = {
  509. .owner = THIS_MODULE,
  510. .name = "hfsplus",
  511. .mount = hfsplus_mount,
  512. .kill_sb = kill_block_super,
  513. .fs_flags = FS_REQUIRES_DEV,
  514. };
  515. MODULE_ALIAS_FS("hfsplus");
  516. static void hfsplus_init_once(void *p)
  517. {
  518. struct hfsplus_inode_info *i = p;
  519. inode_init_once(&i->vfs_inode);
  520. }
  521. static int __init init_hfsplus_fs(void)
  522. {
  523. int err;
  524. hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
  525. HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
  526. hfsplus_init_once);
  527. if (!hfsplus_inode_cachep)
  528. return -ENOMEM;
  529. err = register_filesystem(&hfsplus_fs_type);
  530. if (err)
  531. kmem_cache_destroy(hfsplus_inode_cachep);
  532. return err;
  533. }
  534. static void __exit exit_hfsplus_fs(void)
  535. {
  536. unregister_filesystem(&hfsplus_fs_type);
  537. /*
  538. * Make sure all delayed rcu free inodes are flushed before we
  539. * destroy cache.
  540. */
  541. rcu_barrier();
  542. kmem_cache_destroy(hfsplus_inode_cachep);
  543. }
  544. module_init(init_hfsplus_fs)
  545. module_exit(exit_hfsplus_fs)