summaryrefslogtreecommitdiffstats
path: root/libfdisk
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
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')
-rw-r--r--libfdisk/src/fdiskP.h1
-rw-r--r--libfdisk/src/libfdisk.h9
-rw-r--r--libfdisk/src/table.c14
3 files changed, 22 insertions, 2 deletions
diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h
index ec6123083..1db19b648 100644
--- a/libfdisk/src/fdiskP.h
+++ b/libfdisk/src/fdiskP.h
@@ -198,6 +198,7 @@ struct fdisk_partition {
struct fdisk_table {
struct list_head parts; /* partitions */
int refcount;
+ size_t nents; /* number of partitions */
};
/*
diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h
index c093fa8e4..f3cc0d390 100644
--- a/libfdisk/src/libfdisk.h
+++ b/libfdisk/src/libfdisk.h
@@ -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);
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;
}