* Misleading error message in btrfsctl
@ 2009-01-18 13:40 Peter Klotz
2009-01-18 14:12 ` Calvin Walton
0 siblings, 1 reply; 3+ messages in thread
From: Peter Klotz @ 2009-01-18 13:40 UTC (permalink / raw)
To: linux-btrfs
[-- Attachment #1: Type: text/plain, Size: 602 bytes --]
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.
[-- Attachment #2: btrfs-control-open.patch --]
[-- Type: text/x-patch, Size: 522 bytes --]
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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Misleading error message in btrfsctl
2009-01-18 13:40 Misleading error message in btrfsctl Peter Klotz
@ 2009-01-18 14:12 ` Calvin Walton
2009-01-21 15:05 ` Chris Mason
0 siblings, 1 reply; 3+ messages in thread
From: Calvin Walton @ 2009-01-18 14:12 UTC (permalink / raw)
To: Peter Klotz; +Cc: linux-btrfs
On Sun, 2009-01-18 at 14:40 +0100, Peter Klotz wrote:
> Calling btrfsctl results in this message when module btrfs.ko is not loaded:
>
> root@asus:/root# btrfsctl -A /dev/sda
> ioctl:: Bad file descriptor
..
> 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:
diff --git a/btrfsctl.c b/btrfsctl.c
index e049799..df1a165 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -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);
--
Calvin Walton <calvin.walton@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Misleading error message in btrfsctl
2009-01-18 14:12 ` Calvin Walton
@ 2009-01-21 15:05 ` Chris Mason
0 siblings, 0 replies; 3+ messages in thread
From: Chris Mason @ 2009-01-21 15:05 UTC (permalink / raw)
To: Calvin Walton; +Cc: Peter Klotz, linux-btrfs
On Sun, 2009-01-18 at 09:12 -0500, Calvin Walton wrote:
> On Sun, 2009-01-18 at 14:40 +0100, Peter Klotz wrote:
> > Calling btrfsctl results in this message when module btrfs.ko is not loaded:
> >
> > root@asus:/root# btrfsctl -A /dev/sda
> > ioctl:: Bad file descriptor
> ..
> > 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:
>
Thanks
-chris
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-01-21 15:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-18 13:40 Misleading error message in btrfsctl Peter Klotz
2009-01-18 14:12 ` Calvin Walton
2009-01-21 15:05 ` Chris Mason
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox