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>
8
* This file may be redistributed under the terms of the
9
* GNU Lesser General Public License.
13
#include "superblocks.h"
15
struct minix_super_block {
18
uint16_t s_imap_blocks;
19
uint16_t s_zmap_blocks;
20
uint16_t s_firstdatazone;
21
uint16_t s_log_zone_size;
28
struct minix3_super_block {
31
uint16_t s_imap_blocks;
32
uint16_t s_zmap_blocks;
33
uint16_t s_firstdatazone;
34
uint16_t s_log_zone_size;
41
uint8_t s_disk_version;
44
#define MINIX_BLOCK_SIZE_BITS 10
45
#define MINIX_BLOCK_SIZE (1 << MINIX_BLOCK_SIZE_BITS)
47
static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
52
/* for more details see magic strings below */
53
switch(mag->magic[1]) {
69
struct minix_super_block *sb;
72
sb = blkid_probe_get_sb(pr, mag, struct minix_super_block);
73
if (!sb || sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
76
zones = version == 2 ? sb->s_zones : sb->s_nzones;
78
/* sanity checks to be sure that the FS is really minix */
79
if (sb->s_imap_blocks * MINIX_BLOCK_SIZE * 8 < sb->s_ninodes + 1)
81
if (sb->s_zmap_blocks * MINIX_BLOCK_SIZE * 8 < zones - sb->s_firstdatazone + 1)
84
} else if (version == 3) {
85
struct minix3_super_block *sb;
87
sb = blkid_probe_get_sb(pr, mag, struct minix3_super_block);
88
if (!sb || sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
93
/* unfortunately, some parts of ext3 is sometimes possible to
94
* interpreted as minix superblock. So check for extN magic
95
* string. (For extN magic string and offsets see ext.c.)
97
ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2);
98
if (ext && memcmp(ext, "\123\357", 2) == 0)
101
blkid_probe_sprintf_version(pr, "%d", version);
105
const struct blkid_idinfo minix_idinfo =
108
.usage = BLKID_USAGE_FILESYSTEM,
109
.probefunc = probe_minix,
113
{ .magic = "\177\023", .len = 2, .kboff = 1, .sboff = 0x10 },
114
{ .magic = "\217\023", .len = 2, .kboff = 1, .sboff = 0x10 },
117
{ .magic = "\150\044", .len = 2, .kboff = 1, .sboff = 0x10 },
118
{ .magic = "\170\044", .len = 2, .kboff = 1, .sboff = 0x10 },
121
{ .magic = "\132\115", .len = 2, .kboff = 1, .sboff = 0x18 },