summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/table.c
diff options
context:
space:
mode:
authorKarel Zak2014-01-06 08:32:20 +0100
committerKarel Zak2014-03-11 11:35:13 +0100
commit04406c0d0cccdc85521531091e0e18e8cd876c72 (patch)
tree145e299ac6acb7a736a5bb74d5fa59868b1a90d2 /libfdisk/src/table.c
parentlibfdisk: tiny clean up in fdisk_table_to_string() (diff)
downloadkernel-qcow2-util-linux-04406c0d0cccdc85521531091e0e18e8cd876c72.tar.gz
kernel-qcow2-util-linux-04406c0d0cccdc85521531091e0e18e8cd876c72.tar.xz
kernel-qcow2-util-linux-04406c0d0cccdc85521531091e0e18e8cd876c72.zip
libfdisk: add fdisk_table_get_nents()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/table.c')
-rw-r--r--libfdisk/src/table.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 44580146f..9a19dd39f 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -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;
}