blob: 54e71396bf79f734e9143c97c2b42fcf93207575 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Copyright (C) 1999 by Andries Brouwer
3 * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
4 * Copyright (C) 2001 by Andreas Dilger
5 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
7 *
8 * This file may be redistributed under the terms of the
9 * GNU Lesser General Public License.
10 */
11
12#include <string.h>
13#include "superblocks.h"
14#include "minix.h"
15
16static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
17{
18 unsigned char *ext;
19 int version;
20
21 /* for more details see magic strings below */
22 switch(mag->magic[1]) {
23 case '\023':
24 version = 1;
25 break;
26 case '\044':
27 version = 2;
28 break;
29 case '\115':
30 version = 3;
31 break;
32 default:
33 return -1;
34 break;
35 }
36
37 if (version <= 2) {
38 struct minix_super_block *sb;
39 uint32_t zones;
40
41 sb = blkid_probe_get_sb(pr, mag, struct minix_super_block);
42 if (!sb || sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
43 return -1;
44
45 zones = version == 2 ? sb->s_zones : sb->s_nzones;
46
47 /* sanity checks to be sure that the FS is really minix */
48 if (sb->s_imap_blocks * MINIX_BLOCK_SIZE * 8 < sb->s_ninodes + 1)
49 return -1;
50 if (sb->s_zmap_blocks * MINIX_BLOCK_SIZE * 8 < zones - sb->s_firstdatazone + 1)
51 return -1;
52
53 } else if (version == 3) {
54 struct minix3_super_block *sb;
55
56 sb = blkid_probe_get_sb(pr, mag, struct minix3_super_block);
57 if (!sb || sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
58 return -1;
59
60 }
61
62 /* unfortunately, some parts of ext3 is sometimes possible to
63 * interpreted as minix superblock. So check for extN magic
64 * string. (For extN magic string and offsets see ext.c.)
65 */
66 ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2);
67 if (ext && memcmp(ext, "\123\357", 2) == 0)
68 return -1;
69
70 blkid_probe_sprintf_version(pr, "%d", version);
71 return 0;
72}
73
74const struct blkid_idinfo minix_idinfo =
75{
76 .name = "minix",
77 .usage = BLKID_USAGE_FILESYSTEM,
78 .probefunc = probe_minix,
79 .magics =
80 {
81 /* version 1 */
82 { .magic = "\177\023", .len = 2, .kboff = 1, .sboff = 0x10 },
83 { .magic = "\217\023", .len = 2, .kboff = 1, .sboff = 0x10 },
84
85 /* version 2 */
86 { .magic = "\150\044", .len = 2, .kboff = 1, .sboff = 0x10 },
87 { .magic = "\170\044", .len = 2, .kboff = 1, .sboff = 0x10 },
88
89 /* version 3 */
90 { .magic = "\132\115", .len = 2, .kboff = 1, .sboff = 0x18 },
91 { NULL }
92 }
93};
94