diff options
author | Davidlohr Bueso | 2012-06-03 20:15:17 +0200 |
---|---|---|
committer | Karel Zak | 2012-06-06 10:30:07 +0200 |
commit | e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf (patch) | |
tree | e18917c027cae4af05e2e5a4002ea6de7a5d7cf8 /fdisk/fdisksgilabel.c | |
parent | fdisk: sun: use sector_t (diff) | |
download | kernel-qcow2-util-linux-e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf.tar.gz kernel-qcow2-util-linux-e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf.tar.xz kernel-qcow2-util-linux-e53ced85bf2dc2a9c501c9eef8681c1b2ffad5cf.zip |
fdisk: add device topology to the API
This patch adds device topology discovery to the internal API. This
functionality is static only to the API and therefore hidden from general fdisk
code. Functionality itself doesn't really change, min_io_size, io_size, logical
and physical sector sizes and alignment offset are added to the fdisk_context
structure and elements are accessed from there. The logical sector size
(sector_size) is now unsigned long instead of unsigned int, this as no effect
otherwise.
A few things to notice:
- The patch is larger than I wanted but we need to modify function parameters
across fdisk and its labels to use the topology data from cxt-> instances.
Hopefully this will be pretty much it regarding this kind of modifications -
perhaps geometry will need something of the like too.
- The -b option must override internal discovery.
- A new helper function has added to verify if the device provides topology
information, this replaces the 'has_topology' global variable.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisk/fdisksgilabel.c')
-rw-r--r-- | fdisk/fdisksgilabel.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c index 14e3443cf..9c425b393 100644 --- a/fdisk/fdisksgilabel.c +++ b/fdisk/fdisksgilabel.c @@ -190,20 +190,20 @@ sgi_list_table(struct fdisk_context *cxt, int xtra) { "%d cylinders, %d physical cylinders\n" "%d extra sects/cyl, interleave %d:1\n" "%s\n" - "Units = %s of %d * %d bytes\n\n"), + "Units = %s of %d * %ld bytes\n\n"), cxt->dev_path, heads, sectors, cylinders, SSWAP16(sgiparam.pcylcount), (int) sgiparam.sparecyl, SSWAP16(sgiparam.ilfact), (char *)sgilabel, str_units(PLURAL), units_per_sector, - sector_size); + cxt->sector_size); } else { printf(_("\nDisk %s (SGI disk label): " "%d heads, %llu sectors, %d cylinders\n" - "Units = %s of %d * %d bytes\n\n"), + "Units = %s of %d * %ld bytes\n\n"), cxt->dev_path, heads, sectors, cylinders, str_units(PLURAL), units_per_sector, - sector_size); + cxt->sector_size); } printf(_("----- partitions -----\n" "Pt# %*s Info Start End Sectors Id System\n"), @@ -563,7 +563,8 @@ sgi_entire(void) { } static void -sgi_set_partition(int i, unsigned int start, unsigned int length, int sys) { +sgi_set_partition(struct fdisk_context *cxt, + int i, unsigned int start, unsigned int length, int sys) { sgilabel->partitions[i].id = SSWAP32(sys); sgilabel->partitions[i].num_sectors = SSWAP32(length); sgilabel->partitions[i].start_sector = SSWAP32(start); @@ -571,16 +572,16 @@ sgi_set_partition(int i, unsigned int start, unsigned int length, int sys) { if (sgi_gaps() < 0) /* rebuild freelist */ printf(_("Partition overlap on the disk.\n")); if (length) - print_partition_size(i + 1, start, start + length, sys); + print_partition_size(cxt, i + 1, start, start + length, sys); } static void -sgi_set_entire(void) { +sgi_set_entire(struct fdisk_context *cxt) { int n; for (n=10; n<partitions; n++) { if (!sgi_get_num_sectors(n)) { - sgi_set_partition(n, 0, sgi_get_lastblock(), SGI_VOLUME); + sgi_set_partition(cxt, n, 0, sgi_get_lastblock(), SGI_VOLUME); break; } } @@ -588,7 +589,7 @@ sgi_set_entire(void) { static void -sgi_set_volhdr(void) +sgi_set_volhdr(struct fdisk_context *cxt) { int n; @@ -599,20 +600,20 @@ sgi_set_volhdr(void) * as IRIX fx uses. */ if (4096 < sgi_get_lastblock()) - sgi_set_partition(n, 0, 4096, SGI_VOLHDR); + sgi_set_partition(cxt, n, 0, 4096, SGI_VOLHDR); break; } } } void -sgi_delete_partition(int i) +sgi_delete_partition(struct fdisk_context *cxt, int i) { - sgi_set_partition(i, 0, 0, 0); + sgi_set_partition(cxt, i, 0, 0, 0); } void -sgi_add_partition(int n, int sys) +sgi_add_partition(struct fdisk_context *cxt, int n, int sys) { char mesg[256]; unsigned int first=0, last=0; @@ -630,8 +631,8 @@ sgi_add_partition(int n, int sys) if ((sgi_entire() == -1) && (sys != SGI_VOLUME)) { printf(_("Attempting to generate entire disk entry automatically.\n")); - sgi_set_entire(); - sgi_set_volhdr(); + sgi_set_entire(cxt); + sgi_set_volhdr(cxt); } if ((sgi_gaps() == 0) && (sys != SGI_VOLUME)) { printf(_("The entire disk is already covered with partitions.\n")); @@ -645,7 +646,7 @@ sgi_add_partition(int n, int sys) for (;;) { if (sys == SGI_VOLUME) { last = sgi_get_lastblock(); - first = read_int(0, 0, last-1, 0, mesg); + first = read_int(cxt, 0, 0, last-1, 0, mesg); if (first != 0) { printf(_("It is highly recommended that eleventh partition\n" "covers the entire disk and is of type `SGI volume'\n")); @@ -653,7 +654,7 @@ sgi_add_partition(int n, int sys) } else { first = freelist[0].first; last = freelist[0].last; - first = read_int(scround(first), scround(first), scround(last)-1, + first = read_int(cxt, scround(first), scround(first), scround(last)-1, 0, mesg); } if (display_in_cyl_units) @@ -669,7 +670,7 @@ sgi_add_partition(int n, int sys) break; } snprintf(mesg, sizeof(mesg), _(" Last %s"), str_units(SINGULAR)); - last = read_int(scround(first), scround(last)-1, scround(last)-1, + last = read_int(cxt, scround(first), scround(last)-1, scround(last)-1, scround(first), mesg)+1; if (display_in_cyl_units) last *= units_per_sector; @@ -678,7 +679,7 @@ sgi_add_partition(int n, int sys) if ((sys == SGI_VOLUME) && (first != 0 || last != sgi_get_lastblock())) printf(_("It is highly recommended that eleventh partition\n" "covers the entire disk and is of type `SGI volume'\n")); - sgi_set_partition(n, first, last-first, sys); + sgi_set_partition(cxt, n, first, last-first, sys); } void @@ -695,7 +696,7 @@ create_sgilabel(struct fdisk_context *cxt) int res; /* the result from the ioctl */ int sec_fac; /* the sector factor */ - sec_fac = sector_size / 512; /* determine the sector factor */ + sec_fac = cxt->sector_size / 512; /* determine the sector factor */ fprintf(stderr, _("Building a new SGI disklabel.\n")); @@ -769,7 +770,7 @@ create_sgilabel(struct fdisk_context *cxt) sgilabel->devparam.unused1 = SSWAP16(0); sgilabel->devparam.nsect = SSWAP16(geometry.sectors); /* sectors/track */ - sgilabel->devparam.bytes = SSWAP16(sector_size); + sgilabel->devparam.bytes = SSWAP16(cxt->sector_size); sgilabel->devparam.ilfact = SSWAP16(1); sgilabel->devparam.flags = SSWAP32(TRACK_FWD|\ IGNORE_ERRORS|RESEEK); @@ -787,11 +788,11 @@ create_sgilabel(struct fdisk_context *cxt) disklabel = SGI_LABEL; partitions = 16; volumes = 15; - sgi_set_entire(); - sgi_set_volhdr(); + sgi_set_entire(cxt); + sgi_set_volhdr(cxt); for (i = 0; i < 4; i++) { if (old[i].sysid) { - sgi_set_partition(i, old[i].start, old[i].nsect, old[i].sysid); + sgi_set_partition(cxt, i, old[i].start, old[i].nsect, old[i].sysid); } } } |