Skip to contentSkip to conversation

Misleading error message in btrfsctl

PATCH Peter Klotz 3 participants 3 messages Jan 18, 2009 – Jan 21, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Calling btrfsctl results in this message when module btrfs.ko is not loaded:

root@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:

root@asus:/root# btrfsctl -A /dev/sda
failed to open /dev/btrfs-control

Regards, Peter.

btrfsctl.c +4 -0
diff -Nur btrfs-progs-0.18/btrfsctl.c btrfs-progs-0.18.patched/btrfsctl.c
@@ -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);
#1 lore raw
Quoted 4 lines · Peter Klotz

Calling btrfsctl results in this message when module btrfs.ko is not loaded:

root@asus:/root# btrfsctl -A /dev/sda
ioctl:: Bad file descriptor

..

Quoted 4 lines

The output with applied patch:

root@asus:/root# btrfsctl -A /dev/sda
failed to open /dev/btrfs-control

It would probably be better to use perror() instead of fprintf, in order to give the actual error message. I often find it useful to know why the device failed to open - is it missing, permission issues? I've updated the patch:

btrfsctl.c +4 -0
index e049799..df1a165 100644
@@ -189,6 +189,10 @@ int main(int ac, char **av)
 
 	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;
 	 } else {
 		fd = open_file_or_dir(fname);
Signature · 1 line
Calvin Walton <[email protected]>
#2 lore raw
Quoted 8 lines · Calvin Walton
Quoted 4 lines · Peter Klotz

Calling btrfsctl results in this message when module btrfs.ko is not loaded:

root@asus:/root# btrfsctl -A /dev/sda
ioctl:: Bad file descriptor

..

Quoted 2 lines

The output with applied patch:

Quoted 8 lines
Quoted 2 lines
root@asus:/root# btrfsctl -A /dev/sda
failed to open /dev/btrfs-control

It would probably be better to use perror() instead of fprintf, in order to give the actual error message. I often find it useful to know why the device failed to open - is it missing, permission issues? I've updated the patch:

Thanks

-chris