super.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. #include "xattr.h"
  21. static int hfsplus_system_read_inode(struct inode *inode)
  22. {
  23. struct hfsplus_vh *vhdr = HFSPLUS_SB(inode->i_sb)->s_vhdr;
  24. switch (inode->i_ino) {
  25. case HFSPLUS_EXT_CNID:
  26. hfsplus_inode_read_fork(inode, &vhdr->ext_file);
  27. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  28. break;
  29. case HFSPLUS_CAT_CNID:
  30. hfsplus_inode_read_fork(inode, &vhdr->cat_file);
  31. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  32. break;
  33. case HFSPLUS_ALLOC_CNID:
  34. hfsplus_inode_read_fork(inode, &vhdr->alloc_file);
  35. inode->i_mapping->a_ops = &hfsplus_aops;
  36. break;
  37. case HFSPLUS_START_CNID:
  38. hfsplus_inode_read_fork(inode, &vhdr->start_file);
  39. break;
  40. case HFSPLUS_ATTR_CNID:
  41. hfsplus_inode_read_fork(inode, &vhdr->attr_file);
  42. inode->i_mapping->a_ops = &hfsplus_btree_aops;
  43. break;
  44. default:
  45. return -EIO;
  46. }
  47. return 0;
  48. }
  49. struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
  50. {
  51. struct hfs_find_data fd;
  52. struct inode *inode;
  53. int err;
  54. inode = iget_locked(sb, ino);
  55. if (!inode)
  56. return ERR_PTR(-ENOMEM);
  57. if (!(inode->i_state & I_NEW))
  58. return inode;
  59. INIT_LIST_HEAD(&HFSPLUS_I(inode)->open_dir_list);
  60. mutex_init(&HFSPLUS_I(inode)->extents_lock);
  61. HFSPLUS_I(inode)->flags = 0;
  62. HFSPLUS_I(inode)->extent_state = 0;
  63. HFSPLUS_I(inode)->rsrc_inode = NULL;
  64. atomic_set(&HFSPLUS_I(inode)->opencnt, 0);
  65. if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID ||
  66. inode->i_ino == HFSPLUS_ROOT_CNID) {
  67. err = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
  68. if (!err) {
  69. err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
  70. if (!err)
  71. err = hfsplus_cat_read_inode(inode, &fd);
  72. hfs_find_exit(&fd);
  73. }
  74. } else {
  75. err = hfsplus_system_read_inode(inode);
  76. }
  77. if (err) {
  78. iget_failed(inode);
  79. return ERR_PTR(err);
  80. }
  81. unlock_new_inode(inode);
  82. return inode;
  83. }
  84. static int hfsplus_system_write_inode(struct inode *inode)
  85. {
  86. struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  87. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  88. struct hfsplus_fork_raw *fork;
  89. struct hfs_btree *tree = NULL;
  90. switch (inode->i_ino) {
  91. case HFSPLUS_EXT_CNID:
  92. fork = &vhdr->ext_file;
  93. tree = sbi->ext_tree;
  94. break;
  95. case HFSPLUS_CAT_CNID:
  96. fork = &vhdr->cat_file;
  97. tree = sbi->cat_tree;
  98. break;
  99. case HFSPLUS_ALLOC_CNID:
  100. fork = &vhdr->alloc_file;
  101. break;
  102. case HFSPLUS_START_CNID:
  103. fork = &vhdr->start_file;
  104. break;
  105. case HFSPLUS_ATTR_CNID:
  106. fork = &vhdr->attr_file;
  107. tree = sbi->attr_tree;
  108. break;
  109. default:
  110. return -EIO;
  111. }
  112. if (fork->total_size != cpu_to_be64(inode->i_size)) {
  113. set_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags);
  114. hfsplus_mark_mdb_dirty(inode->i_sb);
  115. }
  116. hfsplus_inode_write_fork(inode, fork);
  117. if (tree) {
  118. int err = hfs_btree_write(tree);
  119. if (err) {
  120. printk(KERN_ERR "hfs: b-tree write err: %d, ino %lu\n",
  121. err, inode->i_ino);
  122. return err;
  123. }
  124. }
  125. return 0;
  126. }
  127. static int hfsplus_write_inode(struct inode *inode,
  128. struct writeback_control *wbc)
  129. {
  130. int err;
  131. dprint(DBG_INODE, "hfsplus_write_inode: %lu\n", inode->i_ino);
  132. err = hfsplus_ext_write_extent(inode);
  133. if (err)
  134. return err;
  135. if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID ||
  136. inode->i_ino == HFSPLUS_ROOT_CNID)
  137. return hfsplus_cat_write_inode(inode);
  138. else
  139. return hfsplus_system_write_inode(inode);
  140. }
  141. static void hfsplus_evict_inode(struct inode *inode)
  142. {
  143. dprint(DBG_INODE, "hfsplus_evict_inode: %lu\n", inode->i_ino);
  144. truncate_inode_pages(&inode->i_data, 0);
  145. clear_inode(inode);
  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. }
  151. static int hfsplus_sync_fs(struct super_block *sb, int wait)
  152. {
  153. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  154. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  155. int write_backup = 0;
  156. int error, error2;
  157. if (!wait)
  158. return 0;
  159. dprint(DBG_SUPER, "hfsplus_sync_fs\n");
  160. /*
  161. * Explicitly write out the special metadata inodes.
  162. *
  163. * While these special inodes are marked as hashed and written
  164. * out peridocically by the flusher threads we redirty them
  165. * during writeout of normal inodes, and thus the life lock
  166. * prevents us from getting the latest state to disk.
  167. */
  168. error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
  169. error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
  170. if (!error)
  171. error = error2;
  172. if (sbi->attr_tree) {
  173. error2 =
  174. filemap_write_and_wait(sbi->attr_tree->inode->i_mapping);
  175. if (!error)
  176. error = error2;
  177. }
  178. error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
  179. if (!error)
  180. error = error2;
  181. mutex_lock(&sbi->vh_mutex);
  182. mutex_lock(&sbi->alloc_mutex);
  183. vhdr->free_blocks = cpu_to_be32(sbi->free_blocks);
  184. vhdr->next_cnid = cpu_to_be32(sbi->next_cnid);
  185. vhdr->folder_count = cpu_to_be32(sbi->folder_count);
  186. vhdr->file_count = cpu_to_be32(sbi->file_count);
  187. if (test_and_clear_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags)) {
  188. memcpy(sbi->s_backup_vhdr, sbi->s_vhdr, sizeof(*sbi->s_vhdr));
  189. write_backup = 1;
  190. }
  191. error2 = hfsplus_submit_bio(sb,
  192. sbi->part_start + HFSPLUS_VOLHEAD_SECTOR,
  193. sbi->s_vhdr_buf, NULL, WRITE_SYNC);
  194. if (!error)
  195. error = error2;
  196. if (!write_backup)
  197. goto out;
  198. error2 = hfsplus_submit_bio(sb,
  199. sbi->part_start + sbi->sect_count - 2,
  200. sbi->s_backup_vhdr_buf, NULL, WRITE_SYNC);
  201. if (!error)
  202. error2 = error;
  203. out:
  204. mutex_unlock(&sbi->alloc_mutex);
  205. mutex_unlock(&sbi->vh_mutex);
  206. if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
  207. blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
  208. return error;
  209. }
  210. static void delayed_sync_fs(struct work_struct *work)
  211. {
  212. int err;
  213. struct hfsplus_sb_info *sbi;
  214. sbi = container_of(work, struct hfsplus_sb_info, sync_work.work);
  215. spin_lock(&sbi->work_lock);
  216. sbi->work_queued = 0;
  217. spin_unlock(&sbi->work_lock);
  218. err = hfsplus_sync_fs(sbi->alloc_file->i_sb, 1);
  219. if (err)
  220. printk(KERN_ERR "hfs: delayed sync fs err %d\n", err);
  221. }
  222. void hfsplus_mark_mdb_dirty(struct super_block *sb)
  223. {
  224. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  225. unsigned long delay;
  226. if (sb->s_flags & MS_RDONLY)
  227. return;
  228. spin_lock(&sbi->work_lock);
  229. if (!sbi->work_queued) {
  230. delay = msecs_to_jiffies(dirty_writeback_interval * 10);
  231. queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
  232. sbi->work_queued = 1;
  233. }
  234. spin_unlock(&sbi->work_lock);
  235. }
  236. static void hfsplus_put_super(struct super_block *sb)
  237. {
  238. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  239. dprint(DBG_SUPER, "hfsplus_put_super\n");
  240. cancel_delayed_work_sync(&sbi->sync_work);
  241. if (!(sb->s_flags & MS_RDONLY) && sbi->s_vhdr) {
  242. struct hfsplus_vh *vhdr = sbi->s_vhdr;
  243. vhdr->modify_date = hfsp_now2mt();
  244. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_UNMNT);
  245. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_INCNSTNT);
  246. hfsplus_sync_fs(sb, 1);
  247. }
  248. hfs_btree_close(sbi->attr_tree);
  249. hfs_btree_close(sbi->cat_tree);
  250. hfs_btree_close(sbi->ext_tree);
  251. iput(sbi->alloc_file);
  252. iput(sbi->hidden_dir);
  253. kfree(sbi->s_vhdr_buf);
  254. kfree(sbi->s_backup_vhdr_buf);
  255. unload_nls(sbi->nls);
  256. kfree(sb->s_fs_info);
  257. sb->s_fs_info = NULL;
  258. }
  259. static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)
  260. {
  261. struct super_block *sb = dentry->d_sb;
  262. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  263. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  264. buf->f_type = HFSPLUS_SUPER_MAGIC;
  265. buf->f_bsize = sb->s_blocksize;
  266. buf->f_blocks = sbi->total_blocks << sbi->fs_shift;
  267. buf->f_bfree = sbi->free_blocks << sbi->fs_shift;
  268. buf->f_bavail = buf->f_bfree;
  269. buf->f_files = 0xFFFFFFFF;
  270. buf->f_ffree = 0xFFFFFFFF - sbi->next_cnid;
  271. buf->f_fsid.val[0] = (u32)id;
  272. buf->f_fsid.val[1] = (u32)(id >> 32);
  273. buf->f_namelen = HFSPLUS_MAX_STRLEN;
  274. return 0;
  275. }
  276. static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
  277. {
  278. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  279. return 0;
  280. if (!(*flags & MS_RDONLY)) {
  281. struct hfsplus_vh *vhdr = HFSPLUS_SB(sb)->s_vhdr;
  282. int force = 0;
  283. if (!hfsplus_parse_options_remount(data, &force))
  284. return -EINVAL;
  285. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  286. printk(KERN_WARNING "hfs: filesystem was "
  287. "not cleanly unmounted, "
  288. "running fsck.hfsplus is recommended. "
  289. "leaving read-only.\n");
  290. sb->s_flags |= MS_RDONLY;
  291. *flags |= MS_RDONLY;
  292. } else if (force) {
  293. /* nothing */
  294. } else if (vhdr->attributes &
  295. cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  296. printk(KERN_WARNING "hfs: filesystem is marked locked, "
  297. "leaving read-only.\n");
  298. sb->s_flags |= MS_RDONLY;
  299. *flags |= MS_RDONLY;
  300. } else if (vhdr->attributes &
  301. cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
  302. printk(KERN_WARNING "hfs: filesystem is "
  303. "marked journaled, "
  304. "leaving read-only.\n");
  305. sb->s_flags |= MS_RDONLY;
  306. *flags |= MS_RDONLY;
  307. }
  308. }
  309. return 0;
  310. }
  311. static const struct super_operations hfsplus_sops = {
  312. .alloc_inode = hfsplus_alloc_inode,
  313. .destroy_inode = hfsplus_destroy_inode,
  314. .write_inode = hfsplus_write_inode,
  315. .evict_inode = hfsplus_evict_inode,
  316. .put_super = hfsplus_put_super,
  317. .sync_fs = hfsplus_sync_fs,
  318. .statfs = hfsplus_statfs,
  319. .remount_fs = hfsplus_remount,
  320. .show_options = hfsplus_show_options,
  321. };
  322. static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
  323. {
  324. struct hfsplus_vh *vhdr;
  325. struct hfsplus_sb_info *sbi;
  326. hfsplus_cat_entry entry;
  327. struct hfs_find_data fd;
  328. struct inode *root, *inode;
  329. struct qstr str;
  330. struct nls_table *nls = NULL;
  331. u64 last_fs_block, last_fs_page;
  332. int err;
  333. err = -ENOMEM;
  334. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  335. if (!sbi)
  336. goto out;
  337. sb->s_fs_info = sbi;
  338. mutex_init(&sbi->alloc_mutex);
  339. mutex_init(&sbi->vh_mutex);
  340. spin_lock_init(&sbi->work_lock);
  341. INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
  342. hfsplus_fill_defaults(sbi);
  343. err = -EINVAL;
  344. if (!hfsplus_parse_options(data, sbi)) {
  345. printk(KERN_ERR "hfs: unable to parse mount options\n");
  346. goto out_unload_nls;
  347. }
  348. /* temporarily use utf8 to correctly find the hidden dir below */
  349. nls = sbi->nls;
  350. sbi->nls = load_nls("utf8");
  351. if (!sbi->nls) {
  352. printk(KERN_ERR "hfs: unable to load nls for utf8\n");
  353. goto out_unload_nls;
  354. }
  355. /* Grab the volume header */
  356. if (hfsplus_read_wrapper(sb)) {
  357. if (!silent)
  358. printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
  359. goto out_unload_nls;
  360. }
  361. vhdr = sbi->s_vhdr;
  362. /* Copy parts of the volume header into the superblock */
  363. sb->s_magic = HFSPLUS_VOLHEAD_SIG;
  364. if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
  365. be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
  366. printk(KERN_ERR "hfs: wrong filesystem version\n");
  367. goto out_free_vhdr;
  368. }
  369. sbi->total_blocks = be32_to_cpu(vhdr->total_blocks);
  370. sbi->free_blocks = be32_to_cpu(vhdr->free_blocks);
  371. sbi->next_cnid = be32_to_cpu(vhdr->next_cnid);
  372. sbi->file_count = be32_to_cpu(vhdr->file_count);
  373. sbi->folder_count = be32_to_cpu(vhdr->folder_count);
  374. sbi->data_clump_blocks =
  375. be32_to_cpu(vhdr->data_clump_sz) >> sbi->alloc_blksz_shift;
  376. if (!sbi->data_clump_blocks)
  377. sbi->data_clump_blocks = 1;
  378. sbi->rsrc_clump_blocks =
  379. be32_to_cpu(vhdr->rsrc_clump_sz) >> sbi->alloc_blksz_shift;
  380. if (!sbi->rsrc_clump_blocks)
  381. sbi->rsrc_clump_blocks = 1;
  382. err = -EFBIG;
  383. last_fs_block = sbi->total_blocks - 1;
  384. last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
  385. PAGE_CACHE_SHIFT;
  386. if ((last_fs_block > (sector_t)(~0ULL) >> (sbi->alloc_blksz_shift - 9)) ||
  387. (last_fs_page > (pgoff_t)(~0ULL))) {
  388. printk(KERN_ERR "hfs: filesystem size too large.\n");
  389. goto out_free_vhdr;
  390. }
  391. /* Set up operations so we can load metadata */
  392. sb->s_op = &hfsplus_sops;
  393. sb->s_maxbytes = MAX_LFS_FILESIZE;
  394. if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
  395. printk(KERN_WARNING "hfs: Filesystem was "
  396. "not cleanly unmounted, "
  397. "running fsck.hfsplus is recommended. "
  398. "mounting read-only.\n");
  399. sb->s_flags |= MS_RDONLY;
  400. } else if (test_and_clear_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
  401. /* nothing */
  402. } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
  403. printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
  404. sb->s_flags |= MS_RDONLY;
  405. } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
  406. !(sb->s_flags & MS_RDONLY)) {
  407. printk(KERN_WARNING "hfs: write access to "
  408. "a journaled filesystem is not supported, "
  409. "use the force option at your own risk, "
  410. "mounting read-only.\n");
  411. sb->s_flags |= MS_RDONLY;
  412. }
  413. err = -EINVAL;
  414. /* Load metadata objects (B*Trees) */
  415. sbi->ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
  416. if (!sbi->ext_tree) {
  417. printk(KERN_ERR "hfs: failed to load extents file\n");
  418. goto out_free_vhdr;
  419. }
  420. sbi->cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
  421. if (!sbi->cat_tree) {
  422. printk(KERN_ERR "hfs: failed to load catalog file\n");
  423. goto out_close_ext_tree;
  424. }
  425. if (vhdr->attr_file.total_blocks != 0) {
  426. sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
  427. if (!sbi->attr_tree) {
  428. printk(KERN_ERR "hfs: failed to load attributes file\n");
  429. goto out_close_cat_tree;
  430. }
  431. }
  432. sb->s_xattr = hfsplus_xattr_handlers;
  433. inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
  434. if (IS_ERR(inode)) {
  435. printk(KERN_ERR "hfs: failed to load allocation file\n");
  436. err = PTR_ERR(inode);
  437. goto out_close_attr_tree;
  438. }
  439. sbi->alloc_file = inode;
  440. /* Load the root directory */
  441. root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
  442. if (IS_ERR(root)) {
  443. printk(KERN_ERR "hfs: failed to load root directory\n");
  444. err = PTR_ERR(root);
  445. goto out_put_alloc_file;
  446. }
  447. sb->s_d_op = &hfsplus_dentry_operations;
  448. sb->s_root = d_make_root(root);
  449. if (!sb->s_root) {
  450. err = -ENOMEM;
  451. goto out_put_alloc_file;
  452. }
  453. str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
  454. str.name = HFSP_HIDDENDIR_NAME;
  455. err = hfs_find_init(sbi->cat_tree, &fd);
  456. if (err)
  457. goto out_put_root;
  458. hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
  459. if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
  460. hfs_find_exit(&fd);
  461. if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
  462. goto out_put_root;
  463. inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
  464. if (IS_ERR(inode)) {
  465. err = PTR_ERR(inode);
  466. goto out_put_root;
  467. }
  468. sbi->hidden_dir = inode;
  469. } else
  470. hfs_find_exit(&fd);
  471. if (!(sb->s_flags & MS_RDONLY)) {
  472. /*
  473. * H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
  474. * all three are registered with Apple for our use
  475. */
  476. vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
  477. vhdr->modify_date = hfsp_now2mt();
  478. be32_add_cpu(&vhdr->write_count, 1);
  479. vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
  480. vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
  481. hfsplus_sync_fs(sb, 1);
  482. if (!sbi->hidden_dir) {
  483. mutex_lock(&sbi->vh_mutex);
  484. sbi->hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
  485. if (!sbi->hidden_dir) {
  486. mutex_unlock(&sbi->vh_mutex);
  487. err = -ENOMEM;
  488. goto out_put_root;
  489. }
  490. err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root,
  491. &str, sbi->hidden_dir);
  492. if (err) {
  493. mutex_unlock(&sbi->vh_mutex);
  494. goto out_put_hidden_dir;
  495. }
  496. err = hfsplus_init_inode_security(sbi->hidden_dir,
  497. root, &str);
  498. if (err == -EOPNOTSUPP)
  499. err = 0; /* Operation is not supported. */
  500. else if (err) {
  501. /*
  502. * Try to delete anyway without
  503. * error analysis.
  504. */
  505. hfsplus_delete_cat(sbi->hidden_dir->i_ino,
  506. root, &str);
  507. mutex_unlock(&sbi->vh_mutex);
  508. goto out_put_hidden_dir;
  509. }
  510. mutex_unlock(&sbi->vh_mutex);
  511. hfsplus_mark_inode_dirty(sbi->hidden_dir,
  512. HFSPLUS_I_CAT_DIRTY);
  513. }
  514. }
  515. unload_nls(sbi->nls);
  516. sbi->nls = nls;
  517. return 0;
  518. out_put_hidden_dir:
  519. iput(sbi->hidden_dir);
  520. out_put_root:
  521. dput(sb->s_root);
  522. sb->s_root = NULL;
  523. out_put_alloc_file:
  524. iput(sbi->alloc_file);
  525. out_close_attr_tree:
  526. hfs_btree_close(sbi->attr_tree);
  527. out_close_cat_tree:
  528. hfs_btree_close(sbi->cat_tree);
  529. out_close_ext_tree:
  530. hfs_btree_close(sbi->ext_tree);
  531. out_free_vhdr:
  532. kfree(sbi->s_vhdr_buf);
  533. kfree(sbi->s_backup_vhdr_buf);
  534. out_unload_nls:
  535. unload_nls(sbi->nls);
  536. unload_nls(nls);
  537. kfree(sbi);
  538. out:
  539. return err;
  540. }
  541. MODULE_AUTHOR("Brad Boyer");
  542. MODULE_DESCRIPTION("Extended Macintosh Filesystem");
  543. MODULE_LICENSE("GPL");
  544. static struct kmem_cache *hfsplus_inode_cachep;
  545. static struct inode *hfsplus_alloc_inode(struct super_block *sb)
  546. {
  547. struct hfsplus_inode_info *i;
  548. i = kmem_cache_alloc(hfsplus_inode_cachep, GFP_KERNEL);
  549. return i ? &i->vfs_inode : NULL;
  550. }
  551. static void hfsplus_i_callback(struct rcu_head *head)
  552. {
  553. struct inode *inode = container_of(head, struct inode, i_rcu);
  554. kmem_cache_free(hfsplus_inode_cachep, HFSPLUS_I(inode));
  555. }
  556. static void hfsplus_destroy_inode(struct inode *inode)
  557. {
  558. call_rcu(&inode->i_rcu, hfsplus_i_callback);
  559. }
  560. #define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
  561. static struct dentry *hfsplus_mount(struct file_system_type *fs_type,
  562. int flags, const char *dev_name, void *data)
  563. {
  564. return mount_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
  565. }
  566. static struct file_system_type hfsplus_fs_type = {
  567. .owner = THIS_MODULE,
  568. .name = "hfsplus",
  569. .mount = hfsplus_mount,
  570. .kill_sb = kill_block_super,
  571. .fs_flags = FS_REQUIRES_DEV,
  572. };
  573. MODULE_ALIAS_FS("hfsplus");
  574. static void hfsplus_init_once(void *p)
  575. {
  576. struct hfsplus_inode_info *i = p;
  577. inode_init_once(&i->vfs_inode);
  578. }
  579. static int __init init_hfsplus_fs(void)
  580. {
  581. int err;
  582. hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
  583. HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
  584. hfsplus_init_once);
  585. if (!hfsplus_inode_cachep)
  586. return -ENOMEM;
  587. err = hfsplus_create_attr_tree_cache();
  588. if (err)
  589. goto destroy_inode_cache;
  590. err = register_filesystem(&hfsplus_fs_type);
  591. if (err)
  592. goto destroy_attr_tree_cache;
  593. return 0;
  594. destroy_attr_tree_cache:
  595. hfsplus_destroy_attr_tree_cache();
  596. destroy_inode_cache:
  597. kmem_cache_destroy(hfsplus_inode_cachep);
  598. return err;
  599. }
  600. static void __exit exit_hfsplus_fs(void)
  601. {
  602. unregister_filesystem(&hfsplus_fs_type);
  603. /*
  604. * Make sure all delayed rcu free inodes are flushed before we
  605. * destroy cache.
  606. */
  607. rcu_barrier();
  608. hfsplus_destroy_attr_tree_cache();
  609. kmem_cache_destroy(hfsplus_inode_cachep);
  610. }
  611. module_init(init_hfsplus_fs)
  612. module_exit(exit_hfsplus_fs)