From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz, gene@czarc.net
Subject: [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c
Date: Mon, 28 Jan 2013 12:10:19 +0800 [thread overview]
Message-ID: <1359346228-24804-2-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1359346228-24804-1-git-send-email-anand.jain@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.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@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 | 5 +++--
11 files changed, 42 insertions(+), 58 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 25b83d2..f10bf55 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -23,6 +23,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..0000000
--- 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; 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;
-}
diff --git a/utils.c b/utils.c
index 938f9a5..78530e1 100644
--- a/utils.c
+++ b/utils.c
@@ -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 /* due to an error in dirent.h, to get dirfd() */
#include <stdio.h>
#include <stdlib.h>
#ifndef __CHECKER__
@@ -1268,3 +1269,28 @@ u64 parse_size(char *s)
return strtoull(s, NULL, 10) * mult;
}
+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;
+}
diff --git a/utils.h b/utils.h
index 714fd7a..ed43e84 100644
--- a/utils.h
+++ b/utils.h
@@ -19,6 +19,8 @@
#ifndef __UTILS__
#define __UTILS__
+#include "ctree.h"
+
#define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
int make_btrfs(int fd, const char *device, const char *label,
@@ -44,8 +46,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
char *pretty_sizes(u64 size);
int check_label(char *input);
int get_mountpt(char *dev, char *mntpt, size_t size);
-
int btrfs_scan_block_devices(int run_ioctl);
-
u64 parse_size(char *s);
+int open_file_or_dir(const char *fname);
#endif
--
1.8.1.227.g44fe835
next prev parent reply other threads:[~2013-01-28 4:04 UTC|newest]
Thread overview: 131+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-25 9:19 [PATCH 00/10 V2] add show sub-command for btrfs subvol cli Anand Jain
2013-01-23 8:12 ` [PATCH 00/10] " Anand Jain
2013-01-23 8:12 ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-24 4:39 ` Eric Sandeen
2013-01-24 9:23 ` Stefan Behrens
2013-01-24 17:57 ` Goffredo Baroncelli
2013-01-24 19:42 ` Eric Sandeen
2013-01-24 22:09 ` Goffredo Baroncelli
2013-01-24 22:36 ` Chris Mason
2013-01-24 22:49 ` David Sterba
2013-01-24 22:52 ` Avi Miller
2013-01-25 16:14 ` Eric Sandeen
2013-01-25 16:48 ` Hugo Mills
2013-01-25 18:47 ` Gene Czarcinski
2013-01-28 3:12 ` Anand Jain
2013-01-25 15:19 ` Eric Sandeen
2013-01-25 9:21 ` Anand Jain
2013-01-23 8:12 ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-23 8:12 ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-23 8:12 ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-23 8:12 ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-24 4:49 ` Eric Sandeen
2013-01-25 9:20 ` Anand Jain
2013-01-23 8:12 ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-23 8:12 ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-23 8:12 ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-23 8:12 ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-23 8:12 ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-24 5:06 ` Eric Sandeen
2013-01-24 19:42 ` Zach Brown
2013-01-24 23:14 ` Chris Mason
2013-01-24 23:24 ` Zach Brown
2013-01-25 9:24 ` Anand Jain
2013-01-23 21:57 ` [PATCH 00/10] add show sub-command for btrfs " Gene Czarcinski
2013-01-24 4:11 ` Anand Jain
2013-01-24 20:52 ` Gene Czarcinski
2013-01-25 9:23 ` Anand Jain
2013-01-25 9:19 ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-25 9:19 ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-25 9:19 ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-25 9:19 ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-25 9:19 ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-25 9:19 ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-25 9:19 ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-25 9:19 ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-25 9:19 ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-25 9:19 ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-25 9:30 ` [RESEND] [PATCH 00/10 V2] add show sub-command for btrfs " Anand Jain
2013-01-25 9:30 ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-25 9:30 ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-25 9:30 ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-25 9:30 ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-25 9:30 ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-25 9:30 ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-25 9:30 ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-25 9:30 ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-25 9:30 ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-25 9:30 ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-25 10:07 ` Stefan Behrens
2013-01-28 5:26 ` Anand Jain
2013-01-28 4:10 ` [PATCH 00/10 v3] add show sub-command for btrfs " Anand Jain
2013-01-28 4:10 ` Anand Jain [this message]
2013-01-28 4:10 ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-28 4:10 ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-28 4:10 ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-28 4:10 ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-28 4:10 ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-28 4:10 ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-28 4:10 ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-28 4:10 ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-28 4:10 ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-28 5:29 ` [PATCH 00/10 v3] add show sub-command for btrfs " Anand Jain
2013-01-28 5:22 ` [RESEND] " Anand Jain
2013-01-28 5:22 ` [PATCH 01/10] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-28 18:08 ` David Sterba
2013-01-28 5:22 ` [PATCH 02/10] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-28 5:22 ` [PATCH 03/10] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-28 5:22 ` [PATCH 04/10] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-28 5:22 ` [PATCH 05/10] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-29 4:42 ` Wang Shilong
2013-01-28 18:04 ` David Sterba
2013-01-29 6:59 ` Anand Jain
2013-01-28 5:22 ` [PATCH 06/10] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-28 5:22 ` [PATCH 07/10] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-28 5:22 ` [PATCH 08/10] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-28 5:22 ` [PATCH 09/10] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-28 5:22 ` [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-29 6:48 ` [PATCH 00/12 v4] add show sub-command for btrfs " Anand Jain
2013-01-29 6:48 ` [PATCH 01/12] Btrfs-progs: move open_file_or_dir() to utils.c Anand Jain
2013-01-29 6:48 ` [PATCH 02/12] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-30 3:27 ` Wang Shilong
2013-01-30 9:57 ` Anand Jain
2013-01-29 6:48 ` [PATCH 03/12] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-29 6:48 ` [PATCH 04/12] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-29 6:48 ` [PATCH 05/12] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-29 6:48 ` [PATCH 06/12] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-29 6:48 ` [PATCH 07/12] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-29 6:48 ` [PATCH 08/12] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-29 6:48 ` [PATCH 09/12] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-29 6:48 ` [PATCH 10/12] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-30 10:32 ` Wang Shilong
2013-01-31 3:13 ` Anand Jain
2013-01-29 6:49 ` [PATCH 11/12] Btrfs-progs: filter the deleted subvolumes when listing snapshots Anand Jain
2013-01-29 6:49 ` [PATCH 12/12] Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes Anand Jain
2013-01-30 9:56 ` [PATCH 00/12 v5] Btrfs-progs: add show sub-command for btrfs subvol cli Anand Jain
2013-01-30 9:56 ` [PATCH 01/12] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-01-30 9:56 ` [PATCH 02/12] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-01-30 9:56 ` [PATCH 03/12] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-01-30 9:56 ` [PATCH 04/12] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-01-30 9:56 ` [PATCH 05/12] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-01-30 9:56 ` [PATCH 06/12] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-01-30 9:56 ` [PATCH 07/12] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-01-30 9:56 ` [PATCH 08/12] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-01-30 9:56 ` [PATCH 09/12] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-01-30 9:56 ` [PATCH 10/12] Btrfs-progs: filter the deleted subvolumes when listing snapshots Anand Jain
2013-01-30 9:56 ` [PATCH 11/12] Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes Anand Jain
2013-01-30 9:56 ` [PATCH 12/12] Btrfs-progs: Fix a small memory leak in managing the btrfs list filter Anand Jain
2013-02-01 7:56 ` [PATCH 00/13 v6] Btrfs-progs: add show sub-command for btrfs subvol cli Anand Jain
2013-02-01 7:56 ` [PATCH 01/13] Btrfs-progs: move printing subvol list outside of btrfs_list_subvols Anand Jain
2013-02-01 7:56 ` [PATCH 02/13] Btrfs-progs: add parent uuid for snapshots Anand Jain
2013-02-01 7:56 ` [PATCH 03/13] Btrfs-progs: move struct root_info to btrfs-list.h Anand Jain
2013-02-01 7:56 ` [PATCH 04/13] Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol Anand Jain
2013-02-01 7:56 ` [PATCH 05/13] Btrfs-progs: add method to filter snapshots by parent uuid Anand Jain
2013-02-01 7:56 ` [PATCH 06/13] Btrfs-progs: put find_mount_root() in commands.h Anand Jain
2013-02-01 7:56 ` [PATCH 07/13] Btrfs-progs: make printing subvol extensible to newer layouts Anand Jain
2013-02-01 7:56 ` [PATCH 08/13] Btrfs-progs: make get_subvol_name non cmds-send specific Anand Jain
2013-02-01 7:56 ` [PATCH 09/13] Btrfs-progs: add show subcommand to subvol cli Anand Jain
2013-02-01 7:56 ` [PATCH 10/13] Btrfs-progs: filter the deleted subvolumes when listing snapshots Anand Jain
2013-02-01 7:56 ` [PATCH 11/13] Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes Anand Jain
2013-02-01 7:56 ` [PATCH 12/13] Btrfs-progs: Fix a small memory leak in managing the btrfs list filter Anand Jain
2013-02-01 7:56 ` [PATCH 13/13] Btrfs-progs: add subvol flags to print Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359346228-24804-2-git-send-email-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=dsterba@suse.cz \
--cc=gene@czarc.net \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).