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

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/partitions/sgi.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
 
 * sgi partition parsing code
3
 
 *
4
 
 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
5
 
 *
6
 
 * This file may be redistributed under the terms of the
7
 
 * GNU Lesser General Public License.
8
 
 *
9
 
 */
10
 
#include <stdio.h>
11
 
#include <string.h>
12
 
#include <stdlib.h>
13
 
#include <stdint.h>
14
 
 
15
 
#include "partitions.h"
16
 
 
17
 
#define SGI_MAXPARTITIONS       16
18
 
 
19
 
/* partition type */
20
 
#define SGI_TYPE_VOLHDR         0x00
21
 
#define SGI_TYPE_VOLULME        0x06    /* entire disk */
22
 
 
23
 
struct sgi_device_parameter {
24
 
        unsigned char skew;
25
 
        unsigned char gap1;
26
 
        unsigned char gap2;
27
 
        unsigned char sparecyl;
28
 
 
29
 
        uint16_t pcylcount;
30
 
        uint16_t head_vol0;
31
 
        uint16_t ntrks;         /* tracks in cyl 0 or vol 0 */
32
 
 
33
 
        unsigned char cmd_tag_queue_depth;
34
 
        unsigned char unused0;
35
 
 
36
 
        uint16_t unused1;
37
 
        uint16_t nsect;         /* sectors/tracks in cyl 0 or vol 0 */
38
 
        uint16_t bytes;
39
 
        uint16_t ilfact;
40
 
        uint32_t flags;         /* controller flags */
41
 
        uint32_t datarate;
42
 
        uint32_t retries_on_error;
43
 
        uint32_t ms_per_word;
44
 
        uint16_t xylogics_gap1;
45
 
        uint16_t xylogics_syncdelay;
46
 
        uint16_t xylogics_readdelay;
47
 
        uint16_t xylogics_gap2;
48
 
        uint16_t xylogics_readgate;
49
 
        uint16_t xylogics_writecont;
50
 
} __attribute__((packed));
51
 
 
52
 
struct sgi_disklabel {
53
 
        uint32_t magic;                 /* magic number */
54
 
        uint16_t root_part_num;         /* # root partition */
55
 
        uint16_t swap_part_num;         /* # swap partition */
56
 
        unsigned char boot_file[16];    /* name of boot file */
57
 
 
58
 
        struct sgi_device_parameter     devparam;       /* not used now */
59
 
 
60
 
        struct sgi_volume {
61
 
                unsigned char name[8];  /* name of volume */
62
 
                uint32_t block_num;     /* logical block number */
63
 
                uint32_t num_bytes;     /* how big, in bytes */
64
 
        } __attribute__((packed)) volume[15];
65
 
 
66
 
        struct sgi_partition {
67
 
                uint32_t num_blocks;    /* size in logical blocks */
68
 
                uint32_t first_block;   /* first logical block */
69
 
                uint32_t type;          /* type of this partition */
70
 
        } __attribute__((packed)) partitions[SGI_MAXPARTITIONS];
71
 
 
72
 
        /* checksum is the 32bit 2's complement sum of the disklabel */
73
 
        uint32_t csum;                  /* disk label checksum */
74
 
        uint32_t padding;               /* padding */
75
 
} __attribute__((packed));
76
 
 
77
 
static uint32_t count_checksum(struct sgi_disklabel *label)
78
 
{
79
 
        int i;
80
 
        uint32_t *ptr = (uint32_t *) label;
81
 
        uint32_t sum = 0;
82
 
 
83
 
        i = sizeof(*label) / sizeof(*ptr);
84
 
 
85
 
        while (i--)
86
 
                sum += be32_to_cpu(ptr[i]);
87
 
 
88
 
        return sum;
89
 
}
90
 
 
91
 
 
92
 
static int probe_sgi_pt(blkid_probe pr, const struct blkid_idmag *mag)
93
 
{
94
 
        struct sgi_disklabel *l;
95
 
        struct sgi_partition *p;
96
 
        blkid_parttable tab = NULL;
97
 
        blkid_partlist ls;
98
 
        int i;
99
 
 
100
 
        l = (struct sgi_disklabel *) blkid_probe_get_sector(pr, 0);
101
 
        if (!l)
102
 
                goto nothing;
103
 
 
104
 
        if (count_checksum(l)) {
105
 
                DBG(DEBUG_LOWPROBE, printf(
106
 
                        "detected corrupted sgi disk label -- ignore\n"));
107
 
                goto nothing;
108
 
        }
109
 
 
110
 
        if (blkid_partitions_need_typeonly(pr))
111
 
                /* caller does not ask for details about partitions */
112
 
                return 0;
113
 
 
114
 
        ls = blkid_probe_get_partlist(pr);
115
 
        if (!ls)
116
 
                goto err;
117
 
 
118
 
        tab = blkid_partlist_new_parttable(ls, "sgi", 0);
119
 
        if (!tab)
120
 
                goto err;
121
 
 
122
 
        for(i = 0, p = &l->partitions[0]; i < SGI_MAXPARTITIONS; i++, p++) {
123
 
                uint32_t size = be32_to_cpu(p->num_blocks);
124
 
                uint32_t start = be32_to_cpu(p->first_block);
125
 
                uint32_t type = be32_to_cpu(p->type);
126
 
                blkid_partition par;
127
 
 
128
 
                if (size == 0 || type == SGI_TYPE_VOLULME ||
129
 
                                 type == SGI_TYPE_VOLHDR) {
130
 
                        blkid_partlist_increment_partno(ls);
131
 
                        continue;
132
 
                }
133
 
                par = blkid_partlist_add_partition(ls, tab, start, size);
134
 
                if (!par)
135
 
                        goto err;
136
 
 
137
 
                blkid_partition_set_type(par, type);
138
 
        }
139
 
 
140
 
        return 0;
141
 
 
142
 
nothing:
143
 
        return 1;
144
 
err:
145
 
        return -1;
146
 
}
147
 
 
148
 
const struct blkid_idinfo sgi_pt_idinfo =
149
 
{
150
 
        .name           = "sgi",
151
 
        .probefunc      = probe_sgi_pt,
152
 
        .magics         =
153
 
        {
154
 
                { .magic = "\x0B\xE5\xA9\x41", .len = 4 },
155
 
                { NULL }
156
 
        }
157
 
};
158