From a3efed2adbad6bb85b931be0c44d24d74eedbce1 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 29 Sep 2021 16:13:30 +0200 Subject: [PATCH] btrfs-progs: libbtrfs: merge utils-lib.c back to utils.c The separate file was needed for libbtrfs in the past to avoid pulling utils.c in, but this is not needed after recent cleanups. Signed-off-by: David Sterba --- Makefile | 1 - common/utils-lib.c | 82 ---------------------------------------------- common/utils.c | 57 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 83 deletions(-) delete mode 100644 common/utils-lib.c diff --git a/Makefile b/Makefile index ae596bea..1bba7ffd 100644 --- a/Makefile +++ b/Makefile @@ -186,7 +186,6 @@ objects = \ common/string-table.o \ common/task-utils.o \ common/units.o \ - common/utils-lib.o \ common/utils.o \ check/qgroup-verify.o \ cmds/receive-dump.o \ diff --git a/common/utils-lib.c b/common/utils-lib.c deleted file mode 100644 index 3d061c25..00000000 --- a/common/utils-lib.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License v2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#include "kerncompat.h" -#include "common/utils.h" -#include -#include -#include -#include -#include -#include "kernel-shared/ctree.h" - -/* - * This function should be only used when parsing command arg, it won't return - * error to its caller and rather exit directly just like usage(). - */ -u64 arg_strtou64(const char *str) -{ - u64 value; - char *ptr_parse_end = NULL; - - value = strtoull(str, &ptr_parse_end, 0); - if (ptr_parse_end && *ptr_parse_end != '\0') { - fprintf(stderr, "ERROR: %s is not a valid numeric value.\n", - str); - exit(1); - } - - /* - * if we pass a negative number to strtoull, it will return an - * unexpected number to us, so let's do the check ourselves. - */ - if (str[0] == '-') { - fprintf(stderr, "ERROR: %s: negative value is invalid.\n", - str); - exit(1); - } - if (value == ULLONG_MAX) { - fprintf(stderr, "ERROR: %s is too large.\n", str); - exit(1); - } - return value; -} - -/* - * For a given: - * - file or directory return the containing tree root id - * - subvolume return its own tree id - * - BTRFS_EMPTY_SUBVOL_DIR_OBJECTID (directory with ino == 2) the result is - * undefined and function returns -1 - */ -int lookup_path_rootid(int fd, u64 *rootid) -{ - struct btrfs_ioctl_ino_lookup_args args; - int ret; - - memset(&args, 0, sizeof(args)); - args.treeid = 0; - args.objectid = BTRFS_FIRST_FREE_OBJECTID; - - ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); - if (ret < 0) - return -errno; - - *rootid = args.treeid; - - return 0; -} - diff --git a/common/utils.c b/common/utils.c index 86ed2035..e0b1dc8f 100644 --- a/common/utils.c +++ b/common/utils.c @@ -1632,3 +1632,60 @@ out: return ret; } + +/* + * This function should be only used when parsing command arg, it won't return + * error to its caller and rather exit directly just like usage(). + */ +u64 arg_strtou64(const char *str) +{ + u64 value; + char *ptr_parse_end = NULL; + + value = strtoull(str, &ptr_parse_end, 0); + if (ptr_parse_end && *ptr_parse_end != '\0') { + fprintf(stderr, "ERROR: %s is not a valid numeric value.\n", + str); + exit(1); + } + + /* + * if we pass a negative number to strtoull, it will return an + * unexpected number to us, so let's do the check ourselves. + */ + if (str[0] == '-') { + fprintf(stderr, "ERROR: %s: negative value is invalid.\n", + str); + exit(1); + } + if (value == ULLONG_MAX) { + fprintf(stderr, "ERROR: %s is too large.\n", str); + exit(1); + } + return value; +} + +/* + * For a given: + * - file or directory return the containing tree root id + * - subvolume return its own tree id + * - BTRFS_EMPTY_SUBVOL_DIR_OBJECTID (directory with ino == 2) the result is + * undefined and function returns -1 + */ +int lookup_path_rootid(int fd, u64 *rootid) +{ + struct btrfs_ioctl_ino_lookup_args args; + int ret; + + memset(&args, 0, sizeof(args)); + args.treeid = 0; + args.objectid = BTRFS_FIRST_FREE_OBJECTID; + + ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); + if (ret < 0) + return -errno; + + *rootid = args.treeid; + + return 0; +}