super.c 15 KB

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