Blame view

fs/affs/super.c 14.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   *  linux/fs/affs/inode.c
   *
   *  (c) 1996  Hans-Joachim Widmaier - Rewritten
   *
   *  (C) 1993  Ray Burr - Modified for Amiga FFS filesystem.
   *
   *  (C) 1992  Eric Youngdale Modified for ISO 9660 filesystem.
   *
   *  (C) 1991  Linus Torvalds - minix filesystem
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/statfs.h>
  #include <linux/parser.h>
e18fa700c   Jeff Garzik   Move several *_SU...
17
  #include <linux/magic.h>
e8edc6e03   Alexey Dobriyan   Detach sched.h fr...
18
  #include <linux/sched.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
19
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
  #include "affs.h"
  
  extern struct timezone sys_tz;
726c33422   David Howells   [PATCH] VFS: Perm...
23
  static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
  static int affs_remount (struct super_block *sb, int *flags, char *data);
  
  static void
7435d5061   Artem Bityutskiy   AFFS: wait for sb...
27
  affs_commit_super(struct super_block *sb, int wait, int clean)
e28964365   Christoph Hellwig   affs: add ->sync_fs
28
29
30
31
32
33
34
35
36
  {
  	struct affs_sb_info *sbi = AFFS_SB(sb);
  	struct buffer_head *bh = sbi->s_root_bh;
  	struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh);
  
  	tail->bm_flag = cpu_to_be32(clean);
  	secs_to_datestamp(get_seconds(), &tail->disk_change);
  	affs_fix_checksum(sb, bh);
  	mark_buffer_dirty(bh);
7435d5061   Artem Bityutskiy   AFFS: wait for sb...
37
38
  	if (wait)
  		sync_dirty_buffer(bh);
e28964365   Christoph Hellwig   affs: add ->sync_fs
39
40
41
  }
  
  static void
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
  affs_put_super(struct super_block *sb)
  {
  	struct affs_sb_info *sbi = AFFS_SB(sb);
  	pr_debug("AFFS: put_super()
  ");
7435d5061   Artem Bityutskiy   AFFS: wait for sb...
47
48
  	if (!(sb->s_flags & MS_RDONLY) && sb->s_dirt)
  		affs_commit_super(sb, 1, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49

f99d49adf   Jesper Juhl   [PATCH] kfree cle...
50
  	kfree(sbi->s_prefix);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
53
54
  	affs_free_bitmap(sb);
  	affs_brelse(sbi->s_root_bh);
  	kfree(sbi);
  	sb->s_fs_info = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
59
  }
  
  static void
  affs_write_super(struct super_block *sb)
  {
ebc1ac164   Christoph Hellwig   ->write_super loc...
60
  	lock_super(sb);
669d5f1f6   Artem Bityutskiy   AFFS: clean up di...
61
  	if (!(sb->s_flags & MS_RDONLY))
7435d5061   Artem Bityutskiy   AFFS: wait for sb...
62
  		affs_commit_super(sb, 1, 2);
669d5f1f6   Artem Bityutskiy   AFFS: clean up di...
63
  	sb->s_dirt = 0;
ebc1ac164   Christoph Hellwig   ->write_super loc...
64
  	unlock_super(sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65

669d5f1f6   Artem Bityutskiy   AFFS: clean up di...
66
67
  	pr_debug("AFFS: write_super() at %lu, clean=2
  ", get_seconds());
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
  }
e28964365   Christoph Hellwig   affs: add ->sync_fs
69
70
71
72
  static int
  affs_sync_fs(struct super_block *sb, int wait)
  {
  	lock_super(sb);
7435d5061   Artem Bityutskiy   AFFS: wait for sb...
73
  	affs_commit_super(sb, wait, 2);
e28964365   Christoph Hellwig   affs: add ->sync_fs
74
75
76
77
  	sb->s_dirt = 0;
  	unlock_super(sb);
  	return 0;
  }
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
78
  static struct kmem_cache * affs_inode_cachep;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
80
81
  
  static struct inode *affs_alloc_inode(struct super_block *sb)
  {
dca3c3365   Roman Zippel   [PATCH] fix reser...
82
83
84
85
  	struct affs_inode_info *i;
  
  	i = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL);
  	if (!i)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
  		return NULL;
dca3c3365   Roman Zippel   [PATCH] fix reser...
87
88
89
90
91
92
93
  
  	i->vfs_inode.i_version = 1;
  	i->i_lc = NULL;
  	i->i_ext_bh = NULL;
  	i->i_pa_cnt = 0;
  
  	return &i->vfs_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
95
  static void affs_i_callback(struct rcu_head *head)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
  {
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
97
  	struct inode *inode = container_of(head, struct inode, i_rcu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
99
  	kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
100
101
102
103
  static void affs_destroy_inode(struct inode *inode)
  {
  	call_rcu(&inode->i_rcu, affs_i_callback);
  }
51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
104
  static void init_once(void *foo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
  {
  	struct affs_inode_info *ei = (struct affs_inode_info *) foo;
756b0322e   Thomas Gleixner   affs: Use sema_in...
107
108
  	sema_init(&ei->i_link_lock, 1);
  	sema_init(&ei->i_ext_lock, 1);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
109
  	inode_init_once(&ei->vfs_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
115
  }
  
  static int init_inodecache(void)
  {
  	affs_inode_cachep = kmem_cache_create("affs_inode_cache",
  					     sizeof(struct affs_inode_info),
fffb60f93   Paul Jackson   [PATCH] cpuset me...
116
117
  					     0, (SLAB_RECLAIM_ACCOUNT|
  						SLAB_MEM_SPREAD),
20c2df83d   Paul Mundt   mm: Remove slab d...
118
  					     init_once);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
123
124
125
  	if (affs_inode_cachep == NULL)
  		return -ENOMEM;
  	return 0;
  }
  
  static void destroy_inodecache(void)
  {
1a1d92c10   Alexey Dobriyan   [PATCH] Really ig...
126
  	kmem_cache_destroy(affs_inode_cachep);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  }
ee9b6d61a   Josef 'Jeff' Sipek   [PATCH] Mark stru...
128
  static const struct super_operations affs_sops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
  	.alloc_inode	= affs_alloc_inode,
  	.destroy_inode	= affs_destroy_inode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
  	.write_inode	= affs_write_inode,
f053ddde7   Al Viro   switch affs to ->...
132
  	.evict_inode	= affs_evict_inode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
134
  	.put_super	= affs_put_super,
  	.write_super	= affs_write_super,
e28964365   Christoph Hellwig   affs: add ->sync_fs
135
  	.sync_fs	= affs_sync_fs,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
137
  	.statfs		= affs_statfs,
  	.remount_fs	= affs_remount,
e9b3961b6   Miklos Szeredi   mount options: fi...
138
  	.show_options	= generic_show_options,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
140
141
142
143
144
145
  };
  
  enum {
  	Opt_bs, Opt_mode, Opt_mufs, Opt_prefix, Opt_protect,
  	Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
  	Opt_verbose, Opt_volume, Opt_ignore, Opt_err,
  };
a447c0932   Steven Whitehouse   vfs: Use const fo...
146
  static const match_table_t tokens = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  	{Opt_bs, "bs=%u"},
  	{Opt_mode, "mode=%o"},
  	{Opt_mufs, "mufs"},
  	{Opt_prefix, "prefix=%s"},
  	{Opt_protect, "protect"},
  	{Opt_reserved, "reserved=%u"},
  	{Opt_root, "root=%u"},
  	{Opt_setgid, "setgid=%u"},
  	{Opt_setuid, "setuid=%u"},
  	{Opt_verbose, "verbose"},
  	{Opt_volume, "volume=%s"},
  	{Opt_ignore, "grpquota"},
  	{Opt_ignore, "noquota"},
  	{Opt_ignore, "quota"},
  	{Opt_ignore, "usrquota"},
  	{Opt_err, NULL},
  };
  
  static int
  parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s32 *root,
  		int *blocksize, char **prefix, char *volume, unsigned long *mount_opts)
  {
  	char *p;
  	substring_t args[MAX_OPT_ARGS];
  
  	/* Fill in defaults */
215599815   David Howells   CRED: Wrap task c...
173
174
  	*uid        = current_uid();
  	*gid        = current_gid();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
  	*reserved   = 2;
  	*root       = -1;
  	*blocksize  = -1;
  	volume[0]   = ':';
  	volume[1]   = 0;
  	*mount_opts = 0;
  	if (!options)
  		return 1;
  
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token, n, option;
  		if (!*p)
  			continue;
  
  		token = match_token(p, tokens, args);
  		switch (token) {
  		case Opt_bs:
  			if (match_int(&args[0], &n))
217686e98   Al Viro   fix affs parse_op...
193
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
195
196
197
198
199
200
201
202
203
  			if (n != 512 && n != 1024 && n != 2048
  			    && n != 4096) {
  				printk ("AFFS: Invalid blocksize (512, 1024, 2048, 4096 allowed)
  ");
  				return 0;
  			}
  			*blocksize = n;
  			break;
  		case Opt_mode:
  			if (match_octal(&args[0], &option))
217686e98   Al Viro   fix affs parse_op...
204
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
206
207
208
209
210
211
  			*mode = option & 0777;
  			*mount_opts |= SF_SETMODE;
  			break;
  		case Opt_mufs:
  			*mount_opts |= SF_MUFS;
  			break;
  		case Opt_prefix:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
213
214
215
216
217
218
219
220
221
  			*prefix = match_strdup(&args[0]);
  			if (!*prefix)
  				return 0;
  			*mount_opts |= SF_PREFIX;
  			break;
  		case Opt_protect:
  			*mount_opts |= SF_IMMUTABLE;
  			break;
  		case Opt_reserved:
  			if (match_int(&args[0], reserved))
217686e98   Al Viro   fix affs parse_op...
222
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
  			break;
  		case Opt_root:
  			if (match_int(&args[0], root))
217686e98   Al Viro   fix affs parse_op...
226
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
228
229
  			break;
  		case Opt_setgid:
  			if (match_int(&args[0], &option))
217686e98   Al Viro   fix affs parse_op...
230
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
232
233
234
235
  			*gid = option;
  			*mount_opts |= SF_SETGID;
  			break;
  		case Opt_setuid:
  			if (match_int(&args[0], &option))
217686e98   Al Viro   fix affs parse_op...
236
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
239
240
241
242
243
244
  			*uid = option;
  			*mount_opts |= SF_SETUID;
  			break;
  		case Opt_verbose:
  			*mount_opts |= SF_VERBOSE;
  			break;
  		case Opt_volume: {
  			char *vol = match_strdup(&args[0]);
6db27dd9d   Jim Meyering   affs: handle matc...
245
246
  			if (!vol)
  				return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
  			strlcpy(volume, vol, 32);
  			kfree(vol);
  			break;
  		}
  		case Opt_ignore:
  		 	/* Silently ignore the quota options */
  			break;
  		default:
  			printk("AFFS: Unrecognized mount option \"%s\" "
  					"or missing value
  ", p);
  			return 0;
  		}
  	}
  	return 1;
  }
  
  /* This function definitely needs to be split up. Some fine day I'll
   * hopefully have the guts to do so. Until then: sorry for the mess.
   */
  
  static int affs_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct affs_sb_info	*sbi;
  	struct buffer_head	*root_bh = NULL;
  	struct buffer_head	*boot_bh;
  	struct inode		*root_inode = NULL;
  	s32			 root_block;
  	int			 size, blocksize;
  	u32			 chksum;
  	int			 num_bm;
  	int			 i, j;
  	s32			 key;
  	uid_t			 uid;
  	gid_t			 gid;
  	int			 reserved;
  	unsigned long		 mount_flags;
  	int			 tmp_flags;	/* fix remount prototype... */
2b943cf09   Al Viro   [PATCH] fix %s in...
285
  	u8			 sig[4];
210f85596   David Howells   iget: stop AFFS f...
286
  	int			 ret = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
287

e9b3961b6   Miklos Szeredi   mount options: fi...
288
  	save_mount_options(sb, data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
290
291
292
293
294
  	pr_debug("AFFS: read_super(%s)
  ",data ? (const char *)data : "no options");
  
  	sb->s_magic             = AFFS_SUPER_MAGIC;
  	sb->s_op                = &affs_sops;
  	sb->s_flags |= MS_NODIRATIME;
f8314dc60   Panagiotis Issaris   [PATCH] fs: Conve...
295
  	sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296
297
  	if (!sbi)
  		return -ENOMEM;
74c41429a   Jan Blunck   BKL: Remove BKL f...
298

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
  	sb->s_fs_info = sbi;
7d135a5d5   Matthias Kaehlcke   affs: convert s_b...
300
  	mutex_init(&sbi->s_bmlock);
29333920a   Al Viro   Fix remount races...
301
  	spin_lock_init(&sbi->symlink_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
303
304
305
306
307
  
  	if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block,
  				&blocksize,&sbi->s_prefix,
  				sbi->s_volume, &mount_flags)) {
  		printk(KERN_ERR "AFFS: Error parsing options
  ");
afc70ed05   Al Viro   Fix a leak in aff...
308
309
  		kfree(sbi->s_prefix);
  		kfree(sbi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
  		return -EINVAL;
  	}
  	/* N.B. after this point s_prefix must be released */
  
  	sbi->s_flags   = mount_flags;
  	sbi->s_mode    = i;
  	sbi->s_uid     = uid;
  	sbi->s_gid     = gid;
  	sbi->s_reserved= reserved;
  
  	/* Get the size of the device in 512-byte blocks.
  	 * If we later see that the partition uses bigger
  	 * blocks, we will have to change it.
  	 */
  
  	size = sb->s_bdev->bd_inode->i_size >> 9;
  	pr_debug("AFFS: initial blocksize=%d, #blocks=%d
  ", 512, size);
  
  	affs_set_blocksize(sb, PAGE_SIZE);
  	/* Try to find root block. Its location depends on the block size. */
  
  	i = 512;
  	j = 4096;
  	if (blocksize > 0) {
  		i = j = blocksize;
  		size = size / (blocksize / 512);
  	}
  	for (blocksize = i, key = 0; blocksize <= j; blocksize <<= 1, size >>= 1) {
  		sbi->s_root_block = root_block;
  		if (root_block < 0)
  			sbi->s_root_block = (reserved + size - 1) / 2;
  		pr_debug("AFFS: setting blocksize to %d
  ", blocksize);
  		affs_set_blocksize(sb, blocksize);
  		sbi->s_partition_size = size;
  
  		/* The root block location that was calculated above is not
  		 * correct if the partition size is an odd number of 512-
  		 * byte blocks, which will be rounded down to a number of
  		 * 1024-byte blocks, and if there were an even number of
  		 * reserved blocks. Ideally, all partition checkers should
  		 * report the real number of blocks of the real blocksize,
  		 * but since this just cannot be done, we have to try to
  		 * find the root block anyways. In the above case, it is one
  		 * block behind the calculated one. So we check this one, too.
  		 */
  		for (num_bm = 0; num_bm < 2; num_bm++) {
  			pr_debug("AFFS: Dev %s, trying root=%u, bs=%d, "
  				"size=%d, reserved=%d
  ",
  				sb->s_id,
  				sbi->s_root_block + num_bm,
  				blocksize, size, reserved);
  			root_bh = affs_bread(sb, sbi->s_root_block + num_bm);
  			if (!root_bh)
  				continue;
  			if (!affs_checksum_block(sb, root_bh) &&
  			    be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT &&
  			    be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) {
  				sbi->s_hashsize    = blocksize / 4 - 56;
  				sbi->s_root_block += num_bm;
  				key                        = 1;
  				goto got_root;
  			}
  			affs_brelse(root_bh);
  			root_bh = NULL;
  		}
  	}
  	if (!silent)
  		printk(KERN_ERR "AFFS: No valid root block on device %s
  ",
  			sb->s_id);
  	goto out_error;
  
  	/* N.B. after this point bh must be released */
  got_root:
  	root_block = sbi->s_root_block;
  
  	/* Find out which kind of FS we have */
  	boot_bh = sb_bread(sb, 0);
  	if (!boot_bh) {
  		printk(KERN_ERR "AFFS: Cannot read boot block
  ");
  		goto out_error;
  	}
2b943cf09   Al Viro   [PATCH] fix %s in...
396
  	memcpy(sig, boot_bh->b_data, 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
  	brelse(boot_bh);
2b943cf09   Al Viro   [PATCH] fix %s in...
398
  	chksum = be32_to_cpu(*(__be32 *)sig);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
  
  	/* Dircache filesystems are compatible with non-dircache ones
  	 * when reading. As long as they aren't supported, writing is
  	 * not recommended.
  	 */
  	if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
  	     || chksum == MUFS_DCOFS) && !(sb->s_flags & MS_RDONLY)) {
  		printk(KERN_NOTICE "AFFS: Dircache FS - mounting %s read only
  ",
  			sb->s_id);
  		sb->s_flags |= MS_RDONLY;
  	}
  	switch (chksum) {
  		case MUFS_FS:
  		case MUFS_INTLFFS:
  		case MUFS_DCFFS:
  			sbi->s_flags |= SF_MUFS;
  			/* fall thru */
  		case FS_INTLFFS:
  		case FS_DCFFS:
  			sbi->s_flags |= SF_INTL;
  			break;
  		case MUFS_FFS:
  			sbi->s_flags |= SF_MUFS;
  			break;
  		case FS_FFS:
  			break;
  		case MUFS_OFS:
  			sbi->s_flags |= SF_MUFS;
  			/* fall thru */
  		case FS_OFS:
  			sbi->s_flags |= SF_OFS;
  			sb->s_flags |= MS_NOEXEC;
  			break;
  		case MUFS_DCOFS:
  		case MUFS_INTLOFS:
  			sbi->s_flags |= SF_MUFS;
  		case FS_DCOFS:
  		case FS_INTLOFS:
  			sbi->s_flags |= SF_INTL | SF_OFS;
  			sb->s_flags |= MS_NOEXEC;
  			break;
  		default:
  			printk(KERN_ERR "AFFS: Unknown filesystem on device %s: %08X
  ",
  				sb->s_id, chksum);
  			goto out_error;
  	}
  
  	if (mount_flags & SF_VERBOSE) {
2b943cf09   Al Viro   [PATCH] fix %s in...
449
450
451
452
  		u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
  		printk(KERN_NOTICE "AFFS: Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d
  ",
  			len > 31 ? 31 : len,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
  			AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1,
2b943cf09   Al Viro   [PATCH] fix %s in...
454
  			sig, sig[3] + '0', blocksize);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
  	}
  
  	sb->s_flags |= MS_NODEV | MS_NOSUID;
  
  	sbi->s_data_blksize = sb->s_blocksize;
  	if (sbi->s_flags & SF_OFS)
  		sbi->s_data_blksize -= 24;
  
  	/* Keep super block in cache */
  	sbi->s_root_bh = root_bh;
  	/* N.B. after this point s_root_bh must be released */
  
  	tmp_flags = sb->s_flags;
  	if (affs_init_bitmap(sb, &tmp_flags))
  		goto out_error;
  	sb->s_flags = tmp_flags;
  
  	/* set up enough so that it can read an inode */
210f85596   David Howells   iget: stop AFFS f...
473
474
475
476
477
  	root_inode = affs_iget(sb, root_block);
  	if (IS_ERR(root_inode)) {
  		ret = PTR_ERR(root_inode);
  		goto out_error_noinode;
  	}
a129880da   Al Viro   switch affs
478
479
480
481
  	if (AFFS_SB(sb)->s_flags & SF_INTL)
  		sb->s_d_op = &affs_intl_dentry_operations;
  	else
  		sb->s_d_op = &affs_dentry_operations;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
482
483
484
485
486
487
  	sb->s_root = d_alloc_root(root_inode);
  	if (!sb->s_root) {
  		printk(KERN_ERR "AFFS: Get root inode failed
  ");
  		goto out_error;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
488
489
490
491
492
493
494
495
496
497
498
  
  	pr_debug("AFFS: s_flags=%lX
  ",sb->s_flags);
  	return 0;
  
  	/*
  	 * Begin the cascaded cleanup ...
  	 */
  out_error:
  	if (root_inode)
  		iput(root_inode);
210f85596   David Howells   iget: stop AFFS f...
499
  out_error_noinode:
f99d49adf   Jesper Juhl   [PATCH] kfree cle...
500
  	kfree(sbi->s_bitmap);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501
  	affs_brelse(root_bh);
f99d49adf   Jesper Juhl   [PATCH] kfree cle...
502
  	kfree(sbi->s_prefix);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503
504
  	kfree(sbi);
  	sb->s_fs_info = NULL;
210f85596   David Howells   iget: stop AFFS f...
505
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
507
508
509
510
511
512
513
514
515
516
517
518
519
  }
  
  static int
  affs_remount(struct super_block *sb, int *flags, char *data)
  {
  	struct affs_sb_info	*sbi = AFFS_SB(sb);
  	int			 blocksize;
  	uid_t			 uid;
  	gid_t			 gid;
  	int			 mode;
  	int			 reserved;
  	int			 root_block;
  	unsigned long		 mount_flags;
  	int			 res = 0;
e9b3961b6   Miklos Szeredi   mount options: fi...
520
  	char			*new_opts = kstrdup(data, GFP_KERNEL);
29333920a   Al Viro   Fix remount races...
521
522
  	char			 volume[32];
  	char			*prefix = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523
524
525
526
527
  
  	pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")
  ",*flags,data);
  
  	*flags |= MS_NODIRATIME;
29333920a   Al Viro   Fix remount races...
528
  	memcpy(volume, sbi->s_volume, 32);
e9b3961b6   Miklos Szeredi   mount options: fi...
529
  	if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
29333920a   Al Viro   Fix remount races...
530
  			   &blocksize, &prefix, volume,
e9b3961b6   Miklos Szeredi   mount options: fi...
531
  			   &mount_flags)) {
29333920a   Al Viro   Fix remount races...
532
  		kfree(prefix);
e9b3961b6   Miklos Szeredi   mount options: fi...
533
  		kfree(new_opts);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
  		return -EINVAL;
e9b3961b6   Miklos Szeredi   mount options: fi...
535
  	}
74c41429a   Jan Blunck   BKL: Remove BKL f...
536

2a32cebd6   Al Viro   Fix races around ...
537
  	replace_mount_options(sb, new_opts);
e9b3961b6   Miklos Szeredi   mount options: fi...
538

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
539
540
541
542
  	sbi->s_flags = mount_flags;
  	sbi->s_mode  = mode;
  	sbi->s_uid   = uid;
  	sbi->s_gid   = gid;
29333920a   Al Viro   Fix remount races...
543
544
545
546
547
548
549
550
  	/* protect against readers */
  	spin_lock(&sbi->symlink_lock);
  	if (prefix) {
  		kfree(sbi->s_prefix);
  		sbi->s_prefix = prefix;
  	}
  	memcpy(sbi->s_volume, volume, 32);
  	spin_unlock(&sbi->symlink_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551

74c41429a   Jan Blunck   BKL: Remove BKL f...
552
  	if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
  		return 0;
74c41429a   Jan Blunck   BKL: Remove BKL f...
554

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
555
  	if (*flags & MS_RDONLY) {
669d5f1f6   Artem Bityutskiy   AFFS: clean up di...
556
  		affs_write_super(sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
558
559
560
561
562
563
564
  		affs_free_bitmap(sb);
  	} else
  		res = affs_init_bitmap(sb, flags);
  
  	return res;
  }
  
  static int
726c33422   David Howells   [PATCH] VFS: Perm...
565
  affs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
566
  {
726c33422   David Howells   [PATCH] VFS: Perm...
567
  	struct super_block *sb = dentry->d_sb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
568
  	int		 free;
a6a2a73c4   Coly Li   fs/affs: return f...
569
  	u64		 id = huge_encode_dev(sb->s_bdev->bd_dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
570
571
572
573
574
575
576
577
578
579
580
  
  	pr_debug("AFFS: statfs() partsize=%d, reserved=%d
  ",AFFS_SB(sb)->s_partition_size,
  	     AFFS_SB(sb)->s_reserved);
  
  	free          = affs_count_free_blocks(sb);
  	buf->f_type    = AFFS_SUPER_MAGIC;
  	buf->f_bsize   = sb->s_blocksize;
  	buf->f_blocks  = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
  	buf->f_bfree   = free;
  	buf->f_bavail  = free;
a6a2a73c4   Coly Li   fs/affs: return f...
581
582
583
  	buf->f_fsid.val[0] = (u32)id;
  	buf->f_fsid.val[1] = (u32)(id >> 32);
  	buf->f_namelen = 30;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
584
585
  	return 0;
  }
152a08366   Al Viro   new helper: mount...
586
587
  static struct dentry *affs_mount(struct file_system_type *fs_type,
  	int flags, const char *dev_name, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
588
  {
152a08366   Al Viro   new helper: mount...
589
  	return mount_bdev(fs_type, flags, dev_name, data, affs_fill_super);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
590
591
592
593
594
  }
  
  static struct file_system_type affs_fs_type = {
  	.owner		= THIS_MODULE,
  	.name		= "affs",
152a08366   Al Viro   new helper: mount...
595
  	.mount		= affs_mount,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
  	.kill_sb	= kill_block_super,
  	.fs_flags	= FS_REQUIRES_DEV,
  };
  
  static int __init init_affs_fs(void)
  {
  	int err = init_inodecache();
  	if (err)
  		goto out1;
  	err = register_filesystem(&affs_fs_type);
  	if (err)
  		goto out;
  	return 0;
  out:
  	destroy_inodecache();
  out1:
  	return err;
  }
  
  static void __exit exit_affs_fs(void)
  {
  	unregister_filesystem(&affs_fs_type);
  	destroy_inodecache();
  }
  
  MODULE_DESCRIPTION("Amiga filesystem support for Linux");
  MODULE_LICENSE("GPL");
  
  module_init(init_affs_fs)
  module_exit(exit_affs_fs)