super.c 15 KB

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