diff options
author | Karel Zak | 2013-06-19 15:42:47 +0200 |
---|---|---|
committer | Karel Zak | 2013-09-16 16:47:02 +0200 |
commit | e8bf93ded2d055eabefd337b9eb324bde5c6efab (patch) | |
tree | 206b13f05df4286a5bc03fb7d8285550d21a5279 | |
parent | fdisk: (dos) remove inline function from header file (diff) | |
download | kernel-qcow2-util-linux-e8bf93ded2d055eabefd337b9eb324bde5c6efab.tar.gz kernel-qcow2-util-linux-e8bf93ded2d055eabefd337b9eb324bde5c6efab.tar.xz kernel-qcow2-util-linux-e8bf93ded2d055eabefd337b9eb324bde5c6efab.zip |
fdisk: add mbr_get_partition()
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | fdisks/fdiskdoslabel.c | 10 | ||||
-rw-r--r-- | fdisks/fdiskdoslabel.h | 3 | ||||
-rw-r--r-- | include/pt-mbr.h | 6 | ||||
-rw-r--r-- | libblkid/src/partitions/dos.c | 7 | ||||
-rw-r--r-- | libblkid/src/partitions/gpt.c | 4 | ||||
-rw-r--r-- | libblkid/src/partitions/minix.c | 6 |
6 files changed, 18 insertions, 18 deletions
diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index 637afd888..278197002 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -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; diff --git a/fdisks/fdiskdoslabel.h b/fdisks/fdiskdoslabel.h index efac02ecc..bf58b8065 100644 --- a/fdisks/fdiskdoslabel.h +++ b/fdisks/fdiskdoslabel.h @@ -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); diff --git a/include/pt-mbr.h b/include/pt-mbr.h index 5e5e60376..1279e3cf2 100644 --- a/include/pt-mbr.h +++ b/include/pt-mbr.h @@ -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) { diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c index c92d8ec0f..14f326d20 100644 --- a/libblkid/src/partitions/dos.c +++ b/libblkid/src/partitions/dos.c @@ -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) diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c index eea9ba437..9894417e7 100644 --- a/libblkid/src/partitions/gpt.c +++ b/libblkid/src/partitions/gpt.c @@ -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; } diff --git a/libblkid/src/partitions/minix.c b/libblkid/src/partitions/minix.c index 2aad80f64..0a597fbc4 100644 --- a/libblkid/src/partitions/minix.c +++ b/libblkid/src/partitions/minix.c @@ -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; |