~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/superblocks/minix.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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
 
 
15
 
struct minix_super_block {
16
 
        uint16_t s_ninodes;
17
 
        uint16_t s_nzones;
18
 
        uint16_t s_imap_blocks;
19
 
        uint16_t s_zmap_blocks;
20
 
        uint16_t s_firstdatazone;
21
 
        uint16_t s_log_zone_size;
22
 
        uint32_t s_max_size;
23
 
        uint16_t s_magic;
24
 
        uint16_t s_state;
25
 
        uint32_t s_zones;
26
 
};
27
 
 
28
 
struct minix3_super_block {
29
 
        uint32_t s_ninodes;
30
 
        uint16_t s_pad0;
31
 
        uint16_t s_imap_blocks;
32
 
        uint16_t s_zmap_blocks;
33
 
        uint16_t s_firstdatazone;
34
 
        uint16_t s_log_zone_size;
35
 
        uint16_t s_pad1;
36
 
        uint32_t s_max_size;
37
 
        uint32_t s_zones;
38
 
        uint16_t s_magic;
39
 
        uint16_t s_pad2;
40
 
        uint16_t s_blocksize;
41
 
        uint8_t  s_disk_version;
42
 
};
43
 
 
44
 
#define MINIX_BLOCK_SIZE_BITS 10
45
 
#define MINIX_BLOCK_SIZE (1 << MINIX_BLOCK_SIZE_BITS)
46
 
 
47
 
static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
48
 
{
49
 
        unsigned char *ext;
50
 
        int version;
51
 
 
52
 
        /* for more details see magic strings below */
53
 
        switch(mag->magic[1]) {
54
 
        case '\023':
55
 
                version = 1;
56
 
                break;
57
 
        case '\044':
58
 
                version = 2;
59
 
                break;
60
 
        case '\115':
61
 
                version = 3;
62
 
                break;
63
 
        default:
64
 
                return -1;
65
 
                break;
66
 
        }
67
 
 
68
 
        if (version <= 2) {
69
 
                struct minix_super_block *sb;
70
 
                uint32_t zones;
71
 
 
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)
74
 
                        return -1;
75
 
 
76
 
                zones = version == 2 ? sb->s_zones : sb->s_nzones;
77
 
 
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)
80
 
                        return -1;
81
 
                if (sb->s_zmap_blocks * MINIX_BLOCK_SIZE * 8 < zones - sb->s_firstdatazone + 1)
82
 
                        return -1;
83
 
 
84
 
        } else if (version == 3) {
85
 
                struct minix3_super_block *sb;
86
 
 
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)
89
 
                        return -1;
90
 
 
91
 
        }
92
 
 
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.)
96
 
         */
97
 
        ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2);
98
 
        if (ext && memcmp(ext, "\123\357", 2) == 0)
99
 
                return -1;
100
 
 
101
 
        blkid_probe_sprintf_version(pr, "%d", version);
102
 
        return 0;
103
 
}
104
 
 
105
 
const struct blkid_idinfo minix_idinfo =
106
 
{
107
 
        .name           = "minix",
108
 
        .usage          = BLKID_USAGE_FILESYSTEM,
109
 
        .probefunc      = probe_minix,
110
 
        .magics         =
111
 
        {
112
 
                /* version 1 */
113
 
                { .magic = "\177\023", .len = 2, .kboff = 1, .sboff = 0x10 },
114
 
                { .magic = "\217\023", .len = 2, .kboff = 1, .sboff = 0x10 },
115
 
 
116
 
                /* version 2 */
117
 
                { .magic = "\150\044", .len = 2, .kboff = 1, .sboff = 0x10 },
118
 
                { .magic = "\170\044", .len = 2, .kboff = 1, .sboff = 0x10 },
119
 
 
120
 
                /* version 3 */
121
 
                { .magic = "\132\115", .len = 2, .kboff = 1, .sboff = 0x18 },
122
 
                { NULL }
123
 
        }
124
 
};
125