blob: 0ed8b7e8e87fb97bc7934d3ae1cd3fe1771138f0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
10#include <linux/config.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/pagemap.h>
14#include <linux/fs.h>
15#include <linux/sched.h>
16#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/vfs.h>
18#include <linux/nls.h>
19
20static struct inode *hfsplus_alloc_inode(struct super_block *sb);
21static void hfsplus_destroy_inode(struct inode *inode);
22
23#include "hfsplus_fs.h"
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static void hfsplus_read_inode(struct inode *inode)
26{
27 struct hfs_find_data fd;
28 struct hfsplus_vh *vhdr;
29 int err;
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
32 init_MUTEX(&HFSPLUS_I(inode).extents_lock);
33 HFSPLUS_I(inode).flags = 0;
34 HFSPLUS_I(inode).rsrc_inode = NULL;
Peter Wainwright94c1d312005-10-26 01:59:02 -070035 atomic_set(&HFSPLUS_I(inode).opencnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID) {
38 read_inode:
39 hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
40 err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
41 if (!err)
42 err = hfsplus_cat_read_inode(inode, &fd);
43 hfs_find_exit(&fd);
44 if (err)
45 goto bad_inode;
46 return;
47 }
48 vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
49 switch(inode->i_ino) {
50 case HFSPLUS_ROOT_CNID:
51 goto read_inode;
52 case HFSPLUS_EXT_CNID:
53 hfsplus_inode_read_fork(inode, &vhdr->ext_file);
54 inode->i_mapping->a_ops = &hfsplus_btree_aops;
55 break;
56 case HFSPLUS_CAT_CNID:
57 hfsplus_inode_read_fork(inode, &vhdr->cat_file);
58 inode->i_mapping->a_ops = &hfsplus_btree_aops;
59 break;
60 case HFSPLUS_ALLOC_CNID:
61 hfsplus_inode_read_fork(inode, &vhdr->alloc_file);
62 inode->i_mapping->a_ops = &hfsplus_aops;
63 break;
64 case HFSPLUS_START_CNID:
65 hfsplus_inode_read_fork(inode, &vhdr->start_file);
66 break;
67 case HFSPLUS_ATTR_CNID:
68 hfsplus_inode_read_fork(inode, &vhdr->attr_file);
69 inode->i_mapping->a_ops = &hfsplus_btree_aops;
70 break;
71 default:
72 goto bad_inode;
73 }
74
75 return;
76
77 bad_inode:
78 make_bad_inode(inode);
79}
80
81static int hfsplus_write_inode(struct inode *inode, int unused)
82{
83 struct hfsplus_vh *vhdr;
84 int ret = 0;
85
86 dprint(DBG_INODE, "hfsplus_write_inode: %lu\n", inode->i_ino);
87 hfsplus_ext_write_extent(inode);
88 if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID) {
89 return hfsplus_cat_write_inode(inode);
90 }
91 vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
92 switch (inode->i_ino) {
93 case HFSPLUS_ROOT_CNID:
94 ret = hfsplus_cat_write_inode(inode);
95 break;
96 case HFSPLUS_EXT_CNID:
97 if (vhdr->ext_file.total_size != cpu_to_be64(inode->i_size)) {
98 HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
99 inode->i_sb->s_dirt = 1;
100 }
101 hfsplus_inode_write_fork(inode, &vhdr->ext_file);
102 hfs_btree_write(HFSPLUS_SB(inode->i_sb).ext_tree);
103 break;
104 case HFSPLUS_CAT_CNID:
105 if (vhdr->cat_file.total_size != cpu_to_be64(inode->i_size)) {
106 HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
107 inode->i_sb->s_dirt = 1;
108 }
109 hfsplus_inode_write_fork(inode, &vhdr->cat_file);
110 hfs_btree_write(HFSPLUS_SB(inode->i_sb).cat_tree);
111 break;
112 case HFSPLUS_ALLOC_CNID:
113 if (vhdr->alloc_file.total_size != cpu_to_be64(inode->i_size)) {
114 HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
115 inode->i_sb->s_dirt = 1;
116 }
117 hfsplus_inode_write_fork(inode, &vhdr->alloc_file);
118 break;
119 case HFSPLUS_START_CNID:
120 if (vhdr->start_file.total_size != cpu_to_be64(inode->i_size)) {
121 HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
122 inode->i_sb->s_dirt = 1;
123 }
124 hfsplus_inode_write_fork(inode, &vhdr->start_file);
125 break;
126 case HFSPLUS_ATTR_CNID:
127 if (vhdr->attr_file.total_size != cpu_to_be64(inode->i_size)) {
128 HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
129 inode->i_sb->s_dirt = 1;
130 }
131 hfsplus_inode_write_fork(inode, &vhdr->attr_file);
132 hfs_btree_write(HFSPLUS_SB(inode->i_sb).attr_tree);
133 break;
134 }
135 return ret;
136}
137
138static void hfsplus_clear_inode(struct inode *inode)
139{
140 dprint(DBG_INODE, "hfsplus_clear_inode: %lu\n", inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (HFSPLUS_IS_RSRC(inode)) {
142 HFSPLUS_I(HFSPLUS_I(inode).rsrc_inode).rsrc_inode = NULL;
143 iput(HFSPLUS_I(inode).rsrc_inode);
144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
147static void hfsplus_write_super(struct super_block *sb)
148{
149 struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
150
151 dprint(DBG_SUPER, "hfsplus_write_super\n");
152 sb->s_dirt = 0;
153 if (sb->s_flags & MS_RDONLY)
154 /* warn? */
155 return;
156
157 vhdr->free_blocks = cpu_to_be32(HFSPLUS_SB(sb).free_blocks);
158 vhdr->next_alloc = cpu_to_be32(HFSPLUS_SB(sb).next_alloc);
159 vhdr->next_cnid = cpu_to_be32(HFSPLUS_SB(sb).next_cnid);
160 vhdr->folder_count = cpu_to_be32(HFSPLUS_SB(sb).folder_count);
161 vhdr->file_count = cpu_to_be32(HFSPLUS_SB(sb).file_count);
162
163 mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
164 if (HFSPLUS_SB(sb).flags & HFSPLUS_SB_WRITEBACKUP) {
165 if (HFSPLUS_SB(sb).sect_count) {
166 struct buffer_head *bh;
167 u32 block, offset;
168
169 block = HFSPLUS_SB(sb).blockoffset;
170 block += (HFSPLUS_SB(sb).sect_count - 2) >> (sb->s_blocksize_bits - 9);
171 offset = ((HFSPLUS_SB(sb).sect_count - 2) << 9) & (sb->s_blocksize - 1);
Roman Zippel634725a2006-01-18 17:43:05 -0800172 printk(KERN_DEBUG "hfs: backup: %u,%u,%u,%u\n", HFSPLUS_SB(sb).blockoffset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 HFSPLUS_SB(sb).sect_count, block, offset);
174 bh = sb_bread(sb, block);
175 if (bh) {
176 vhdr = (struct hfsplus_vh *)(bh->b_data + offset);
177 if (be16_to_cpu(vhdr->signature) == HFSPLUS_VOLHEAD_SIG) {
178 memcpy(vhdr, HFSPLUS_SB(sb).s_vhdr, sizeof(*vhdr));
179 mark_buffer_dirty(bh);
180 brelse(bh);
181 } else
Roman Zippel634725a2006-01-18 17:43:05 -0800182 printk(KERN_WARNING "hfs: backup not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
184 }
185 HFSPLUS_SB(sb).flags &= ~HFSPLUS_SB_WRITEBACKUP;
186 }
187}
188
189static void hfsplus_put_super(struct super_block *sb)
190{
191 dprint(DBG_SUPER, "hfsplus_put_super\n");
Colin Leroy945b0922005-05-01 08:59:16 -0700192 if (!sb->s_fs_info)
193 return;
194 if (!(sb->s_flags & MS_RDONLY) && HFSPLUS_SB(sb).s_vhdr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
196
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);
Jan Karae39f07c2005-09-06 15:19:16 -0700201 sync_dirty_buffer(HFSPLUS_SB(sb).s_vhbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
204 hfs_btree_close(HFSPLUS_SB(sb).cat_tree);
205 hfs_btree_close(HFSPLUS_SB(sb).ext_tree);
206 iput(HFSPLUS_SB(sb).alloc_file);
207 iput(HFSPLUS_SB(sb).hidden_dir);
208 brelse(HFSPLUS_SB(sb).s_vhbh);
209 if (HFSPLUS_SB(sb).nls)
210 unload_nls(HFSPLUS_SB(sb).nls);
Colin Leroy945b0922005-05-01 08:59:16 -0700211 kfree(sb->s_fs_info);
212 sb->s_fs_info = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
215static int hfsplus_statfs(struct super_block *sb, struct kstatfs *buf)
216{
217 buf->f_type = HFSPLUS_SUPER_MAGIC;
218 buf->f_bsize = sb->s_blocksize;
219 buf->f_blocks = HFSPLUS_SB(sb).total_blocks << HFSPLUS_SB(sb).fs_shift;
220 buf->f_bfree = HFSPLUS_SB(sb).free_blocks << HFSPLUS_SB(sb).fs_shift;
221 buf->f_bavail = buf->f_bfree;
222 buf->f_files = 0xFFFFFFFF;
223 buf->f_ffree = 0xFFFFFFFF - HFSPLUS_SB(sb).next_cnid;
224 buf->f_namelen = HFSPLUS_MAX_STRLEN;
225
226 return 0;
227}
228
229static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
230{
231 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
232 return 0;
233 if (!(*flags & MS_RDONLY)) {
234 struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
Roman Zippelb0b623c2005-11-29 19:34:41 -0800235 struct hfsplus_sb_info sbi;
236
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
Roman Zippel634725a2006-01-18 17:43:05 -0800243 printk(KERN_WARNING "hfs: filesystem was not cleanly unmounted, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 "running fsck.hfsplus is recommended. leaving read-only.\n");
245 sb->s_flags |= MS_RDONLY;
246 *flags |= MS_RDONLY;
Roman Zippelb0b623c2005-11-29 19:34:41 -0800247 } else if (sbi.flags & HFSPLUS_SB_FORCE) {
248 /* nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
Roman Zippel634725a2006-01-18 17:43:05 -0800250 printk(KERN_WARNING "hfs: filesystem is marked locked, leaving read-only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 sb->s_flags |= MS_RDONLY;
252 *flags |= MS_RDONLY;
Roman Zippelb0b623c2005-11-29 19:34:41 -0800253 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
Roman Zippel634725a2006-01-18 17:43:05 -0800254 printk(KERN_WARNING "hfs: filesystem is marked journaled, leaving read-only.\n");
Roman Zippelb0b623c2005-11-29 19:34:41 -0800255 sb->s_flags |= MS_RDONLY;
256 *flags |= MS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258 }
259 return 0;
260}
261
262static struct super_operations hfsplus_sops = {
263 .alloc_inode = hfsplus_alloc_inode,
264 .destroy_inode = hfsplus_destroy_inode,
265 .read_inode = hfsplus_read_inode,
266 .write_inode = hfsplus_write_inode,
267 .clear_inode = hfsplus_clear_inode,
268 .put_super = hfsplus_put_super,
269 .write_super = hfsplus_write_super,
270 .statfs = hfsplus_statfs,
271 .remount_fs = hfsplus_remount,
Roman Zippel717dd80e2005-09-06 15:18:48 -0700272 .show_options = hfsplus_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273};
274
275static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
276{
277 struct hfsplus_vh *vhdr;
278 struct hfsplus_sb_info *sbi;
279 hfsplus_cat_entry entry;
280 struct hfs_find_data fd;
281 struct inode *root;
282 struct qstr str;
283 struct nls_table *nls = NULL;
284 int err = -EINVAL;
285
286 sbi = kmalloc(sizeof(struct hfsplus_sb_info), GFP_KERNEL);
287 if (!sbi)
288 return -ENOMEM;
289
290 memset(sbi, 0, sizeof(HFSPLUS_SB(sb)));
291 sb->s_fs_info = sbi;
292 INIT_HLIST_HEAD(&sbi->rsrc_inodes);
Roman Zippel717dd80e2005-09-06 15:18:48 -0700293 hfsplus_fill_defaults(sbi);
294 if (!hfsplus_parse_options(data, sbi)) {
Roman Zippel634725a2006-01-18 17:43:05 -0800295 printk(KERN_ERR "hfs: unable to parse mount options\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 err = -EINVAL;
297 goto cleanup;
298 }
299
300 /* temporarily use utf8 to correctly find the hidden dir below */
301 nls = sbi->nls;
302 sbi->nls = load_nls("utf8");
Joshua Kwanbd6a59b2006-01-06 00:09:45 -0800303 if (!sbi->nls) {
Roman Zippel634725a2006-01-18 17:43:05 -0800304 printk(KERN_ERR "hfs: unable to load nls for utf8\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 err = -EINVAL;
306 goto cleanup;
307 }
308
309 /* Grab the volume header */
310 if (hfsplus_read_wrapper(sb)) {
311 if (!silent)
Roman Zippel634725a2006-01-18 17:43:05 -0800312 printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 err = -EINVAL;
314 goto cleanup;
315 }
316 vhdr = HFSPLUS_SB(sb).s_vhdr;
317
318 /* Copy parts of the volume header into the superblock */
David Elliott2179d372006-01-18 17:43:08 -0800319 sb->s_magic = HFSPLUS_VOLHEAD_SIG;
320 if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
321 be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
Roman Zippel634725a2006-01-18 17:43:05 -0800322 printk(KERN_ERR "hfs: wrong filesystem version\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 goto cleanup;
324 }
325 HFSPLUS_SB(sb).total_blocks = be32_to_cpu(vhdr->total_blocks);
326 HFSPLUS_SB(sb).free_blocks = be32_to_cpu(vhdr->free_blocks);
327 HFSPLUS_SB(sb).next_alloc = be32_to_cpu(vhdr->next_alloc);
328 HFSPLUS_SB(sb).next_cnid = be32_to_cpu(vhdr->next_cnid);
329 HFSPLUS_SB(sb).file_count = be32_to_cpu(vhdr->file_count);
330 HFSPLUS_SB(sb).folder_count = be32_to_cpu(vhdr->folder_count);
331 HFSPLUS_SB(sb).data_clump_blocks = be32_to_cpu(vhdr->data_clump_sz) >> HFSPLUS_SB(sb).alloc_blksz_shift;
332 if (!HFSPLUS_SB(sb).data_clump_blocks)
333 HFSPLUS_SB(sb).data_clump_blocks = 1;
334 HFSPLUS_SB(sb).rsrc_clump_blocks = be32_to_cpu(vhdr->rsrc_clump_sz) >> HFSPLUS_SB(sb).alloc_blksz_shift;
335 if (!HFSPLUS_SB(sb).rsrc_clump_blocks)
336 HFSPLUS_SB(sb).rsrc_clump_blocks = 1;
337
338 /* Set up operations so we can load metadata */
339 sb->s_op = &hfsplus_sops;
340 sb->s_maxbytes = MAX_LFS_FILESIZE;
341
342 if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
Roman Zippel634725a2006-01-18 17:43:05 -0800343 printk(KERN_WARNING "hfs: Filesystem was not cleanly unmounted, "
344 "running fsck.hfsplus is recommended. mounting read-only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 sb->s_flags |= MS_RDONLY;
Roman Zippelb0b623c2005-11-29 19:34:41 -0800346 } else if (sbi->flags & HFSPLUS_SB_FORCE) {
347 /* nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
Roman Zippel634725a2006-01-18 17:43:05 -0800349 printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 sb->s_flags |= MS_RDONLY;
Roman Zippelb0b623c2005-11-29 19:34:41 -0800351 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
Roman Zippel634725a2006-01-18 17:43:05 -0800352 printk(KERN_WARNING "hfs: write access to a jounaled filesystem is not supported, "
353 "use the force option at your own risk, mounting read-only.\n");
Roman Zippelb0b623c2005-11-29 19:34:41 -0800354 sb->s_flags |= MS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
Roman Zippelb0b623c2005-11-29 19:34:41 -0800356 sbi->flags &= ~HFSPLUS_SB_FORCE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* Load metadata objects (B*Trees) */
359 HFSPLUS_SB(sb).ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
360 if (!HFSPLUS_SB(sb).ext_tree) {
Roman Zippel634725a2006-01-18 17:43:05 -0800361 printk(KERN_ERR "hfs: failed to load extents file\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 goto cleanup;
363 }
364 HFSPLUS_SB(sb).cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
365 if (!HFSPLUS_SB(sb).cat_tree) {
Roman Zippel634725a2006-01-18 17:43:05 -0800366 printk(KERN_ERR "hfs: failed to load catalog file\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 goto cleanup;
368 }
369
370 HFSPLUS_SB(sb).alloc_file = iget(sb, HFSPLUS_ALLOC_CNID);
371 if (!HFSPLUS_SB(sb).alloc_file) {
Roman Zippel634725a2006-01-18 17:43:05 -0800372 printk(KERN_ERR "hfs: failed to load allocation file\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 goto cleanup;
374 }
375
376 /* Load the root directory */
377 root = iget(sb, HFSPLUS_ROOT_CNID);
378 sb->s_root = d_alloc_root(root);
379 if (!sb->s_root) {
Roman Zippel634725a2006-01-18 17:43:05 -0800380 printk(KERN_ERR "hfs: failed to load root directory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 iput(root);
382 goto cleanup;
383 }
384
385 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
386 str.name = HFSP_HIDDENDIR_NAME;
387 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
388 hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
389 if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
390 hfs_find_exit(&fd);
391 if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
392 goto cleanup;
393 HFSPLUS_SB(sb).hidden_dir = iget(sb, be32_to_cpu(entry.folder.id));
394 if (!HFSPLUS_SB(sb).hidden_dir)
395 goto cleanup;
396 } else
397 hfs_find_exit(&fd);
398
399 if (sb->s_flags & MS_RDONLY)
400 goto out;
401
402 /* H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
403 * all three are registered with Apple for our use
404 */
405 vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
406 vhdr->modify_date = hfsp_now2mt();
407 vhdr->write_count = cpu_to_be32(be32_to_cpu(vhdr->write_count) + 1);
408 vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
409 vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
410 mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
Jan Karae39f07c2005-09-06 15:19:16 -0700411 sync_dirty_buffer(HFSPLUS_SB(sb).s_vhbh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 if (!HFSPLUS_SB(sb).hidden_dir) {
Roman Zippel634725a2006-01-18 17:43:05 -0800414 printk(KERN_DEBUG "hfs: create hidden dir...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 HFSPLUS_SB(sb).hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
416 hfsplus_create_cat(HFSPLUS_SB(sb).hidden_dir->i_ino, sb->s_root->d_inode,
417 &str, HFSPLUS_SB(sb).hidden_dir);
418 mark_inode_dirty(HFSPLUS_SB(sb).hidden_dir);
419 }
420out:
421 unload_nls(sbi->nls);
422 sbi->nls = nls;
423 return 0;
424
425cleanup:
426 hfsplus_put_super(sb);
427 if (nls)
428 unload_nls(nls);
429 return err;
430}
431
432MODULE_AUTHOR("Brad Boyer");
433MODULE_DESCRIPTION("Extended Macintosh Filesystem");
434MODULE_LICENSE("GPL");
435
436static kmem_cache_t *hfsplus_inode_cachep;
437
438static struct inode *hfsplus_alloc_inode(struct super_block *sb)
439{
440 struct hfsplus_inode_info *i;
441
442 i = kmem_cache_alloc(hfsplus_inode_cachep, SLAB_KERNEL);
443 return i ? &i->vfs_inode : NULL;
444}
445
446static void hfsplus_destroy_inode(struct inode *inode)
447{
448 kmem_cache_free(hfsplus_inode_cachep, &HFSPLUS_I(inode));
449}
450
451#define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
452
David Howells454e2392006-06-23 02:02:57 -0700453static int hfsplus_get_sb(struct file_system_type *fs_type,
454 int flags, const char *dev_name, void *data,
455 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
David Howells454e2392006-06-23 02:02:57 -0700457 return get_sb_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super,
458 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
461static struct file_system_type hfsplus_fs_type = {
462 .owner = THIS_MODULE,
463 .name = "hfsplus",
464 .get_sb = hfsplus_get_sb,
465 .kill_sb = kill_block_super,
466 .fs_flags = FS_REQUIRES_DEV,
467};
468
469static void hfsplus_init_once(void *p, kmem_cache_t *cachep, unsigned long flags)
470{
471 struct hfsplus_inode_info *i = p;
472
473 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)
474 inode_init_once(&i->vfs_inode);
475}
476
477static int __init init_hfsplus_fs(void)
478{
479 int err;
480
481 hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
482 HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
483 hfsplus_init_once, NULL);
484 if (!hfsplus_inode_cachep)
485 return -ENOMEM;
486 err = register_filesystem(&hfsplus_fs_type);
487 if (err)
488 kmem_cache_destroy(hfsplus_inode_cachep);
489 return err;
490}
491
492static void __exit exit_hfsplus_fs(void)
493{
494 unregister_filesystem(&hfsplus_fs_type);
495 if (kmem_cache_destroy(hfsplus_inode_cachep))
Roman Zippel634725a2006-01-18 17:43:05 -0800496 printk(KERN_ERR "hfsplus_inode_cache: not all structures were freed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499module_init(init_hfsplus_fs)
500module_exit(exit_hfsplus_fs)