]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add fdisk_table_get_nents()
authorKarel Zak <kzak@redhat.com>
Mon, 6 Jan 2014 07:32:20 +0000 (08:32 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:13 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/fdiskP.h
libfdisk/src/libfdisk.h
libfdisk/src/table.c

index ec61230832906126b736915ce3fc4e25eb6f5ed1..1db19b648bf2924cad4adeb7bae5b635a84e2a44 100644 (file)
@@ -198,6 +198,7 @@ struct fdisk_partition {
 struct fdisk_table {
        struct list_head        parts;          /* partitions */
        int                     refcount;
+       size_t                  nents;          /* number of partitions */
 };
 
 /*
index c093fa8e4af71ca4e79abf52ed754b7b24f8a5ad..f3cc0d390154b3e41f4e2b4c1a2f0589fc179ac3 100644 (file)
@@ -33,8 +33,8 @@ struct fdisk_label;
 struct fdisk_parttype;
 struct fdisk_partition;
 struct fdisk_ask;
-struct libfdisk_iter;
-struct tt;
+struct fdisk_iter;
+struct fdisk_table;
 
 /*
  * Supported partition table types (labels)
@@ -214,6 +214,7 @@ extern struct fdisk_table *fdisk_new_table(void);
 extern int fdisk_reset_table(struct fdisk_table *tb);
 extern void fdisk_ref_table(struct fdisk_table *tb);
 extern void fdisk_unref_table(struct fdisk_table *tb);
+extern int fdisk_table_get_nents(struct fdisk_table *tb);
 extern int fdisk_table_is_empty(struct fdisk_table *tb);
 extern int fdisk_table_add_partition(struct fdisk_table *tb, struct fdisk_partition *pa);
 extern int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_partition *pa);
@@ -223,6 +224,10 @@ extern int fdisk_table_to_string(struct fdisk_table *tb,
                          struct fdisk_context *cxt,
                          int *cols, size_t ncols,  char **data);
 
+extern int fdisk_table_next_partition(
+                       struct fdisk_table *tb,
+                       struct fdisk_iter *itr,
+                       struct fdisk_partition **pa);
 /* alignment.c */
 extern int fdisk_reset_alignment(struct fdisk_context *cxt);
 extern int fdisk_reset_device_properties(struct fdisk_context *cxt);
index 44580146feb2340532d9717744bba38294e924d8..9a19dd39f64f8561270a25dfa869ecb769eefb07 100644 (file)
@@ -46,6 +46,7 @@ int fdisk_reset_table(struct fdisk_table *tb)
                fdisk_table_remove_partition(tb, pa);
        }
 
+       tb->nents = 0;
        return 0;
 }
 
@@ -94,6 +95,16 @@ int fdisk_table_is_empty(struct fdisk_table *tb)
        return tb == NULL || list_empty(&tb->parts) ? 1 : 0;
 }
 
+/**
+ * fdisk_table_get_nents:
+ * @tb: pointer to tab
+ *
+ * Returns: number of entries in table.
+ */
+int fdisk_table_get_nents(struct fdisk_table *tb)
+{
+       return tb ? tb->nents : 0;
+}
 
 /**
  * fdisk_table_next_partition:
@@ -158,6 +169,7 @@ int fdisk_table_add_partition(struct fdisk_table *tb, struct fdisk_partition *pa
 
        fdisk_ref_partition(pa);
        list_add_tail(&pa->parts, &tb->parts);
+       tb->nents++;
 
        DBG(TAB, dbgprint("add entry %p [start=%ju, size=%ju, freespace=%s]",
                                pa, pa->start, pa->size,
@@ -190,6 +202,8 @@ int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_partition
        INIT_LIST_HEAD(&pa->parts);
 
        fdisk_unref_partition(pa);
+       tb->nents--;
+
        return 0;
 }