]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: clean up scols usage
authorKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 09:58:48 +0000 (11:58 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:21 +0000 (12:29 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
libfdisk/src/table.c

index 030cc19bf22bcbd2c0772393a140f41dbb4bdbd7..624d7991d18e55b8cf27d30bccf8de834955440a 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "fdiskP.h"
 
-#define ARROW_CURSOR_STRING    " >> "
+#define ARROW_CURSOR_STRING    ">>  "
 #define ARROW_CURSOR_DUMMY     "    "
 #define ARROW_CURSOR_WIDTH     (sizeof(ARROW_CURSOR_STRING) - 1)
 
@@ -158,6 +158,28 @@ static int cols_init(struct cfdisk *cf)
        return fdisk_get_columns(cf->cxt, 0, &cf->cols, &cf->ncols);
 }
 
+/* Reads partition in tree-like order from scols
+ */
+static int partition_from_scols(struct fdisk_table *tb,
+                               struct libscols_line *ln)
+{
+       struct fdisk_partition *pa = scols_line_get_userdata(ln);
+
+       fdisk_table_add_partition(tb, pa);
+       fdisk_unref_partition(pa);
+
+       if (scols_line_has_children(ln)) {
+               struct libscols_line *chln;
+               struct libscols_iter *itr = scols_new_iter(SCOLS_ITER_FORWARD);
+
+               if (!itr)
+                       return -EINVAL;
+               while (scols_line_next_child(ln, itr, &chln) == 0)
+                       partition_from_scols(tb, chln);
+       }
+       return 0;
+}
+
 /* It would be possible to use fdisk_table_to_string(), but we want some
  * extension to the output format, so let's do it without libfdisk
  */
@@ -231,7 +253,7 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
                                continue;
                        if (fdisk_partition_to_string(pa, cf->cxt, col->id, &cdata))
                                continue;
-                       scols_line_set_data(ln, i, cdata);
+                       scols_line_refer_data(ln, i, cdata);
                }
                if (tree && fdisk_partition_is_container(pa))
                        ln_cont = ln;
@@ -255,16 +277,16 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
        while (fdisk_table_next_partition(tb, itr, &pa) == 0)
                fdisk_table_remove_partition(tb, pa);
 
-       /* add all in the right order */
        s_itr = scols_new_iter(SCOLS_ITER_FORWARD);
        if (!s_itr)
                goto done;
 
+       /* add all in the right order (don't forget the output is tree) */
        while (scols_table_next_line(table, s_itr, &ln) == 0) {
-               struct fdisk_partition *pa = scols_line_get_userdata(ln);
-
-               fdisk_table_add_partition(tb, pa);
-               fdisk_unref_partition(pa);
+               if (scols_line_get_parent(ln))
+                       continue;
+               if (partition_from_scols(tb, ln))
+                       break;
        }
 done:
        scols_unref_table(table);
index 8c86f7c17000fb66c7979bcfb4ccf42084079257..e83ffaf4dcee6284ab8ef549010ac714c843177a 100644 (file)
@@ -437,7 +437,7 @@ static int check_container_freespace(struct fdisk_context *cxt,
                if (!pa->used || !fdisk_partition_is_nested(pa))
                        continue;
                lastfree = pa->start - 1 - cxt->first_lba;
-               if (last + grain < lastfree)
+               if (last + grain <= lastfree)
                        rc = table_add_freespace(cxt, tb, last + grain, lastfree, cont);
                if (rc)
                        return rc;
@@ -459,6 +459,9 @@ static int check_container_freespace(struct fdisk_context *cxt,
  *
  * This function adds freespace (described by fdisk_partition) to @table, it
  * allocates a new table if the @table points to NULL.
+ *
+ * Note that free space smaller than grain (see fdisk_topology_get_grain()) is
+ * ignored.
 
  * Returns 0 on success, otherwise, a corresponding error.
  */
@@ -491,7 +494,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
                        continue;
                DBG(CXT, ul_debugobj(cxt, "freespace analyze: partno=%zu, start=%ju, end=%ju",
                                        pa->partno, pa->start, pa->end));
-               if (last + grain < pa->start) {
+               if (last + grain <= pa->start) {
                        rc = table_add_freespace(cxt, *tb,
                                last + (last > cxt->first_lba ? 1 : 0),
                                pa->start - 1, NULL);