diff options
author | Davidlohr Bueso | 2012-05-21 22:28:03 +0200 |
---|---|---|
committer | Karel Zak | 2012-05-23 10:53:05 +0200 |
commit | 823f0fd107415ced8edde12306b9134058aafdc0 (patch) | |
tree | e5f7edcc875cd7013e23c2320232d1943990e5be /fdisk/fdisksgilabel.c | |
parent | fdisk: refactor -s option (diff) | |
download | kernel-qcow2-util-linux-823f0fd107415ced8edde12306b9134058aafdc0.tar.gz kernel-qcow2-util-linux-823f0fd107415ced8edde12306b9134058aafdc0.tar.xz kernel-qcow2-util-linux-823f0fd107415ced8edde12306b9134058aafdc0.zip |
fdisk: introduce fdisk context
This is the first patch that adds the initial parts of the new fdisk internal
API. Two functions are created to both init and deinit the fdisk context. Only
the device's descriptor and path are added as a start and these are replaced
throughout fdisk.c and label specific code.
All logic that opens the file does it with fdisk_new_context_from_filename(),
and this enforces always opening the device with rw, then, if unsuccesfull,
with read-only. This changes the current logic that opens the device with
certain permissions depending on the user given options. For example, -l opens
the device read-only.
This patch passed regression tests and local modifications for sgi/dos/sun disk
labels.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisk/fdisksgilabel.c')
-rw-r--r-- | fdisk/fdisksgilabel.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c index 5e851bc8e..c2ef06d13 100644 --- a/fdisk/fdisksgilabel.c +++ b/fdisk/fdisksgilabel.c @@ -183,7 +183,7 @@ sgi_list_table(int xtra) { int kpi = 0; /* kernel partition ID */ char *type; - w = strlen(disk_device); + w = strlen(cxt->dev_path); if (xtra) { printf(_("\nDisk %s (SGI disk label): %d heads, %llu sectors\n" @@ -191,7 +191,7 @@ sgi_list_table(int xtra) { "%d extra sects/cyl, interleave %d:1\n" "%s\n" "Units = %s of %d * %d bytes\n\n"), - disk_device, heads, sectors, cylinders, + cxt->dev_path, heads, sectors, cylinders, SSWAP16(sgiparam.pcylcount), (int) sgiparam.sparecyl, SSWAP16(sgiparam.ilfact), (char *)sgilabel, @@ -201,7 +201,7 @@ sgi_list_table(int xtra) { printf(_("\nDisk %s (SGI disk label): " "%d heads, %llu sectors, %d cylinders\n" "Units = %s of %d * %d bytes\n\n"), - disk_device, heads, sectors, cylinders, + cxt->dev_path, heads, sectors, cylinders, str_units(PLURAL), units_per_sector, sector_size); } @@ -216,7 +216,7 @@ sgi_list_table(int xtra) { printf( "%2d: %s %4s %9ld %9ld %9ld %2x %s\n", /* fdisk part number */ i+1, -/* device */ partname(disk_device, kpi, w+2), +/* device */ partname(cxt->dev_path, kpi, w+2), /* flags */ (sgi_get_swappartition() == i) ? "swap" : /* flags */ (sgi_get_bootpartition() == i) ? "boot" : " ", /* start */ (long) scround(start), @@ -357,9 +357,9 @@ sgi_write_table(void) { sizeof(*sgilabel))); assert(two_s_complement_32bit_sum( (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0); - if (lseek(fd, 0, SEEK_SET) < 0) + if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0) fatal(unable_to_seek); - if (write(fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE) + if (write(cxt->dev_fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE) fatal(unable_to_write); if (! strncmp((char *) sgilabel->directory[0].vol_file_name, "sgilabel", 8)) { /* @@ -368,10 +368,10 @@ sgi_write_table(void) { */ sgiinfo *info = fill_sgiinfo(); int infostartblock = SSWAP32(sgilabel->directory[0].vol_file_start); - if (lseek(fd, (off_t) infostartblock* + if (lseek(cxt->dev_fd, (off_t) infostartblock* SECTOR_SIZE, SEEK_SET) < 0) fatal(unable_to_seek); - if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE) + if (write(cxt->dev_fd, info, SECTOR_SIZE) != SECTOR_SIZE) fatal(unable_to_write); free(info); } @@ -702,11 +702,11 @@ create_sgilabel(void) other_endian = (BYTE_ORDER == LITTLE_ENDIAN); - res = blkdev_get_sectors(fd, &llsectors); + res = blkdev_get_sectors(cxt->dev_fd, &llsectors); #ifdef HDIO_GETGEO - if (ioctl(fd, HDIO_GETGEO, &geometry) < 0) - err(EXIT_FAILURE, _("HDIO_GETGEO ioctl failed on %s"), disk_device); + if (ioctl(cxt->dev_fd, HDIO_GETGEO, &geometry) < 0) + err(EXIT_FAILURE, _("HDIO_GETGEO ioctl failed on %s"), cxt->dev_path); heads = geometry.heads; sectors = geometry.sectors; @@ -724,7 +724,7 @@ create_sgilabel(void) _("Warning: BLKGETSIZE ioctl failed on %s. " "Using geometry cylinder value of %d.\n" "This value may be truncated for devices" - " > 33.8 GB.\n"), disk_device, cylinders); + " > 33.8 GB.\n"), cxt->dev_path, cylinders); } #endif for (i = 0; i < 4; i++) { |