aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2021-09-29 16:13:30 +0200
committerDavid Sterba <dsterba@suse.com>2021-10-08 20:47:03 +0200
commita3efed2adbad6bb85b931be0c44d24d74eedbce1 (patch)
tree96bffa48644da81161afb88eb59afa5197e288be /common
parent00610f5853f013aba1738d3fd8c8091574ff2f20 (diff)
downloadbtrfs-progs-a3efed2adbad6bb85b931be0c44d24d74eedbce1.tar.gz
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 <dsterba@suse.com>
Diffstat (limited to 'common')
-rw-r--r--common/utils-lib.c82
-rw-r--r--common/utils.c57
2 files changed, 57 insertions, 82 deletions
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 <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <sys/ioctl.h>
-#include <ioctl.h>
-#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;
+}