#include "fdiskP.h"
-#define ARROW_CURSOR_STRING " >> "
+#define ARROW_CURSOR_STRING ">> "
#define ARROW_CURSOR_DUMMY " "
#define ARROW_CURSOR_WIDTH (sizeof(ARROW_CURSOR_STRING) - 1)
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
*/
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;
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);
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;
*
* 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.
*/
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);