summaryrefslogtreecommitdiffstats
path: root/fdisk/fdiskdoslabel.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2012-05-27 21:44:04 +0200
committerKarel Zak2012-06-06 10:11:41 +0200
commit7737f698508a9ad3b6aa0ee7e02cbaa646e815b6 (patch)
treef65d64499351fdfa0154489f6641079e20edf602 /fdisk/fdiskdoslabel.c
parentfdisk: stop buffering welcome message (diff)
downloadkernel-qcow2-util-linux-7737f698508a9ad3b6aa0ee7e02cbaa646e815b6.tar.gz
kernel-qcow2-util-linux-7737f698508a9ad3b6aa0ee7e02cbaa646e815b6.tar.xz
kernel-qcow2-util-linux-7737f698508a9ad3b6aa0ee7e02cbaa646e815b6.zip
fdisk: use context as a parameter
This program heavily uses global variables, which isn't very elegant and can lead to nasty bugs. Modify functions that use fdisk's context current features (descriptor and path), to receive the context as a parameter instead of globally. This includes DOS, SUN, SGI and BSD label code. Another benefit that comes with this is that as the API grows all the information regarding fdisk will be accessible from this structure so we can reduce even more global variables and simply code. This patch passed: - building - regression tests - local dos/sun/bsd partition changes Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisk/fdiskdoslabel.c')
-rw-r--r--fdisk/fdiskdoslabel.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/fdisk/fdiskdoslabel.c b/fdisk/fdiskdoslabel.c
index 4a9369130..1bd27ef5f 100644
--- a/fdisk/fdiskdoslabel.c
+++ b/fdisk/fdiskdoslabel.c
@@ -59,13 +59,13 @@ static int get_nonexisting_partition(int warn, int max)
/* Allocate a buffer and read a partition table sector */
-static void read_pte(int fd, int pno, unsigned long long offset)
+static void read_pte(struct fdisk_context *cxt, int pno, unsigned long long offset)
{
struct pte *pe = &ptes[pno];
pe->offset = offset;
pe->sectorbuffer = xmalloc(sector_size);
- read_sector(fd, offset, pe->sectorbuffer);
+ read_sector(cxt, offset, pe->sectorbuffer);
pe->changed = 0;
pe->part_table = pe->ext_pointer = NULL;
}
@@ -120,7 +120,7 @@ void dos_init(void)
warn_alignment();
}
-static void read_extended(int ext)
+static void read_extended(struct fdisk_context *cxt, int ext)
{
int i;
struct pte *pex;
@@ -156,7 +156,7 @@ static void read_extended(int ext)
return;
}
- read_pte(cxt->dev_fd, partitions, extended_offset + get_start_sect(p));
+ read_pte(cxt, partitions, extended_offset + get_start_sect(p));
if (!extended_offset)
extended_offset = get_start_sect(p);
@@ -317,7 +317,7 @@ void dos_delete_partition(int i)
}
}
-int check_dos_label(void)
+int check_dos_label(struct fdisk_context *cxt)
{
int i;
@@ -334,7 +334,7 @@ int check_dos_label(void)
fprintf(stderr, _("Ignoring extra extended "
"partition %d\n"), i + 1);
else
- read_extended(i);
+ read_extended(cxt, i);
}
}
@@ -658,7 +658,7 @@ void dos_new_partition(void)
}
}
-void dos_write_table(void)
+void dos_write_table(struct fdisk_context *cxt)
{
int i;
@@ -670,7 +670,7 @@ void dos_write_table(void)
}
if (MBRbuffer_changed) {
write_part_table_flag(MBRbuffer);
- write_sector(cxt->dev_fd, 0, MBRbuffer);
+ write_sector(cxt, 0, MBRbuffer);
}
/* EBR (logical partitions) */
for (i = 4; i < partitions; i++) {
@@ -678,7 +678,7 @@ void dos_write_table(void)
if (pe->changed) {
write_part_table_flag(pe->sectorbuffer);
- write_sector(cxt->dev_fd, pe->offset, pe->sectorbuffer);
+ write_sector(cxt, pe->offset, pe->sectorbuffer);
}
}
}