super.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. hfsplus_mark_mdb_dirty(inode->i_sb);
  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. clear_inode(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. static 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_sync_fs\n");
  152. /*
  153. * Explicitly write out the special metadata inodes.
  154. *
  155. * While these special inodes are marked as hashed and written
  156. * out peridocically by the flusher threads we redirty them
  157. * during writeout of normal inodes, and thus the life lock
  158. * prevents us from getting the latest state to disk.
  159. */
  160. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  161. error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  162. if (!error)
  163. error = error2;
  164. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  165. if (!error)
  166. error = error2;
  167. mutex_lock(&sbi->vh_mutex);
  168. mutex_lock(&sbi->alloc_mutex);
  169. vhdr->free_blocks = cpu_to_be32(sbi->free_blocks);
  170. vhdr->next_cnid = cpu_to_be32(sbi->next_cnid);
  171. vhdr->folder_count = cpu_to_be32(sbi->folder_count);
  172. vhdr->file_count = cpu_to_be32(sbi->file_count);
  173. if (test_and_clear_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags)) {
  174. memcpy(sbi->s_backup_vhdr, sbi->s_vhdr, sizeof(*sbi->s_vhdr));
  175. write_backup = 1;
  176. }
  177. error2 = hfsplus_submit_bio(sb,
  178. sbi->part_start + HFSPLUS_VOLHEAD_SECTOR,
  179. sbi->s_vhdr_buf, NULL, WRITE_SYNC);
  180. if (!error)
  181. error = error2;
  182. if (!write_backup)
  183. goto out;
  184. error2 = hfsplus_submit_bio(sb,
  185. sbi->part_start + sbi->sect_count - 2,
  186. sbi->s_backup_vhdr_buf, NULL, WRITE_SYNC);
  187. if (!error)
  188. error2 = error;
  189. out:
  190. mutex_unlock(&sbi->alloc_mutex);
  191. mutex_unlock(&sbi->vh_mutex);
  192. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  193. blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
  194. return error;
  195. }
  196. static void delayed_sync_fs(struct work_struct *work)
  197. {
  198. struct hfsplus_sb_info *sbi;
  199. sbi = container_of(work, struct hfsplus_sb_info, sync_work.work);
  200. spin_lock(&sbi->work_lock);
  201. sbi->work_queued = 0;
  202. spin_unlock(&sbi->work_lock);
  203. hfsplus_sync_fs(sbi->alloc_file->i_sb, 1);
  204. }
  205. void hfsplus_mark_mdb_dirty(struct super_block *sb)
  206. {
  207. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  208. unsigned long delay;
  209. if (sb->s_flags & MS_RDONLY)
  210. return;
  211. spin_lock(&sbi->work_lock);
  212. if (!sbi->work_queued) {
  213. delay = msecs_to_jiffies(dirty_writeback_interval * 10);
  214. queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
  215. sbi->work_queued = 1;
  216. }
  217. spin_unlock(&sbi->work_lock);
  218. }
  219. static void hfsplus_put_super(struct super_block *sb)
  220. {
  221. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  222. dprint(DBG_SUPER, "hfsplus_put_super\n");
  223. cancel_delayed_work_sync(&sbi->sync_work);
  224. if (!(sb->s_flags & MS_RDONLY) && sbi->s_vhdr) {
  225. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  226. vhdr->modify_date = hfsp_now2mt();
  227. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_UNMNT);
  228. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_INCNSTNT);
  229. hfsplus_sync_fs(sb, 1);
  230. }
  231. hfs_btree_close(sbi->cat_tree);
  232. hfs_btree_close(sbi->ext_tree);
  233. iput(sbi->alloc_file);
  234. iput(sbi->hidden_dir);
  235. kfree(sbi->s_vhdr_buf);
  236. kfree(sbi->s_backup_vhdr_buf);
  237. unload_nls(sbi->nls);
  238. kfree(sb->s_fs_info);
  239. sb->s_fs_info = NULL;
  240. }
  241. static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)
  242. {
  243. struct super_block *sb = dentry->d_sb;
  244. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  245. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  246. buf->f_type = HFSPLUS_SUPER_MAGIC;
  247. buf->f_bsize = sb->s_blocksize;
  248. buf->f_blocks = sbi->total_blocks << sbi->fs_shift;
  249. buf->f_bfree = sbi->free_blocks << sbi->fs_shift;
  250. buf->f_bavail = buf->f_bfree;
  251. buf->f_files = 0xFFFFFFFF;
  252. buf->f_ffree = 0xFFFFFFFF - sbi->next_cnid;
  253. buf->f_fsid.val[0] = (u32)id;
  254. buf->f_fsid.val[1] = (u32)(id >> 32);
  255. buf->f_namelen = HFSPLUS_MAX_STRLEN;
  256. return 0;
  257. }
  258. static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
  259. {
  260. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  261. return 0;
  262. if (!(*flags & MS_RDONLY)) {
  263. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb)->s_vhdr;
  264. int force = 0;
  265. if (!hfsplus_parse_options_remount(data, &force))
  266. return -EINVAL;
  267. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  268. printk(KERN_WARNING "hfs: filesystem was "
  269. "not cleanly unmounted, "
  270. "running fsck.hfsplus is recommended. "
  271. "leaving read-only.\n");
  272. sb->s_flags |= MS_RDONLY;
  273. *flags |= MS_RDONLY;
  274. } else if (force) {
  275. /* nothing */
  276. } else if (vhdr->attributes &
  277. cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  278. printk(KERN_WARNING "hfs: filesystem is marked locked, "
  279. "leaving read-only.\n");
  280. sb->s_flags |= MS_RDONLY;
  281. *flags |= MS_RDONLY;
  282. } else if (vhdr->attributes &
  283. cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
  284. printk(KERN_WARNING "hfs: filesystem is "
  285. "marked journaled, "
  286. "leaving read-only.\n");
  287. sb->s_flags |= MS_RDONLY;
  288. *flags |= MS_RDONLY;
  289. }
  290. }
  291. return 0;
  292. }
  293. static const struct super_operations hfsplus_sops = {
  294. .alloc_inode = hfsplus_alloc_inode,
  295. .destroy_inode = hfsplus_destroy_inode,
  296. .write_inode = hfsplus_write_inode,
  297. .evict_inode = hfsplus_evict_inode,
  298. .put_super = hfsplus_put_super,
  299. .sync_fs = hfsplus_sync_fs,
  300. .statfs = hfsplus_statfs,
  301. .remount_fs = hfsplus_remount,
  302. .show_options = hfsplus_show_options,
  303. };
  304. static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
  305. {
  306. struct hfsplus_vh *vhdr;
  307. struct hfsplus_sb_info *sbi;
  308. hfsplus_cat_entry entry;
  309. struct hfs_find_data fd;
  310. struct inode *root, *inode;
  311. struct qstr str;
  312. struct nls_table *nls = NULL;
  313. u64 last_fs_block, last_fs_page;
  314. int err;
  315. err = -ENOMEM;
  316. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  317. if (!sbi)
  318. goto out;
  319. sb->s_fs_info = sbi;
  320. mutex_init(&sbi->alloc_mutex);
  321. mutex_init(&sbi->vh_mutex);
  322. spin_lock_init(&sbi->work_lock);
  323. INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
  324. hfsplus_fill_defaults(sbi);
  325. err = -EINVAL;
  326. if (!hfsplus_parse_options(data, sbi)) {
  327. printk(KERN_ERR "hfs: unable to parse mount options\n");
  328. goto out_unload_nls;
  329. }
  330. /* temporarily use utf8 to correctly find the hidden dir below */
  331. nls = sbi->nls;
  332. sbi->nls = load_nls("utf8");
  333. if (!sbi->nls) {
  334. printk(KERN_ERR "hfs: unable to load nls for utf8\n");
  335. goto out_unload_nls;
  336. }
  337. /* Grab the volume header */
  338. if (hfsplus_read_wrapper(sb)) {
  339. if (!silent)
  340. printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
  341. goto out_unload_nls;
  342. }
  343. vhdr = sbi->s_vhdr;
  344. /* Copy parts of the volume header into the superblock */
  345. sb->s_magic = HFSPLUS_VOLHEAD_SIG;
  346. if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
  347. be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
  348. printk(KERN_ERR "hfs: wrong filesystem version\n");
  349. goto out_free_vhdr;
  350. }
  351. sbi->total_blocks = be32_to_cpu(vhdr->total_blocks);
  352. sbi->free_blocks = be32_to_cpu(vhdr->free_blocks);
  353. sbi->next_cnid = be32_to_cpu(vhdr->next_cnid);
  354. sbi->file_count = be32_to_cpu(vhdr->file_count);
  355. sbi->folder_count = be32_to_cpu(vhdr->folder_count);
  356. sbi->data_clump_blocks =
  357. be32_to_cpu(vhdr->data_clump_sz) >> sbi->alloc_blksz_shift;
  358. if (!sbi->data_clump_blocks)
  359. sbi->data_clump_blocks = 1;
  360. sbi->rsrc_clump_blocks =
  361. be32_to_cpu(vhdr->rsrc_clump_sz) >> sbi->alloc_blksz_shift;
  362. if (!sbi->rsrc_clump_blocks)
  363. sbi->rsrc_clump_blocks = 1;
  364. err = -EFBIG;
  365. last_fs_block = sbi->total_blocks - 1;
  366. last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
  367. PAGE_CACHE_SHIFT;
  368. if ((last_fs_block > (sector_t)(~0ULL) >> (sbi->alloc_blksz_shift - 9)) ||
  369. (last_fs_page > (pgoff_t)(~0ULL))) {
  370. printk(KERN_ERR "hfs: filesystem size too large.\n");
  371. goto out_free_vhdr;
  372. }
  373. /* Set up operations so we can load metadata */
  374. sb->s_op = &hfsplus_sops;
  375. sb->s_maxbytes = MAX_LFS_FILESIZE;
  376. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  377. printk(KERN_WARNING "hfs: Filesystem was "
  378. "not cleanly unmounted, "
  379. "running fsck.hfsplus is recommended. "
  380. "mounting read-only.\n");
  381. sb->s_flags |= MS_RDONLY;
  382. } else if (test_and_clear_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
  383. /* nothing */
  384. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  385. printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
  386. sb->s_flags |= MS_RDONLY;
  387. } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
  388. !(sb->s_flags & MS_RDONLY)) {
  389. printk(KERN_WARNING "hfs: write access to "
  390. "a journaled filesystem is not supported, "
  391. "use the force option at your own risk, "
  392. "mounting read-only.\n");
  393. sb->s_flags |= MS_RDONLY;
  394. }
  395. err = -EINVAL;
  396. /* Load metadata objects (B*Trees) */
  397. sbi->ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
  398. if (!sbi->ext_tree) {
  399. printk(KERN_ERR "hfs: failed to load extents file\n");
  400. goto out_free_vhdr;
  401. }
  402. sbi->cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
  403. if (!sbi->cat_tree) {
  404. printk(KERN_ERR "hfs: failed to load catalog file\n");
  405. goto out_close_ext_tree;
  406. }
  407. inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
  408. if (IS_ERR(inode)) {
  409. printk(KERN_ERR "hfs: failed to load allocation file\n");
  410. err = PTR_ERR(inode);
  411. goto out_close_cat_tree;
  412. }
  413. sbi->alloc_file = inode;
  414. /* Load the root directory */
  415. root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
  416. if (IS_ERR(root)) {
  417. printk(KERN_ERR "hfs: failed to load root directory\n");
  418. err = PTR_ERR(root);
  419. goto out_put_alloc_file;
  420. }
  421. sb->s_d_op = &hfsplus_dentry_operations;
  422. sb->s_root = d_make_root(root);
  423. if (!sb->s_root) {
  424. err = -ENOMEM;
  425. goto out_put_alloc_file;
  426. }
  427. str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
  428. str.name = HFSP_HIDDENDIR_NAME;
  429. err = hfs_find_init(sbi->cat_tree, &fd);
  430. if (err)
  431. goto out_put_root;
  432. hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
  433. if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
  434. hfs_find_exit(&fd);
  435. if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
  436. goto out_put_root;
  437. inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
  438. if (IS_ERR(inode)) {
  439. err = PTR_ERR(inode);
  440. goto out_put_root;
  441. }
  442. sbi->hidden_dir = inode;
  443. } else
  444. hfs_find_exit(&fd);
  445. if (!(sb->s_flags & MS_RDONLY)) {
  446. /*
  447. * H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
  448. * all three are registered with Apple for our use
  449. */
  450. vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
  451. vhdr->modify_date = hfsp_now2mt();
  452. be32_add_cpu(&vhdr->write_count, 1);
  453. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
  454. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
  455. hfsplus_sync_fs(sb, 1);
  456. if (!sbi->hidden_dir) {
  457. mutex_lock(&sbi->vh_mutex);
  458. sbi->hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
  459. if (!sbi->hidden_dir) {
  460. mutex_unlock(&sbi->vh_mutex);
  461. err = -ENOMEM;
  462. goto out_put_root;
  463. }
  464. err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root,
  465. &str, sbi->hidden_dir);
  466. mutex_unlock(&sbi->vh_mutex);
  467. if (err)
  468. goto out_put_hidden_dir;
  469. hfsplus_mark_inode_dirty(sbi->hidden_dir,
  470. HFSPLUS_I_CAT_DIRTY);
  471. }
  472. }
  473. unload_nls(sbi->nls);
  474. sbi->nls = nls;
  475. return 0;
  476. out_put_hidden_dir:
  477. iput(sbi->hidden_dir);
  478. out_put_root:
  479. dput(sb->s_root);
  480. sb->s_root = NULL;
  481. out_put_alloc_file:
  482. iput(sbi->alloc_file);
  483. out_close_cat_tree:
  484. hfs_btree_close(sbi->cat_tree);
  485. out_close_ext_tree:
  486. hfs_btree_close(sbi->ext_tree);
  487. out_free_vhdr:
  488. kfree(sbi->s_vhdr_buf);
  489. kfree(sbi->s_backup_vhdr_buf);
  490. out_unload_nls:
  491. unload_nls(sbi->nls);
  492. unload_nls(nls);
  493. kfree(sbi);
  494. out:
  495. return err;
  496. }
  497. MODULE_AUTHOR("Brad Boyer");
  498. MODULE_DESCRIPTION("Extended Macintosh Filesystem");
  499. MODULE_LICENSE("GPL");
  500. static struct kmem_cache *hfsplus_inode_cachep;
  501. static struct inode *hfsplus_alloc_inode(struct super_block *sb)
  502. {
  503. struct hfsplus_inode_info *i;
  504. i = kmem_cache_alloc(hfsplus_inode_cachep, GFP_KERNEL);
  505. return i ? &i->vfs_inode : NULL;
  506. }
  507. static void hfsplus_i_callback(struct rcu_head *head)
  508. {
  509. struct inode *inode = container_of(head, struct inode, i_rcu);
  510. kmem_cache_free(hfsplus_inode_cachep, HFSPLUS_I(inode));
  511. }
  512. static void hfsplus_destroy_inode(struct inode *inode)
  513. {
  514. call_rcu(&inode->i_rcu, hfsplus_i_callback);
  515. }
  516. #define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
  517. static struct dentry *hfsplus_mount(struct file_system_type *fs_type,
  518. int flags, const char *dev_name, void *data)
  519. {
  520. return mount_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
  521. }
  522. static struct file_system_type hfsplus_fs_type = {
  523. .owner = THIS_MODULE,
  524. .name = "hfsplus",
  525. .mount = hfsplus_mount,
  526. .kill_sb = kill_block_super,
  527. .fs_flags = FS_REQUIRES_DEV,
  528. };
  529. static void hfsplus_init_once(void *p)
  530. {
  531. struct hfsplus_inode_info *i = p;
  532. inode_init_once(&i->vfs_inode);
  533. }
  534. static int __init init_hfsplus_fs(void)
  535. {
  536. int err;
  537. hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
  538. HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
  539. hfsplus_init_once);
  540. if (!hfsplus_inode_cachep)
  541. return -ENOMEM;
  542. err = register_filesystem(&hfsplus_fs_type);
  543. if (err)
  544. kmem_cache_destroy(hfsplus_inode_cachep);
  545. return err;
  546. }
  547. static void __exit exit_hfsplus_fs(void)
  548. {
  549. unregister_filesystem(&hfsplus_fs_type);
  550. kmem_cache_destroy(hfsplus_inode_cachep);
  551. }
  552. module_init(init_hfsplus_fs)
  553. module_exit(exit_hfsplus_fs)