@@ -41,8 +41,8 @@ all: version $(progs) manpages
version:
bash version.sh
-btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects)
- $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \
+btrfs: $(objects) btrfs.o help.o $(cmds_objects)
+ $(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
$(objects) $(LDFLAGS) $(LIBS) -lpthread
calc-size: $(objects) calc-size.o
@@ -63,7 +63,7 @@ static void print_usage(void)
exit(1);
}
-static int open_file_or_dir(const char *fname)
+static int btrfsctl_open_file_or_dir(const char *fname)
{
int ret;
struct stat st;
@@ -128,7 +128,7 @@ int main(int ac, char **av)
snap_location = strdup(fullpath);
snap_location = dirname(snap_location);
- snap_fd = open_file_or_dir(snap_location);
+ snap_fd = btrfsctl_open_file_or_dir(snap_location);
name = strdup(fullpath);
name = basename(name);
@@ -238,7 +238,7 @@ int main(int ac, char **av)
}
name = fname;
} else {
- fd = open_file_or_dir(fname);
+ fd = btrfsctl_open_file_or_dir(fname);
}
if (name) {
@@ -26,6 +26,7 @@
#include "ctree.h"
#include "ioctl.h"
#include "volumes.h"
+#include "utils.h"
#include "commands.h"
@@ -21,6 +21,7 @@
#include <errno.h>
#include "kerncompat.h"
+#include "utils.h"
#include "ioctl.h"
#include "commands.h"
@@ -22,6 +22,7 @@
#include "ctree.h"
#include "ioctl.h"
+#include "utils.h"
#include "commands.h"
@@ -21,6 +21,7 @@
#include "ctree.h"
#include "ioctl.h"
+#include "utils.h"
#include "commands.h"
@@ -32,6 +32,7 @@
#include "ctree.h"
#include "commands.h"
#include "btrfs-list.h"
+#include "utils.h"
static const char * const subvolume_cmd_group_usage[] = {
"btrfs subvolume <command> <args>",
@@ -79,9 +79,6 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
void help_command_group(const struct cmd_group *grp, int argc, char **argv);
-/* common.c */
-int open_file_or_dir(const char *fname);
-
extern const struct cmd_group subvolume_cmd_group;
extern const struct cmd_group filesystem_cmd_group;
extern const struct cmd_group balance_cmd_group;
deleted file mode 100644
@@ -1,46 +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 <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <fcntl.h>
-
-int open_file_or_dir(const char *fname)
-{
- int ret;
- struct stat st;
- DIR *dirstream;
- int fd;
-
- ret = stat(fname, &st);
- if (ret < 0) {
- return -1;
- }
- if (S_ISDIR(st.st_mode)) {
- dirstream = opendir(fname);
- if (!dirstream) {
- return -2;
- }
- fd = dirfd(dirstream);
- } else {
- fd = open(fname, O_RDWR);
- }
- if (fd < 0) {
- return -3;
- }
- return fd;
-}
@@ -16,8 +16,9 @@
* Boston, MA 021110-1307, USA.
*/
-#define _XOPEN_SOURCE 600
-#define __USE_XOPEN2K
+#define _XOPEN_SOURCE 700
+#define __USE_XOPEN2K8
+#define __XOPEN2K8
#include <stdio.h>
#include <stdlib.h>
#ifndef __CHECKER__
@@ -1117,6 +1118,30 @@ char *pretty_sizes(u64 size)
return pretty;
}
+int open_file_or_dir(const char *fname)
+{
+ int ret;
+ struct stat st;
+ DIR *dirstream;
+ int fd;
+
+ ret = stat(fname, &st);
+ if (ret < 0)
+ return -1;
+ if (S_ISDIR(st.st_mode)) {
+ dirstream = opendir(fname);
+ if (!dirstream)
+ return -2;
+ fd = dirfd(dirstream);
+ } else {
+ fd = open(fname, O_RDWR);
+ }
+ if (fd < 0)
+ return -3;
+
+ return fd;
+}
+
/*
* Checks to make sure that the label matches our requirements.
* Returns:
@@ -45,6 +45,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size,
int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
int super_offset);
char *pretty_sizes(u64 size);
+int open_file_or_dir(const char *fname);
int check_label(char *input);
int get_mountpt(char *dev, char *mntpt, size_t size);