]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: add mbr_get_partition()
authorKarel Zak <kzak@redhat.com>
Wed, 19 Jun 2013 13:42:47 +0000 (15:42 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:02 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdiskdoslabel.c
fdisks/fdiskdoslabel.h
include/pt-mbr.h
libblkid/src/partitions/dos.c
libblkid/src/partitions/gpt.c
libblkid/src/partitions/minix.c

index 637afd888490e33bddc8c3b54f58db8b48d11408..2781970024b66f2c13263af1448e85439a621f02 100644 (file)
@@ -159,7 +159,7 @@ void dos_init(struct fdisk_context *cxt)
        for (i = 0; i < 4; i++) {
                struct pte *pe = &ptes[i];
 
-               pe->pt_entry = pt_offset(cxt->firstsector, i);
+               pe->pt_entry = mbr_get_partition(cxt->firstsector, i);
                pe->ex_entry = NULL;
                pe->offset = 0;
                pe->sectorbuffer = cxt->firstsector;
@@ -286,7 +286,7 @@ static void read_extended(struct fdisk_context *cxt, int ext)
                if (!extended_offset)
                        extended_offset = dos_partition_get_start(p);
 
-               q = p = pt_offset(pe->sectorbuffer, 0);
+               q = p = mbr_get_partition(pe->sectorbuffer, 0);
                for (i = 0; i < 4; i++, p++) if (dos_partition_get_size(p)) {
                        if (IS_EXTENDED (p->sys_ind)) {
                                if (pe->ex_entry)
@@ -408,7 +408,7 @@ static void get_partition_table_geometry(struct fdisk_context *cxt,
 
        hh = ss = 0;
        for (i=0; i<4; i++) {
-               p = pt_offset(bufp, i);
+               p = mbr_get_partition(bufp, i);
                if (p->sys_ind != 0) {
                        h = p->eh + 1;
                        s = (p->es & 077);
@@ -772,7 +772,7 @@ static int add_partition(struct fdisk_context *cxt, int n, struct fdisk_parttype
                pen->ex_entry = p;
                pe4->offset = extended_offset = start;
                pe4->sectorbuffer = xcalloc(1, cxt->sector_size);
-               pe4->pt_entry = pt_offset(pe4->sectorbuffer, 0);
+               pe4->pt_entry = mbr_get_partition(pe4->sectorbuffer, 0);
                pe4->ex_entry = pe4->pt_entry + 1;
                pe4->changed = 1;
                cxt->label->nparts_max = 5;
@@ -791,7 +791,7 @@ static int add_logical(struct fdisk_context *cxt)
                struct pte *pe = &ptes[cxt->label->nparts_max];
 
                pe->sectorbuffer = xcalloc(1, cxt->sector_size);
-               pe->pt_entry = pt_offset(pe->sectorbuffer, 0);
+               pe->pt_entry = mbr_get_partition(pe->sectorbuffer, 0);
                pe->ex_entry = pe->pt_entry + 1;
                pe->offset = 0;
                pe->changed = 1;
index efac02ecc460916fd05438a8b282619a7e4a9364..bf58b8065b1c62e389b5535501e1bb8a17052250 100644 (file)
@@ -22,9 +22,6 @@ struct pte {
 
 extern struct pte ptes[MAXIMUM_PARTS];
 
-#define pt_offset(b, n)        ((struct dos_partition *)((b) + 0x1be + \
-                                             (n) * sizeof(struct dos_partition)))
-
 extern sector_t extended_offset;
 
 extern struct dos_partition *dos_get_pt_entry(int);
index 5e5e603765571adfef126d6749d755c873f233b8..1279e3cf2290440ffe31a226d256b3dffbbf42a8 100644 (file)
@@ -12,6 +12,12 @@ struct dos_partition {
 
 #define MBR_PT_OFFSET          0x1be
 
+static inline struct dos_partition *mbr_get_partition(unsigned char *mbr, int i)
+{
+       return (struct dos_partition *)
+               (mbr + MBR_PT_OFFSET + (i * sizeof(struct dos_partition)));
+}
+
 /* assemble badly aligned little endian integer */
 static inline unsigned int __dos_assemble_4le(const unsigned char *p)
 {
index c92d8ec0fe9cc8dc261819f7763d0803526b62c6..14f326d200470000163cfd18b0a780fe0e55d301 100644 (file)
@@ -60,7 +60,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
                if (!mbr_is_valid_magic(data))
                        goto leave;
 
-               p0 = (struct dos_partition *) (data + MBR_PT_OFFSET);
+               p0 = mbr_get_partition(data, 0);
 
                /* Usually, the first entry is the real data partition,
                 * the 2nd entry is the next extended partition, or empty,
@@ -159,7 +159,7 @@ static int probe_dos_pt(blkid_probe pr,
                goto nothing;
        }
 
-       p0 = (struct dos_partition *) (data + MBR_PT_OFFSET);
+       p0 = mbr_get_partition(data, 0);
 
        /*
         * Reject PT where boot indicator is not 0 or 0x80.
@@ -180,8 +180,7 @@ static int probe_dos_pt(blkid_probe pr,
                }
        }
 
-       blkid_probe_use_wiper(pr, MBR_PT_OFFSET,
-                                 512 - MBR_PT_OFFSET);
+       blkid_probe_use_wiper(pr, MBR_PT_OFFSET, 512 - MBR_PT_OFFSET);
 
        id = mbr_get_id(data);
        if (id)
index eea9ba437700fbc519feb048e15afb23a61673a2..9894417e7cfbd77c9756663283ccc327f6660ac9 100644 (file)
@@ -172,9 +172,7 @@ static int is_pmbr_valid(blkid_probe pr)
        if (!mbr_is_valid_magic(data))
                goto failed;
 
-       p = (struct dos_partition *) (data + MBR_PT_OFFSET);
-
-       for (i = 0; i < 4; i++, p++) {
+       for (i = 0, p = mbr_get_partition(data, 0); i < 4; i++, p++) {
                if (p->sys_ind == MBR_GPT_PARTITION)
                        goto ok;
        }
index 2aad80f6498a14fe2898d73bcbf75319eed8c2a2..0a597fbc4aa0f38ffd07f488702d22329b5b7ce1 100644 (file)
@@ -46,13 +46,13 @@ static int probe_minix_pt(blkid_probe pr,
                /* caller does not ask for details about partitions */
                return 0;
 
-       p = (struct dos_partition *) (data + MBR_PT_OFFSET);
-
        tab = blkid_partlist_new_parttable(ls, "minix", MBR_PT_OFFSET);
        if (!tab)
                goto err;
 
-       for (i = 0; i < MINIX_MAXPARTITIONS; i++, p++) {
+       for (i = 0, p = mbr_get_partition(data, 0);
+                       i < MINIX_MAXPARTITIONS; i++, p++) {
+
                uint32_t start, size;
                blkid_partition par;