if (!input)
return BTRFS_ARG_UNKNOWN;
- if (realpath(input, path))
- return BTRFS_ARG_PATH;
+ if (realpath(input, path)) {
+ if (is_block_device(input) == 1)
+ return BTRFS_ARG_BLKDEV;
+
+ if (is_mount_point(input) == 1)
+ return BTRFS_ARG_MNTPOINT;
+
+ return BTRFS_ARG_UNKNOWN;
+ }
if (!uuid_parse(input, out))
return BTRFS_ARG_UUID;
return 1;
type = check_arg_type(search);
+ if (type == BTRFS_ARG_BLKDEV)
+ return 1;
while ((mnt = getmntent(f)) != NULL) {
if (strcmp(mnt->mnt_type, "btrfs"))
if (uuid_compare(fs_info_arg.fsid, uuid))
continue;
break;
- case BTRFS_ARG_PATH:
+ case BTRFS_ARG_MNTPOINT:
if (strcmp(search, mnt->mnt_dir))
continue;
break;
- default:
+ case BTRFS_ARG_UNKNOWN:
break;
}
}
static const char * const cmd_show_usage[] = {
- "btrfs filesystem show [options] [<path>|<uuid>]",
+ "btrfs filesystem show [options|<path>|<uuid>]",
"Show the structure of a filesystem",
"-d|--all-devices show only disks under /dev containing btrfs filesystem",
"-m|--mounted show only mounted btrfs",
int ret;
int where = BTRFS_SCAN_LBLKID;
int type = 0;
+ char mp[BTRFS_PATH_NAME_MAX + 1];
while (1) {
int long_index;
}
}
- if (check_argc_max(argc, optind + 1))
- usage(cmd_show_usage);
+ if (where == BTRFS_SCAN_LBLKID) {
+ if (check_argc_max(argc, optind + 1))
+ usage(cmd_show_usage);
+ } else {
+ if (check_argc_max(argc, optind))
+ usage(cmd_show_usage);
+ }
if (argc > optind) {
search = argv[optind];
type = check_arg_type(search);
fprintf(stderr, "ERROR: arg type unknown\n");
usage(cmd_show_usage);
}
+ if (type == BTRFS_ARG_BLKDEV) {
+ ret = get_btrfs_mount(search, mp, sizeof(mp));
+ if (ret == 0)
+ search = mp;
+ }
}
if (where == BTRFS_SCAN_DEV)
* Returns negative errno on failure, otherwise
* returns 1 for blockdev, 0 for not-blockdev
*/
-int is_block_device(const char *path) {
+int is_block_device(const char *path)
+{
struct stat statbuf;
if (stat(path, &statbuf) < 0)
}
/*
+ * check if given path is a mount point
+ * return 1 if yes. 0 if no. -1 for error
+ */
+int is_mount_point(const char *path)
+{
+ FILE *f;
+ struct mntent *mnt;
+ int ret = 0;
+
+ f = setmntent("/proc/self/mounts", "r");
+ if (f == NULL)
+ return -1;
+
+ while ((mnt = getmntent(f)) != NULL) {
+ if (strcmp(mnt->mnt_dir, path))
+ continue;
+ ret = 1;
+ break;
+ }
+ endmntent(f);
+ return ret;
+}
+
+/*
* Find the mount point for a mounted device.
* On success, returns 0 with mountpoint in *mp.
* On failure, returns -errno (not mounted yields -EINVAL)
#define BTRFS_UPDATE_KERNEL 1
#define BTRFS_ARG_UNKNOWN 0
-#define BTRFS_ARG_PATH 1
+#define BTRFS_ARG_MNTPOINT 1
#define BTRFS_ARG_UUID 2
+#define BTRFS_ARG_BLKDEV 3
int make_btrfs(int fd, const char *device, const char *label,
u64 blocks[6], u64 num_bytes, u32 nodesize,
char *__strncpy__null(char *dest, const char *src, size_t n);
int is_block_device(const char *file);
+int is_mount_point(const char *file);
int open_path_or_dev_mnt(const char *path, DIR **dirstream);
u64 btrfs_device_size(int fd, struct stat *st);
/* Helper to always get proper size of the destination string */