Basavanagowda Kanur
2009-Dec-21 15:50 UTC
[PATCH] btrfsctl: scan device and exit without using ioctl
''btrfsctl -A /path/to/device/file'' would only scan for a valid
btrfs
on the device using volume recognition helpers.
---
btrfsctl.c | 42 ++++++++++++++++++++++++++++++++++++------
1 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/btrfsctl.c b/btrfsctl.c
index 66c4e89..61020de 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -34,6 +34,8 @@
#include "transaction.h"
#include "utils.h"
#include "version.h"
+#include "disk-io.h"
+#include "volumes.h"
#ifdef __CHECKER__
#define BLKGETSIZE64 0
@@ -88,6 +90,30 @@ static int open_file_or_dir(const char *fname)
}
return fd;
}
+
+int btrfs_scan_file (const char *path)
+{
+ int ret = -1;
+ struct btrfs_fs_devices *fs_devices = NULL;
+ u64 dev_count = 0;
+ int fd = -1;
+
+ fd = open (path, O_RDONLY);
+ if (fd < 0) {
+ fprintf (stderr, "failed to open %s: %s\n",
+ path, strerror (errno));
+ } else {
+
+ ret = btrfs_scan_one_device (fd, path, &fs_devices,
+ &dev_count,
+ BTRFS_SUPER_INFO_OFFSET);
+
+ close (fd);
+ }
+
+ return ret;
+}
+
int main(int ac, char **av)
{
char *fname = NULL;
@@ -201,12 +227,16 @@ int main(int ac, char **av)
fname = av[ac - 1];
if (command == BTRFS_IOC_SCAN_DEV) {
- fd = open("/dev/btrfs-control", O_RDWR);
- if (fd < 0) {
- perror("failed to open /dev/btrfs-control");
- exit(1);
- }
- name = fname;
+ ret = btrfs_scan_file (fname);
+ if (ret < 0) {
+ fprintf (stdout, "could not find a btrfs volume on
"
+ "%s\n", fname);
+ } else {
+ fprintf (stdout, "found a btrfs volume on
%s\n",
+ fname);
+ }
+
+ exit (1);
} else {
fd = open_file_or_dir(fname);
}
--
1.6.4
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
