diff options
author | Karel Zak | 2013-12-18 10:28:55 +0100 |
---|---|---|
committer | Karel Zak | 2014-03-11 11:35:12 +0100 |
commit | 6c89f750d28d2c554b4bebb8d617f4202d36bbb6 (patch) | |
tree | ff9e8fdb1d69b7e0f6a24f712a3438b5d2d6b247 /libfdisk/src/iter.c | |
parent | include/tt: add function to convert table to string (diff) | |
download | kernel-qcow2-util-linux-6c89f750d28d2c554b4bebb8d617f4202d36bbb6.tar.gz kernel-qcow2-util-linux-6c89f750d28d2c554b4bebb8d617f4202d36bbb6.tar.xz kernel-qcow2-util-linux-6c89f750d28d2c554b4bebb8d617f4202d36bbb6.zip |
libfdisk: use fdisk_table to generate output
* add generic fdisk_iter iterator
* use fdisk_table to convert partition table to human readable output
* clean up partition.c API (don't use reference to fdisk_context in
fdisk_partition struct)
* extern table.c API to use fdisk_iter iterator
* remove old fdisk_list_partitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/iter.c')
-rw-r--r-- | libfdisk/src/iter.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libfdisk/src/iter.c b/libfdisk/src/iter.c new file mode 100644 index 000000000..8e2f34202 --- /dev/null +++ b/libfdisk/src/iter.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2009 Karel Zak <kzak@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +/** + * SECTION: iter + * @title: Iterator + * @short_description: unified iterator + * + * The iterator keeps the direction and the last position + * for access to the internal library tables/lists. + */ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "fdiskP.h" + +/** + * fdisk_new_iter: + * @direction: FDISK_INTER_{FOR,BACK}WARD direction + * + * Returns: newly allocated generic libmount iterator. + */ +struct fdisk_iter *fdisk_new_iter(int direction) +{ + struct fdisk_iter *itr = calloc(1, sizeof(*itr)); + if (!itr) + return NULL; + itr->direction = direction; + return itr; +} + +/** + * fdisk_free_iter: + * @itr: iterator pointer + * + * Deallocates the iterator. + */ +void fdisk_free_iter(struct fdisk_iter *itr) +{ + free(itr); +} + +/** + * fdisk_reset_iter: + * @itr: iterator pointer + * @direction: FDISK_INTER_{FOR,BACK}WARD or -1 to keep the direction unchanged + * + * Resets the iterator. + */ +void fdisk_reset_iter(struct fdisk_iter *itr, int direction) +{ + if (direction == -1) + direction = itr->direction; + + memset(itr, 0, sizeof(*itr)); + itr->direction = direction; +} + +/** + * fdisk_iter_get_direction: + * @itr: iterator pointer + * + * Returns: FDISK_INTER_{FOR,BACK}WARD + */ +int fdisk_iter_get_direction(struct fdisk_iter *itr) +{ + return itr->direction; +} |