9
is_extended(int type) {
10
return (type == 5 || type == 0xf || type == 0x85);
13
/* assemble badly aligned little endian integer */
14
static inline unsigned int
15
assemble4le(unsigned char *p) {
16
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
19
static inline unsigned int
20
partition_start(struct partition *p) {
21
return assemble4le(&(p->start_sect[0]));
24
static inline unsigned int
25
partition_size(struct partition *p) {
26
return assemble4le(&(p->nr_sects[0]));
30
read_extended_partition(int fd, struct partition *ep,
31
struct slice *sp, int ns, int ssf)
34
unsigned long start, here;
40
here = start = partition_start(ep);;
47
bp = getblock(fd, here * ssf); /* in 512 blocks */
51
if (bp[510] != 0x55 || bp[511] != 0xaa)
54
p = (struct partition *) (bp + 0x1be);
56
for (i=0; i<2; i++, p++) {
57
if (partition_size(p) == 0 || is_extended(p->sys_type))
60
sp[n].start = (here + partition_start(p)) * ssf;
61
sp[n].size = partition_size(p) * ssf;
65
"dos_extd_partition: too many slices\n");
72
for (i=0; i<2; i++, p++) {
73
if (partition_size(p) != 0 &&
74
is_extended(p->sys_type)) {
75
here = start + partition_start(p);
86
return (type == 0xEE);
90
read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) {
92
unsigned long offset = all.start;
97
bp = getblock(fd, offset);
101
if (bp[510] != 0x55 || bp[511] != 0xaa)
104
/* msdos PT depends sector size... */
105
if (blkdev_get_sector_size(fd, &ssf) != 0)
106
ssf = DEFAULT_SECTOR_SIZE;
108
/* ... but partx counts everything in 512-byte sectors */
111
p = (struct partition *) (bp + 0x1be);
112
for (i=0; i<4; i++) {
113
if (is_gpt(p->sys_type))
117
p = (struct partition *) (bp + 0x1be);
118
for (i=0; i<4; i++) {
119
/* always add, even if zero length */
121
sp[n].start = partition_start(p) * ssf;
122
sp[n].size = partition_size(p) * ssf;
126
"dos_partition: too many slices\n");
131
p = (struct partition *) (bp + 0x1be);
132
for (i=0; i<4; i++) {
133
if (is_extended(p->sys_type))
134
n += read_extended_partition(fd, p, sp+n, ns-n, ssf);