projects
/
platform
/
upstream
/
btrfs-progs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
btrfs-progs: docs: add note about mount option applicability
[platform/upstream/btrfs-progs.git]
/
cmds-inspect.c
diff --git
a/cmds-inspect.c
b/cmds-inspect.c
index
25ddd4c
..
885f3ab
100644
(file)
--- a/
cmds-inspect.c
+++ b/
cmds-inspect.c
@@
-31,7
+31,7
@@
#include "disk-io.h"
#include "commands.h"
#include "btrfs-list.h"
#include "disk-io.h"
#include "commands.h"
#include "btrfs-list.h"
-#include "
cmds-inspect-dump-tree
.h"
+#include "
help
.h"
static const char * const inspect_cmd_group_usage[] = {
"btrfs inspect-internal <command> <args>",
static const char * const inspect_cmd_group_usage[] = {
"btrfs inspect-internal <command> <args>",
@@
-52,7
+52,7
@@
static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
ret = ioctl(fd, BTRFS_IOC_INO_PATHS, &ipa);
if (ret < 0) {
ret = ioctl(fd, BTRFS_IOC_INO_PATHS, &ipa);
if (ret < 0) {
-
printf("ioctl ret=%d, error: %s\n", ret
, strerror(errno));
+
error("ino paths ioctl: %s"
, strerror(errno));
goto out;
}
goto out;
}
@@
-94,7
+94,6
@@
static int cmd_inspect_inode_resolve(int argc, char **argv)
int ret;
DIR *dirstream = NULL;
int ret;
DIR *dirstream = NULL;
- optind = 1;
while (1) {
int c = getopt(argc, argv, "v");
if (c < 0)
while (1) {
int c = getopt(argc, argv, "v");
if (c < 0)
@@
-145,11
+144,10
@@
static int cmd_inspect_logical_resolve(int argc, char **argv)
struct btrfs_ioctl_logical_ino_args loi;
struct btrfs_data_container *inodes;
u64 size = 4096;
struct btrfs_ioctl_logical_ino_args loi;
struct btrfs_data_container *inodes;
u64 size = 4096;
- char full_path[
4096
];
+ char full_path[
PATH_MAX
];
char *path_ptr;
DIR *dirstream = NULL;
char *path_ptr;
DIR *dirstream = NULL;
- optind = 1;
while (1) {
int c = getopt(argc, argv, "Pvs:");
if (c < 0)
while (1) {
int c = getopt(argc, argv, "Pvs:");
if (c < 0)
@@
-173,7
+171,7
@@
static int cmd_inspect_logical_resolve(int argc, char **argv)
if (check_argc_exact(argc - optind, 2))
usage(cmd_inspect_logical_resolve_usage);
if (check_argc_exact(argc - optind, 2))
usage(cmd_inspect_logical_resolve_usage);
- size = min(size, (u64)
64 * 1024
);
+ size = min(size, (u64)
SZ_64K
);
inodes = malloc(size);
if (!inodes)
return 1;
inodes = malloc(size);
if (!inodes)
return 1;
@@
-191,7
+189,7
@@
static int cmd_inspect_logical_resolve(int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_LOGICAL_INO, &loi);
if (ret < 0) {
ret = ioctl(fd, BTRFS_IOC_LOGICAL_INO, &loi);
if (ret < 0) {
-
printf("ioctl ret=%d, error: %s\n", ret
, strerror(errno));
+
error("logical ino ioctl: %s"
, strerror(errno));
goto out;
}
goto out;
}
@@
-207,7
+205,10
@@
static int cmd_inspect_logical_resolve(int argc, char **argv)
ret = snprintf(full_path, bytes_left, "%s/", argv[optind+1]);
path_ptr = full_path + ret;
bytes_left -= ret + 1;
ret = snprintf(full_path, bytes_left, "%s/", argv[optind+1]);
path_ptr = full_path + ret;
bytes_left -= ret + 1;
- BUG_ON(bytes_left < 0);
+ if (bytes_left < 0) {
+ error("path buffer too small: %d bytes", bytes_left);
+ goto out;
+ }
for (i = 0; i < inodes->elem_cnt; i += 3) {
u64 inum = inodes->val[i];
for (i = 0; i < inodes->elem_cnt; i += 3) {
u64 inum = inodes->val[i];
@@
-230,8
+231,12
@@
static int cmd_inspect_logical_resolve(int argc, char **argv)
path_ptr[-1] = '/';
ret = snprintf(path_ptr, bytes_left, "%s",
name);
path_ptr[-1] = '/';
ret = snprintf(path_ptr, bytes_left, "%s",
name);
- BUG_ON(ret >= bytes_left);
free(name);
free(name);
+ if (ret >= bytes_left) {
+ error("path buffer too small: %d bytes",
+ bytes_left - ret);
+ goto out;
+ }
path_fd = btrfs_open_dir(full_path, &dirs, 1);
if (path_fd < 0) {
ret = -ENOENT;
path_fd = btrfs_open_dir(full_path, &dirs, 1);
if (path_fd < 0) {
ret = -ENOENT;
@@
-267,22
+272,23
@@
static int cmd_inspect_subvolid_resolve(int argc, char **argv)
char path[PATH_MAX];
DIR *dirstream = NULL;
char path[PATH_MAX];
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_inspect_subvolid_resolve_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_inspect_subvolid_resolve_usage);
usage(cmd_inspect_subvolid_resolve_usage);
- fd = btrfs_open_dir(argv[
2
], &dirstream, 1);
+ fd = btrfs_open_dir(argv[
optind + 1
], &dirstream, 1);
if (fd < 0) {
ret = -ENOENT;
goto out;
}
if (fd < 0) {
ret = -ENOENT;
goto out;
}
- subvol_id = arg_strtou64(argv[
1
]);
+ subvol_id = arg_strtou64(argv[
optind
]);
ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id);
if (ret) {
ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id);
if (ret) {
- fprintf(stderr,
- "%s: btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n",
- argv[0], (unsigned long long)subvol_id, ret);
+ error("resolving subvolid %llu error %d",
+ (unsigned long long)subvol_id, ret);
goto out;
}
goto out;
}
@@
-291,7
+297,7
@@
static int cmd_inspect_subvolid_resolve(int argc, char **argv)
out:
close_file_or_dir(fd, dirstream);
out:
close_file_or_dir(fd, dirstream);
- return
ret ? 1 : 0
;
+ return
!!ret
;
}
static const char* const cmd_inspect_rootid_usage[] = {
}
static const char* const cmd_inspect_rootid_usage[] = {
@@
-307,19
+313,20
@@
static int cmd_inspect_rootid(int argc, char **argv)
u64 rootid;
DIR *dirstream = NULL;
u64 rootid;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_inspect_rootid_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_inspect_rootid_usage);
usage(cmd_inspect_rootid_usage);
- fd = btrfs_open_
dir(argv[1
], &dirstream, 1);
+ fd = btrfs_open_
file_or_dir(argv[optind
], &dirstream, 1);
if (fd < 0) {
ret = -ENOENT;
goto out;
}
if (fd < 0) {
ret = -ENOENT;
goto out;
}
- ret = lookup_
ino
_rootid(fd, &rootid);
+ ret = lookup_
path
_rootid(fd, &rootid);
if (ret) {
if (ret) {
- fprintf(stderr, "%s: rootid failed with ret=%d\n",
- argv[0], ret);
+ error("failed to lookup root id: %s", strerror(-ret));
goto out;
}
goto out;
}
@@
-411,7
+418,7
@@
static void adjust_dev_min_size(struct list_head *extents,
/*
* List of device extents is sorted by descending order of the extent's
* end offset. If some extent goes beyond the computed minimum size,
/*
* List of device extents is sorted by descending order of the extent's
* end offset. If some extent goes beyond the computed minimum size,
- * which initially matches the sum of the leng
ht
s of all extents,
+ * which initially matches the sum of the leng
th
s of all extents,
* we need to check if the extent can be relocated to an hole in the
* device between [0, *min_size[ (which is what the resize ioctl does).
*/
* we need to check if the extent can be relocated to an hole in the
* device between [0, *min_size[ (which is what the resize ioctl does).
*/
@@
-477,7
+484,7
@@
static void adjust_dev_min_size(struct list_head *extents,
* chunk tree, so often this can lead to the need of allocating
* a new system chunk too, which has a maximum size of 32Mb.
*/
* chunk tree, so often this can lead to the need of allocating
* a new system chunk too, which has a maximum size of 32Mb.
*/
- *min_size +=
32 * 1024 * 1024
;
+ *min_size +=
SZ_32M
;
}
}
}
}
@@
-491,7
+498,7
@@
static int print_min_dev_size(int fd, u64 devid)
* possibility of deprecating/removing it has been discussed, so we
* ignore it here.
*/
* possibility of deprecating/removing it has been discussed, so we
* ignore it here.
*/
- u64 min_size =
1 * 1024 * 1024ull
;
+ u64 min_size =
SZ_1M
;
struct btrfs_ioctl_search_args args;
struct btrfs_ioctl_search_key *sk = &args.key;
u64 last_pos = (u64)-1;
struct btrfs_ioctl_search_args args;
struct btrfs_ioctl_search_key *sk = &args.key;
u64 last_pos = (u64)-1;
@@
-517,9
+524,7
@@
static int print_min_dev_size(int fd, u64 devid)
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- fprintf(stderr,
- "Error invoking tree search ioctl: %s\n",
- strerror(errno));
+ error("tree search ioctl: %s", strerror(errno));
ret = 1;
goto out;
}
ret = 1;
goto out;
}
@@
-535,32
+540,33
@@
static int print_min_dev_size(int fd, u64 devid)
off);
off += sizeof(*sh);
extent = (struct btrfs_dev_extent *)(args.buf + off);
off);
off += sizeof(*sh);
extent = (struct btrfs_dev_extent *)(args.buf + off);
- off +=
sh->len
;
+ off +=
btrfs_search_header_len(sh)
;
- sk->min_objectid =
sh->objectid
;
- sk->min_type =
sh->type
;
- sk->min_offset =
sh->offset
+ 1;
+ sk->min_objectid =
btrfs_search_header_objectid(sh)
;
+ sk->min_type =
btrfs_search_header_type(sh)
;
+ sk->min_offset =
btrfs_search_header_offset(sh)
+ 1;
- if (
sh->objectid
!= devid ||
-
sh->type
!= BTRFS_DEV_EXTENT_KEY)
+ if (
btrfs_search_header_objectid(sh)
!= devid ||
+
btrfs_search_header_type(sh)
!= BTRFS_DEV_EXTENT_KEY)
continue;
len = btrfs_stack_dev_extent_length(extent);
min_size += len;
continue;
len = btrfs_stack_dev_extent_length(extent);
min_size += len;
- ret = add_dev_extent(&extents, sh->offset,
- sh->offset + len - 1, 0);
+ ret = add_dev_extent(&extents,
+ btrfs_search_header_offset(sh),
+ btrfs_search_header_offset(sh) + len - 1, 0);
if (!ret && last_pos != (u64)-1 &&
if (!ret && last_pos != (u64)-1 &&
- last_pos !=
sh->offset
)
+ last_pos !=
btrfs_search_header_offset(sh)
)
ret = add_dev_extent(&holes, last_pos,
ret = add_dev_extent(&holes, last_pos,
-
sh->offset
- 1, 1);
+
btrfs_search_header_offset(sh)
- 1, 1);
if (ret) {
if (ret) {
-
fprintf(stderr, "Error: %s\n
", strerror(-ret));
+
error("add device extent: %s
", strerror(-ret));
ret = 1;
goto out;
}
ret = 1;
goto out;
}
- last_pos =
sh->offset
+ len;
+ last_pos =
btrfs_search_header_offset(sh)
+ len;
}
if (sk->min_type != BTRFS_DEV_EXTENT_KEY ||
}
if (sk->min_type != BTRFS_DEV_EXTENT_KEY ||
@@
-620,11
+626,6
@@
out:
return !!ret;
}
return !!ret;
}
-static int cmd_inspect_dump_tree_hook(int ac, char **av)
-{
- return cmd_inspect_dump_tree(ac, av);
-}
-
static const char inspect_cmd_group_info[] =
"query various internal information";
static const char inspect_cmd_group_info[] =
"query various internal information";
@@
-640,8
+641,12
@@
const struct cmd_group inspect_cmd_group = {
0 },
{ "min-dev-size", cmd_inspect_min_dev_size,
cmd_inspect_min_dev_size_usage, NULL, 0 },
0 },
{ "min-dev-size", cmd_inspect_min_dev_size,
cmd_inspect_min_dev_size_usage, NULL, 0 },
- { "dump-tree", cmd_inspect_dump_tree
_hook
,
+ { "dump-tree", cmd_inspect_dump_tree,
cmd_inspect_dump_tree_usage, NULL, 0 },
cmd_inspect_dump_tree_usage, NULL, 0 },
+ { "dump-super", cmd_inspect_dump_super,
+ cmd_inspect_dump_super_usage, NULL, 0 },
+ { "tree-stats", cmd_inspect_tree_stats,
+ cmd_inspect_tree_stats_usage, NULL, 0 },
NULL_CMD_STRUCT
}
};
NULL_CMD_STRUCT
}
};