Calling btrfsctl results in this message when module btrfs.ko is not loaded:
r...@asus:/root# btrfsctl -A /dev/sda
ioctl:: Bad file descriptor
An strace shows that actually opening of /dev/btrfs-control failed.
open("/dev/btrfs-control", O_RDWR) = -1 ENOENT (No such file or
directory)
ioctl(4294967295, 0x50009404, 0x7fff11fb76b0) = -1 EBADF (Bad file
descriptor)
The attached patch (against btrfsctl 0.18) terminates btrfsctl if
/dev/btrfs-control cannot be opened.
The output with applied patch:
r...@asus:/root# btrfsctl -A /dev/sda
failed to open /dev/btrfs-control
Regards, Peter.
diff -Nur btrfs-progs-0.18/btrfsctl.c btrfs-progs-0.18.patched/btrfsctl.c
--- btrfs-progs-0.18/btrfsctl.c 2009-01-17 02:08:19.000000000 +0100
+++ btrfs-progs-0.18.patched/btrfsctl.c 2009-01-18 14:16:25.000000000 +0100
@@ -189,6 +189,10 @@
if (command == BTRFS_IOC_SCAN_DEV) {
fd = open("/dev/btrfs-control", O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "failed to open /dev/btrfs-control\n");
+ exit(1);
+ }
name = fname;
} else {
fd = open_file_or_dir(fname);