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

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/superblocks/sysv.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) 2008 Karel Zak <kzak@redhat.com>
3
 
 *
4
 
 * This is written from sratch according to Linux kernel fs/sysv/super.c file.
5
 
 * It seems that sysv probing code in libvolume_id and also in the original
6
 
 * blkid is useless.
7
 
 *
8
 
 * This file may be redistributed under the terms of the
9
 
 * GNU Lesser General Public License.
10
 
 */
11
 
#include <stdio.h>
12
 
#include <stdlib.h>
13
 
#include <unistd.h>
14
 
#include <stdint.h>
15
 
#include <stddef.h>
16
 
 
17
 
#include "superblocks.h"
18
 
 
19
 
#define XENIX_NICINOD                           100
20
 
#define XENIX_NICFREE                           100
21
 
 
22
 
struct xenix_super_block {
23
 
        uint16_t        s_isize;
24
 
        uint32_t        s_fsize;
25
 
        uint16_t        s_nfree;
26
 
        uint32_t        s_free[XENIX_NICFREE];
27
 
        uint16_t        s_ninode;
28
 
        uint16_t        s_inode[XENIX_NICINOD];
29
 
        uint8_t         s_flock;
30
 
        uint8_t         s_ilock;
31
 
        uint8_t         s_fmod;
32
 
        uint8_t         s_ronly;
33
 
        uint32_t        s_time;
34
 
        uint32_t        s_tfree;
35
 
        uint16_t        s_tinode;
36
 
        uint16_t        s_dinfo[4];
37
 
        uint8_t         s_fname[6];
38
 
        uint8_t         s_fpack[6];
39
 
        uint8_t         s_clean;
40
 
        uint8_t         s_fill[371];
41
 
        uint32_t        s_magic;
42
 
        uint32_t        s_type;
43
 
} __attribute__((packed));
44
 
 
45
 
 
46
 
#define SYSV_NICINOD                    100
47
 
#define SYSV_NICFREE                    50
48
 
 
49
 
struct sysv_super_block
50
 
{
51
 
        uint16_t        s_isize;
52
 
        uint16_t        s_pad0;
53
 
        uint32_t        s_fsize;
54
 
        uint16_t        s_nfree;
55
 
        uint16_t        s_pad1;
56
 
        uint32_t        s_free[SYSV_NICFREE];
57
 
        uint16_t        s_ninode;
58
 
        uint16_t        s_pad2;
59
 
        uint16_t        s_inode[SYSV_NICINOD];
60
 
        uint8_t         s_flock;
61
 
        uint8_t         s_ilock;
62
 
        uint8_t         s_fmod;
63
 
        uint8_t         s_ronly;
64
 
        uint32_t        s_time;
65
 
        uint16_t        s_dinfo[4];
66
 
        uint32_t        s_tfree;
67
 
        uint16_t        s_tinode;
68
 
        uint16_t        s_pad3;
69
 
        uint8_t         s_fname[6];
70
 
        uint8_t         s_fpack[6];
71
 
        uint32_t        s_fill[12];
72
 
        uint32_t        s_state;
73
 
        uint32_t        s_magic;
74
 
        uint32_t        s_type;
75
 
};
76
 
 
77
 
static int probe_xenix(blkid_probe pr, const struct blkid_idmag *mag)
78
 
{
79
 
        struct xenix_super_block *sb;
80
 
 
81
 
        sb = blkid_probe_get_sb(pr, mag, struct xenix_super_block);
82
 
        if (!sb)
83
 
                return -1;
84
 
        blkid_probe_set_label(pr, sb->s_fname, sizeof(sb->s_fname));
85
 
        return 0;
86
 
}
87
 
 
88
 
#define SYSV_BLOCK_SIZE 1024
89
 
 
90
 
/* Note that we don't probe for Coherent FS, this FS does not have
91
 
 * magic string. (It requires to probe fname/fpack field..)
92
 
 */
93
 
static int probe_sysv(blkid_probe pr, const struct blkid_idmag *mag)
94
 
{
95
 
        struct sysv_super_block *sb;
96
 
        int blocks[] = {0, 9, 15, 18};
97
 
        int i;
98
 
 
99
 
        for (i = 0; i < ARRAY_SIZE(blocks); i++) {
100
 
                int off = blocks[i] * SYSV_BLOCK_SIZE + SYSV_BLOCK_SIZE/2;
101
 
 
102
 
                sb = (struct sysv_super_block *)
103
 
                        blkid_probe_get_buffer(pr,
104
 
                                        off,
105
 
                                        sizeof(struct sysv_super_block));
106
 
                if (!sb)
107
 
                        return -1;
108
 
 
109
 
                if (sb->s_magic == cpu_to_le32(0xfd187e20) ||
110
 
                    sb->s_magic == cpu_to_be32(0xfd187e20)) {
111
 
 
112
 
                        if (blkid_probe_set_label(pr, sb->s_fname,
113
 
                                                sizeof(sb->s_fname)))
114
 
                                return -1;
115
 
 
116
 
                        if (blkid_probe_set_magic(pr,
117
 
                                        off + offsetof(struct sysv_super_block,
118
 
                                                                s_magic),
119
 
                                        sizeof(sb->s_magic),
120
 
                                        (unsigned char *) &sb->s_magic))
121
 
                                return -1;
122
 
 
123
 
                        return 0;
124
 
                }
125
 
        }
126
 
        return 1;
127
 
}
128
 
 
129
 
const struct blkid_idinfo xenix_idinfo =
130
 
{
131
 
        .name           = "xenix",
132
 
        .usage          = BLKID_USAGE_FILESYSTEM,
133
 
        .probefunc      = probe_xenix,
134
 
        .magics         =
135
 
        {
136
 
                { .magic = "\x2b\x55\x44", .len = 3, .kboff = 1, .sboff = 0x400 },
137
 
                { .magic = "\x44\x55\x2b", .len = 3, .kboff = 1, .sboff = 0x400 },
138
 
                { NULL }
139
 
        }
140
 
};
141
 
 
142
 
const struct blkid_idinfo sysv_idinfo =
143
 
{
144
 
        .name           = "sysv",
145
 
        .usage          = BLKID_USAGE_FILESYSTEM,
146
 
        .probefunc      = probe_sysv,
147
 
 
148
 
        /* SYSV is BE and LE and superblock could be on four positions. It's
149
 
         * simpler to probe for the magic string by .probefunc().
150
 
         */
151
 
        .magics         = BLKID_NONE_MAGIC
152
 
};
153