From: Basavanagowda Kanur <gowda@kanur.in>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfsctl: scan device and exit without using ioctl
Date: Mon, 21 Dec 2009 21:20:46 +0530 [thread overview]
Message-ID: <20091221154140.GA26204@shift> (raw)
'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
reply other threads:[~2009-12-21 15:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20091221154140.GA26204@shift \
--to=gowda@kanur.in \
--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