btrfs-progs: subvol list: copy btrfs_list_alloc_comparer_set from btrfs-list.c

There's only one caller of btrfs_list_alloc_comparer_set so move it
there. Also move the definitions of BTRFS_LIST_* to the header so they
can be used by both btrfs-list and subvolume.c.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-09-29 18:33:25 +02:00
parent fb0bfb967f
commit acefefce61
3 changed files with 21 additions and 22 deletions

View File

@ -34,9 +34,6 @@
#include "btrfs-list.h"
#include "common/rbtree-utils.h"
#define BTRFS_LIST_NFILTERS_INCREASE (2 * BTRFS_LIST_FILTER_MAX)
#define BTRFS_LIST_NCOMPS_INCREASE (2 * BTRFS_LIST_COMP_MAX)
/* we store all the roots we find in an rbtree so that we can
* search for them later.
*/
@ -224,24 +221,6 @@ static int btrfs_list_get_sort_item(char *sort_name)
return -1;
}
struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void)
{
struct btrfs_list_comparer_set *set;
int size;
size = sizeof(struct btrfs_list_comparer_set) +
BTRFS_LIST_NCOMPS_INCREASE * sizeof(struct btrfs_list_comparer);
set = calloc(1, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
exit(1);
}
set->total = BTRFS_LIST_NCOMPS_INCREASE;
return set;
}
static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
enum btrfs_list_comp_enum comparer, int is_descending)
{

View File

@ -24,6 +24,9 @@
#include "ioctl.h"
#include <time.h>
#define BTRFS_LIST_NFILTERS_INCREASE (2 * BTRFS_LIST_FILTER_MAX)
#define BTRFS_LIST_NCOMPS_INCREASE (2 * BTRFS_LIST_COMP_MAX)
enum btrfs_list_layout {
BTRFS_LIST_LAYOUT_DEFAULT = 0,
BTRFS_LIST_LAYOUT_TABLE,
@ -157,7 +160,6 @@ void btrfs_list_setup_print_column(enum btrfs_list_column_enum column);
struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void);
void btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
enum btrfs_list_filter_enum filter, u64 data);
struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
struct btrfs_list_comparer_set *comp_set,

View File

@ -69,6 +69,24 @@ static const char * const cmd_subvol_list_usage[] = {
NULL,
};
static struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void)
{
struct btrfs_list_comparer_set *set;
int size;
size = sizeof(struct btrfs_list_comparer_set) +
BTRFS_LIST_NCOMPS_INCREASE * sizeof(struct btrfs_list_comparer);
set = calloc(1, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
exit(1);
}
set->total = BTRFS_LIST_NCOMPS_INCREASE;
return set;
}
static int cmd_subvol_list(const struct cmd_struct *cmd, int argc, char **argv)
{
struct btrfs_list_filter_set *filter_set;