blob: d1def0771a40830bd0b410befb54a4f798a02131 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/fs/sysv/inode.c
4 *
5 * minix/inode.c
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 *
8 * xenix/inode.c
9 * Copyright (C) 1992 Doug Evans
10 *
11 * coh/inode.c
12 * Copyright (C) 1993 Pascal Haible, Bruno Haible
13 *
14 * sysv/inode.c
15 * Copyright (C) 1993 Paul B. Monday
16 *
17 * sysv/inode.c
18 * Copyright (C) 1993 Bruno Haible
19 * Copyright (C) 1997, 1998 Krzysztof G. Baranowski
20 *
21 * This file contains code for read/parsing the superblock.
22 */
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/buffer_head.h>
28#include "sysv.h"
29
30/*
31 * The following functions try to recognize specific filesystems.
32 *
33 * We recognize:
34 * - Xenix FS by its magic number.
35 * - SystemV FS by its magic number.
36 * - Coherent FS by its funny fname/fpack field.
37 * - SCO AFS by s_nfree == 0xffff
38 * - V7 FS has no distinguishing features.
39 *
40 * We discriminate among SystemV4 and SystemV2 FS by the assumption that
41 * the time stamp is not < 01-01-1980.
42 */
43
44enum {
45 JAN_1_1980 = (10*365 + 2) * 24 * 60 * 60
46};
47
Al Viro8de52772012-02-06 12:45:27 -050048static void detected_xenix(struct sysv_sb_info *sbi, unsigned *max_links)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 struct buffer_head *bh1 = sbi->s_bh1;
51 struct buffer_head *bh2 = sbi->s_bh2;
52 struct xenix_super_block * sbd1;
53 struct xenix_super_block * sbd2;
54
55 if (bh1 != bh2)
56 sbd1 = sbd2 = (struct xenix_super_block *) bh1->b_data;
57 else {
58 /* block size = 512, so bh1 != bh2 */
59 sbd1 = (struct xenix_super_block *) bh1->b_data;
60 sbd2 = (struct xenix_super_block *) (bh2->b_data - 512);
61 }
62
Al Viro8de52772012-02-06 12:45:27 -050063 *max_links = XENIX_LINK_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 sbi->s_fic_size = XENIX_NICINOD;
65 sbi->s_flc_size = XENIX_NICFREE;
66 sbi->s_sbd1 = (char *)sbd1;
67 sbi->s_sbd2 = (char *)sbd2;
68 sbi->s_sb_fic_count = &sbd1->s_ninode;
69 sbi->s_sb_fic_inodes = &sbd1->s_inode[0];
70 sbi->s_sb_total_free_inodes = &sbd2->s_tinode;
71 sbi->s_bcache_count = &sbd1->s_nfree;
72 sbi->s_bcache = &sbd1->s_free[0];
73 sbi->s_free_blocks = &sbd2->s_tfree;
74 sbi->s_sb_time = &sbd2->s_time;
75 sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd1->s_isize);
76 sbi->s_nzones = fs32_to_cpu(sbi, sbd1->s_fsize);
77}
78
Al Viro8de52772012-02-06 12:45:27 -050079static void detected_sysv4(struct sysv_sb_info *sbi, unsigned *max_links)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 struct sysv4_super_block * sbd;
82 struct buffer_head *bh1 = sbi->s_bh1;
83 struct buffer_head *bh2 = sbi->s_bh2;
84
85 if (bh1 == bh2)
86 sbd = (struct sysv4_super_block *) (bh1->b_data + BLOCK_SIZE/2);
87 else
88 sbd = (struct sysv4_super_block *) bh2->b_data;
89
Al Viro8de52772012-02-06 12:45:27 -050090 *max_links = SYSV_LINK_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 sbi->s_fic_size = SYSV_NICINOD;
92 sbi->s_flc_size = SYSV_NICFREE;
93 sbi->s_sbd1 = (char *)sbd;
94 sbi->s_sbd2 = (char *)sbd;
95 sbi->s_sb_fic_count = &sbd->s_ninode;
96 sbi->s_sb_fic_inodes = &sbd->s_inode[0];
97 sbi->s_sb_total_free_inodes = &sbd->s_tinode;
98 sbi->s_bcache_count = &sbd->s_nfree;
99 sbi->s_bcache = &sbd->s_free[0];
100 sbi->s_free_blocks = &sbd->s_tfree;
101 sbi->s_sb_time = &sbd->s_time;
102 sbi->s_sb_state = &sbd->s_state;
103 sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
104 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
105}
106
Al Viro8de52772012-02-06 12:45:27 -0500107static void detected_sysv2(struct sysv_sb_info *sbi, unsigned *max_links)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 struct sysv2_super_block *sbd;
110 struct buffer_head *bh1 = sbi->s_bh1;
111 struct buffer_head *bh2 = sbi->s_bh2;
112
113 if (bh1 == bh2)
114 sbd = (struct sysv2_super_block *) (bh1->b_data + BLOCK_SIZE/2);
115 else
116 sbd = (struct sysv2_super_block *) bh2->b_data;
117
Al Viro8de52772012-02-06 12:45:27 -0500118 *max_links = SYSV_LINK_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 sbi->s_fic_size = SYSV_NICINOD;
120 sbi->s_flc_size = SYSV_NICFREE;
121 sbi->s_sbd1 = (char *)sbd;
122 sbi->s_sbd2 = (char *)sbd;
123 sbi->s_sb_fic_count = &sbd->s_ninode;
124 sbi->s_sb_fic_inodes = &sbd->s_inode[0];
125 sbi->s_sb_total_free_inodes = &sbd->s_tinode;
126 sbi->s_bcache_count = &sbd->s_nfree;
127 sbi->s_bcache = &sbd->s_free[0];
128 sbi->s_free_blocks = &sbd->s_tfree;
129 sbi->s_sb_time = &sbd->s_time;
130 sbi->s_sb_state = &sbd->s_state;
131 sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
132 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
133}
134
Al Viro8de52772012-02-06 12:45:27 -0500135static void detected_coherent(struct sysv_sb_info *sbi, unsigned *max_links)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
137 struct coh_super_block * sbd;
138 struct buffer_head *bh1 = sbi->s_bh1;
139
140 sbd = (struct coh_super_block *) bh1->b_data;
141
Al Viro8de52772012-02-06 12:45:27 -0500142 *max_links = COH_LINK_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 sbi->s_fic_size = COH_NICINOD;
144 sbi->s_flc_size = COH_NICFREE;
145 sbi->s_sbd1 = (char *)sbd;
146 sbi->s_sbd2 = (char *)sbd;
147 sbi->s_sb_fic_count = &sbd->s_ninode;
148 sbi->s_sb_fic_inodes = &sbd->s_inode[0];
149 sbi->s_sb_total_free_inodes = &sbd->s_tinode;
150 sbi->s_bcache_count = &sbd->s_nfree;
151 sbi->s_bcache = &sbd->s_free[0];
152 sbi->s_free_blocks = &sbd->s_tfree;
153 sbi->s_sb_time = &sbd->s_time;
154 sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
155 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
156}
157
Al Viro8de52772012-02-06 12:45:27 -0500158static void detected_v7(struct sysv_sb_info *sbi, unsigned *max_links)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 struct buffer_head *bh2 = sbi->s_bh2;
161 struct v7_super_block *sbd = (struct v7_super_block *)bh2->b_data;
162
Al Viro8de52772012-02-06 12:45:27 -0500163 *max_links = V7_LINK_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 sbi->s_fic_size = V7_NICINOD;
165 sbi->s_flc_size = V7_NICFREE;
166 sbi->s_sbd1 = (char *)sbd;
167 sbi->s_sbd2 = (char *)sbd;
168 sbi->s_sb_fic_count = &sbd->s_ninode;
169 sbi->s_sb_fic_inodes = &sbd->s_inode[0];
170 sbi->s_sb_total_free_inodes = &sbd->s_tinode;
171 sbi->s_bcache_count = &sbd->s_nfree;
172 sbi->s_bcache = &sbd->s_free[0];
173 sbi->s_free_blocks = &sbd->s_tfree;
174 sbi->s_sb_time = &sbd->s_time;
175 sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize);
176 sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize);
177}
178
179static int detect_xenix(struct sysv_sb_info *sbi, struct buffer_head *bh)
180{
181 struct xenix_super_block *sbd = (struct xenix_super_block *)bh->b_data;
182 if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0x2b5544))
183 sbi->s_bytesex = BYTESEX_LE;
184 else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0x2b5544))
185 sbi->s_bytesex = BYTESEX_BE;
186 else
187 return 0;
188 switch (fs32_to_cpu(sbi, sbd->s_type)) {
189 case 1:
190 sbi->s_type = FSTYPE_XENIX;
191 return 1;
192 case 2:
193 sbi->s_type = FSTYPE_XENIX;
194 return 2;
195 default:
196 return 0;
197 }
198}
199
200static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
201{
202 struct super_block *sb = sbi->s_sb;
203 /* All relevant fields are at the same offsets in R2 and R4 */
204 struct sysv4_super_block * sbd;
205 u32 type;
206
207 sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
208 if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0xfd187e20))
209 sbi->s_bytesex = BYTESEX_LE;
210 else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0xfd187e20))
211 sbi->s_bytesex = BYTESEX_BE;
212 else
213 return 0;
214
215 type = fs32_to_cpu(sbi, sbd->s_type);
216
217 if (fs16_to_cpu(sbi, sbd->s_nfree) == 0xffff) {
218 sbi->s_type = FSTYPE_AFS;
219 sbi->s_forced_ro = 1;
David Howellsbc98a422017-07-17 08:45:34 +0100220 if (!sb_rdonly(sb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 printk("SysV FS: SCO EAFS on %s detected, "
222 "forcing read-only mode.\n",
223 sb->s_id);
224 }
225 return type;
226 }
227
228 if (fs32_to_cpu(sbi, sbd->s_time) < JAN_1_1980) {
229 /* this is likely to happen on SystemV2 FS */
230 if (type > 3 || type < 1)
231 return 0;
232 sbi->s_type = FSTYPE_SYSV2;
233 return type;
234 }
235 if ((type > 3 || type < 1) && (type > 0x30 || type < 0x10))
236 return 0;
237
238 /* On Interactive Unix (ISC) Version 4.0/3.x s_type field = 0x10,
239 0x20 or 0x30 indicates that symbolic links and the 14-character
240 filename limit is gone. Due to lack of information about this
241 feature read-only mode seems to be a reasonable approach... -KGB */
242
243 if (type >= 0x10) {
244 printk("SysV FS: can't handle long file names on %s, "
245 "forcing read-only mode.\n", sb->s_id);
246 sbi->s_forced_ro = 1;
247 }
248
249 sbi->s_type = FSTYPE_SYSV4;
250 return type >= 0x10 ? type >> 4 : type;
251}
252
253static int detect_coherent(struct sysv_sb_info *sbi, struct buffer_head *bh)
254{
255 struct coh_super_block * sbd;
256
257 sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
258 if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
259 || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
260 return 0;
261 sbi->s_bytesex = BYTESEX_PDP;
262 sbi->s_type = FSTYPE_COH;
263 return 1;
264}
265
266static int detect_sysv_odd(struct sysv_sb_info *sbi, struct buffer_head *bh)
267{
268 int size = detect_sysv(sbi, bh);
269
270 return size>2 ? 0 : size;
271}
272
273static struct {
274 int block;
275 int (*test)(struct sysv_sb_info *, struct buffer_head *);
276} flavours[] = {
277 {1, detect_xenix},
278 {0, detect_sysv},
279 {0, detect_coherent},
280 {9, detect_sysv_odd},
281 {15,detect_sysv_odd},
282 {18,detect_sysv},
283};
284
285static char *flavour_names[] = {
286 [FSTYPE_XENIX] = "Xenix",
287 [FSTYPE_SYSV4] = "SystemV",
288 [FSTYPE_SYSV2] = "SystemV Release 2",
289 [FSTYPE_COH] = "Coherent",
290 [FSTYPE_V7] = "V7",
291 [FSTYPE_AFS] = "AFS",
292};
293
Al Viro8de52772012-02-06 12:45:27 -0500294static void (*flavour_setup[])(struct sysv_sb_info *, unsigned *) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 [FSTYPE_XENIX] = detected_xenix,
296 [FSTYPE_SYSV4] = detected_sysv4,
297 [FSTYPE_SYSV2] = detected_sysv2,
298 [FSTYPE_COH] = detected_coherent,
299 [FSTYPE_V7] = detected_v7,
300 [FSTYPE_AFS] = detected_sysv4,
301};
302
303static int complete_read_super(struct super_block *sb, int silent, int size)
304{
305 struct sysv_sb_info *sbi = SYSV_SB(sb);
306 struct inode *root_inode;
307 char *found = flavour_names[sbi->s_type];
308 u_char n_bits = size+8;
309 int bsize = 1 << n_bits;
310 int bsize_4 = bsize >> 2;
311
312 sbi->s_firstinodezone = 2;
313
Al Viro8de52772012-02-06 12:45:27 -0500314 flavour_setup[sbi->s_type](sbi, &sb->s_max_links);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone;
317 sbi->s_inodes_per_block = bsize >> 6;
318 sbi->s_inodes_per_block_1 = (bsize >> 6)-1;
319 sbi->s_inodes_per_block_bits = n_bits-6;
320 sbi->s_ind_per_block = bsize_4;
321 sbi->s_ind_per_block_2 = bsize_4*bsize_4;
322 sbi->s_toobig_block = 10 + bsize_4 * (1 + bsize_4 * (1 + bsize_4));
323 sbi->s_ind_per_block_bits = n_bits-2;
324
325 sbi->s_ninodes = (sbi->s_firstdatazone - sbi->s_firstinodezone)
326 << sbi->s_inodes_per_block_bits;
327
328 if (!silent)
329 printk("VFS: Found a %s FS (block size = %ld) on device %s\n",
330 found, sb->s_blocksize, sb->s_id);
331
332 sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type;
333 /* set up enough so that it can read an inode */
334 sb->s_op = &sysv_sops;
Al Viro30304ab2010-12-18 11:16:30 -0500335 if (sbi->s_forced_ro)
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800336 sb->s_flags |= SB_RDONLY;
David Howellsb8e13432008-02-07 00:15:47 -0800337 root_inode = sysv_iget(sb, SYSV_ROOT_INO);
338 if (IS_ERR(root_inode)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 printk("SysV FS: get root inode failed\n");
340 return 0;
341 }
Al Viro48fde702012-01-08 22:15:13 -0500342 sb->s_root = d_make_root(root_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (!sb->s_root) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 printk("SysV FS: get root dentry failed\n");
345 return 0;
346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return 1;
348}
349
350static int sysv_fill_super(struct super_block *sb, void *data, int silent)
351{
352 struct buffer_head *bh1, *bh = NULL;
353 struct sysv_sb_info *sbi;
354 unsigned long blocknr;
355 int size = 0, i;
356
Alexey Dobriyan2ecd05a2006-10-11 01:22:05 -0700357 BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
358 BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
359 BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
360 BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
361 BUILD_BUG_ON(64 != sizeof (struct sysv_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Panagiotis Issarisf8314dc2006-09-27 01:49:37 -0700363 sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (!sbi)
365 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 sbi->s_sb = sb;
368 sbi->s_block_base = 0;
Marco Stornellic07cb012012-10-06 12:41:46 +0200369 mutex_init(&sbi->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 sb->s_fs_info = sbi;
Deepa Dinamani452c2772019-03-08 12:40:03 -0800371 sb->s_time_min = 0;
372 sb->s_time_max = U32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 sb_set_blocksize(sb, BLOCK_SIZE);
374
Tobias Klausere8c96f82006-03-24 03:15:34 -0800375 for (i = 0; i < ARRAY_SIZE(flavours) && !size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 brelse(bh);
377 bh = sb_bread(sb, flavours[i].block);
378 if (!bh)
379 continue;
380 size = flavours[i].test(SYSV_SB(sb), bh);
381 }
382
383 if (!size)
384 goto Eunknown;
385
386 switch (size) {
387 case 1:
388 blocknr = bh->b_blocknr << 1;
389 brelse(bh);
390 sb_set_blocksize(sb, 512);
391 bh1 = sb_bread(sb, blocknr);
392 bh = sb_bread(sb, blocknr + 1);
393 break;
394 case 2:
395 bh1 = bh;
396 break;
397 case 3:
398 blocknr = bh->b_blocknr >> 1;
399 brelse(bh);
400 sb_set_blocksize(sb, 2048);
401 bh1 = bh = sb_bread(sb, blocknr);
402 break;
403 default:
404 goto Ebadsize;
405 }
406
407 if (bh && bh1) {
408 sbi->s_bh1 = bh1;
409 sbi->s_bh2 = bh;
410 if (complete_read_super(sb, silent, size))
411 return 0;
412 }
413
414 brelse(bh1);
415 brelse(bh);
416 sb_set_blocksize(sb, BLOCK_SIZE);
417 printk("oldfs: cannot read superblock\n");
418failed:
419 kfree(sbi);
420 return -EINVAL;
421
422Eunknown:
423 brelse(bh);
424 if (!silent)
425 printk("VFS: unable to find oldfs superblock on device %s\n",
426 sb->s_id);
427 goto failed;
428Ebadsize:
429 brelse(bh);
430 if (!silent)
431 printk("VFS: oldfs: unsupported block size (%dKb)\n",
432 1<<(size-2));
433 goto failed;
434}
435
Lubomir Rintel6d0b5452010-08-10 18:03:34 -0700436static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh)
437{
438 struct v7_super_block *v7sb;
439 struct sysv_inode *v7i;
440 struct buffer_head *bh2;
441 struct sysv_sb_info *sbi;
442
443 sbi = sb->s_fs_info;
444
445 /* plausibility check on superblock */
446 v7sb = (struct v7_super_block *) bh->b_data;
447 if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE ||
448 fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD ||
449 fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE)
450 return 0;
451
452 /* plausibility check on root inode: it is a directory,
453 with a nonzero size that is a multiple of 16 */
454 bh2 = sb_bread(sb, 2);
455 if (bh2 == NULL)
456 return 0;
457
458 v7i = (struct sysv_inode *)(bh2->b_data + 64);
459 if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
460 (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
461 (fs32_to_cpu(sbi, v7i->i_size) & 017) ||
462 (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES *
463 sizeof(struct sysv_dir_entry))) {
464 brelse(bh2);
465 return 0;
466 }
467
468 brelse(bh2);
469 return 1;
470}
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472static int v7_fill_super(struct super_block *sb, void *data, int silent)
473{
474 struct sysv_sb_info *sbi;
Lubomir Rintel6d0b5452010-08-10 18:03:34 -0700475 struct buffer_head *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Pavel Skripkin7eb0e282021-11-08 18:35:25 -0800477 BUILD_BUG_ON(sizeof(struct v7_super_block) != 440);
478 BUILD_BUG_ON(sizeof(struct sysv_inode) != 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Panagiotis Issarisf8314dc2006-09-27 01:49:37 -0700480 sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (!sbi)
482 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 sbi->s_sb = sb;
485 sbi->s_block_base = 0;
486 sbi->s_type = FSTYPE_V7;
Lubomir Rintel49475552013-09-18 12:39:16 +0200487 mutex_init(&sbi->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 sb->s_fs_info = sbi;
Deepa Dinamani452c2772019-03-08 12:40:03 -0800489 sb->s_time_min = 0;
490 sb->s_time_max = U32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 sb_set_blocksize(sb, 512);
493
494 if ((bh = sb_bread(sb, 1)) == NULL) {
495 if (!silent)
496 printk("VFS: unable to read V7 FS superblock on "
497 "device %s.\n", sb->s_id);
498 goto failed;
499 }
500
Lubomir Rintel6d0b5452010-08-10 18:03:34 -0700501 /* Try PDP-11 UNIX */
502 sbi->s_bytesex = BYTESEX_PDP;
503 if (v7_sanity_check(sb, bh))
504 goto detected;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Lubomir Rintel6d0b5452010-08-10 18:03:34 -0700506 /* Try PC/IX, v7/x86 */
507 sbi->s_bytesex = BYTESEX_LE;
508 if (v7_sanity_check(sb, bh))
509 goto detected;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Lubomir Rintel6d0b5452010-08-10 18:03:34 -0700511 goto failed;
512
513detected:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 sbi->s_bh1 = bh;
515 sbi->s_bh2 = bh;
516 if (complete_read_super(sb, silent, 1))
517 return 0;
518
519failed:
Lubomir Rintel6d0b5452010-08-10 18:03:34 -0700520 printk(KERN_ERR "VFS: could not find a valid V7 on %s.\n",
521 sb->s_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 brelse(bh);
523 kfree(sbi);
524 return -EINVAL;
525}
526
527/* Every kernel module contains stuff like this. */
528
Al Viro152a0832010-07-25 00:46:55 +0400529static struct dentry *sysv_mount(struct file_system_type *fs_type,
530 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Al Viro152a0832010-07-25 00:46:55 +0400532 return mount_bdev(fs_type, flags, dev_name, data, sysv_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
Al Viro152a0832010-07-25 00:46:55 +0400535static struct dentry *v7_mount(struct file_system_type *fs_type,
536 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Al Viro152a0832010-07-25 00:46:55 +0400538 return mount_bdev(fs_type, flags, dev_name, data, v7_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
541static struct file_system_type sysv_fs_type = {
542 .owner = THIS_MODULE,
543 .name = "sysv",
Al Viro152a0832010-07-25 00:46:55 +0400544 .mount = sysv_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .kill_sb = kill_block_super,
546 .fs_flags = FS_REQUIRES_DEV,
547};
Eric W. Biederman7f78e032013-03-02 19:39:14 -0800548MODULE_ALIAS_FS("sysv");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550static struct file_system_type v7_fs_type = {
551 .owner = THIS_MODULE,
552 .name = "v7",
Al Viro152a0832010-07-25 00:46:55 +0400553 .mount = v7_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .kill_sb = kill_block_super,
555 .fs_flags = FS_REQUIRES_DEV,
556};
Eric W. Biederman7f78e032013-03-02 19:39:14 -0800557MODULE_ALIAS_FS("v7");
Eric W. Biedermanfa7614dd2013-03-12 18:27:41 -0700558MODULE_ALIAS("v7");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560static int __init init_sysv_fs(void)
561{
562 int error;
563
564 error = sysv_init_icache();
565 if (error)
566 goto out;
567 error = register_filesystem(&sysv_fs_type);
568 if (error)
569 goto destroy_icache;
570 error = register_filesystem(&v7_fs_type);
571 if (error)
572 goto unregister;
573 return 0;
574
575unregister:
576 unregister_filesystem(&sysv_fs_type);
577destroy_icache:
578 sysv_destroy_icache();
579out:
580 return error;
581}
582
583static void __exit exit_sysv_fs(void)
584{
585 unregister_filesystem(&sysv_fs_type);
586 unregister_filesystem(&v7_fs_type);
587 sysv_destroy_icache();
588}
589
590module_init(init_sysv_fs)
591module_exit(exit_sysv_fs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592MODULE_LICENSE("GPL");