]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: remove 'end' from struct fdisk_partition
authorKarel Zak <kzak@redhat.com>
Thu, 4 Dec 2014 11:24:31 +0000 (12:24 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 4 Dec 2014 11:24:31 +0000 (12:24 +0100)
This struct member duplicate "start+size".

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/docs/libfdisk-sections.txt
libfdisk/src/bsd.c
libfdisk/src/dos.c
libfdisk/src/fdiskP.h
libfdisk/src/gpt.c
libfdisk/src/libfdisk.h.in
libfdisk/src/libfdisk.sym
libfdisk/src/partition.c
libfdisk/src/sgi.c
libfdisk/src/sun.c
libfdisk/src/table.c

index 2dff5c998b14c9821ec53ea0eb9954245a8bdaa2..c0aaeaef8de6a032d004799ea5db0c56941a3f3f 100644 (file)
@@ -145,6 +145,7 @@ fdisk_partition_cmp_start
 fdisk_partition_end_follow_default
 fdisk_partition_end_is_default
 fdisk_partition_get_attrs
+fdisk_partition_get_end
 fdisk_partition_get_name
 fdisk_partition_get_parent
 fdisk_partition_get_partno
@@ -152,6 +153,7 @@ fdisk_partition_get_size
 fdisk_partition_get_start
 fdisk_partition_get_type
 fdisk_partition_get_uuid
+fdisk_partition_has_end
 fdisk_partition_has_partno
 fdisk_partition_has_size
 fdisk_partition_has_start
index 0e45f6dcab4e3a734b1eca45a0ec94f7c19c6eb7..618a3eef98aee1f5debee22163f495f6b61547b1 100644 (file)
@@ -499,7 +499,6 @@ static int bsd_get_partition(struct fdisk_context *cxt, size_t n,
        }
 
        pa->start = p->p_offset;
-       pa->end = p->p_offset + p->p_size - 1;
        pa->size = p->p_size;
        pa->type = bsd_partition_parttype(cxt, p);
 
index ef336f632a0303ddc5ac136f712fcc5ad1a58afc..2a067076e394788565fd6b1e83625224f8918baa 100644 (file)
@@ -1836,7 +1836,6 @@ static int dos_get_partition(struct fdisk_context *cxt, size_t n,
        pa->type = dos_partition_parttype(cxt, p);
        pa->boot = p->boot_ind == ACTIVE_FLAG ? 1 : 0;
        pa->start = get_abs_partition_start(pe);
-       pa->end = get_abs_partition_end(pe);
        pa->size = dos_partition_get_size(p);
        pa->container = lb->ext_offset && n == lb->ext_index;
 
index b912e6c6bc0d9eb36f0f5213c75cc136e53ff5a4..b169a9ffb2a12035910bf9f96d1971567d34c219 100644 (file)
@@ -119,7 +119,6 @@ struct fdisk_partition {
        size_t          parent_partno;          /* for logical partitions */
 
        fdisk_sector_t  start;                  /* first sectors */
-       fdisk_sector_t  end;                    /* last sector */
        fdisk_sector_t  size;                   /* size in sectors */
 
        char            *name;                  /* partition name */
index fc18441d627c19f418fd30802a3c6534321304b2..8c1c96c37240a363c73a6fa196425336254ec1b3 100644 (file)
@@ -1474,7 +1474,6 @@ static int gpt_get_partition(struct fdisk_context *cxt, size_t n,
                return 0;
 
        pa->start = gpt_partition_start(e);
-       pa->end = gpt_partition_end(e);
        pa->size = gpt_partition_size(e);
        pa->type = gpt_partition_parttype(cxt, e);
 
index 0b500b2364129b9f27ced46bbdfeb13cd30b09df..f82d5bd974ada70d0cfb2c2b12be1323114eecbc 100644 (file)
@@ -330,6 +330,9 @@ uint64_t fdisk_partition_get_size(struct fdisk_partition *pa);
 int fdisk_partition_has_size(struct fdisk_partition *pa);
 int fdisk_partition_size_explicit(struct fdisk_partition *pa, int enable);
 
+int fdisk_partition_has_end(struct fdisk_partition *pa);
+fdisk_sector_t fdisk_partition_get_end(struct fdisk_partition *pa);
+
 int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t num);
 int fdisk_partition_unset_partno(struct fdisk_partition *pa);
 size_t fdisk_partition_get_partno(struct fdisk_partition *pa);
index ee0b9bcfc7066122c2143696ff10a7ba27915f09..bf85d4e2a8dbb95aadcf38f9b5b32f25a7cbd4ff 100644 (file)
@@ -130,6 +130,7 @@ global:
        fdisk_partition_end_follow_default;
        fdisk_partition_end_is_default;
        fdisk_partition_get_attrs;
+       fdisk_partition_get_end;
        fdisk_partition_get_name;
        fdisk_partition_get_parent;
        fdisk_partition_get_partno;
@@ -137,6 +138,7 @@ global:
        fdisk_partition_get_start;
        fdisk_partition_get_type;
        fdisk_partition_get_uuid;
+       fdisk_partition_has_end;
        fdisk_partition_has_partno;
        fdisk_partition_has_size;
        fdisk_partition_has_start;
index 1ea0b7aea989f77a2d6608a957e69008db8eead0..8ebdb4682e82a959fc62d179ae1fd9dd5436efe2 100644 (file)
@@ -21,7 +21,6 @@ static void init_partition(struct fdisk_partition *pa)
 {
        FDISK_INIT_UNDEF(pa->size);
        FDISK_INIT_UNDEF(pa->start);
-       FDISK_INIT_UNDEF(pa->end);
        FDISK_INIT_UNDEF(pa->partno);
        FDISK_INIT_UNDEF(pa->parent_partno);
        FDISK_INIT_UNDEF(pa->boot);
@@ -475,7 +474,33 @@ int fdisk_partition_set_uuid(struct fdisk_partition *pa, const char *uuid)
        return 0;
 }
 
+/**
+ * fdisk_partition_has_end:
+ * @pa: partition
+ *
+ * Returns: 1 if the partition has defined last sector
+ */
+int fdisk_partition_has_end(struct fdisk_partition *pa)
+{
+       return pa && !FDISK_IS_UNDEF(pa->start) && !FDISK_IS_UNDEF(pa->size);
+}
 
+/**
+ * fdisk_partition_get_end:
+ * @pa: partition
+ *
+ * This function may returns absolute non-sense, always check
+ * fdisk_partition_has_end().
+ *
+ * Note that partition end is defined by fdisk_partition_set_start() and
+ * fdisk_partition_set_size().
+ *
+ * Returns: last partition sector LBA.
+ */
+fdisk_sector_t fdisk_partition_get_end(struct fdisk_partition *pa)
+{
+       return pa->start + pa->size - (pa->size == 0 ? 0 : 1);
+}
 
 /**
  * fdisk_partition_end_follow_default
@@ -663,10 +688,12 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
                }
                break;
        case FDISK_FIELD_END:
-               x = fdisk_cround(cxt, pa->end);
-               rc = pa->end_post ?
-                               asprintf(&p, "%ju%c", x, pa->end_post) :
-                               asprintf(&p, "%ju", x);
+               if (fdisk_partition_has_end(pa)) {
+                       x = fdisk_cround(cxt, fdisk_partition_get_end(pa));
+                       rc = pa->end_post ?
+                                       asprintf(&p, "%ju%c", x, pa->end_post) :
+                                       asprintf(&p, "%ju", x);
+               }
                break;
        case FDISK_FIELD_SIZE:
                if (fdisk_partition_has_size(pa)) {
@@ -808,9 +835,9 @@ int fdisk_set_partition(struct fdisk_context *cxt, size_t partno,
        DBG(CXT, ul_debugobj(cxt, "setting partition %zu %p (start=%ju, end=%ju, size=%ju, "
                    "defaults(start=%s, end=%s, partno=%s)",
                    partno, pa,
-                   pa->start,
-                   pa->end,
-                   pa->size,
+                   (uintmax_t) fdisk_partition_get_start(pa),
+                   (uintmax_t) fdisk_partition_get_end(pa),
+                   (uintmax_t) fdisk_partition_get_size(pa),
                    pa->start_follow_default ? "yes" : "no",
                    pa->end_follow_default ? "yes" : "no",
                    pa->partno_follow_default ? "yes" : "no"));
@@ -851,9 +878,9 @@ int fdisk_add_partition(struct fdisk_context *cxt,
                DBG(CXT, ul_debugobj(cxt, "adding new partition %p (start=%ju, end=%ju, size=%ju, "
                            "defaults(start=%s, end=%s, partno=%s)",
                            pa,
-                           pa->start,
-                           pa->end,
-                           pa->size,
+                           (uintmax_t) fdisk_partition_get_start(pa),
+                           (uintmax_t) fdisk_partition_get_end(pa),
+                           (uintmax_t) fdisk_partition_get_size(pa),
                            pa->start_follow_default ? "yes" : "no",
                            pa->end_follow_default ? "yes" : "no",
                            pa->partno_follow_default ? "yes" : "no"));
index a646cf39099f662df20285118c686483ca2c3b7d..cd4cedff07c1eb4b28427b7033373c0467fb1271 100644 (file)
@@ -344,7 +344,6 @@ static int sgi_get_partition(struct fdisk_context *cxt, size_t n, struct fdisk_p
        pa->type = sgi_get_parttype(cxt, n);
        pa->size = len;
        pa->start = start;
-       pa->end = start + len - (len ? 1 : 0);
 
        if (pa->type && pa->type->code == SGI_TYPE_ENTIRE_DISK)
                pa->wholedisk = 1;
index 6c77a8f61a2290e8242bd79cd7c9a606de062202..babff6263cc5780eb3607c3bb5d85cc56e37a6bd 100644 (file)
@@ -814,7 +814,6 @@ static int sun_get_partition(struct fdisk_context *cxt, size_t n,
        }
 
        pa->start = start;
-       pa->end = start + len - (len ? 1 : 0);
        pa->size = len;
 
        return 0;
index 221ec46bd49c3675d362608b2e9827195f0f3e4b..18944e0c44eb873784c3cccb3436a69ca73146ff 100644 (file)
@@ -203,7 +203,10 @@ int fdisk_table_add_partition(struct fdisk_table *tb, struct fdisk_partition *pa
        tb->nents++;
 
        DBG(TAB, ul_debugobj(tb, "add entry %p [start=%ju, end=%ju, size=%ju, %s %s %s]",
-                       pa, pa->start, pa->end, pa->size,
+                       pa,
+                       (uintmax_t) fdisk_partition_get_start(pa),
+                       (uintmax_t) fdisk_partition_get_end(pa),
+                       (uintmax_t) fdisk_partition_get_size(pa),
                        fdisk_partition_is_freespace(pa) ? "freespace" : "",
                        fdisk_partition_is_nested(pa)    ? "nested"    : "",
                        fdisk_partition_is_container(pa) ? "container" : "primary"));
@@ -227,7 +230,10 @@ static int table_insert_partition(
        tb->nents++;
 
        DBG(TAB, ul_debugobj(tb, "insert entry %p pre=%p [start=%ju, end=%ju, size=%ju, %s %s %s]",
-                       pa, poz ? poz : NULL, pa->start, pa->end, pa->size,
+                       pa, poz ? poz : NULL,
+                       (uintmax_t) fdisk_partition_get_start(pa),
+                       (uintmax_t) fdisk_partition_get_end(pa),
+                       (uintmax_t) fdisk_partition_get_size(pa),
                        fdisk_partition_is_freespace(pa) ? "freespace" : "",
                        fdisk_partition_is_nested(pa)    ? "nested"    : "",
                        fdisk_partition_is_container(pa) ? "container" : ""));
@@ -351,10 +357,13 @@ static int new_freespace(struct fdisk_context *cxt,
        if (!*pa)
                return -ENOMEM;
 
+       assert(start);
+       assert(end);
+       assert(end > start);
+
        (*pa)->freespace = 1;
        (*pa)->start = fdisk_align_lba_in_range(cxt, start, start, end);
-       (*pa)->end = end;
-       (*pa)->size = (*pa)->end - (*pa)->start + 1ULL;
+       (*pa)->size = end - (*pa)->start + 1ULL;
 
        if (parent)
                (*pa)->parent_partno = parent->partno;
@@ -381,6 +390,9 @@ static int table_add_freespace(
        if (!pa)
                return 0;
 
+       assert(fdisk_partition_has_start(pa));
+       assert(fdisk_partition_has_end(pa));
+
        DBG(TAB, ul_debugobj(tb, "adding freespace"));
 
        fdisk_reset_iter(&itr, FDISK_ITER_FORWARD);
@@ -401,7 +413,15 @@ static int table_add_freespace(
        }
 
        while (fdisk_table_next_partition(tb, &itr, &x) == 0) {
-               if (x->end < pa->start && (!best || best->end < x->end))
+               fdisk_sector_t end, best_end;
+
+               if (!fdisk_partition_has_end(x))
+                       continue;
+
+               end = fdisk_partition_get_end(x);
+               best_end = fdisk_partition_get_end(best);
+
+               if (end < pa->start && (!best || best_end < end))
                        best = x;
        }
 
@@ -449,7 +469,7 @@ static int check_container_freespace(struct fdisk_context *cxt,
                        rc = table_add_freespace(cxt, tb, lastplusoff, pa->start, cont);
                if (rc)
                        goto done;
-               last = pa->end;
+               last = fdisk_partition_get_end(pa);
        }
 
        /* free-space remaining in extended partition */
@@ -513,7 +533,9 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
                              || !fdisk_partition_has_start(pa))
                        continue;
                DBG(CXT, ul_debugobj(cxt, "freespace analyze: partno=%zu, start=%ju, end=%ju",
-                                       pa->partno, pa->start, pa->end));
+                                       pa->partno,
+                                       (uintmax_t) fdisk_partition_get_start(pa),
+                                       (uintmax_t) fdisk_partition_get_end(pa)));
                if (last + grain <= pa->start) {
                        rc = table_add_freespace(cxt, *tb,
                                last + (last > cxt->first_lba ? 1 : 0),
@@ -522,7 +544,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
                /* add gaps between logical partitions */
                if (fdisk_partition_is_container(pa))
                        rc = check_container_freespace(cxt, parts, *tb, pa);
-               last = pa->end;
+               last = fdisk_partition_get_end(pa);
        }
 
        /* add free-space behind last partition to the end of the table (so