diff options
author | Davidlohr Bueso | 2012-07-23 18:47:42 +0200 |
---|---|---|
committer | Karel Zak | 2012-07-24 09:13:59 +0200 |
commit | fae7b1bcb5eab5c470b15fd8c491f42244210837 (patch) | |
tree | 2aba16eca7a0cf274e798e23490a38cb4262f51c /fdisks/fdiskdoslabel.c | |
parent | fdisk: API: add delete partition to label operations (diff) | |
download | kernel-qcow2-util-linux-fae7b1bcb5eab5c470b15fd8c491f42244210837.tar.gz kernel-qcow2-util-linux-fae7b1bcb5eab5c470b15fd8c491f42244210837.tar.xz kernel-qcow2-util-linux-fae7b1bcb5eab5c470b15fd8c491f42244210837.zip |
fdisk: API: add write to label operations
[kzak@redhat.com: - rename functions
- use errno]
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisks/fdiskdoslabel.c')
-rw-r--r-- | fdisks/fdiskdoslabel.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index d9369b691..398e5e040 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -706,9 +706,18 @@ void dos_new_partition(struct fdisk_context *cxt) } } -void dos_write_table(struct fdisk_context *cxt) +static int write_sector(struct fdisk_context *cxt, sector_t secno, + unsigned char *buf) { - int i; + seek_sector(cxt, secno); + if (write(cxt->dev_fd, buf, cxt->sector_size) != (ssize_t) cxt->sector_size) + return -errno; + return 0; +} + +static int dos_write_disklabel(struct fdisk_context *cxt) +{ + int i, rc = 0; /* MBR (primary partitions) */ if (!MBRbuffer_changed) { @@ -718,7 +727,9 @@ void dos_write_table(struct fdisk_context *cxt) } if (MBRbuffer_changed) { mbr_set_magic(cxt->firstsector); - write_sector(cxt, 0, cxt->firstsector); + rc = write_sector(cxt, 0, cxt->firstsector); + if (rc) + goto done; } /* EBR (logical partitions) */ for (i = 4; i < partitions; i++) { @@ -726,14 +737,20 @@ void dos_write_table(struct fdisk_context *cxt) if (pe->changed) { mbr_set_magic(pe->sectorbuffer); - write_sector(cxt, pe->offset, pe->sectorbuffer); + rc = write_sector(cxt, pe->offset, pe->sectorbuffer); + if (rc) + goto done; } } + +done: + return rc; } const struct fdisk_label dos_label = { .name = "dos", .probe = dos_probe_label, + .write = dos_write_disklabel, .part_delete = dos_delete_partition, }; |