]> Git Repo - linux.git/blame - fs/hfsplus/super.c
hfsplus: optimize fsync
[linux.git] / fs / hfsplus / super.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/hfsplus/super.c
3 *
4 * Copyright (C) 2001
5 * Brad Boyer ([email protected])
6 * (C) 2003 Ardis Technologies <[email protected]>
7 *
8 */
9
1da177e4
LT
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/pagemap.h>
13#include <linux/fs.h>
1da177e4 14#include <linux/slab.h>
1da177e4
LT
15#include <linux/vfs.h>
16#include <linux/nls.h>
17
18static struct inode *hfsplus_alloc_inode(struct super_block *sb);
19static void hfsplus_destroy_inode(struct inode *inode);
20
21#include "hfsplus_fs.h"
22
fc4fff82
CH
23static int hfsplus_system_read_inode(struct inode *inode)
24{
25 struct hfsplus_vh *vhdr = HFSPLUS_SB(inode->i_sb)->s_vhdr;
26
27 switch (inode->i_ino) {
28 case HFSPLUS_EXT_CNID:
29 hfsplus_inode_read_fork(inode, &vhdr->ext_file);
30 inode->i_mapping->a_ops = &hfsplus_btree_aops;
31 break;
32 case HFSPLUS_CAT_CNID:
33 hfsplus_inode_read_fork(inode, &vhdr->cat_file);
34 inode->i_mapping->a_ops = &hfsplus_btree_aops;
35 break;
36 case HFSPLUS_ALLOC_CNID:
37 hfsplus_inode_read_fork(inode, &vhdr->alloc_file);
38 inode->i_mapping->a_ops = &hfsplus_aops;
39 break;
40 case HFSPLUS_START_CNID:
41 hfsplus_inode_read_fork(inode, &vhdr->start_file);
42 break;
43 case HFSPLUS_ATTR_CNID:
44 hfsplus_inode_read_fork(inode, &vhdr->attr_file);
45 inode->i_mapping->a_ops = &hfsplus_btree_aops;
46 break;
47 default:
48 return -EIO;
49 }
50
51 return 0;
52}
53
63525391 54struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
1da177e4
LT
55{
56 struct hfs_find_data fd;
63525391 57 struct inode *inode;
fc4fff82 58 int err;
63525391
DH
59
60 inode = iget_locked(sb, ino);
61 if (!inode)
62 return ERR_PTR(-ENOMEM);
63 if (!(inode->i_state & I_NEW))
64 return inode;
1da177e4 65
6af502de
CH
66 INIT_LIST_HEAD(&HFSPLUS_I(inode)->open_dir_list);
67 mutex_init(&HFSPLUS_I(inode)->extents_lock);
68 HFSPLUS_I(inode)->flags = 0;
b33b7921 69 HFSPLUS_I(inode)->extent_state = 0;
6af502de
CH
70 HFSPLUS_I(inode)->rsrc_inode = NULL;
71 atomic_set(&HFSPLUS_I(inode)->opencnt, 0);
1da177e4 72
fc4fff82
CH
73 if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID ||
74 inode->i_ino == HFSPLUS_ROOT_CNID) {
dd73a01a 75 hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
1da177e4
LT
76 err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
77 if (!err)
78 err = hfsplus_cat_read_inode(inode, &fd);
79 hfs_find_exit(&fd);
fc4fff82
CH
80 } else {
81 err = hfsplus_system_read_inode(inode);
1da177e4 82 }
fc4fff82
CH
83
84 if (err) {
85 iget_failed(inode);
86 return ERR_PTR(err);
1da177e4
LT
87 }
88
63525391
DH
89 unlock_new_inode(inode);
90 return inode;
1da177e4
LT
91}
92
b5080f77 93static int hfsplus_system_write_inode(struct inode *inode)
1da177e4 94{
dd73a01a 95 struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
b5080f77
CH
96 struct hfsplus_vh *vhdr = sbi->s_vhdr;
97 struct hfsplus_fork_raw *fork;
98 struct hfs_btree *tree = NULL;
1da177e4 99
1da177e4 100 switch (inode->i_ino) {
1da177e4 101 case HFSPLUS_EXT_CNID:
b5080f77
CH
102 fork = &vhdr->ext_file;
103 tree = sbi->ext_tree;
1da177e4
LT
104 break;
105 case HFSPLUS_CAT_CNID:
b5080f77
CH
106 fork = &vhdr->cat_file;
107 tree = sbi->cat_tree;
1da177e4
LT
108 break;
109 case HFSPLUS_ALLOC_CNID:
b5080f77 110 fork = &vhdr->alloc_file;
1da177e4
LT
111 break;
112 case HFSPLUS_START_CNID:
b5080f77 113 fork = &vhdr->start_file;
1da177e4
LT
114 break;
115 case HFSPLUS_ATTR_CNID:
b5080f77
CH
116 fork = &vhdr->attr_file;
117 tree = sbi->attr_tree;
118 default:
119 return -EIO;
120 }
121
122 if (fork->total_size != cpu_to_be64(inode->i_size)) {
84adede3 123 set_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags);
b5080f77 124 inode->i_sb->s_dirt = 1;
1da177e4 125 }
b5080f77
CH
126 hfsplus_inode_write_fork(inode, fork);
127 if (tree)
128 hfs_btree_write(tree);
129 return 0;
130}
131
132static int hfsplus_write_inode(struct inode *inode,
133 struct writeback_control *wbc)
134{
135 dprint(DBG_INODE, "hfsplus_write_inode: %lu\n", inode->i_ino);
136
137 hfsplus_ext_write_extent(inode);
138
139 if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID ||
140 inode->i_ino == HFSPLUS_ROOT_CNID)
141 return hfsplus_cat_write_inode(inode);
142 else
143 return hfsplus_system_write_inode(inode);
1da177e4
LT
144}
145
b57922d9 146static void hfsplus_evict_inode(struct inode *inode)
1da177e4 147{
b57922d9
AV
148 dprint(DBG_INODE, "hfsplus_evict_inode: %lu\n", inode->i_ino);
149 truncate_inode_pages(&inode->i_data, 0);
150 end_writeback(inode);
1da177e4 151 if (HFSPLUS_IS_RSRC(inode)) {
6af502de
CH
152 HFSPLUS_I(HFSPLUS_I(inode)->rsrc_inode)->rsrc_inode = NULL;
153 iput(HFSPLUS_I(inode)->rsrc_inode);
1da177e4 154 }
1da177e4
LT
155}
156
b5fc510c 157int hfsplus_sync_fs(struct super_block *sb, int wait)
1da177e4 158{
dd73a01a
CH
159 struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
160 struct hfsplus_vh *vhdr = sbi->s_vhdr;
52399b17
CH
161 int write_backup = 0;
162 int error, error2;
1da177e4 163
f02e26f8
CH
164 if (!wait)
165 return 0;
166
1da177e4 167 dprint(DBG_SUPER, "hfsplus_write_super\n");
ebc1ac16 168
1da177e4 169 sb->s_dirt = 0;
1da177e4 170
7dc4f001
CH
171 /*
172 * Explicitly write out the special metadata inodes.
173 *
174 * While these special inodes are marked as hashed and written
175 * out peridocically by the flusher threads we redirty them
176 * during writeout of normal inodes, and thus the life lock
177 * prevents us from getting the latest state to disk.
178 */
179 error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
180 error2 = filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
181 if (!error)
182 error = error2;
183 error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
184 if (!error)
185 error = error2;
186
52399b17
CH
187 mutex_lock(&sbi->vh_mutex);
188 mutex_lock(&sbi->alloc_mutex);
dd73a01a 189 vhdr->free_blocks = cpu_to_be32(sbi->free_blocks);
dd73a01a
CH
190 vhdr->next_cnid = cpu_to_be32(sbi->next_cnid);
191 vhdr->folder_count = cpu_to_be32(sbi->folder_count);
192 vhdr->file_count = cpu_to_be32(sbi->file_count);
1da177e4 193
84adede3 194 if (test_and_clear_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags)) {
52399b17
CH
195 memcpy(sbi->s_backup_vhdr, sbi->s_vhdr, sizeof(*sbi->s_vhdr));
196 write_backup = 1;
1da177e4 197 }
52399b17 198
7dc4f001 199 error2 = hfsplus_submit_bio(sb->s_bdev,
52399b17
CH
200 sbi->part_start + HFSPLUS_VOLHEAD_SECTOR,
201 sbi->s_vhdr, WRITE_SYNC);
7dc4f001
CH
202 if (!error)
203 error = error2;
52399b17
CH
204 if (!write_backup)
205 goto out;
206
207 error2 = hfsplus_submit_bio(sb->s_bdev,
208 sbi->part_start + sbi->sect_count - 2,
209 sbi->s_backup_vhdr, WRITE_SYNC);
210 if (!error)
211 error2 = error;
212out:
dd73a01a 213 mutex_unlock(&sbi->alloc_mutex);
7ac9fb9c 214 mutex_unlock(&sbi->vh_mutex);
52399b17 215 return error;
7fbc6df0
CH
216}
217
218static void hfsplus_write_super(struct super_block *sb)
219{
220 if (!(sb->s_flags & MS_RDONLY))
221 hfsplus_sync_fs(sb, 1);
222 else
223 sb->s_dirt = 0;
1da177e4
LT
224}
225
226static void hfsplus_put_super(struct super_block *sb)
227{
dd73a01a
CH
228 struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
229
1da177e4 230 dprint(DBG_SUPER, "hfsplus_put_super\n");
dd73a01a 231
945b0920
CL
232 if (!sb->s_fs_info)
233 return;
6cfd0148 234
dd73a01a
CH
235 if (!(sb->s_flags & MS_RDONLY) && sbi->s_vhdr) {
236 struct hfsplus_vh *vhdr = sbi->s_vhdr;
1da177e4
LT
237
238 vhdr->modify_date = hfsp_now2mt();
239 vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_UNMNT);
240 vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_INCNSTNT);
3b5ce8ae
CH
241
242 hfsplus_sync_fs(sb, 1);
1da177e4
LT
243 }
244
dd73a01a
CH
245 hfs_btree_close(sbi->cat_tree);
246 hfs_btree_close(sbi->ext_tree);
247 iput(sbi->alloc_file);
248 iput(sbi->hidden_dir);
52399b17
CH
249 kfree(sbi->s_vhdr);
250 kfree(sbi->s_backup_vhdr);
dd73a01a 251 unload_nls(sbi->nls);
945b0920
CL
252 kfree(sb->s_fs_info);
253 sb->s_fs_info = NULL;
1da177e4
LT
254}
255
726c3342 256static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4 257{
726c3342 258 struct super_block *sb = dentry->d_sb;
dd73a01a 259 struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
25564dd8 260 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
726c3342 261
1da177e4
LT
262 buf->f_type = HFSPLUS_SUPER_MAGIC;
263 buf->f_bsize = sb->s_blocksize;
dd73a01a
CH
264 buf->f_blocks = sbi->total_blocks << sbi->fs_shift;
265 buf->f_bfree = sbi->free_blocks << sbi->fs_shift;
1da177e4
LT
266 buf->f_bavail = buf->f_bfree;
267 buf->f_files = 0xFFFFFFFF;
dd73a01a 268 buf->f_ffree = 0xFFFFFFFF - sbi->next_cnid;
25564dd8
CL
269 buf->f_fsid.val[0] = (u32)id;
270 buf->f_fsid.val[1] = (u32)(id >> 32);
1da177e4
LT
271 buf->f_namelen = HFSPLUS_MAX_STRLEN;
272
273 return 0;
274}
275
276static 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)) {
dd73a01a 281 struct hfsplus_vh *vhdr = HFSPLUS_SB(sb)->s_vhdr;
6f80dfe5 282 int force = 0;
b0b623c3 283
6f80dfe5 284 if (!hfsplus_parse_options_remount(data, &force))
b0b623c3 285 return -EINVAL;
1da177e4
LT
286
287 if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
634725a9 288 printk(KERN_WARNING "hfs: filesystem was not cleanly unmounted, "
1da177e4
LT
289 "running fsck.hfsplus is recommended. leaving read-only.\n");
290 sb->s_flags |= MS_RDONLY;
291 *flags |= MS_RDONLY;
6f80dfe5 292 } else if (force) {
b0b623c3 293 /* nothing */
1da177e4 294 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
634725a9 295 printk(KERN_WARNING "hfs: filesystem is marked locked, leaving read-only.\n");
1da177e4
LT
296 sb->s_flags |= MS_RDONLY;
297 *flags |= MS_RDONLY;
b0b623c3 298 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
634725a9 299 printk(KERN_WARNING "hfs: filesystem is marked journaled, leaving read-only.\n");
b0b623c3
RZ
300 sb->s_flags |= MS_RDONLY;
301 *flags |= MS_RDONLY;
1da177e4
LT
302 }
303 }
304 return 0;
305}
306
ee9b6d61 307static const struct super_operations hfsplus_sops = {
1da177e4
LT
308 .alloc_inode = hfsplus_alloc_inode,
309 .destroy_inode = hfsplus_destroy_inode,
1da177e4 310 .write_inode = hfsplus_write_inode,
b57922d9 311 .evict_inode = hfsplus_evict_inode,
1da177e4
LT
312 .put_super = hfsplus_put_super,
313 .write_super = hfsplus_write_super,
7fbc6df0 314 .sync_fs = hfsplus_sync_fs,
1da177e4
LT
315 .statfs = hfsplus_statfs,
316 .remount_fs = hfsplus_remount,
717dd80e 317 .show_options = hfsplus_show_options,
1da177e4
LT
318};
319
320static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
321{
322 struct hfsplus_vh *vhdr;
323 struct hfsplus_sb_info *sbi;
324 hfsplus_cat_entry entry;
325 struct hfs_find_data fd;
63525391 326 struct inode *root, *inode;
1da177e4
LT
327 struct qstr str;
328 struct nls_table *nls = NULL;
329 int err = -EINVAL;
330
a5001a27 331 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
1da177e4
LT
332 if (!sbi)
333 return -ENOMEM;
334
1da177e4 335 sb->s_fs_info = sbi;
40bf48af 336 mutex_init(&sbi->alloc_mutex);
7ac9fb9c 337 mutex_init(&sbi->vh_mutex);
717dd80e
RZ
338 hfsplus_fill_defaults(sbi);
339 if (!hfsplus_parse_options(data, sbi)) {
634725a9 340 printk(KERN_ERR "hfs: unable to parse mount options\n");
1da177e4
LT
341 err = -EINVAL;
342 goto cleanup;
343 }
344
345 /* temporarily use utf8 to correctly find the hidden dir below */
346 nls = sbi->nls;
347 sbi->nls = load_nls("utf8");
bd6a59b2 348 if (!sbi->nls) {
634725a9 349 printk(KERN_ERR "hfs: unable to load nls for utf8\n");
1da177e4
LT
350 err = -EINVAL;
351 goto cleanup;
352 }
353
354 /* Grab the volume header */
355 if (hfsplus_read_wrapper(sb)) {
356 if (!silent)
634725a9 357 printk(KERN_WARNING "hfs: unable to find HFS+ superblock\n");
1da177e4
LT
358 err = -EINVAL;
359 goto cleanup;
360 }
dd73a01a 361 vhdr = sbi->s_vhdr;
1da177e4
LT
362
363 /* Copy parts of the volume header into the superblock */
2179d372
DE
364 sb->s_magic = HFSPLUS_VOLHEAD_SIG;
365 if (be16_to_cpu(vhdr->version) < HFSPLUS_MIN_VERSION ||
366 be16_to_cpu(vhdr->version) > HFSPLUS_CURRENT_VERSION) {
634725a9 367 printk(KERN_ERR "hfs: wrong filesystem version\n");
1da177e4
LT
368 goto cleanup;
369 }
dd73a01a
CH
370 sbi->total_blocks = be32_to_cpu(vhdr->total_blocks);
371 sbi->free_blocks = be32_to_cpu(vhdr->free_blocks);
dd73a01a
CH
372 sbi->next_cnid = be32_to_cpu(vhdr->next_cnid);
373 sbi->file_count = be32_to_cpu(vhdr->file_count);
374 sbi->folder_count = be32_to_cpu(vhdr->folder_count);
375 sbi->data_clump_blocks =
376 be32_to_cpu(vhdr->data_clump_sz) >> sbi->alloc_blksz_shift;
377 if (!sbi->data_clump_blocks)
378 sbi->data_clump_blocks = 1;
379 sbi->rsrc_clump_blocks =
380 be32_to_cpu(vhdr->rsrc_clump_sz) >> sbi->alloc_blksz_shift;
381 if (!sbi->rsrc_clump_blocks)
382 sbi->rsrc_clump_blocks = 1;
1da177e4
LT
383
384 /* Set up operations so we can load metadata */
385 sb->s_op = &hfsplus_sops;
386 sb->s_maxbytes = MAX_LFS_FILESIZE;
387
388 if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
634725a9
RZ
389 printk(KERN_WARNING "hfs: Filesystem was not cleanly unmounted, "
390 "running fsck.hfsplus is recommended. mounting read-only.\n");
1da177e4 391 sb->s_flags |= MS_RDONLY;
84adede3 392 } else if (test_and_clear_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
b0b623c3 393 /* nothing */
1da177e4 394 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
634725a9 395 printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
1da177e4 396 sb->s_flags |= MS_RDONLY;
81a73719 397 } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) && !(sb->s_flags & MS_RDONLY)) {
355a4696 398 printk(KERN_WARNING "hfs: write access to a journaled filesystem is not supported, "
634725a9 399 "use the force option at your own risk, mounting read-only.\n");
b0b623c3 400 sb->s_flags |= MS_RDONLY;
1da177e4
LT
401 }
402
403 /* Load metadata objects (B*Trees) */
dd73a01a
CH
404 sbi->ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);
405 if (!sbi->ext_tree) {
634725a9 406 printk(KERN_ERR "hfs: failed to load extents file\n");
1da177e4
LT
407 goto cleanup;
408 }
dd73a01a
CH
409 sbi->cat_tree = hfs_btree_open(sb, HFSPLUS_CAT_CNID);
410 if (!sbi->cat_tree) {
634725a9 411 printk(KERN_ERR "hfs: failed to load catalog file\n");
1da177e4
LT
412 goto cleanup;
413 }
414
63525391
DH
415 inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
416 if (IS_ERR(inode)) {
634725a9 417 printk(KERN_ERR "hfs: failed to load allocation file\n");
63525391 418 err = PTR_ERR(inode);
1da177e4
LT
419 goto cleanup;
420 }
dd73a01a 421 sbi->alloc_file = inode;
1da177e4
LT
422
423 /* Load the root directory */
63525391
DH
424 root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
425 if (IS_ERR(root)) {
426 printk(KERN_ERR "hfs: failed to load root directory\n");
427 err = PTR_ERR(root);
428 goto cleanup;
429 }
1da177e4
LT
430 sb->s_root = d_alloc_root(root);
431 if (!sb->s_root) {
1da177e4 432 iput(root);
63525391 433 err = -ENOMEM;
1da177e4
LT
434 goto cleanup;
435 }
d45bce8f 436 sb->s_root->d_op = &hfsplus_dentry_operations;
1da177e4
LT
437
438 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
439 str.name = HFSP_HIDDENDIR_NAME;
dd73a01a 440 hfs_find_init(sbi->cat_tree, &fd);
1da177e4
LT
441 hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
442 if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
443 hfs_find_exit(&fd);
444 if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
445 goto cleanup;
63525391
DH
446 inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
447 if (IS_ERR(inode)) {
448 err = PTR_ERR(inode);
1da177e4 449 goto cleanup;
63525391 450 }
dd73a01a 451 sbi->hidden_dir = inode;
1da177e4
LT
452 } else
453 hfs_find_exit(&fd);
454
455 if (sb->s_flags & MS_RDONLY)
456 goto out;
457
458 /* H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
459 * all three are registered with Apple for our use
460 */
461 vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
462 vhdr->modify_date = hfsp_now2mt();
20c79e78 463 be32_add_cpu(&vhdr->write_count, 1);
1da177e4
LT
464 vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
465 vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
3b5ce8ae 466 hfsplus_sync_fs(sb, 1);
1da177e4 467
dd73a01a 468 if (!sbi->hidden_dir) {
7ac9fb9c 469 mutex_lock(&sbi->vh_mutex);
dd73a01a
CH
470 sbi->hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
471 hfsplus_create_cat(sbi->hidden_dir->i_ino, sb->s_root->d_inode,
472 &str, sbi->hidden_dir);
7ac9fb9c
CH
473 mutex_unlock(&sbi->vh_mutex);
474
e3494705 475 hfsplus_mark_inode_dirty(sbi->hidden_dir, HFSPLUS_I_CAT_DIRTY);
1da177e4
LT
476 }
477out:
478 unload_nls(sbi->nls);
479 sbi->nls = nls;
480 return 0;
481
482cleanup:
483 hfsplus_put_super(sb);
6d729e44 484 unload_nls(nls);
1da177e4
LT
485 return err;
486}
487
488MODULE_AUTHOR("Brad Boyer");
489MODULE_DESCRIPTION("Extended Macintosh Filesystem");
490MODULE_LICENSE("GPL");
491
e18b890b 492static struct kmem_cache *hfsplus_inode_cachep;
1da177e4
LT
493
494static struct inode *hfsplus_alloc_inode(struct super_block *sb)
495{
496 struct hfsplus_inode_info *i;
497
e94b1766 498 i = kmem_cache_alloc(hfsplus_inode_cachep, GFP_KERNEL);
1da177e4
LT
499 return i ? &i->vfs_inode : NULL;
500}
501
502static void hfsplus_destroy_inode(struct inode *inode)
503{
6af502de 504 kmem_cache_free(hfsplus_inode_cachep, HFSPLUS_I(inode));
1da177e4
LT
505}
506
507#define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
508
152a0836
AV
509static struct dentry *hfsplus_mount(struct file_system_type *fs_type,
510 int flags, const char *dev_name, void *data)
1da177e4 511{
152a0836 512 return mount_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
1da177e4
LT
513}
514
515static struct file_system_type hfsplus_fs_type = {
516 .owner = THIS_MODULE,
517 .name = "hfsplus",
152a0836 518 .mount = hfsplus_mount,
1da177e4
LT
519 .kill_sb = kill_block_super,
520 .fs_flags = FS_REQUIRES_DEV,
521};
522
51cc5068 523static void hfsplus_init_once(void *p)
1da177e4
LT
524{
525 struct hfsplus_inode_info *i = p;
526
a35afb83 527 inode_init_once(&i->vfs_inode);
1da177e4
LT
528}
529
530static int __init init_hfsplus_fs(void)
531{
532 int err;
533
534 hfsplus_inode_cachep = kmem_cache_create("hfsplus_icache",
535 HFSPLUS_INODE_SIZE, 0, SLAB_HWCACHE_ALIGN,
20c2df83 536 hfsplus_init_once);
1da177e4
LT
537 if (!hfsplus_inode_cachep)
538 return -ENOMEM;
539 err = register_filesystem(&hfsplus_fs_type);
540 if (err)
541 kmem_cache_destroy(hfsplus_inode_cachep);
542 return err;
543}
544
545static void __exit exit_hfsplus_fs(void)
546{
547 unregister_filesystem(&hfsplus_fs_type);
1a1d92c1 548 kmem_cache_destroy(hfsplus_inode_cachep);
1da177e4
LT
549}
550
551module_init(init_hfsplus_fs)
552module_exit(exit_hfsplus_fs)
This page took 0.672594 seconds and 4 git commands to generate.