Blame view

fs/sysv/super.c 15.1 KB
09c434b8a   Thomas Gleixner   treewide: Add SPD...
1
  // SPDX-License-Identifier: GPL-2.0-only
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  /*
   *  linux/fs/sysv/inode.c
   *
   *  minix/inode.c
   *  Copyright (C) 1991, 1992  Linus Torvalds
   *
   *  xenix/inode.c
   *  Copyright (C) 1992  Doug Evans
   *
   *  coh/inode.c
   *  Copyright (C) 1993  Pascal Haible, Bruno Haible
   *
   *  sysv/inode.c
   *  Copyright (C) 1993  Paul B. Monday
   *
   *  sysv/inode.c
   *  Copyright (C) 1993  Bruno Haible
   *  Copyright (C) 1997, 1998  Krzysztof G. Baranowski
   *
   *  This file contains code for read/parsing the superblock.
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/slab.h>
  #include <linux/buffer_head.h>
  #include "sysv.h"
  
  /*
   * The following functions try to recognize specific filesystems.
   *
   * We recognize:
   * - Xenix FS by its magic number.
   * - SystemV FS by its magic number.
   * - Coherent FS by its funny fname/fpack field.
   * - SCO AFS by s_nfree == 0xffff
   * - V7 FS has no distinguishing features.
   *
   * We discriminate among SystemV4 and SystemV2 FS by the assumption that
   * the time stamp is not < 01-01-1980.
   */
  
  enum {
  	JAN_1_1980 = (10*365 + 2) * 24 * 60 * 60
  };
8de527787   Al Viro   vfs: check i_nlin...
47
  static void detected_xenix(struct sysv_sb_info *sbi, unsigned *max_links)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
50
51
52
53
54
55
56
57
58
59
60
  {
  	struct buffer_head *bh1 = sbi->s_bh1;
  	struct buffer_head *bh2 = sbi->s_bh2;
  	struct xenix_super_block * sbd1;
  	struct xenix_super_block * sbd2;
  
  	if (bh1 != bh2)
  		sbd1 = sbd2 = (struct xenix_super_block *) bh1->b_data;
  	else {
  		/* block size = 512, so bh1 != bh2 */
  		sbd1 = (struct xenix_super_block *) bh1->b_data;
  		sbd2 = (struct xenix_super_block *) (bh2->b_data - 512);
  	}
8de527787   Al Viro   vfs: check i_nlin...
61
  	*max_links = XENIX_LINK_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  	sbi->s_fic_size = XENIX_NICINOD;
  	sbi->s_flc_size = XENIX_NICFREE;
  	sbi->s_sbd1 = (char *)sbd1;
  	sbi->s_sbd2 = (char *)sbd2;
  	sbi->s_sb_fic_count = &sbd1->s_ninode;
  	sbi->s_sb_fic_inodes = &sbd1->s_inode[0];
  	sbi->s_sb_total_free_inodes = &sbd2->s_tinode;
  	sbi->s_bcache_count = &sbd1->s_nfree;
  	sbi->s_bcache = &sbd1->s_free[0];
  	sbi->s_free_blocks = &sbd2->s_tfree;
  	sbi->s_sb_time = &sbd2->s_time;
  	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd1->s_isize);
  	sbi->s_nzones = fs32_to_cpu(sbi, sbd1->s_fsize);
  }
8de527787   Al Viro   vfs: check i_nlin...
76
  static void detected_sysv4(struct sysv_sb_info *sbi, unsigned *max_links)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
78
79
80
81
82
83
84
85
  {
  	struct sysv4_super_block * sbd;
  	struct buffer_head *bh1 = sbi->s_bh1;
  	struct buffer_head *bh2 = sbi->s_bh2;
  
  	if (bh1 == bh2)
  		sbd = (struct sysv4_super_block *) (bh1->b_data + BLOCK_SIZE/2);
  	else
  		sbd = (struct sysv4_super_block *) bh2->b_data;
8de527787   Al Viro   vfs: check i_nlin...
86
  	*max_links = SYSV_LINK_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  	sbi->s_fic_size = SYSV_NICINOD;
  	sbi->s_flc_size = SYSV_NICFREE;
  	sbi->s_sbd1 = (char *)sbd;
  	sbi->s_sbd2 = (char *)sbd;
  	sbi->s_sb_fic_count = &sbd->s_ninode;
  	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
  	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
  	sbi->s_bcache_count = &sbd->s_nfree;
  	sbi->s_bcache = &sbd->s_free[0];
  	sbi->s_free_blocks = &sbd->s_tfree;
  	sbi->s_sb_time = &sbd->s_time;
  	sbi->s_sb_state = &sbd->s_state;
  	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
  	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
  }
8de527787   Al Viro   vfs: check i_nlin...
102
  static void detected_sysv2(struct sysv_sb_info *sbi, unsigned *max_links)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
108
109
110
111
  {
  	struct sysv2_super_block *sbd;
  	struct buffer_head *bh1 = sbi->s_bh1;
  	struct buffer_head *bh2 = sbi->s_bh2;
  
  	if (bh1 == bh2)
  		sbd = (struct sysv2_super_block *) (bh1->b_data + BLOCK_SIZE/2);
  	else
  		sbd = (struct sysv2_super_block *) bh2->b_data;
8de527787   Al Viro   vfs: check i_nlin...
112
  	*max_links = SYSV_LINK_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  	sbi->s_fic_size = SYSV_NICINOD;
  	sbi->s_flc_size = SYSV_NICFREE;
  	sbi->s_sbd1 = (char *)sbd;
  	sbi->s_sbd2 = (char *)sbd;
  	sbi->s_sb_fic_count = &sbd->s_ninode;
  	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
  	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
  	sbi->s_bcache_count = &sbd->s_nfree;
  	sbi->s_bcache = &sbd->s_free[0];
  	sbi->s_free_blocks = &sbd->s_tfree;
  	sbi->s_sb_time = &sbd->s_time;
  	sbi->s_sb_state = &sbd->s_state;
  	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
  	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
  }
8de527787   Al Viro   vfs: check i_nlin...
128
  static void detected_coherent(struct sysv_sb_info *sbi, unsigned *max_links)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
131
132
133
  {
  	struct coh_super_block * sbd;
  	struct buffer_head *bh1 = sbi->s_bh1;
  
  	sbd = (struct coh_super_block *) bh1->b_data;
8de527787   Al Viro   vfs: check i_nlin...
134
  	*max_links = COH_LINK_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  	sbi->s_fic_size = COH_NICINOD;
  	sbi->s_flc_size = COH_NICFREE;
  	sbi->s_sbd1 = (char *)sbd;
  	sbi->s_sbd2 = (char *)sbd;
  	sbi->s_sb_fic_count = &sbd->s_ninode;
  	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
  	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
  	sbi->s_bcache_count = &sbd->s_nfree;
  	sbi->s_bcache = &sbd->s_free[0];
  	sbi->s_free_blocks = &sbd->s_tfree;
  	sbi->s_sb_time = &sbd->s_time;
  	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
  	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
  }
8de527787   Al Viro   vfs: check i_nlin...
149
  static void detected_v7(struct sysv_sb_info *sbi, unsigned *max_links)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
151
152
  {
  	struct buffer_head *bh2 = sbi->s_bh2;
  	struct v7_super_block *sbd = (struct v7_super_block *)bh2->b_data;
8de527787   Al Viro   vfs: check i_nlin...
153
  	*max_links = V7_LINK_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  	sbi->s_fic_size = V7_NICINOD;
  	sbi->s_flc_size = V7_NICFREE;
  	sbi->s_sbd1 = (char *)sbd;
  	sbi->s_sbd2 = (char *)sbd;
  	sbi->s_sb_fic_count = &sbd->s_ninode;
  	sbi->s_sb_fic_inodes = &sbd->s_inode[0];
  	sbi->s_sb_total_free_inodes = &sbd->s_tinode;
  	sbi->s_bcache_count = &sbd->s_nfree;
  	sbi->s_bcache = &sbd->s_free[0];
  	sbi->s_free_blocks = &sbd->s_tfree;
  	sbi->s_sb_time = &sbd->s_time;
  	sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
  	sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
  }
  
  static int detect_xenix(struct sysv_sb_info *sbi, struct buffer_head *bh)
  {
  	struct xenix_super_block *sbd = (struct xenix_super_block *)bh->b_data;
  	if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0x2b5544))
  		sbi->s_bytesex = BYTESEX_LE;
  	else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0x2b5544))
  		sbi->s_bytesex = BYTESEX_BE;
  	else
  		return 0;
  	switch (fs32_to_cpu(sbi, sbd->s_type)) {
  	case 1:
  		sbi->s_type = FSTYPE_XENIX;
  		return 1;
  	case 2:
  		sbi->s_type = FSTYPE_XENIX;
  		return 2;
  	default:
  		return 0;
  	}
  }
  
  static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
  {
  	struct super_block *sb = sbi->s_sb;
  	/* All relevant fields are at the same offsets in R2 and R4 */
  	struct sysv4_super_block * sbd;
  	u32 type;
  
  	sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
  	if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0xfd187e20))
  		sbi->s_bytesex = BYTESEX_LE;
  	else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0xfd187e20))
  		sbi->s_bytesex = BYTESEX_BE;
  	else
  		return 0;
  
  	type = fs32_to_cpu(sbi, sbd->s_type);
   
   	if (fs16_to_cpu(sbi, sbd->s_nfree) == 0xffff) {
   		sbi->s_type = FSTYPE_AFS;
  		sbi->s_forced_ro = 1;
bc98a42c1   David Howells   VFS: Convert sb->...
210
   		if (!sb_rdonly(sb)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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
285
   			printk("SysV FS: SCO EAFS on %s detected, " 
   				"forcing read-only mode.
  ", 
   				sb->s_id);
   		}
   		return type;
   	}
   
  	if (fs32_to_cpu(sbi, sbd->s_time) < JAN_1_1980) {
  		/* this is likely to happen on SystemV2 FS */
  		if (type > 3 || type < 1)
  			return 0;
  		sbi->s_type = FSTYPE_SYSV2;
  		return type;
  	}
  	if ((type > 3 || type < 1) && (type > 0x30 || type < 0x10))
  		return 0;
  
  	/* On Interactive Unix (ISC) Version 4.0/3.x s_type field = 0x10,
  	   0x20 or 0x30 indicates that symbolic links and the 14-character
  	   filename limit is gone. Due to lack of information about this
             feature read-only mode seems to be a reasonable approach... -KGB */
  
  	if (type >= 0x10) {
  		printk("SysV FS: can't handle long file names on %s, "
  		       "forcing read-only mode.
  ", sb->s_id);
  		sbi->s_forced_ro = 1;
  	}
  
  	sbi->s_type = FSTYPE_SYSV4;
  	return type >= 0x10 ? type >> 4 : type;
  }
  
  static int detect_coherent(struct sysv_sb_info *sbi, struct buffer_head *bh)
  {
  	struct coh_super_block * sbd;
  
  	sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
  	if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
  	    || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx
  ",6)))
  		return 0;
  	sbi->s_bytesex = BYTESEX_PDP;
  	sbi->s_type = FSTYPE_COH;
  	return 1;
  }
  
  static int detect_sysv_odd(struct sysv_sb_info *sbi, struct buffer_head *bh)
  {
  	int size = detect_sysv(sbi, bh);
  
  	return size>2 ? 0 : size;
  }
  
  static struct {
  	int block;
  	int (*test)(struct sysv_sb_info *, struct buffer_head *);
  } flavours[] = {
  	{1, detect_xenix},
  	{0, detect_sysv},
  	{0, detect_coherent},
  	{9, detect_sysv_odd},
  	{15,detect_sysv_odd},
  	{18,detect_sysv},
  };
  
  static char *flavour_names[] = {
  	[FSTYPE_XENIX]	= "Xenix",
  	[FSTYPE_SYSV4]	= "SystemV",
  	[FSTYPE_SYSV2]	= "SystemV Release 2",
  	[FSTYPE_COH]	= "Coherent",
  	[FSTYPE_V7]	= "V7",
  	[FSTYPE_AFS]	= "AFS",
  };
8de527787   Al Viro   vfs: check i_nlin...
286
  static void (*flavour_setup[])(struct sysv_sb_info *, unsigned *) = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  	[FSTYPE_XENIX]	= detected_xenix,
  	[FSTYPE_SYSV4]	= detected_sysv4,
  	[FSTYPE_SYSV2]	= detected_sysv2,
  	[FSTYPE_COH]	= detected_coherent,
  	[FSTYPE_V7]	= detected_v7,
  	[FSTYPE_AFS]	= detected_sysv4,
  };
  
  static int complete_read_super(struct super_block *sb, int silent, int size)
  {
  	struct sysv_sb_info *sbi = SYSV_SB(sb);
  	struct inode *root_inode;
  	char *found = flavour_names[sbi->s_type];
  	u_char n_bits = size+8;
  	int bsize = 1 << n_bits;
  	int bsize_4 = bsize >> 2;
  
  	sbi->s_firstinodezone = 2;
8de527787   Al Viro   vfs: check i_nlin...
305
  	flavour_setup[sbi->s_type](sbi, &sb->s_max_links);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306
  	
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
  	sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone;
  	sbi->s_inodes_per_block = bsize >> 6;
  	sbi->s_inodes_per_block_1 = (bsize >> 6)-1;
  	sbi->s_inodes_per_block_bits = n_bits-6;
  	sbi->s_ind_per_block = bsize_4;
  	sbi->s_ind_per_block_2 = bsize_4*bsize_4;
  	sbi->s_toobig_block = 10 + bsize_4 * (1 + bsize_4 * (1 + bsize_4));
  	sbi->s_ind_per_block_bits = n_bits-2;
  
  	sbi->s_ninodes = (sbi->s_firstdatazone - sbi->s_firstinodezone)
  		<< sbi->s_inodes_per_block_bits;
  
  	if (!silent)
  		printk("VFS: Found a %s FS (block size = %ld) on device %s
  ",
  		       found, sb->s_blocksize, sb->s_id);
  
  	sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type;
  	/* set up enough so that it can read an inode */
  	sb->s_op = &sysv_sops;
30304aba6   Al Viro   switch sysv
327
  	if (sbi->s_forced_ro)
1751e8a6c   Linus Torvalds   Rename superblock...
328
  		sb->s_flags |= SB_RDONLY;
b8e1343f6   David Howells   iget: stop the SY...
329
330
  	root_inode = sysv_iget(sb, SYSV_ROOT_INO);
  	if (IS_ERR(root_inode)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
332
333
334
  		printk("SysV FS: get root inode failed
  ");
  		return 0;
  	}
48fde701a   Al Viro   switch open-coded...
335
  	sb->s_root = d_make_root(root_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
  	if (!sb->s_root) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
337
338
339
340
  		printk("SysV FS: get root dentry failed
  ");
  		return 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
342
343
344
345
346
347
348
349
350
  	return 1;
  }
  
  static int sysv_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct buffer_head *bh1, *bh = NULL;
  	struct sysv_sb_info *sbi;
  	unsigned long blocknr;
  	int size = 0, i;
  	
2ecd05ae6   Alexey Dobriyan   [PATCH] fs/*: use...
351
352
353
354
355
  	BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
  	BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
  	BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
  	BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
  	BUILD_BUG_ON(64 != sizeof (struct sysv_inode));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
356

f8314dc60   Panagiotis Issaris   [PATCH] fs: Conve...
357
  	sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
358
359
  	if (!sbi)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
361
362
  
  	sbi->s_sb = sb;
  	sbi->s_block_base = 0;
c07cb01c4   Marco Stornelli   sysv: drop lock/u...
363
  	mutex_init(&sbi->s_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
  	sb->s_fs_info = sbi;
452c27794   Deepa Dinamani   fs: sysv: Initial...
365
366
  	sb->s_time_min = 0;
  	sb->s_time_max = U32_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367
  	sb_set_blocksize(sb, BLOCK_SIZE);
e8c96f8c2   Tobias Klauser   [PATCH] fs: Use A...
368
  	for (i = 0; i < ARRAY_SIZE(flavours) && !size; i++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
396
397
398
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
  		brelse(bh);
  		bh = sb_bread(sb, flavours[i].block);
  		if (!bh)
  			continue;
  		size = flavours[i].test(SYSV_SB(sb), bh);
  	}
  
  	if (!size)
  		goto Eunknown;
  
  	switch (size) {
  		case 1:
  			blocknr = bh->b_blocknr << 1;
  			brelse(bh);
  			sb_set_blocksize(sb, 512);
  			bh1 = sb_bread(sb, blocknr);
  			bh = sb_bread(sb, blocknr + 1);
  			break;
  		case 2:
  			bh1 = bh;
  			break;
  		case 3:
  			blocknr = bh->b_blocknr >> 1;
  			brelse(bh);
  			sb_set_blocksize(sb, 2048);
  			bh1 = bh = sb_bread(sb, blocknr);
  			break;
  		default:
  			goto Ebadsize;
  	}
  
  	if (bh && bh1) {
  		sbi->s_bh1 = bh1;
  		sbi->s_bh2 = bh;
  		if (complete_read_super(sb, silent, size))
  			return 0;
  	}
  
  	brelse(bh1);
  	brelse(bh);
  	sb_set_blocksize(sb, BLOCK_SIZE);
  	printk("oldfs: cannot read superblock
  ");
  failed:
  	kfree(sbi);
  	return -EINVAL;
  
  Eunknown:
  	brelse(bh);
  	if (!silent)
  		printk("VFS: unable to find oldfs superblock on device %s
  ",
  			sb->s_id);
  	goto failed;
  Ebadsize:
  	brelse(bh);
  	if (!silent)
  		printk("VFS: oldfs: unsupported block size (%dKb)
  ",
  			1<<(size-2));
  	goto failed;
  }
6d0b5456e   Lubomir Rintel   fs/sysv/super.c: ...
431
  static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
433
434
  	struct v7_super_block *v7sb;
  	struct sysv_inode *v7i;
6d0b5456e   Lubomir Rintel   fs/sysv/super.c: ...
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
  	struct buffer_head *bh2;
  	struct sysv_sb_info *sbi;
  
  	sbi = sb->s_fs_info;
  
  	/* plausibility check on superblock */
  	v7sb = (struct v7_super_block *) bh->b_data;
  	if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE ||
  	    fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD ||
  	    fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE)
  		return 0;
  
  	/* plausibility check on root inode: it is a directory,
  	   with a nonzero size that is a multiple of 16 */
  	bh2 = sb_bread(sb, 2);
  	if (bh2 == NULL)
  		return 0;
  
  	v7i = (struct sysv_inode *)(bh2->b_data + 64);
  	if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
  	    (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
  	    (fs32_to_cpu(sbi, v7i->i_size) & 017) ||
  	    (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES *
  	     sizeof(struct sysv_dir_entry))) {
  		brelse(bh2);
  		return 0;
  	}
  
  	brelse(bh2);
  	return 1;
  }
  
  static int v7_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct sysv_sb_info *sbi;
  	struct buffer_head *bh;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
472
473
474
475
  
  	if (440 != sizeof (struct v7_super_block))
  		panic("V7 FS: bad super-block size");
  	if (64 != sizeof (struct sysv_inode))
  		panic("sysv fs: bad i-node size");
f8314dc60   Panagiotis Issaris   [PATCH] fs: Conve...
476
  	sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
477
478
  	if (!sbi)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
480
481
482
  
  	sbi->s_sb = sb;
  	sbi->s_block_base = 0;
  	sbi->s_type = FSTYPE_V7;
494755558   Lubomir Rintel   sysv: Add forgott...
483
  	mutex_init(&sbi->s_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
484
  	sb->s_fs_info = sbi;
452c27794   Deepa Dinamani   fs: sysv: Initial...
485
486
  	sb->s_time_min = 0;
  	sb->s_time_max = U32_MAX;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487
488
489
490
491
492
493
494
495
496
  	
  	sb_set_blocksize(sb, 512);
  
  	if ((bh = sb_bread(sb, 1)) == NULL) {
  		if (!silent)
  			printk("VFS: unable to read V7 FS superblock on "
  			       "device %s.
  ", sb->s_id);
  		goto failed;
  	}
6d0b5456e   Lubomir Rintel   fs/sysv/super.c: ...
497
498
499
500
  	/* Try PDP-11 UNIX */
  	sbi->s_bytesex = BYTESEX_PDP;
  	if (v7_sanity_check(sb, bh))
  		goto detected;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501

6d0b5456e   Lubomir Rintel   fs/sysv/super.c: ...
502
503
504
505
  	/* Try PC/IX, v7/x86 */
  	sbi->s_bytesex = BYTESEX_LE;
  	if (v7_sanity_check(sb, bh))
  		goto detected;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506

6d0b5456e   Lubomir Rintel   fs/sysv/super.c: ...
507
508
509
  	goto failed;
  
  detected:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510
511
512
513
514
515
  	sbi->s_bh1 = bh;
  	sbi->s_bh2 = bh;
  	if (complete_read_super(sb, silent, 1))
  		return 0;
  
  failed:
6d0b5456e   Lubomir Rintel   fs/sysv/super.c: ...
516
517
518
  	printk(KERN_ERR "VFS: could not find a valid V7 on %s.
  ",
  		sb->s_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519
520
521
522
523
524
  	brelse(bh);
  	kfree(sbi);
  	return -EINVAL;
  }
  
  /* Every kernel module contains stuff like this. */
152a08366   Al Viro   new helper: mount...
525
526
  static struct dentry *sysv_mount(struct file_system_type *fs_type,
  	int flags, const char *dev_name, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
527
  {
152a08366   Al Viro   new helper: mount...
528
  	return mount_bdev(fs_type, flags, dev_name, data, sysv_fill_super);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529
  }
152a08366   Al Viro   new helper: mount...
530
531
  static struct dentry *v7_mount(struct file_system_type *fs_type,
  	int flags, const char *dev_name, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
532
  {
152a08366   Al Viro   new helper: mount...
533
  	return mount_bdev(fs_type, flags, dev_name, data, v7_fill_super);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
535
536
537
538
  }
  
  static struct file_system_type sysv_fs_type = {
  	.owner		= THIS_MODULE,
  	.name		= "sysv",
152a08366   Al Viro   new helper: mount...
539
  	.mount		= sysv_mount,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540
541
542
  	.kill_sb	= kill_block_super,
  	.fs_flags	= FS_REQUIRES_DEV,
  };
7f78e0351   Eric W. Biederman   fs: Limit sys_mou...
543
  MODULE_ALIAS_FS("sysv");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
544
545
546
547
  
  static struct file_system_type v7_fs_type = {
  	.owner		= THIS_MODULE,
  	.name		= "v7",
152a08366   Al Viro   new helper: mount...
548
  	.mount		= v7_mount,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
549
550
551
  	.kill_sb	= kill_block_super,
  	.fs_flags	= FS_REQUIRES_DEV,
  };
7f78e0351   Eric W. Biederman   fs: Limit sys_mou...
552
  MODULE_ALIAS_FS("v7");
fa7614ddd   Eric W. Biederman   fs: Readd the fs ...
553
  MODULE_ALIAS("v7");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
554

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
  static int __init init_sysv_fs(void)
  {
  	int error;
  
  	error = sysv_init_icache();
  	if (error)
  		goto out;
  	error = register_filesystem(&sysv_fs_type);
  	if (error)
  		goto destroy_icache;
  	error = register_filesystem(&v7_fs_type);
  	if (error)
  		goto unregister;
  	return 0;
  
  unregister:
  	unregister_filesystem(&sysv_fs_type);
  destroy_icache:
  	sysv_destroy_icache();
  out:
  	return error;
  }
  
  static void __exit exit_sysv_fs(void)
  {
  	unregister_filesystem(&sysv_fs_type);
  	unregister_filesystem(&v7_fs_type);
  	sysv_destroy_icache();
  }
  
  module_init(init_sysv_fs)
  module_exit(exit_sysv_fs)
  MODULE_LICENSE("GPL");