mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-16 09:46:55 +00:00
btrfs-progs: move parse_qgroupid_or_path to parse-utils
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
6edd4b2121
commit
eac3cb577c
@ -15,11 +15,16 @@
|
||||
*/
|
||||
|
||||
#include "kerncompat.h"
|
||||
#include <sys/stat.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "libbtrfsutil/btrfsutil.h"
|
||||
#include "kernel-shared/volumes.h"
|
||||
#include "common/parse-utils.h"
|
||||
#include "common/messages.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
int parse_u64(const char *str, u64 *result)
|
||||
{
|
||||
@ -307,3 +312,44 @@ int parse_qgroupid(const char *str, u64 *qgroupid)
|
||||
*qgroupid = (level << BTRFS_QGROUP_LEVEL_SHIFT) | id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 parse_qgroupid_or_path(const char *p)
|
||||
{
|
||||
enum btrfs_util_error err;
|
||||
u64 id;
|
||||
u64 qgroupid;
|
||||
int fd;
|
||||
int ret = 0;
|
||||
|
||||
if (p[0] == '/')
|
||||
goto path;
|
||||
|
||||
ret = parse_qgroupid(p, &qgroupid);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
return qgroupid;
|
||||
|
||||
path:
|
||||
/* Path format like subv at 'my_subvol' is the fallback case */
|
||||
err = btrfs_util_is_subvolume(p);
|
||||
if (err)
|
||||
goto err;
|
||||
fd = open(p, O_RDONLY);
|
||||
if (fd < 0)
|
||||
goto err;
|
||||
ret = lookup_path_rootid(fd, &id);
|
||||
if (ret) {
|
||||
errno = -ret;
|
||||
error("failed to lookup root id: %m");
|
||||
}
|
||||
close(fd);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
return id;
|
||||
|
||||
err:
|
||||
error("invalid qgroupid or subvolume path: %s", p);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ int parse_range_strict(const char *range, u64 *start, u64 *end);
|
||||
int parse_bg_profile(const char *profile, u64 *flags);
|
||||
int parse_compress_type(const char *type);
|
||||
int parse_qgroupid(const char *str, u64 *qgroupid);
|
||||
u64 parse_qgroupid_or_path(const char *p);
|
||||
int fls64(u64 x);
|
||||
|
||||
#endif
|
||||
|
@ -226,46 +226,6 @@ int set_label(const char *btrfs_dev, const char *label)
|
||||
return ret;
|
||||
}
|
||||
|
||||
u64 parse_qgroupid_or_path(const char *p)
|
||||
{
|
||||
enum btrfs_util_error err;
|
||||
u64 id;
|
||||
u64 qgroupid;
|
||||
int fd;
|
||||
int ret = 0;
|
||||
|
||||
if (p[0] == '/')
|
||||
goto path;
|
||||
|
||||
ret = parse_qgroupid(p, &qgroupid);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
return qgroupid;
|
||||
|
||||
path:
|
||||
/* Path format like subv at 'my_subvol' is the fallback case */
|
||||
err = btrfs_util_is_subvolume(p);
|
||||
if (err)
|
||||
goto err;
|
||||
fd = open(p, O_RDONLY);
|
||||
if (fd < 0)
|
||||
goto err;
|
||||
ret = lookup_path_rootid(fd, &id);
|
||||
if (ret) {
|
||||
errno = -ret;
|
||||
error("failed to lookup root id: %m");
|
||||
}
|
||||
close(fd);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
return id;
|
||||
|
||||
err:
|
||||
error("invalid qgroupid or subvolume path: %s", p);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void btrfs_format_csum(u16 csum_type, const u8 *data, char *output)
|
||||
{
|
||||
int i;
|
||||
|
@ -45,7 +45,6 @@ enum exclusive_operation {
|
||||
/* 2 for "0x", 2 for each byte, plus nul */
|
||||
#define BTRFS_CSUM_STRING_LEN (2 + 2 * BTRFS_CSUM_SIZE + 1)
|
||||
void btrfs_format_csum(u16 csum_type, const u8 *data, char *output);
|
||||
u64 parse_qgroupid_or_path(const char *p);
|
||||
int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
|
||||
struct btrfs_ioctl_dev_info_args **di_ret);
|
||||
int get_fsid(const char *path, u8 *fsid, int silent);
|
||||
|
Loading…
Reference in New Issue
Block a user