summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/bsd.c
diff options
context:
space:
mode:
authorKarel Zak2014-10-15 12:17:40 +0200
committerKarel Zak2014-10-15 12:17:40 +0200
commitecf40cda764496d3d1b29435ea64a65335ae0acf (patch)
tree9ef1d00a3906fd495194b88ca5023c9729353df0 /libfdisk/src/bsd.c
parenttests: check for wipefs and helpers in fdisk tests (diff)
downloadkernel-qcow2-util-linux-ecf40cda764496d3d1b29435ea64a65335ae0acf.tar.gz
kernel-qcow2-util-linux-ecf40cda764496d3d1b29435ea64a65335ae0acf.tar.xz
kernel-qcow2-util-linux-ecf40cda764496d3d1b29435ea64a65335ae0acf.zip
libfdisk: make it possible to use zero for size and start
The zero may be valid size and start of the partition. This patch introduces: fdisk_partition_has_start() fdisk_partition_has_size() fdisk_partition_unset_size() fdisk_partition_unset_start() to make it possible to work with zero. The feature is internally implemented by magic constant ((type) -1) for undefined sizes and offsets. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/bsd.c')
-rw-r--r--libfdisk/src/bsd.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c
index dfc47bda0..c92c893bb 100644
--- a/libfdisk/src/bsd.c
+++ b/libfdisk/src/bsd.c
@@ -238,7 +238,7 @@ static int bsd_add_partition(struct fdisk_context *cxt,
*/
if (pa && pa->start_follow_default)
;
- else if (pa && pa->start) {
+ else if (pa && fdisk_partition_has_start(pa)) {
if (pa->start < begin || pa->start > end)
return -ERANGE;
begin = pa->start;
@@ -269,7 +269,7 @@ static int bsd_add_partition(struct fdisk_context *cxt,
*/
if (pa && pa->end_follow_default)
;
- else if (pa && pa->size) {
+ else if (pa && fdisk_partition_has_size(pa)) {
if (begin + pa->size > end)
return -ERANGE;
end = begin + pa->size - 1ULL;
@@ -335,11 +335,13 @@ static int bsd_set_partition(struct fdisk_context *cxt, size_t n,
p = &d->d_partitions[n];
/* we have to stay within parental DOS partition */
- if (l->dos_part && (pa->start || pa->size)) {
+ if (l->dos_part && (fdisk_partition_has_start(pa) ||
+ fdisk_partition_has_size(pa))) {
+
sector_t dosbegin = dos_partition_get_start(l->dos_part);
sector_t dosend = dosbegin + dos_partition_get_size(l->dos_part) - 1;
- sector_t begin = pa->start ? pa->start : p->p_offset;
- sector_t end = begin + (pa->size ? pa->size : p->p_size) - 1;
+ sector_t begin = fdisk_partition_has_start(pa) ? pa->start : p->p_offset;
+ sector_t end = begin + (fdisk_partition_has_size(pa) ? pa->size : p->p_size) - 1;
if (begin < dosbegin || begin > dosend)
return -ERANGE;
@@ -353,9 +355,9 @@ static int bsd_set_partition(struct fdisk_context *cxt, size_t n,
return rc;
}
- if (pa->start)
+ if (fdisk_partition_has_start(pa))
d->d_partitions[n].p_offset = pa->start;
- if (pa->size)
+ if (fdisk_partition_has_size(pa))
d->d_partitions[n].p_size = pa->size;
fdisk_label_set_changed(cxt->label, 1);