* [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs.
2014-07-10 3:05 [PATCH RESEND 1/4] btrfs-progs: Check fstype in find_mount_root() Qu Wenruo
@ 2014-07-10 3:05 ` Qu Wenruo
2014-07-10 7:34 ` Satoru Takeuchi
2014-07-29 12:02 ` David Sterba
0 siblings, 2 replies; 8+ messages in thread
From: Qu Wenruo @ 2014-07-10 3:05 UTC (permalink / raw)
To: linux-btrfs
When editing cmds-filesystem.c, I found cmd_filesystem_df() uses 7
spaces as indent instead of 1 tab (or 8 spaces). which makes indent
quite embarrassing.
Such problem is especillay hard to detect when reviewing patches,
since the leading '+' makes a tab only 7 spaces long, makeing 7 spaces
look the same with a tab.
This patch fixes all the 7 spaces indent.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-filesystem.c | 79 +++++++++++++++++++++++++++----------------------------
ctree.h | 15 ++++++-----
utils.c | 10 +++----
3 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 4b2d27e..0a9b62a 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -114,23 +114,23 @@ static const char * const filesystem_cmd_group_usage[] = {
};
static const char * const cmd_filesystem_df_usage[] = {
- "btrfs filesystem df <path>",
- "Show space usage information for a mount point",
- NULL
+ "btrfs filesystem df <path>",
+ "Show space usage information for a mount point",
+ NULL
};
static void print_df(struct btrfs_ioctl_space_args *sargs)
{
- u64 i;
- struct btrfs_ioctl_space_info *sp = sargs->spaces;
-
- for (i = 0; i < sargs->total_spaces; i++, sp++) {
- printf("%s, %s: total=%s, used=%s\n",
- group_type_str(sp->flags),
- group_profile_str(sp->flags),
- pretty_size(sp->total_bytes),
- pretty_size(sp->used_bytes));
- }
+ u64 i;
+ struct btrfs_ioctl_space_info *sp = sargs->spaces;
+
+ for (i = 0; i < sargs->total_spaces; i++, sp++) {
+ printf("%s, %s: total=%s, used=%s\n",
+ group_type_str(sp->flags),
+ group_profile_str(sp->flags),
+ pretty_size(sp->total_bytes),
+ pretty_size(sp->used_bytes));
+ }
}
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
@@ -183,33 +183,32 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
static int cmd_filesystem_df(int argc, char **argv)
{
- struct btrfs_ioctl_space_args *sargs = NULL;
- int ret;
- int fd;
- char *path;
- DIR *dirstream = NULL;
-
- if (check_argc_exact(argc, 2))
- usage(cmd_filesystem_df_usage);
-
- path = argv[1];
-
- fd = open_file_or_dir(path, &dirstream);
- if (fd < 0) {
- fprintf(stderr, "ERROR: can't access '%s'\n", path);
- return 1;
- }
- ret = get_df(fd, &sargs);
-
- if (!ret && sargs) {
- print_df(sargs);
- free(sargs);
- } else {
- fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
- }
-
- close_file_or_dir(fd, dirstream);
- return !!ret;
+ struct btrfs_ioctl_space_args *sargs = NULL;
+ int ret;
+ int fd;
+ char *path;
+ DIR *dirstream = NULL;
+
+ if (check_argc_exact(argc, 2))
+ usage(cmd_filesystem_df_usage);
+
+ path = argv[1];
+
+ fd = open_file_or_dir(path, &dirstream);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 1;
+ }
+ ret = get_df(fd, &sargs);
+ if (!ret && sargs) {
+ print_df(sargs);
+ free(sargs);
+ } else {
+ fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
+ }
+
+ close_file_or_dir(fd, dirstream);
+ return !!ret;
}
static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label,
diff --git a/ctree.h b/ctree.h
index 35d3633..83d85b3 100644
--- a/ctree.h
+++ b/ctree.h
@@ -939,10 +939,10 @@ struct btrfs_block_group_cache {
};
struct btrfs_extent_ops {
- int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
- u64 hint_byte, struct btrfs_key *ins);
- int (*free_extent)(struct btrfs_root *root, u64 bytenr,
- u64 num_bytes);
+ int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
+ u64 hint_byte, struct btrfs_key *ins);
+ int (*free_extent)(struct btrfs_root *root, u64 bytenr,
+ u64 num_bytes);
};
struct btrfs_device;
@@ -2117,9 +2117,10 @@ BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_exclusive,
static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
struct btrfs_item *e)
{
- unsigned long offset;
- offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
- return btrfs_item_size(eb, e) - offset;
+ unsigned long offset;
+
+ offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
+ return btrfs_item_size(eb, e) - offset;
}
/* this returns the number of file bytes represented by the inline item.
diff --git a/utils.c b/utils.c
index 07173ee..356bdce 100644
--- a/utils.c
+++ b/utils.c
@@ -1485,15 +1485,15 @@ char *__strncpy__null(char *dest, const char *src, size_t n)
*/
static int check_label(const char *input)
{
- int len = strlen(input);
+ int len = strlen(input);
- if (len > BTRFS_LABEL_SIZE - 1) {
+ if (len > BTRFS_LABEL_SIZE - 1) {
fprintf(stderr, "ERROR: Label %s is too long (max %d)\n",
input, BTRFS_LABEL_SIZE - 1);
- return -1;
- }
+ return -1;
+ }
- return 0;
+ return 0;
}
static int set_label_unmounted(const char *dev, const char *label)
--
2.0.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs.
2014-07-10 3:05 ` [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs Qu Wenruo
@ 2014-07-10 7:34 ` Satoru Takeuchi
2014-07-29 12:02 ` David Sterba
1 sibling, 0 replies; 8+ messages in thread
From: Satoru Takeuchi @ 2014-07-10 7:34 UTC (permalink / raw)
To: Qu Wenruo, linux-btrfs
(2014/07/10 12:05), Qu Wenruo wrote:
> When editing cmds-filesystem.c, I found cmd_filesystem_df() uses 7
> spaces as indent instead of 1 tab (or 8 spaces). which makes indent
> quite embarrassing.
> Such problem is especillay hard to detect when reviewing patches,
> since the leading '+' makes a tab only 7 spaces long, makeing 7 spaces
> look the same with a tab.
>
> This patch fixes all the 7 spaces indent.
>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
> ---
> cmds-filesystem.c | 79 +++++++++++++++++++++++++++----------------------------
> ctree.h | 15 ++++++-----
> utils.c | 10 +++----
> 3 files changed, 52 insertions(+), 52 deletions(-)
>
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index 4b2d27e..0a9b62a 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -114,23 +114,23 @@ static const char * const filesystem_cmd_group_usage[] = {
> };
>
> static const char * const cmd_filesystem_df_usage[] = {
> - "btrfs filesystem df <path>",
> - "Show space usage information for a mount point",
> - NULL
> + "btrfs filesystem df <path>",
> + "Show space usage information for a mount point",
> + NULL
> };
>
> static void print_df(struct btrfs_ioctl_space_args *sargs)
> {
> - u64 i;
> - struct btrfs_ioctl_space_info *sp = sargs->spaces;
> -
> - for (i = 0; i < sargs->total_spaces; i++, sp++) {
> - printf("%s, %s: total=%s, used=%s\n",
> - group_type_str(sp->flags),
> - group_profile_str(sp->flags),
> - pretty_size(sp->total_bytes),
> - pretty_size(sp->used_bytes));
> - }
> + u64 i;
> + struct btrfs_ioctl_space_info *sp = sargs->spaces;
> +
> + for (i = 0; i < sargs->total_spaces; i++, sp++) {
> + printf("%s, %s: total=%s, used=%s\n",
> + group_type_str(sp->flags),
> + group_profile_str(sp->flags),
> + pretty_size(sp->total_bytes),
> + pretty_size(sp->used_bytes));
> + }
> }
>
> static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
> @@ -183,33 +183,32 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
>
> static int cmd_filesystem_df(int argc, char **argv)
> {
> - struct btrfs_ioctl_space_args *sargs = NULL;
> - int ret;
> - int fd;
> - char *path;
> - DIR *dirstream = NULL;
> -
> - if (check_argc_exact(argc, 2))
> - usage(cmd_filesystem_df_usage);
> -
> - path = argv[1];
> -
> - fd = open_file_or_dir(path, &dirstream);
> - if (fd < 0) {
> - fprintf(stderr, "ERROR: can't access '%s'\n", path);
> - return 1;
> - }
> - ret = get_df(fd, &sargs);
> -
> - if (!ret && sargs) {
> - print_df(sargs);
> - free(sargs);
> - } else {
> - fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
> - }
> -
> - close_file_or_dir(fd, dirstream);
> - return !!ret;
> + struct btrfs_ioctl_space_args *sargs = NULL;
> + int ret;
> + int fd;
> + char *path;
> + DIR *dirstream = NULL;
> +
> + if (check_argc_exact(argc, 2))
> + usage(cmd_filesystem_df_usage);
> +
> + path = argv[1];
> +
> + fd = open_file_or_dir(path, &dirstream);
> + if (fd < 0) {
> + fprintf(stderr, "ERROR: can't access '%s'\n", path);
> + return 1;
> + }
> + ret = get_df(fd, &sargs);
> + if (!ret && sargs) {
> + print_df(sargs);
> + free(sargs);
> + } else {
> + fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
> + }
> +
> + close_file_or_dir(fd, dirstream);
> + return !!ret;
> }
>
> static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label,
> diff --git a/ctree.h b/ctree.h
> index 35d3633..83d85b3 100644
> --- a/ctree.h
> +++ b/ctree.h
> @@ -939,10 +939,10 @@ struct btrfs_block_group_cache {
> };
>
> struct btrfs_extent_ops {
> - int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
> - u64 hint_byte, struct btrfs_key *ins);
> - int (*free_extent)(struct btrfs_root *root, u64 bytenr,
> - u64 num_bytes);
> + int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
> + u64 hint_byte, struct btrfs_key *ins);
> + int (*free_extent)(struct btrfs_root *root, u64 bytenr,
> + u64 num_bytes);
> };
>
> struct btrfs_device;
> @@ -2117,9 +2117,10 @@ BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_exclusive,
> static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
> struct btrfs_item *e)
> {
> - unsigned long offset;
> - offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
> - return btrfs_item_size(eb, e) - offset;
> + unsigned long offset;
> +
> + offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
> + return btrfs_item_size(eb, e) - offset;
> }
>
> /* this returns the number of file bytes represented by the inline item.
> diff --git a/utils.c b/utils.c
> index 07173ee..356bdce 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -1485,15 +1485,15 @@ char *__strncpy__null(char *dest, const char *src, size_t n)
> */
> static int check_label(const char *input)
> {
> - int len = strlen(input);
> + int len = strlen(input);
>
> - if (len > BTRFS_LABEL_SIZE - 1) {
> + if (len > BTRFS_LABEL_SIZE - 1) {
> fprintf(stderr, "ERROR: Label %s is too long (max %d)\n",
> input, BTRFS_LABEL_SIZE - 1);
> - return -1;
> - }
> + return -1;
> + }
>
> - return 0;
> + return 0;
> }
>
> static int set_label_unmounted(const char *dev, const char *label)
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/4] btrfs-progs: Remove fprintf() in find_mount_root().
@ 2014-07-23 5:47 Qu Wenruo
2014-07-23 5:47 ` [PATCH v2 2/4] btrfs-progs: Check fstype " Qu Wenruo
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Qu Wenruo @ 2014-07-23 5:47 UTC (permalink / raw)
To: linux-btrfs
find_mount_root() function in utils.c should not print error string.
Caller should be responsible to print error string.
This patch will remove the only fprintf in find_mount_root() and modify
the caller a little to use strerror() to prompt users.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-receive.c | 4 ++--
cmds-send.c | 4 ++--
utils.c | 6 +-----
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/cmds-receive.c b/cmds-receive.c
index 48380a5..72afe2a 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -980,9 +980,9 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd,
ret = find_mount_root(dest_dir_full_path, &r->root_path);
if (ret < 0) {
- ret = -EINVAL;
fprintf(stderr, "ERROR: failed to determine mount point "
- "for %s\n", dest_dir_full_path);
+ "for %s: %s\n", dest_dir_full_path, strerror(-ret));
+ ret = -EINVAL;
goto out;
}
r->mnt_fd = open(r->root_path, O_RDONLY | O_NOATIME);
diff --git a/cmds-send.c b/cmds-send.c
index 9a73b32..48c3df4 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -356,9 +356,9 @@ static int init_root_path(struct btrfs_send *s, const char *subvol)
ret = find_mount_root(subvol, &s->root_path);
if (ret < 0) {
- ret = -EINVAL;
fprintf(stderr, "ERROR: failed to determine mount point "
- "for %s\n", subvol);
+ "for %s: %s\n", subvol, strerror(-ret));
+ ret = -EINVAL;
goto out;
}
diff --git a/utils.c b/utils.c
index 11250d9..2d0f18e 100644
--- a/utils.c
+++ b/utils.c
@@ -2422,12 +2422,8 @@ int find_mount_root(const char *path, char **mount_root)
}
endmntent(mnttab);
- if (!longest_match) {
- fprintf(stderr,
- "ERROR: Failed to find mount root for path %s.\n",
- path);
+ if (!longest_match)
return -ENOENT;
- }
ret = 0;
*mount_root = realpath(longest_match, NULL);
--
2.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] btrfs-progs: Check fstype in find_mount_root()
2014-07-23 5:47 [PATCH 1/4] btrfs-progs: Remove fprintf() in find_mount_root() Qu Wenruo
@ 2014-07-23 5:47 ` Qu Wenruo
2014-07-29 13:57 ` David Sterba
2014-07-23 5:47 ` [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs Qu Wenruo
2014-07-23 5:47 ` [PATCH v3 4/4] btrfs-progs: Add mount point output for 'btrfs fi df' Qu Wenruo
2 siblings, 1 reply; 8+ messages in thread
From: Qu Wenruo @ 2014-07-23 5:47 UTC (permalink / raw)
To: linux-btrfs
When calling find_mount_root(), caller in fact wants to find the mount
point of *BTRFS*.
So also check ent->fstype in find_mount_root() and do special error
string output in caller.
This will suppress a lot of "Inapproiate ioctl for device" error
message.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
changelog:
v2:
move error message to caller.
---
cmds-receive.c | 7 +++++++
cmds-send.c | 14 ++++++++++++++
cmds-subvolume.c | 7 +++++++
utils.c | 9 +++++++++
4 files changed, 37 insertions(+)
diff --git a/cmds-receive.c b/cmds-receive.c
index 72afe2a..0644b59 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -985,6 +985,13 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd,
ret = -EINVAL;
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ dest_dir_full_path);
+ ret = -EINVAL;
+ goto out;
+ }
r->mnt_fd = open(r->root_path, O_RDONLY | O_NOATIME);
if (r->mnt_fd < 0) {
ret = -errno;
diff --git a/cmds-send.c b/cmds-send.c
index 48c3df4..d6b1855 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -361,6 +361,13 @@ static int init_root_path(struct btrfs_send *s, const char *subvol)
ret = -EINVAL;
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ subvol);
+ ret = -EINVAL;
+ goto out;
+ }
s->mnt_fd = open(s->root_path, O_RDONLY | O_NOATIME);
if (s->mnt_fd < 0) {
@@ -628,6 +635,13 @@ int cmd_send(int argc, char **argv)
strerror(-ret));
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ subvol);
+ ret = -EINVAL;
+ goto out;
+ }
if (strcmp(send.root_path, mount_root) != 0) {
ret = -EINVAL;
fprintf(stderr, "ERROR: all subvols must be from the "
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 639fb10..64a66e3 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -986,6 +986,13 @@ static int cmd_subvol_show(int argc, char **argv)
"%s\n", fullpath, strerror(-ret));
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ fullpath);
+ ret = -EINVAL;
+ goto out;
+ }
ret = 1;
svpath = get_subvol_name(mnt, fullpath);
diff --git a/utils.c b/utils.c
index 2d0f18e..b96d5b4 100644
--- a/utils.c
+++ b/utils.c
@@ -2390,6 +2390,9 @@ int lookup_ino_rootid(int fd, u64 *rootid)
return 0;
}
+/* return 0 if a btrfs mount point if found
+ * return 1 if a mount point is found but not btrfs
+ * return <0 if something goes wrong */
int find_mount_root(const char *path, char **mount_root)
{
FILE *mnttab;
@@ -2397,6 +2400,7 @@ int find_mount_root(const char *path, char **mount_root)
struct mntent *ent;
int len;
int ret;
+ int not_btrfs;
int longest_matchlen = 0;
char *longest_match = NULL;
@@ -2417,6 +2421,7 @@ int find_mount_root(const char *path, char **mount_root)
free(longest_match);
longest_matchlen = len;
longest_match = strdup(ent->mnt_dir);
+ not_btrfs = strcmp(ent->mnt_type, "btrfs");
}
}
}
@@ -2424,6 +2429,10 @@ int find_mount_root(const char *path, char **mount_root)
if (!longest_match)
return -ENOENT;
+ if (not_btrfs) {
+ free(longest_match);
+ return 1;
+ }
ret = 0;
*mount_root = realpath(longest_match, NULL);
--
2.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs.
2014-07-23 5:47 [PATCH 1/4] btrfs-progs: Remove fprintf() in find_mount_root() Qu Wenruo
2014-07-23 5:47 ` [PATCH v2 2/4] btrfs-progs: Check fstype " Qu Wenruo
@ 2014-07-23 5:47 ` Qu Wenruo
2014-07-23 5:47 ` [PATCH v3 4/4] btrfs-progs: Add mount point output for 'btrfs fi df' Qu Wenruo
2 siblings, 0 replies; 8+ messages in thread
From: Qu Wenruo @ 2014-07-23 5:47 UTC (permalink / raw)
To: linux-btrfs
When editing cmds-filesystem.c, I found cmd_filesystem_df() uses 7
spaces as indent instead of 1 tab (or 8 spaces). which makes indent
quite embarrassing.
Such problem is especillay hard to detect when reviewing patches,
since the leading '+' makes a tab only 7 spaces long, makeing 7 spaces
look the same with a tab.
This patch fixes all the 7 spaces indent.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-filesystem.c | 79 +++++++++++++++++++++++++++----------------------------
ctree.h | 15 ++++++-----
utils.c | 10 +++----
3 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index bf87bbe..108d9b7 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -114,23 +114,23 @@ static const char * const filesystem_cmd_group_usage[] = {
};
static const char * const cmd_filesystem_df_usage[] = {
- "btrfs filesystem df <path>",
- "Show space usage information for a mount point",
- NULL
+ "btrfs filesystem df <path>",
+ "Show space usage information for a mount point",
+ NULL
};
static void print_df(struct btrfs_ioctl_space_args *sargs)
{
- u64 i;
- struct btrfs_ioctl_space_info *sp = sargs->spaces;
-
- for (i = 0; i < sargs->total_spaces; i++, sp++) {
- printf("%s, %s: total=%s, used=%s\n",
- group_type_str(sp->flags),
- group_profile_str(sp->flags),
- pretty_size(sp->total_bytes),
- pretty_size(sp->used_bytes));
- }
+ u64 i;
+ struct btrfs_ioctl_space_info *sp = sargs->spaces;
+
+ for (i = 0; i < sargs->total_spaces; i++, sp++) {
+ printf("%s, %s: total=%s, used=%s\n",
+ group_type_str(sp->flags),
+ group_profile_str(sp->flags),
+ pretty_size(sp->total_bytes),
+ pretty_size(sp->used_bytes));
+ }
}
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
@@ -183,33 +183,32 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
static int cmd_filesystem_df(int argc, char **argv)
{
- struct btrfs_ioctl_space_args *sargs = NULL;
- int ret;
- int fd;
- char *path;
- DIR *dirstream = NULL;
-
- if (check_argc_exact(argc, 2))
- usage(cmd_filesystem_df_usage);
-
- path = argv[1];
-
- fd = open_file_or_dir(path, &dirstream);
- if (fd < 0) {
- fprintf(stderr, "ERROR: can't access '%s'\n", path);
- return 1;
- }
- ret = get_df(fd, &sargs);
-
- if (!ret && sargs) {
- print_df(sargs);
- free(sargs);
- } else {
- fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
- }
-
- close_file_or_dir(fd, dirstream);
- return !!ret;
+ struct btrfs_ioctl_space_args *sargs = NULL;
+ int ret;
+ int fd;
+ char *path;
+ DIR *dirstream = NULL;
+
+ if (check_argc_exact(argc, 2))
+ usage(cmd_filesystem_df_usage);
+
+ path = argv[1];
+
+ fd = open_file_or_dir(path, &dirstream);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 1;
+ }
+ ret = get_df(fd, &sargs);
+ if (!ret && sargs) {
+ print_df(sargs);
+ free(sargs);
+ } else {
+ fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
+ }
+
+ close_file_or_dir(fd, dirstream);
+ return !!ret;
}
static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label,
diff --git a/ctree.h b/ctree.h
index 35d3633..83d85b3 100644
--- a/ctree.h
+++ b/ctree.h
@@ -939,10 +939,10 @@ struct btrfs_block_group_cache {
};
struct btrfs_extent_ops {
- int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
- u64 hint_byte, struct btrfs_key *ins);
- int (*free_extent)(struct btrfs_root *root, u64 bytenr,
- u64 num_bytes);
+ int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
+ u64 hint_byte, struct btrfs_key *ins);
+ int (*free_extent)(struct btrfs_root *root, u64 bytenr,
+ u64 num_bytes);
};
struct btrfs_device;
@@ -2117,9 +2117,10 @@ BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_exclusive,
static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
struct btrfs_item *e)
{
- unsigned long offset;
- offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
- return btrfs_item_size(eb, e) - offset;
+ unsigned long offset;
+
+ offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
+ return btrfs_item_size(eb, e) - offset;
}
/* this returns the number of file bytes represented by the inline item.
diff --git a/utils.c b/utils.c
index b96d5b4..8befd57 100644
--- a/utils.c
+++ b/utils.c
@@ -1467,15 +1467,15 @@ char *__strncpy__null(char *dest, const char *src, size_t n)
*/
static int check_label(const char *input)
{
- int len = strlen(input);
+ int len = strlen(input);
- if (len > BTRFS_LABEL_SIZE - 1) {
+ if (len > BTRFS_LABEL_SIZE - 1) {
fprintf(stderr, "ERROR: Label %s is too long (max %d)\n",
input, BTRFS_LABEL_SIZE - 1);
- return -1;
- }
+ return -1;
+ }
- return 0;
+ return 0;
}
static int set_label_unmounted(const char *dev, const char *label)
--
2.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 4/4] btrfs-progs: Add mount point output for 'btrfs fi df'
2014-07-23 5:47 [PATCH 1/4] btrfs-progs: Remove fprintf() in find_mount_root() Qu Wenruo
2014-07-23 5:47 ` [PATCH v2 2/4] btrfs-progs: Check fstype " Qu Wenruo
2014-07-23 5:47 ` [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs Qu Wenruo
@ 2014-07-23 5:47 ` Qu Wenruo
2 siblings, 0 replies; 8+ messages in thread
From: Qu Wenruo @ 2014-07-23 5:47 UTC (permalink / raw)
To: linux-btrfs
Add mount point output for 'btrfs fi df'.
Also since the patch uses find_mount_root() to find mount point,
now 'btrfs fi df' can output more meaningful error message when given a
non-btrfs path.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
changelog:
v2:
Call realpath() before find_mount_root() to deal with relative path
v3:
Only output mount point when get_df() successed.
---
cmds-filesystem.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 108d9b7..ca6bcad 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -187,6 +187,8 @@ static int cmd_filesystem_df(int argc, char **argv)
int ret;
int fd;
char *path;
+ char *real_path = NULL;
+ char *mount_point = NULL;
DIR *dirstream = NULL;
if (check_argc_exact(argc, 2))
@@ -194,6 +196,29 @@ static int cmd_filesystem_df(int argc, char **argv)
path = argv[1];
+ real_path = realpath(path, NULL);
+ if (!real_path) {
+ fprintf(stderr,
+ "ERROR: Failed to resolve real path for %s: %s\n",
+ path, strerror(errno));
+ return 1;
+ }
+ ret = find_mount_root(real_path, &mount_point);
+ if (ret < 0) {
+ fprintf(stderr,
+ "ERROR: failed to determine mount point for %s: %s\n",
+ path, strerror(-ret));
+ free(real_path);
+ return 1;
+ }
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s does not belong to a btrfs mount point\n",
+ path);
+ free(real_path);
+ return 1;
+ }
+
fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", path);
@@ -201,12 +226,15 @@ static int cmd_filesystem_df(int argc, char **argv)
}
ret = get_df(fd, &sargs);
if (!ret && sargs) {
+ printf("Mounted on: %s\n", mount_point);
print_df(sargs);
free(sargs);
} else {
fprintf(stderr, "ERROR: get_df failed %s\n", strerror(-ret));
}
+ free(real_path);
+ free(mount_point);
close_file_or_dir(fd, dirstream);
return !!ret;
}
--
2.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs.
2014-07-10 3:05 ` [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs Qu Wenruo
2014-07-10 7:34 ` Satoru Takeuchi
@ 2014-07-29 12:02 ` David Sterba
1 sibling, 0 replies; 8+ messages in thread
From: David Sterba @ 2014-07-29 12:02 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Thu, Jul 10, 2014 at 11:05:12AM +0800, Qu Wenruo wrote:
> When editing cmds-filesystem.c, I found cmd_filesystem_df() uses 7
> spaces as indent instead of 1 tab (or 8 spaces). which makes indent
> quite embarrassing.
> Such problem is especillay hard to detect when reviewing patches,
> since the leading '+' makes a tab only 7 spaces long, makeing 7 spaces
> look the same with a tab.
>
> This patch fixes all the 7 spaces indent.
The whitespace changes cause patch conflicts and I'm inclined not to add
them or postpone after the patch queue is relatively calm.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/4] btrfs-progs: Check fstype in find_mount_root()
2014-07-23 5:47 ` [PATCH v2 2/4] btrfs-progs: Check fstype " Qu Wenruo
@ 2014-07-29 13:57 ` David Sterba
0 siblings, 0 replies; 8+ messages in thread
From: David Sterba @ 2014-07-29 13:57 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Wed, Jul 23, 2014 at 01:47:35PM +0800, Qu Wenruo wrote:
> --- a/utils.c
> +++ b/utils.c
> @@ -2390,6 +2390,9 @@ int lookup_ino_rootid(int fd, u64 *rootid)
> return 0;
> }
>
> +/* return 0 if a btrfs mount point if found
> + * return 1 if a mount point is found but not btrfs
> + * return <0 if something goes wrong */
> int find_mount_root(const char *path, char **mount_root)
> {
> FILE *mnttab;
> @@ -2397,6 +2400,7 @@ int find_mount_root(const char *path, char **mount_root)
> struct mntent *ent;
> int len;
> int ret;
> + int not_btrfs;
[CC] utils.o
utils.c: In function ‘find_mount_root’:
utils.c:2342:6: warning: ‘not_btrfs’ may be used uninitialized in this function
I've initialized to 1 to fix it, no need to resend the patch.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-07-29 13:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-23 5:47 [PATCH 1/4] btrfs-progs: Remove fprintf() in find_mount_root() Qu Wenruo
2014-07-23 5:47 ` [PATCH v2 2/4] btrfs-progs: Check fstype " Qu Wenruo
2014-07-29 13:57 ` David Sterba
2014-07-23 5:47 ` [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs Qu Wenruo
2014-07-23 5:47 ` [PATCH v3 4/4] btrfs-progs: Add mount point output for 'btrfs fi df' Qu Wenruo
-- strict thread matches above, loose matches on Subject: below --
2014-07-10 3:05 [PATCH RESEND 1/4] btrfs-progs: Check fstype in find_mount_root() Qu Wenruo
2014-07-10 3:05 ` [PATCH 3/4] btrfs-progs: Fix wrong indent in btrfs-progs Qu Wenruo
2014-07-10 7:34 ` Satoru Takeuchi
2014-07-29 12:02 ` David Sterba
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).