Blame view

fs/hfs/super.c 12.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
  /*
   *  linux/fs/hfs/super.c
   *
   * Copyright (C) 1995-1997  Paul H. Hargrove
   * (C) 2003 Ardis Technologies <roman@ardistech.com>
   * This file may be distributed under the terms of the GNU General Public License.
   *
   * This file contains hfs_read_super(), some of the super_ops and
14b30d628   Robert P. J. Day   hfs: update comme...
9
   * init_hfs_fs() and exit_hfs_fs().  The remaining super_ops are in
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
   * inode.c since they deal with inodes.
   *
   * Based on the minix file system code, (C) 1991, 1992 by Linus Torvalds
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
  #include <linux/module.h>
  #include <linux/blkdev.h>
66114cad6   Tejun Heo   writeback: separa...
16
  #include <linux/backing-dev.h>
717dd80e9   Roman Zippel   [PATCH] hfs: show...
17
  #include <linux/mount.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  #include <linux/init.h>
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
19
  #include <linux/nls.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
  #include <linux/parser.h>
717dd80e9   Roman Zippel   [PATCH] hfs: show...
21
  #include <linux/seq_file.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
22
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
  #include <linux/vfs.h>
  
  #include "hfs_fs.h"
  #include "btree.h"
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
27
  static struct kmem_cache *hfs_inode_cachep;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
  
  MODULE_LICENSE("GPL");
58bc5bbb8   Christoph Hellwig   hfs: add ->sync_fs
30
31
  static int hfs_sync_fs(struct super_block *sb, int wait)
  {
58bc5bbb8   Christoph Hellwig   hfs: add ->sync_fs
32
  	hfs_mdb_commit(sb);
58bc5bbb8   Christoph Hellwig   hfs: add ->sync_fs
33
34
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
37
38
39
40
41
42
43
  /*
   * hfs_put_super()
   *
   * This is the put_super() entry in the super_operations structure for
   * HFS filesystems.  The purpose is to release the resources
   * associated with the superblock sb.
   */
  static void hfs_put_super(struct super_block *sb)
  {
5687b5780   Artem Bityutskiy   hfs: get rid of h...
44
  	cancel_delayed_work_sync(&HFS_SB(sb)->mdb_work);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
48
  	hfs_mdb_close(sb);
  	/* release the MDB's resources */
  	hfs_mdb_put(sb);
  }
5687b5780   Artem Bityutskiy   hfs: get rid of h...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  static void flush_mdb(struct work_struct *work)
  {
  	struct hfs_sb_info *sbi;
  	struct super_block *sb;
  
  	sbi = container_of(work, struct hfs_sb_info, mdb_work.work);
  	sb = sbi->sb;
  
  	spin_lock(&sbi->work_lock);
  	sbi->work_queued = 0;
  	spin_unlock(&sbi->work_lock);
  
  	hfs_mdb_commit(sb);
  }
  
  void hfs_mark_mdb_dirty(struct super_block *sb)
  {
  	struct hfs_sb_info *sbi = HFS_SB(sb);
  	unsigned long delay;
bc98a42c1   David Howells   VFS: Convert sb->...
68
  	if (sb_rdonly(sb))
5687b5780   Artem Bityutskiy   hfs: get rid of h...
69
70
71
72
73
74
75
76
77
78
  		return;
  
  	spin_lock(&sbi->work_lock);
  	if (!sbi->work_queued) {
  		delay = msecs_to_jiffies(dirty_writeback_interval * 10);
  		queue_delayed_work(system_long_wq, &sbi->mdb_work, delay);
  		sbi->work_queued = 1;
  	}
  	spin_unlock(&sbi->work_lock);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
80
81
82
83
84
85
86
87
  /*
   * hfs_statfs()
   *
   * This is the statfs() entry in the super_operations structure for
   * HFS filesystems.  The purpose is to return various data about the
   * filesystem.
   *
   * changed f_files/f_ffree to reflect the fs_ablock/free_ablocks.
   */
726c33422   David Howells   [PATCH] VFS: Perm...
88
  static int hfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
  {
726c33422   David Howells   [PATCH] VFS: Perm...
90
  	struct super_block *sb = dentry->d_sb;
7dd2c000f   Coly Li   fs/hfs: return f_...
91
  	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
726c33422   David Howells   [PATCH] VFS: Perm...
92

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
95
96
97
98
99
  	buf->f_type = HFS_SUPER_MAGIC;
  	buf->f_bsize = sb->s_blocksize;
  	buf->f_blocks = (u32)HFS_SB(sb)->fs_ablocks * HFS_SB(sb)->fs_div;
  	buf->f_bfree = (u32)HFS_SB(sb)->free_ablocks * HFS_SB(sb)->fs_div;
  	buf->f_bavail = buf->f_bfree;
  	buf->f_files = HFS_SB(sb)->fs_ablocks;
  	buf->f_ffree = HFS_SB(sb)->free_ablocks;
7dd2c000f   Coly Li   fs/hfs: return f_...
100
101
  	buf->f_fsid.val[0] = (u32)id;
  	buf->f_fsid.val[1] = (u32)(id >> 32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
104
105
106
107
108
  	buf->f_namelen = HFS_NAMELEN;
  
  	return 0;
  }
  
  static int hfs_remount(struct super_block *sb, int *flags, char *data)
  {
02b9984d6   Theodore Ts'o   fs: push sync_fil...
109
  	sync_filesystem(sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  	*flags |= MS_NODIRATIME;
bc98a42c1   David Howells   VFS: Convert sb->...
111
  	if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
113
114
  		return 0;
  	if (!(*flags & MS_RDONLY)) {
  		if (!(HFS_SB(sb)->mdb->drAtrb & cpu_to_be16(HFS_SB_ATTRIB_UNMNT))) {
d61426732   Joe Perches   hfs/hfsplus: conv...
115
116
  			pr_warn("filesystem was not cleanly unmounted, running fsck.hfs is recommended.  leaving read-only.
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
  			sb->s_flags |= MS_RDONLY;
  			*flags |= MS_RDONLY;
  		} else if (HFS_SB(sb)->mdb->drAtrb & cpu_to_be16(HFS_SB_ATTRIB_SLOCK)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
120
121
  			pr_warn("filesystem is marked locked, leaving read-only.
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
123
124
125
126
127
  			sb->s_flags |= MS_RDONLY;
  			*flags |= MS_RDONLY;
  		}
  	}
  	return 0;
  }
34c80b1d9   Al Viro   vfs: switch ->sho...
128
  static int hfs_show_options(struct seq_file *seq, struct dentry *root)
717dd80e9   Roman Zippel   [PATCH] hfs: show...
129
  {
34c80b1d9   Al Viro   vfs: switch ->sho...
130
  	struct hfs_sb_info *sbi = HFS_SB(root->d_sb);
717dd80e9   Roman Zippel   [PATCH] hfs: show...
131
132
  
  	if (sbi->s_creator != cpu_to_be32(0x3f3f3f3f))
a068acf2e   Kees Cook   fs: create and us...
133
  		seq_show_option_n(seq, "creator", (char *)&sbi->s_creator, 4);
717dd80e9   Roman Zippel   [PATCH] hfs: show...
134
  	if (sbi->s_type != cpu_to_be32(0x3f3f3f3f))
a068acf2e   Kees Cook   fs: create and us...
135
  		seq_show_option_n(seq, "type", (char *)&sbi->s_type, 4);
43b5e4ccd   Eric W. Biederman   userns: Convert h...
136
137
138
  	seq_printf(seq, ",uid=%u,gid=%u",
  			from_kuid_munged(&init_user_ns, sbi->s_uid),
  			from_kgid_munged(&init_user_ns, sbi->s_gid));
717dd80e9   Roman Zippel   [PATCH] hfs: show...
139
140
141
142
143
144
145
146
  	if (sbi->s_file_umask != 0133)
  		seq_printf(seq, ",file_umask=%o", sbi->s_file_umask);
  	if (sbi->s_dir_umask != 0022)
  		seq_printf(seq, ",dir_umask=%o", sbi->s_dir_umask);
  	if (sbi->part >= 0)
  		seq_printf(seq, ",part=%u", sbi->part);
  	if (sbi->session >= 0)
  		seq_printf(seq, ",session=%u", sbi->session);
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
147
148
149
150
  	if (sbi->nls_disk)
  		seq_printf(seq, ",codepage=%s", sbi->nls_disk->charset);
  	if (sbi->nls_io)
  		seq_printf(seq, ",iocharset=%s", sbi->nls_io->charset);
717dd80e9   Roman Zippel   [PATCH] hfs: show...
151
152
153
154
  	if (sbi->s_quiet)
  		seq_printf(seq, ",quiet");
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
156
157
  static struct inode *hfs_alloc_inode(struct super_block *sb)
  {
  	struct hfs_inode_info *i;
e94b17660   Christoph Lameter   [PATCH] slab: rem...
158
  	i = kmem_cache_alloc(hfs_inode_cachep, GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
160
  	return i ? &i->vfs_inode : NULL;
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
161
  static void hfs_i_callback(struct rcu_head *head)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  {
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
163
  	struct inode *inode = container_of(head, struct inode, i_rcu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
165
  	kmem_cache_free(hfs_inode_cachep, HFS_I(inode));
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
166
167
168
169
  static void hfs_destroy_inode(struct inode *inode)
  {
  	call_rcu(&inode->i_rcu, hfs_i_callback);
  }
ee9b6d61a   Josef 'Jeff' Sipek   [PATCH] Mark stru...
170
  static const struct super_operations hfs_super_operations = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
172
173
  	.alloc_inode	= hfs_alloc_inode,
  	.destroy_inode	= hfs_destroy_inode,
  	.write_inode	= hfs_write_inode,
b57922d97   Al Viro   convert remaining...
174
  	.evict_inode	= hfs_evict_inode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
  	.put_super	= hfs_put_super,
58bc5bbb8   Christoph Hellwig   hfs: add ->sync_fs
176
  	.sync_fs	= hfs_sync_fs,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
  	.statfs		= hfs_statfs,
  	.remount_fs     = hfs_remount,
717dd80e9   Roman Zippel   [PATCH] hfs: show...
179
  	.show_options	= hfs_show_options,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
181
182
183
184
  };
  
  enum {
  	opt_uid, opt_gid, opt_umask, opt_file_umask, opt_dir_umask,
  	opt_part, opt_session, opt_type, opt_creator, opt_quiet,
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
185
  	opt_codepage, opt_iocharset,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
  	opt_err
  };
a447c0932   Steven Whitehouse   vfs: Use const fo...
188
  static const match_table_t tokens = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
194
195
196
197
198
  	{ opt_uid, "uid=%u" },
  	{ opt_gid, "gid=%u" },
  	{ opt_umask, "umask=%o" },
  	{ opt_file_umask, "file_umask=%o" },
  	{ opt_dir_umask, "dir_umask=%o" },
  	{ opt_part, "part=%u" },
  	{ opt_session, "session=%u" },
  	{ opt_type, "type=%s" },
  	{ opt_creator, "creator=%s" },
  	{ opt_quiet, "quiet" },
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
199
200
  	{ opt_codepage, "codepage=%s" },
  	{ opt_iocharset, "iocharset=%s" },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
  	{ opt_err, NULL }
  };
  
  static inline int match_fourchar(substring_t *arg, u32 *result)
  {
  	if (arg->to - arg->from != 4)
  		return -EINVAL;
  	memcpy(result, arg->from, 4);
  	return 0;
  }
  
  /*
   * parse_options()
   *
   * adapted from linux/fs/msdos/inode.c written 1992,93 by Werner Almesberger
   * This function is called by hfs_read_super() to parse the mount options.
   */
  static int parse_options(char *options, struct hfs_sb_info *hsb)
  {
  	char *p;
  	substring_t args[MAX_OPT_ARGS];
  	int tmp, token;
  
  	/* initialize the sb with defaults */
94c9a5ee4   David Howells   CRED: Wrap task c...
225
226
  	hsb->s_uid = current_uid();
  	hsb->s_gid = current_gid();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  	hsb->s_file_umask = 0133;
  	hsb->s_dir_umask = 0022;
  	hsb->s_type = hsb->s_creator = cpu_to_be32(0x3f3f3f3f);	/* == '????' */
  	hsb->s_quiet = 0;
  	hsb->part = -1;
  	hsb->session = -1;
  
  	if (!options)
  		return 1;
  
  	while ((p = strsep(&options, ",")) != NULL) {
  		if (!*p)
  			continue;
  
  		token = match_token(p, tokens, args);
  		switch (token) {
  		case opt_uid:
  			if (match_int(&args[0], &tmp)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
245
246
  				pr_err("uid requires an argument
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
  				return 0;
  			}
43b5e4ccd   Eric W. Biederman   userns: Convert h...
249
250
  			hsb->s_uid = make_kuid(current_user_ns(), (uid_t)tmp);
  			if (!uid_valid(hsb->s_uid)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
251
252
  				pr_err("invalid uid %d
  ", tmp);
43b5e4ccd   Eric W. Biederman   userns: Convert h...
253
254
  				return 0;
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
256
257
  			break;
  		case opt_gid:
  			if (match_int(&args[0], &tmp)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
258
259
  				pr_err("gid requires an argument
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
261
  				return 0;
  			}
43b5e4ccd   Eric W. Biederman   userns: Convert h...
262
263
  			hsb->s_gid = make_kgid(current_user_ns(), (gid_t)tmp);
  			if (!gid_valid(hsb->s_gid)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
264
265
  				pr_err("invalid gid %d
  ", tmp);
43b5e4ccd   Eric W. Biederman   userns: Convert h...
266
267
  				return 0;
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
269
270
  			break;
  		case opt_umask:
  			if (match_octal(&args[0], &tmp)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
271
272
  				pr_err("umask requires a value
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
273
274
275
276
277
278
279
  				return 0;
  			}
  			hsb->s_file_umask = (umode_t)tmp;
  			hsb->s_dir_umask = (umode_t)tmp;
  			break;
  		case opt_file_umask:
  			if (match_octal(&args[0], &tmp)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
280
281
  				pr_err("file_umask requires a value
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
282
283
284
285
286
287
  				return 0;
  			}
  			hsb->s_file_umask = (umode_t)tmp;
  			break;
  		case opt_dir_umask:
  			if (match_octal(&args[0], &tmp)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
288
289
  				pr_err("dir_umask requires a value
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
295
  				return 0;
  			}
  			hsb->s_dir_umask = (umode_t)tmp;
  			break;
  		case opt_part:
  			if (match_int(&args[0], &hsb->part)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
296
297
  				pr_err("part requires an argument
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
301
302
  				return 0;
  			}
  			break;
  		case opt_session:
  			if (match_int(&args[0], &hsb->session)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
303
304
  				pr_err("session requires an argument
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
306
307
308
309
  				return 0;
  			}
  			break;
  		case opt_type:
  			if (match_fourchar(&args[0], &hsb->s_type)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
310
311
  				pr_err("type requires a 4 character value
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
312
313
314
315
316
  				return 0;
  			}
  			break;
  		case opt_creator:
  			if (match_fourchar(&args[0], &hsb->s_creator)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
317
318
  				pr_err("creator requires a 4 character value
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
320
321
322
323
324
  				return 0;
  			}
  			break;
  		case opt_quiet:
  			hsb->s_quiet = 1;
  			break;
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
325
326
  		case opt_codepage:
  			if (hsb->nls_disk) {
d61426732   Joe Perches   hfs/hfsplus: conv...
327
328
  				pr_err("unable to change codepage
  ");
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
329
330
331
  				return 0;
  			}
  			p = match_strdup(&args[0]);
3fbe5c310   Jim Meyering   hfs: handle match...
332
333
  			if (p)
  				hsb->nls_disk = load_nls(p);
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
334
  			if (!hsb->nls_disk) {
d61426732   Joe Perches   hfs/hfsplus: conv...
335
336
  				pr_err("unable to load codepage \"%s\"
  ", p);
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
337
338
339
340
341
342
343
  				kfree(p);
  				return 0;
  			}
  			kfree(p);
  			break;
  		case opt_iocharset:
  			if (hsb->nls_io) {
d61426732   Joe Perches   hfs/hfsplus: conv...
344
345
  				pr_err("unable to change iocharset
  ");
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
346
347
348
  				return 0;
  			}
  			p = match_strdup(&args[0]);
3fbe5c310   Jim Meyering   hfs: handle match...
349
350
  			if (p)
  				hsb->nls_io = load_nls(p);
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
351
  			if (!hsb->nls_io) {
d61426732   Joe Perches   hfs/hfsplus: conv...
352
353
  				pr_err("unable to load iocharset \"%s\"
  ", p);
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
354
355
356
357
358
  				kfree(p);
  				return 0;
  			}
  			kfree(p);
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
359
360
361
362
  		default:
  			return 0;
  		}
  	}
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
363
364
365
  	if (hsb->nls_disk && !hsb->nls_io) {
  		hsb->nls_io = load_nls_default();
  		if (!hsb->nls_io) {
d61426732   Joe Perches   hfs/hfsplus: conv...
366
367
  			pr_err("unable to load default iocharset
  ");
328b92278   Roman Zippel   [PATCH] hfs: NLS ...
368
369
370
  			return 0;
  		}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
  	hsb->s_dir_umask &= 0777;
  	hsb->s_file_umask &= 0577;
  
  	return 1;
  }
  
  /*
   * hfs_read_super()
   *
   * This is the function that is responsible for mounting an HFS
   * filesystem.	It performs all the tasks necessary to get enough data
   * from the disk to read the root inode.  This includes parsing the
   * mount options, dealing with Macintosh partitions, reading the
   * superblock and the allocation bitmap blocks, calling
   * hfs_btree_init() to get the necessary data about the extents and
   * catalog B-trees and, finally, reading the root inode into memory.
   */
  static int hfs_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct hfs_sb_info *sbi;
  	struct hfs_find_data fd;
  	hfs_cat_rec rec;
  	struct inode *root_inode;
  	int res;
f8314dc60   Panagiotis Issaris   [PATCH] fs: Conve...
395
  	sbi = kzalloc(sizeof(struct hfs_sb_info), GFP_KERNEL);
8526fb37c   Jan Blunck   BKL: Remove BKL f...
396
  	if (!sbi)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
  		return -ENOMEM;
8526fb37c   Jan Blunck   BKL: Remove BKL f...
398

b16ca6263   Artem Bityutskiy   hfs: introduce VF...
399
  	sbi->sb = sb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
  	sb->s_fs_info = sbi;
5687b5780   Artem Bityutskiy   hfs: get rid of h...
401
402
  	spin_lock_init(&sbi->work_lock);
  	INIT_DELAYED_WORK(&sbi->mdb_work, flush_mdb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
404
405
  
  	res = -EINVAL;
  	if (!parse_options((char *)data, sbi)) {
d61426732   Joe Perches   hfs/hfsplus: conv...
406
407
  		pr_err("unable to parse mount options
  ");
945b09201   Colin Leroy   [PATCH] hfs, hfsp...
408
  		goto bail;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
  	}
  
  	sb->s_op = &hfs_super_operations;
b8020eff7   Andreas Gruenbacher   hfs: Switch to ge...
412
  	sb->s_xattr = hfs_xattr_handlers;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
413
  	sb->s_flags |= MS_NODIRATIME;
3084b72de   Matthias Kaehlcke   hfs: convert bitm...
414
  	mutex_init(&sbi->bitmap_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
415
416
417
418
  
  	res = hfs_mdb_get(sb);
  	if (res) {
  		if (!silent)
d61426732   Joe Perches   hfs/hfsplus: conv...
419
420
  			pr_warn("can't find a HFS filesystem on dev %s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
421
422
  				hfs_mdb_name(sb));
  		res = -EINVAL;
945b09201   Colin Leroy   [PATCH] hfs, hfsp...
423
  		goto bail;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
425
426
  	}
  
  	/* try to get the root inode */
9509f1785   Alexey Khoroshilov   hfs: add error ch...
427
428
429
  	res = hfs_find_init(HFS_SB(sb)->cat_tree, &fd);
  	if (res)
  		goto bail_no_root;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
430
  	res = hfs_cat_find_brec(sb, HFS_ROOT_CNID, &fd);
ec81aecb2   Amerigo Wang   hfs: fix a potent...
431
432
433
434
435
  	if (!res) {
  		if (fd.entrylength > sizeof(rec) || fd.entrylength < 0) {
  			res =  -EIO;
  			goto bail;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
436
  		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, fd.entrylength);
ec81aecb2   Amerigo Wang   hfs: fix a potent...
437
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
438
439
440
441
  	if (res) {
  		hfs_find_exit(&fd);
  		goto bail_no_root;
  	}
d6ddf5544   Eric Sandeen   [PATCH] hfs_fill_...
442
  	res = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
445
446
  	root_inode = hfs_iget(sb, &fd.search_key->cat, &rec);
  	hfs_find_exit(&fd);
  	if (!root_inode)
  		goto bail_no_root;
518c79d28   Al Viro   switch hfs
447
  	sb->s_d_op = &hfs_dentry_operations;
d6ddf5544   Eric Sandeen   [PATCH] hfs_fill_...
448
  	res = -ENOMEM;
48fde701a   Al Viro   switch open-coded...
449
  	sb->s_root = d_make_root(root_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
450
  	if (!sb->s_root)
48fde701a   Al Viro   switch open-coded...
451
  		goto bail_no_root;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
452

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
454
  	/* everything's okay */
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
  bail_no_root:
d61426732   Joe Perches   hfs/hfsplus: conv...
456
457
  	pr_err("get root inode failed
  ");
945b09201   Colin Leroy   [PATCH] hfs, hfsp...
458
  bail:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459
  	hfs_mdb_put(sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
460
461
  	return res;
  }
152a08366   Al Viro   new helper: mount...
462
463
  static struct dentry *hfs_mount(struct file_system_type *fs_type,
  		      int flags, const char *dev_name, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
464
  {
152a08366   Al Viro   new helper: mount...
465
  	return mount_bdev(fs_type, flags, dev_name, data, hfs_fill_super);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
466
467
468
469
470
  }
  
  static struct file_system_type hfs_fs_type = {
  	.owner		= THIS_MODULE,
  	.name		= "hfs",
152a08366   Al Viro   new helper: mount...
471
  	.mount		= hfs_mount,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
472
473
474
  	.kill_sb	= kill_block_super,
  	.fs_flags	= FS_REQUIRES_DEV,
  };
7f78e0351   Eric W. Biederman   fs: Limit sys_mou...
475
  MODULE_ALIAS_FS("hfs");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
476

51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
477
  static void hfs_init_once(void *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
478
479
  {
  	struct hfs_inode_info *i = p;
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
480
  	inode_init_once(&i->vfs_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
481
482
483
484
485
486
487
  }
  
  static int __init init_hfs_fs(void)
  {
  	int err;
  
  	hfs_inode_cachep = kmem_cache_create("hfs_inode_cache",
5d097056c   Vladimir Davydov   kmemcg: account c...
488
489
  		sizeof(struct hfs_inode_info), 0,
  		SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, hfs_init_once);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
490
491
492
493
494
495
496
497
498
499
500
  	if (!hfs_inode_cachep)
  		return -ENOMEM;
  	err = register_filesystem(&hfs_fs_type);
  	if (err)
  		kmem_cache_destroy(hfs_inode_cachep);
  	return err;
  }
  
  static void __exit exit_hfs_fs(void)
  {
  	unregister_filesystem(&hfs_fs_type);
8c0a85377   Kirill A. Shutemov   fs: push rcu_barr...
501
502
503
504
505
506
  
  	/*
  	 * Make sure all delayed rcu free inodes are flushed before we
  	 * destroy cache.
  	 */
  	rcu_barrier();
1a1d92c10   Alexey Dobriyan   [PATCH] Really ig...
507
  	kmem_cache_destroy(hfs_inode_cachep);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
509
510
511
  }
  
  module_init(init_hfs_fs)
  module_exit(exit_hfs_fs)