Blame view

fs/adfs/super.c 13.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
  /*
   *  linux/fs/adfs/super.c
   *
   *  Copyright (C) 1997-1999 Russell King
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
  #include <linux/init.h>
  #include <linux/buffer_head.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <linux/parser.h>
e11400b0c   Miklos Szeredi   mount options: fi...
14
15
  #include <linux/mount.h>
  #include <linux/seq_file.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
16
  #include <linux/slab.h>
608ba50bd   Al Viro   Cleanup of adfs h...
17
  #include <linux/statfs.h>
c010d1ff4   Eric W. Biederman   userns: Convert a...
18
  #include <linux/user_namespace.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
  #include "adfs.h"
  #include "dir_f.h"
  #include "dir_fplus.h"
e11400b0c   Miklos Szeredi   mount options: fi...
22
23
  #define ADFS_DEFAULT_OWNER_MASK S_IRWXU
  #define ADFS_DEFAULT_OTHER_MASK (S_IRWXG | S_IRWXO)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
  void __adfs_error(struct super_block *sb, const char *function, const char *fmt, ...)
  {
  	char error_buf[128];
  	va_list args;
  
  	va_start(args, fmt);
4a6e617a4   Alexey Dobriyan   [PATCH] fs/*: tri...
30
  	vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  	va_end(args);
  
  	printk(KERN_CRIT "ADFS-fs error (device %s)%s%s: %s
  ",
  		sb->s_id, function ? ": " : "",
  		function ? function : "", error_buf);
  }
  
  static int adfs_checkdiscrecord(struct adfs_discrecord *dr)
  {
  	int i;
  
  	/* sector size must be 256, 512 or 1024 bytes */
  	if (dr->log2secsize != 8 &&
  	    dr->log2secsize != 9 &&
  	    dr->log2secsize != 10)
  		return 1;
  
  	/* idlen must be at least log2secsize + 3 */
  	if (dr->idlen < dr->log2secsize + 3)
  		return 1;
  
  	/* we cannot have such a large disc that we
  	 * are unable to represent sector offsets in
  	 * 32 bits.  This works out at 2.0 TB.
  	 */
  	if (le32_to_cpu(dr->disc_size_high) >> dr->log2secsize)
  		return 1;
  
  	/* idlen must be no greater than 19 v2 [1.0] */
  	if (dr->idlen > 19)
  		return 1;
  
  	/* reserved bytes should be zero */
  	for (i = 0; i < sizeof(dr->unused52); i++)
  		if (dr->unused52[i] != 0)
  			return 1;
  
  	return 0;
  }
  
  static unsigned char adfs_calczonecheck(struct super_block *sb, unsigned char *map)
  {
  	unsigned int v0, v1, v2, v3;
  	int i;
  
  	v0 = v1 = v2 = v3 = 0;
  	for (i = sb->s_blocksize - 4; i; i -= 4) {
  		v0 += map[i]     + (v3 >> 8);
  		v3 &= 0xff;
  		v1 += map[i + 1] + (v0 >> 8);
  		v0 &= 0xff;
  		v2 += map[i + 2] + (v1 >> 8);
  		v1 &= 0xff;
  		v3 += map[i + 3] + (v2 >> 8);
  		v2 &= 0xff;
  	}
  	v0 +=           v3 >> 8;
  	v1 += map[1] + (v0 >> 8);
  	v2 += map[2] + (v1 >> 8);
  	v3 += map[3] + (v2 >> 8);
  
  	return v0 ^ v1 ^ v2 ^ v3;
  }
  
  static int adfs_checkmap(struct super_block *sb, struct adfs_discmap *dm)
  {
  	unsigned char crosscheck = 0, zonecheck = 1;
  	int i;
  
  	for (i = 0; i < ADFS_SB(sb)->s_map_size; i++) {
  		unsigned char *map;
  
  		map = dm[i].dm_bh->b_data;
  
  		if (adfs_calczonecheck(sb, map) != map[0]) {
  			adfs_error(sb, "zone %d fails zonecheck", i);
  			zonecheck = 0;
  		}
  		crosscheck ^= map[3];
  	}
  	if (crosscheck != 0xff)
  		adfs_error(sb, "crosscheck != 0xff");
  	return crosscheck == 0xff && zonecheck;
  }
  
  static void adfs_put_super(struct super_block *sb)
  {
  	int i;
  	struct adfs_sb_info *asb = ADFS_SB(sb);
  
  	for (i = 0; i < asb->s_map_size; i++)
  		brelse(asb->s_map[i].dm_bh);
  	kfree(asb->s_map);
2d1d9b5b5   Al Viro   adfs: delayed fre...
125
  	kfree_rcu(asb, rcu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
  }
34c80b1d9   Al Viro   vfs: switch ->sho...
127
  static int adfs_show_options(struct seq_file *seq, struct dentry *root)
e11400b0c   Miklos Szeredi   mount options: fi...
128
  {
34c80b1d9   Al Viro   vfs: switch ->sho...
129
  	struct adfs_sb_info *asb = ADFS_SB(root->d_sb);
e11400b0c   Miklos Szeredi   mount options: fi...
130

c010d1ff4   Eric W. Biederman   userns: Convert a...
131
132
133
134
  	if (!uid_eq(asb->s_uid, GLOBAL_ROOT_UID))
  		seq_printf(seq, ",uid=%u", from_kuid_munged(&init_user_ns, asb->s_uid));
  	if (!gid_eq(asb->s_gid, GLOBAL_ROOT_GID))
  		seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, asb->s_gid));
e11400b0c   Miklos Szeredi   mount options: fi...
135
136
137
138
  	if (asb->s_owner_mask != ADFS_DEFAULT_OWNER_MASK)
  		seq_printf(seq, ",ownmask=%o", asb->s_owner_mask);
  	if (asb->s_other_mask != ADFS_DEFAULT_OTHER_MASK)
  		seq_printf(seq, ",othmask=%o", asb->s_other_mask);
da23ef054   Stuart Swales   adfs: add hexadec...
139
140
  	if (asb->s_ftsuffix != 0)
  		seq_printf(seq, ",ftsuffix=%u", asb->s_ftsuffix);
e11400b0c   Miklos Szeredi   mount options: fi...
141
142
143
  
  	return 0;
  }
da23ef054   Stuart Swales   adfs: add hexadec...
144
  enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_ftsuffix, Opt_err};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145

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
  	{Opt_uid, "uid=%u"},
  	{Opt_gid, "gid=%u"},
  	{Opt_ownmask, "ownmask=%o"},
  	{Opt_othmask, "othmask=%o"},
da23ef054   Stuart Swales   adfs: add hexadec...
151
  	{Opt_ftsuffix, "ftsuffix=%u"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  	{Opt_err, NULL}
  };
  
  static int parse_options(struct super_block *sb, char *options)
  {
  	char *p;
  	struct adfs_sb_info *asb = ADFS_SB(sb);
  	int option;
  
  	if (!options)
  		return 0;
  
  	while ((p = strsep(&options, ",")) != NULL) {
  		substring_t args[MAX_OPT_ARGS];
  		int token;
  		if (!*p)
  			continue;
  
  		token = match_token(p, tokens, args);
  		switch (token) {
  		case Opt_uid:
  			if (match_int(args, &option))
  				return -EINVAL;
c010d1ff4   Eric W. Biederman   userns: Convert a...
175
176
177
  			asb->s_uid = make_kuid(current_user_ns(), option);
  			if (!uid_valid(asb->s_uid))
  				return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
179
180
181
  			break;
  		case Opt_gid:
  			if (match_int(args, &option))
  				return -EINVAL;
c010d1ff4   Eric W. Biederman   userns: Convert a...
182
183
184
  			asb->s_gid = make_kgid(current_user_ns(), option);
  			if (!gid_valid(asb->s_gid))
  				return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
186
187
188
189
190
191
192
193
194
195
  			break;
  		case Opt_ownmask:
  			if (match_octal(args, &option))
  				return -EINVAL;
  			asb->s_owner_mask = option;
  			break;
  		case Opt_othmask:
  			if (match_octal(args, &option))
  				return -EINVAL;
  			asb->s_other_mask = option;
  			break;
da23ef054   Stuart Swales   adfs: add hexadec...
196
197
198
199
200
  		case Opt_ftsuffix:
  			if (match_int(args, &option))
  				return -EINVAL;
  			asb->s_ftsuffix = option;
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201
202
203
204
205
206
207
208
209
210
211
212
  		default:
  			printk("ADFS-fs: unrecognised mount option \"%s\" "
  					"or missing value
  ", p);
  			return -EINVAL;
  		}
  	}
  	return 0;
  }
  
  static int adfs_remount(struct super_block *sb, int *flags, char *data)
  {
02b9984d6   Theodore Ts'o   fs: push sync_fil...
213
  	sync_filesystem(sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
215
216
  	*flags |= MS_NODIRATIME;
  	return parse_options(sb, data);
  }
726c33422   David Howells   [PATCH] VFS: Perm...
217
  static int adfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218
  {
accb40122   Coly Li   fs/adfs: return f...
219
220
221
  	struct super_block *sb = dentry->d_sb;
  	struct adfs_sb_info *sbi = ADFS_SB(sb);
  	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
223
  
  	buf->f_type    = ADFS_SUPER_MAGIC;
accb40122   Coly Li   fs/adfs: return f...
224
225
226
227
  	buf->f_namelen = sbi->s_namelen;
  	buf->f_bsize   = sb->s_blocksize;
  	buf->f_blocks  = sbi->s_size;
  	buf->f_files   = sbi->s_ids_per_zone * sbi->s_map_size;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
  	buf->f_bavail  =
accb40122   Coly Li   fs/adfs: return f...
229
  	buf->f_bfree   = adfs_map_free(sb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
  	buf->f_ffree   = (long)(buf->f_bfree * buf->f_files) / (long)buf->f_blocks;
accb40122   Coly Li   fs/adfs: return f...
231
232
  	buf->f_fsid.val[0] = (u32)id;
  	buf->f_fsid.val[1] = (u32)(id >> 32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
  
  	return 0;
  }
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
236
  static struct kmem_cache *adfs_inode_cachep;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
239
240
  
  static struct inode *adfs_alloc_inode(struct super_block *sb)
  {
  	struct adfs_inode_info *ei;
d96f18453   Firo Yang   fs/adfs: remove u...
241
  	ei = kmem_cache_alloc(adfs_inode_cachep, GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
243
244
245
  	if (!ei)
  		return NULL;
  	return &ei->vfs_inode;
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
246
  static void adfs_i_callback(struct rcu_head *head)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
  {
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
248
  	struct inode *inode = container_of(head, struct inode, i_rcu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
  	kmem_cache_free(adfs_inode_cachep, ADFS_I(inode));
  }
fa0d7e3de   Nick Piggin   fs: icache RCU fr...
251
252
253
254
  static void adfs_destroy_inode(struct inode *inode)
  {
  	call_rcu(&inode->i_rcu, adfs_i_callback);
  }
51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
255
  static void init_once(void *foo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
257
  {
  	struct adfs_inode_info *ei = (struct adfs_inode_info *) foo;
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
258
  	inode_init_once(&ei->vfs_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
259
  }
20c2df83d   Paul Mundt   mm: Remove slab d...
260

894122db4   Fabian Frederick   fs/adfs/super.c: ...
261
  static int __init init_inodecache(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262
263
264
  {
  	adfs_inode_cachep = kmem_cache_create("adfs_inode_cache",
  					     sizeof(struct adfs_inode_info),
fffb60f93   Paul Jackson   [PATCH] cpuset me...
265
  					     0, (SLAB_RECLAIM_ACCOUNT|
5d097056c   Vladimir Davydov   kmemcg: account c...
266
  						SLAB_MEM_SPREAD|SLAB_ACCOUNT),
20c2df83d   Paul Mundt   mm: Remove slab d...
267
  					     init_once);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
269
270
271
272
273
274
  	if (adfs_inode_cachep == NULL)
  		return -ENOMEM;
  	return 0;
  }
  
  static void destroy_inodecache(void)
  {
8c0a85377   Kirill A. Shutemov   fs: push rcu_barr...
275
276
277
278
279
  	/*
  	 * Make sure all delayed rcu free inodes are flushed before we
  	 * destroy cache.
  	 */
  	rcu_barrier();
1a1d92c10   Alexey Dobriyan   [PATCH] Really ig...
280
  	kmem_cache_destroy(adfs_inode_cachep);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
281
  }
ee9b6d61a   Josef 'Jeff' Sipek   [PATCH] Mark stru...
282
  static const struct super_operations adfs_sops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
284
285
286
287
288
  	.alloc_inode	= adfs_alloc_inode,
  	.destroy_inode	= adfs_destroy_inode,
  	.write_inode	= adfs_write_inode,
  	.put_super	= adfs_put_super,
  	.statfs		= adfs_statfs,
  	.remount_fs	= adfs_remount,
e11400b0c   Miklos Szeredi   mount options: fi...
289
  	.show_options	= adfs_show_options,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  };
  
  static struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr)
  {
  	struct adfs_discmap *dm;
  	unsigned int map_addr, zone_size, nzones;
  	int i, zone;
  	struct adfs_sb_info *asb = ADFS_SB(sb);
  
  	nzones    = asb->s_map_size;
  	zone_size = (8 << dr->log2secsize) - le16_to_cpu(dr->zone_spare);
  	map_addr  = (nzones >> 1) * zone_size -
  		     ((nzones > 1) ? ADFS_DR_SIZE_BITS : 0);
  	map_addr  = signed_asl(map_addr, asb->s_map2blk);
  
  	asb->s_ids_per_zone = zone_size / (asb->s_idlen + 1);
  
  	dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL);
  	if (dm == NULL) {
  		adfs_error(sb, "not enough memory");
b79641063   Sanidhya Kashyap   adfs: return corr...
310
  		return ERR_PTR(-ENOMEM);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
  	}
  
  	for (zone = 0; zone < nzones; zone++, map_addr++) {
  		dm[zone].dm_startbit = 0;
  		dm[zone].dm_endbit   = zone_size;
  		dm[zone].dm_startblk = zone * zone_size - ADFS_DR_SIZE_BITS;
  		dm[zone].dm_bh       = sb_bread(sb, map_addr);
  
  		if (!dm[zone].dm_bh) {
  			adfs_error(sb, "unable to read map");
  			goto error_free;
  		}
  	}
  
  	/* adjust the limits for the first and last map zones */
  	i = zone - 1;
  	dm[0].dm_startblk = 0;
  	dm[0].dm_startbit = ADFS_DR_SIZE_BITS;
  	dm[i].dm_endbit   = (le32_to_cpu(dr->disc_size_high) << (32 - dr->log2bpmb)) +
  			    (le32_to_cpu(dr->disc_size) >> dr->log2bpmb) +
  			    (ADFS_DR_SIZE_BITS - i * zone_size);
  
  	if (adfs_checkmap(sb, dm))
  		return dm;
1725cd0ae   Andrew Morton   [PATCH] adfs erro...
335
  	adfs_error(sb, "map corrupted");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
337
338
339
340
341
  
  error_free:
  	while (--zone >= 0)
  		brelse(dm[zone].dm_bh);
  
  	kfree(dm);
b79641063   Sanidhya Kashyap   adfs: return corr...
342
  	return ERR_PTR(-EIO);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
  }
  
  static inline unsigned long adfs_discsize(struct adfs_discrecord *dr, int block_bits)
  {
  	unsigned long discsize;
  
  	discsize  = le32_to_cpu(dr->disc_size_high) << (32 - block_bits);
  	discsize |= le32_to_cpu(dr->disc_size) >> block_bits;
  
  	return discsize;
  }
  
  static int adfs_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct adfs_discrecord *dr;
  	struct buffer_head *bh;
  	struct object_info root_obj;
  	unsigned char *b_data;
  	struct adfs_sb_info *asb;
  	struct inode *root;
b79641063   Sanidhya Kashyap   adfs: return corr...
363
  	int ret = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
365
  
  	sb->s_flags |= MS_NODIRATIME;
f8314dc60   Panagiotis Issaris   [PATCH] fs: Conve...
366
  	asb = kzalloc(sizeof(*asb), GFP_KERNEL);
4688a066e   Arnd Bergmann   adfs: remove the ...
367
  	if (!asb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
  		return -ENOMEM;
  	sb->s_fs_info = asb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370
371
  
  	/* set default options */
c010d1ff4   Eric W. Biederman   userns: Convert a...
372
373
  	asb->s_uid = GLOBAL_ROOT_UID;
  	asb->s_gid = GLOBAL_ROOT_GID;
e11400b0c   Miklos Szeredi   mount options: fi...
374
375
  	asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK;
  	asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK;
da23ef054   Stuart Swales   adfs: add hexadec...
376
  	asb->s_ftsuffix = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
378
379
380
381
382
383
  
  	if (parse_options(sb, data))
  		goto error;
  
  	sb_set_blocksize(sb, BLOCK_SIZE);
  	if (!(bh = sb_bread(sb, ADFS_DISCRECORD / BLOCK_SIZE))) {
  		adfs_error(sb, "unable to read superblock");
b79641063   Sanidhya Kashyap   adfs: return corr...
384
  		ret = -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385
386
387
388
389
390
391
392
393
394
  		goto error;
  	}
  
  	b_data = bh->b_data + (ADFS_DISCRECORD % BLOCK_SIZE);
  
  	if (adfs_checkbblk(b_data)) {
  		if (!silent)
  			printk("VFS: Can't find an adfs filesystem on dev "
  				"%s.
  ", sb->s_id);
b79641063   Sanidhya Kashyap   adfs: return corr...
395
  		ret = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
396
397
398
399
400
401
402
403
404
405
406
407
408
  		goto error_free_bh;
  	}
  
  	dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET);
  
  	/*
  	 * Do some sanity checks on the ADFS disc record
  	 */
  	if (adfs_checkdiscrecord(dr)) {
  		if (!silent)
  			printk("VPS: Can't find an adfs filesystem on dev "
  				"%s.
  ", sb->s_id);
b79641063   Sanidhya Kashyap   adfs: return corr...
409
  		ret = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
410
411
412
413
414
415
416
417
418
  		goto error_free_bh;
  	}
  
  	brelse(bh);
  	if (sb_set_blocksize(sb, 1 << dr->log2secsize)) {
  		bh = sb_bread(sb, ADFS_DISCRECORD / sb->s_blocksize);
  		if (!bh) {
  			adfs_error(sb, "couldn't read superblock on "
  				"2nd try.");
b79641063   Sanidhya Kashyap   adfs: return corr...
419
  			ret = -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
420
421
422
423
424
  			goto error;
  		}
  		b_data = bh->b_data + (ADFS_DISCRECORD % sb->s_blocksize);
  		if (adfs_checkbblk(b_data)) {
  			adfs_error(sb, "disc record mismatch, very weird!");
b79641063   Sanidhya Kashyap   adfs: return corr...
425
  			ret = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
426
427
428
429
430
431
432
433
  			goto error_free_bh;
  		}
  		dr = (struct adfs_discrecord *)(b_data + ADFS_DR_OFFSET);
  	} else {
  		if (!silent)
  			printk(KERN_ERR "VFS: Unsupported blocksize on dev "
  				"%s.
  ", sb->s_id);
b79641063   Sanidhya Kashyap   adfs: return corr...
434
  		ret = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
435
436
437
438
439
440
441
442
443
444
445
446
447
448
  		goto error;
  	}
  
  	/*
  	 * blocksize on this device should now be set to the ADFS log2secsize
  	 */
  
  	sb->s_magic		= ADFS_SUPER_MAGIC;
  	asb->s_idlen		= dr->idlen;
  	asb->s_map_size		= dr->nzones | (dr->nzones_high << 8);
  	asb->s_map2blk		= dr->log2bpmb - dr->log2secsize;
  	asb->s_size    		= adfs_discsize(dr, sb->s_blocksize_bits);
  	asb->s_version 		= dr->format_version;
  	asb->s_log2sharesize	= dr->log2sharesize;
b79641063   Sanidhya Kashyap   adfs: return corr...
449

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
450
  	asb->s_map = adfs_read_map(sb, dr);
b79641063   Sanidhya Kashyap   adfs: return corr...
451
452
  	if (IS_ERR(asb->s_map)) {
  		ret =  PTR_ERR(asb->s_map);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
  		goto error_free_bh;
b79641063   Sanidhya Kashyap   adfs: return corr...
454
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
457
458
459
460
461
462
463
464
465
466
  
  	brelse(bh);
  
  	/*
  	 * set up enough so that we can read an inode
  	 */
  	sb->s_op = &adfs_sops;
  
  	dr = (struct adfs_discrecord *)(asb->s_map[0].dm_bh->b_data + 4);
  
  	root_obj.parent_id = root_obj.file_id = le32_to_cpu(dr->root);
  	root_obj.name_len  = 0;
da23ef054   Stuart Swales   adfs: add hexadec...
467
468
469
  	/* Set root object date as 01 Jan 1987 00:00:00 */
  	root_obj.loadaddr  = 0xfff0003f;
  	root_obj.execaddr  = 0xec22c000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
470
471
472
  	root_obj.size	   = ADFS_NEWDIR_SIZE;
  	root_obj.attr	   = ADFS_NDA_DIRECTORY   | ADFS_NDA_OWNER_READ |
  			     ADFS_NDA_OWNER_WRITE | ADFS_NDA_PUBLIC_READ;
da23ef054   Stuart Swales   adfs: add hexadec...
473
  	root_obj.filetype  = -1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
474
475
476
477
478
479
480
481
482
483
484
485
486
  
  	/*
  	 * If this is a F+ disk with variable length directories,
  	 * get the root_size from the disc record.
  	 */
  	if (asb->s_version) {
  		root_obj.size = le32_to_cpu(dr->root_size);
  		asb->s_dir     = &adfs_fplus_dir_ops;
  		asb->s_namelen = ADFS_FPLUS_NAME_LEN;
  	} else {
  		asb->s_dir     = &adfs_f_dir_ops;
  		asb->s_namelen = ADFS_F_NAME_LEN;
  	}
da23ef054   Stuart Swales   adfs: add hexadec...
487
488
489
490
491
492
  	/*
  	 * ,xyz hex filetype suffix may be added by driver
  	 * to files that have valid RISC OS filetype
  	 */
  	if (asb->s_ftsuffix)
  		asb->s_namelen += 4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493

96e139141   Al Viro   switch adfs
494
  	sb->s_d_op = &adfs_dentry_operations;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
495
  	root = adfs_iget(sb, &root_obj);
48fde701a   Al Viro   switch open-coded...
496
  	sb->s_root = d_make_root(root);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
497
498
  	if (!sb->s_root) {
  		int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
499
500
501
502
503
  		for (i = 0; i < asb->s_map_size; i++)
  			brelse(asb->s_map[i].dm_bh);
  		kfree(asb->s_map);
  		adfs_error(sb, "get root inode failed
  ");
b79641063   Sanidhya Kashyap   adfs: return corr...
504
  		ret = -EIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
505
  		goto error;
96e139141   Al Viro   switch adfs
506
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
507
508
509
510
511
512
513
  	return 0;
  
  error_free_bh:
  	brelse(bh);
  error:
  	sb->s_fs_info = NULL;
  	kfree(asb);
b79641063   Sanidhya Kashyap   adfs: return corr...
514
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
  }
152a08366   Al Viro   new helper: mount...
516
517
  static struct dentry *adfs_mount(struct file_system_type *fs_type,
  	int flags, const char *dev_name, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
518
  {
152a08366   Al Viro   new helper: mount...
519
  	return mount_bdev(fs_type, flags, dev_name, data, adfs_fill_super);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
520
521
522
523
524
  }
  
  static struct file_system_type adfs_fs_type = {
  	.owner		= THIS_MODULE,
  	.name		= "adfs",
152a08366   Al Viro   new helper: mount...
525
  	.mount		= adfs_mount,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526
527
528
  	.kill_sb	= kill_block_super,
  	.fs_flags	= FS_REQUIRES_DEV,
  };
7f78e0351   Eric W. Biederman   fs: Limit sys_mou...
529
  MODULE_ALIAS_FS("adfs");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
  
  static int __init init_adfs_fs(void)
  {
  	int err = init_inodecache();
  	if (err)
  		goto out1;
  	err = register_filesystem(&adfs_fs_type);
  	if (err)
  		goto out;
  	return 0;
  out:
  	destroy_inodecache();
  out1:
  	return err;
  }
  
  static void __exit exit_adfs_fs(void)
  {
  	unregister_filesystem(&adfs_fs_type);
  	destroy_inodecache();
  }
  
  module_init(init_adfs_fs)
  module_exit(exit_adfs_fs)
608ba50bd   Al Viro   Cleanup of adfs h...
554
  MODULE_LICENSE("GPL");