2
* sun (solaris-sparc) partition parsing code
4
* Copyright (C) 2009 Karel Zak <kzak@redhat.com>
6
* This file may be redistributed under the terms of the
7
* GNU Lesser General Public License.
15
#include "partitions.h"
17
/* Supported VTOC setting */
18
#define SUN_VTOC_SANITY 0x600DDEEE /* magic number */
19
#define SUN_VTOC_VERSION 1
21
#define SUN_MAXPARTITIONS 8
24
#define SUN_TAG_WHOLEDISK 0x05
26
struct sun_disklabel {
27
unsigned char info[128]; /* Informative text string */
30
uint32_t version; /* version */
31
char volume[8]; /* volume name */
32
uint16_t nparts; /* num of partitions */
34
struct sun_info { /* partition information */
35
uint16_t id; /* tag */
37
} __attribute__ ((packed)) infos[8];
39
uint16_t padding; /* padding */
40
uint32_t bootinfo[3]; /* info needed by mboot */
41
uint32_t sanity; /* magic number */
42
uint32_t reserved[10]; /* padding */
43
uint32_t timestamp[8]; /* partition timestamp */
44
} __attribute__ ((packed)) vtoc;
46
uint32_t write_reinstruct; /* sectors to skip, writes */
47
uint32_t read_reinstruct; /* sectors to skip, reads */
48
unsigned char spare[148]; /* padding */
49
uint16_t rspeed; /* disk rotational speed */
50
uint16_t pcylcount; /* physical cylinder count */
51
uint16_t sparecyl; /* extra sects per cylinder */
54
uint16_t ilfact; /* interleave factor */
55
uint16_t ncyl; /* data cylinder count */
56
uint16_t nacyl; /* alt. cylinder count */
57
uint16_t ntrks; /* tracks per cylinder <---- */
58
uint16_t nsect; /* sectors per track <---- */
62
struct sun_partition { /* partitions */
63
uint32_t start_cylinder;
65
} __attribute__ ((packed)) partitions[8];
67
uint16_t magic; /* magic number */
68
uint16_t csum; /* label xor'd checksum */
69
} __attribute__ ((packed));
72
uint16_t count_checksum(struct sun_disklabel *label)
74
uint16_t *ptr = ((uint16_t *) (label + 1)) - 1;
77
for (sum = 0; ptr >= ((uint16_t *) label);)
83
static int probe_sun_pt(blkid_probe pr, const struct blkid_idmag *mag)
85
struct sun_disklabel *l;
86
struct sun_partition *p;
87
blkid_parttable tab = NULL;
93
l = (struct sun_disklabel *) blkid_probe_get_sector(pr, 0);
97
if (count_checksum(l)) {
98
DBG(DEBUG_LOWPROBE, printf(
99
"detected corrupted sun disk label -- ignore\n"));
103
if (blkid_partitions_need_typeonly(pr))
104
/* caller does not ask for details about partitions */
107
ls = blkid_probe_get_partlist(pr);
111
tab = blkid_partlist_new_parttable(ls, "sun", 0);
115
/* sectors per cylinder (partition offset is in cylinders...) */
116
spc = be16_to_cpu(l->ntrks) * be16_to_cpu(l->nsect);
119
printf("Sun VTOC sanity=%u version=%u nparts=%u\n",
120
be32_to_cpu(l->vtoc.sanity),
121
be32_to_cpu(l->vtoc.version),
122
be16_to_cpu(l->vtoc.nparts)));
124
/* Check to see if we can use the VTOC table */
125
use_vtoc = ((be32_to_cpu(l->vtoc.sanity) == SUN_VTOC_SANITY) &&
126
(be32_to_cpu(l->vtoc.version) == SUN_VTOC_VERSION) &&
127
(be16_to_cpu(l->vtoc.nparts) <= SUN_MAXPARTITIONS));
129
/* Use 8 partition entries if not specified in validated VTOC */
130
nparts = use_vtoc ? be16_to_cpu(l->vtoc.nparts) : SUN_MAXPARTITIONS;
133
* So that old Linux-Sun partitions continue to work,
134
* alow the VTOC to be used under the additional condition ...
136
use_vtoc = use_vtoc || !(l->vtoc.sanity || l->vtoc.version || l->vtoc.nparts);
138
for (i = 0, p = l->partitions; i < nparts; i++, p++) {
140
blkid_loff_t start, size;
141
uint16_t type = 0, flags = 0;
144
start = be32_to_cpu(p->start_cylinder) * spc;
145
size = be32_to_cpu(p->num_sectors);
147
type = be16_to_cpu(l->vtoc.infos[i].id);
148
flags = be16_to_cpu(l->vtoc.infos[i].flags);
151
if (type == SUN_TAG_WHOLEDISK || !size) {
152
blkid_partlist_increment_partno(ls);
155
par = blkid_partlist_add_partition(ls, tab, start, size);
160
blkid_partition_set_type(par, type);
162
blkid_partition_set_flags(par, flags);
173
const struct blkid_idinfo sun_pt_idinfo =
176
.probefunc = probe_sun_pt,
180
.magic = "\xDA\xBE", /* big-endian magic string */
182
.sboff = offsetof(struct sun_disklabel, magic)