mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-08 02:01:16 +00:00
btrfs-progs: move get_df to utils.c
Export the function so it can be used by scrub status. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
832da8ca1d
commit
a2ebaa9e83
@ -61,51 +61,6 @@ static const char * const cmd_filesystem_df_usage[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
|
||||
{
|
||||
u64 count = 0;
|
||||
int ret;
|
||||
struct btrfs_ioctl_space_args *sargs;
|
||||
|
||||
sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
|
||||
if (!sargs)
|
||||
return -ENOMEM;
|
||||
|
||||
sargs->space_slots = 0;
|
||||
sargs->total_spaces = 0;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
if (ret < 0) {
|
||||
error("cannot get space info: %m");
|
||||
free(sargs);
|
||||
return -errno;
|
||||
}
|
||||
/* This really should never happen */
|
||||
if (!sargs->total_spaces) {
|
||||
free(sargs);
|
||||
return -ENOENT;
|
||||
}
|
||||
count = sargs->total_spaces;
|
||||
free(sargs);
|
||||
|
||||
sargs = malloc(sizeof(struct btrfs_ioctl_space_args) +
|
||||
(count * sizeof(struct btrfs_ioctl_space_info)));
|
||||
if (!sargs)
|
||||
return -ENOMEM;
|
||||
|
||||
sargs->space_slots = count;
|
||||
sargs->total_spaces = 0;
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
if (ret < 0) {
|
||||
error("cannot get space info with %llu slots: %m",
|
||||
count);
|
||||
free(sargs);
|
||||
return -errno;
|
||||
}
|
||||
*sargs_ret = sargs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_df(struct btrfs_ioctl_space_args *sargs, unsigned unit_mode)
|
||||
{
|
||||
u64 i;
|
||||
|
46
utils.c
46
utils.c
@ -1584,6 +1584,52 @@ int get_device_info(int fd, u64 devid,
|
||||
return ret < 0 ? -errno : 0;
|
||||
}
|
||||
|
||||
int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
|
||||
{
|
||||
u64 count = 0;
|
||||
int ret;
|
||||
struct btrfs_ioctl_space_args *sargs;
|
||||
|
||||
sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
|
||||
if (!sargs)
|
||||
return -ENOMEM;
|
||||
|
||||
sargs->space_slots = 0;
|
||||
sargs->total_spaces = 0;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
if (ret < 0) {
|
||||
error("cannot get space info: %m");
|
||||
free(sargs);
|
||||
return -errno;
|
||||
}
|
||||
/* This really should never happen */
|
||||
if (!sargs->total_spaces) {
|
||||
free(sargs);
|
||||
return -ENOENT;
|
||||
}
|
||||
count = sargs->total_spaces;
|
||||
free(sargs);
|
||||
|
||||
sargs = malloc(sizeof(struct btrfs_ioctl_space_args) +
|
||||
(count * sizeof(struct btrfs_ioctl_space_info)));
|
||||
if (!sargs)
|
||||
return -ENOMEM;
|
||||
|
||||
sargs->space_slots = count;
|
||||
sargs->total_spaces = 0;
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
if (ret < 0) {
|
||||
error("cannot get space info with %llu slots: %m",
|
||||
count);
|
||||
free(sargs);
|
||||
return -errno;
|
||||
}
|
||||
*sargs_ret = sargs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static u64 find_max_device_id(struct btrfs_ioctl_search_args *search_args,
|
||||
int nr_items)
|
||||
{
|
||||
|
1
utils.h
1
utils.h
@ -145,6 +145,7 @@ int get_btrfs_mount(const char *dev, char *mp, size_t mp_size);
|
||||
int find_mount_root(const char *path, char **mount_root);
|
||||
int get_device_info(int fd, u64 devid,
|
||||
struct btrfs_ioctl_dev_info_args *di_args);
|
||||
int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret);
|
||||
int test_uuid_unique(char *fs_uuid);
|
||||
u64 disk_size(const char *path);
|
||||
u64 get_partition_size(const char *dev);
|
||||
|
Loading…
Reference in New Issue
Block a user