2 * Source: copy of util-linux' partx dos.c
4 * Copyrights of the original file apply
5 * Copyright (c) 2005 Bastian Blank
14 is_extended(int type) {
15 return (type == 5 || type == 0xf || type == 0x85);
19 read_extended_partition(int fd, struct partition *ep, int en,
20 struct slice *sp, int ns)
23 unsigned long start, here, next;
29 next = start = le32_to_cpu(ep->start_sect);
37 bp = (unsigned char *)getblock(fd, here);
41 if (bp[510] != 0x55 || bp[511] != 0xaa)
45 memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
46 if (is_extended(p.sys_type)) {
47 if (p.nr_sects && !moretodo) {
48 next = start + le32_to_cpu(p.start_sect);
54 sp[n].start = here + le32_to_cpu(p.start_sect);
55 sp[n].size = le32_to_cpu(p.nr_sects);
56 sp[n].container = en + 1;
60 "dos_extd_partition: too many slices\n");
71 return (type == 0xEE);
75 read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) {
77 unsigned long offset = all.start;
81 bp = (unsigned char *)getblock(fd, offset);
85 if (bp[510] != 0x55 || bp[511] != 0xaa)
89 memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
90 if (is_gpt(p.sys_type))
93 sp[i].start = le32_to_cpu(p.start_sect);
94 sp[i].size = le32_to_cpu(p.nr_sects);
97 "dos_partition: too many slices\n");
100 if (is_extended(p.sys_type)) {
101 n += read_extended_partition(fd, &p, i, sp+n, ns-n);