[PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c
From: Anand Jain anand.j...@oracle.com The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7. Signed-off-by: Anand Jain anand.j...@oracle.com Original-Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de --- Makefile |4 ++-- btrfsctl.c |7 --- cmds-balance.c |1 + cmds-inspect.c |1 + cmds-qgroup.c|1 + cmds-quota.c |1 + cmds-subvolume.c |1 + commands.h |3 --- common.c | 46 -- utils.c | 30 -- utils.h |3 +++ 11 files changed, 42 insertions(+), 56 deletions(-) delete mode 100644 common.c diff --git a/Makefile b/Makefile index 4894903..8576d90 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/btrfsctl.c b/btrfsctl.c index 518684c..049a5f3 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -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; @@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname) } return fd; } + int main(int ac, char **av) { char *fname = NULL; @@ -128,7 +129,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 +239,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) { diff --git a/cmds-balance.c b/cmds-balance.c index 38a7426..6268b61 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -28,6 +28,7 @@ #include volumes.h #include commands.h +#include utils.h static const char * const balance_cmd_group_usage[] = { btrfs [filesystem] balance command [options] path, diff --git a/cmds-inspect.c b/cmds-inspect.c index edabff5..79e069b 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -22,6 +22,7 @@ #include kerncompat.h #include ioctl.h +#include utils.h #include commands.h #include btrfs-list.h diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 1525c11..cafc284 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -24,6 +24,7 @@ #include ioctl.h #include commands.h +#include utils.h static const char * const qgroup_cmd_group_usage[] = { btrfs qgroup command [options] path, diff --git a/cmds-quota.c b/cmds-quota.c index cf9ad97..8481514 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -23,6 +23,7 @@ #include ioctl.h #include commands.h +#include utils.h static const char * const quota_cmd_group_usage[] = { btrfs quota command [options] path, diff --git a/cmds-subvolume.c b/cmds-subvolume.c index ac39f7b..e3cdb1e 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -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, diff --git a/commands.h b/commands.h index bb6d2dd..8114a73 100644 --- a/commands.h +++ b/commands.h @@ -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; diff --git a/common.c b/common.c deleted file mode 100644 index 03f6570..000 --- a/common.c +++ /dev/null @@ -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;
[PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c
From: Anand Jain anand.j...@oracle.com The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7. Signed-off-by: Anand Jain anand.j...@oracle.com Original-Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de --- Makefile |4 ++-- btrfsctl.c |7 --- cmds-balance.c |1 + cmds-inspect.c |1 + cmds-qgroup.c|1 + cmds-quota.c |1 + cmds-subvolume.c |1 + commands.h |3 --- common.c | 46 -- utils.c | 30 -- utils.h |3 +++ 11 files changed, 42 insertions(+), 56 deletions(-) delete mode 100644 common.c diff --git a/Makefile b/Makefile index 4894903..8576d90 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/btrfsctl.c b/btrfsctl.c index 518684c..049a5f3 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -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; @@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname) } return fd; } + int main(int ac, char **av) { char *fname = NULL; @@ -128,7 +129,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 +239,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) { diff --git a/cmds-balance.c b/cmds-balance.c index 38a7426..6268b61 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -28,6 +28,7 @@ #include volumes.h #include commands.h +#include utils.h static const char * const balance_cmd_group_usage[] = { btrfs [filesystem] balance command [options] path, diff --git a/cmds-inspect.c b/cmds-inspect.c index edabff5..79e069b 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -22,6 +22,7 @@ #include kerncompat.h #include ioctl.h +#include utils.h #include commands.h #include btrfs-list.h diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 1525c11..cafc284 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -24,6 +24,7 @@ #include ioctl.h #include commands.h +#include utils.h static const char * const qgroup_cmd_group_usage[] = { btrfs qgroup command [options] path, diff --git a/cmds-quota.c b/cmds-quota.c index cf9ad97..8481514 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -23,6 +23,7 @@ #include ioctl.h #include commands.h +#include utils.h static const char * const quota_cmd_group_usage[] = { btrfs quota command [options] path, diff --git a/cmds-subvolume.c b/cmds-subvolume.c index ac39f7b..e3cdb1e 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -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, diff --git a/commands.h b/commands.h index bb6d2dd..8114a73 100644 --- a/commands.h +++ b/commands.h @@ -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; diff --git a/common.c b/common.c deleted file mode 100644 index 03f6570..000 --- a/common.c +++ /dev/null @@ -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;
[PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c
From: Anand Jain anand.j...@oracle.com The definition of the function open_file_or_dir() is moved from common.c to utils.c in order to be able to share some common code between scrub and the device stats in the following step. That common code uses open_file_or_dir(). Since open_file_or_dir() makes use of the function dirfd(3), the required XOPEN version was raised from 6 to 7. Signed-off-by: Anand Jain anand.j...@oracle.com Original-Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de --- Makefile |4 ++-- btrfsctl.c |7 --- cmds-balance.c |1 + cmds-inspect.c |1 + cmds-qgroup.c|1 + cmds-quota.c |1 + cmds-subvolume.c |1 + commands.h |3 --- common.c | 46 -- utils.c | 30 -- utils.h |3 +++ 11 files changed, 42 insertions(+), 56 deletions(-) delete mode 100644 common.c diff --git a/Makefile b/Makefile index 4894903..8576d90 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/btrfsctl.c b/btrfsctl.c index 518684c..049a5f3 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -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; @@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname) } return fd; } + int main(int ac, char **av) { char *fname = NULL; @@ -128,7 +129,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 +239,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) { diff --git a/cmds-balance.c b/cmds-balance.c index 38a7426..6268b61 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -28,6 +28,7 @@ #include volumes.h #include commands.h +#include utils.h static const char * const balance_cmd_group_usage[] = { btrfs [filesystem] balance command [options] path, diff --git a/cmds-inspect.c b/cmds-inspect.c index edabff5..79e069b 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -22,6 +22,7 @@ #include kerncompat.h #include ioctl.h +#include utils.h #include commands.h #include btrfs-list.h diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 1525c11..cafc284 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -24,6 +24,7 @@ #include ioctl.h #include commands.h +#include utils.h static const char * const qgroup_cmd_group_usage[] = { btrfs qgroup command [options] path, diff --git a/cmds-quota.c b/cmds-quota.c index cf9ad97..8481514 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -23,6 +23,7 @@ #include ioctl.h #include commands.h +#include utils.h static const char * const quota_cmd_group_usage[] = { btrfs quota command [options] path, diff --git a/cmds-subvolume.c b/cmds-subvolume.c index ac39f7b..e3cdb1e 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -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, diff --git a/commands.h b/commands.h index bb6d2dd..8114a73 100644 --- a/commands.h +++ b/commands.h @@ -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; diff --git a/common.c b/common.c deleted file mode 100644 index 03f6570..000 --- a/common.c +++ /dev/null @@ -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;