error value for opening block devices
PATCH 1/1 error value for opening block devices
Opening a non-existing block device currently yields an ENXIO error. Doing the same for char devices produces the correct error ENODEV.
The attached patch fixes the symptoms. Somebody with more knowledge will have to decide whether there are any negative side effects.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
block_dev.c renamed from block_dev.c-save +2 -1
@@ -550,7 +550,7 @@ static int do_open(struct block_device * {struct module *owner =NULL ;struct gendisk *disk; -int ret = -ENXIO ; +int ret = -ENODEV ;int part; file->f_mapping = bdev->bd_inode->i_mapping;
@@ -563,6 +563,7 @@ static int do_open(struct block_device * } owner = disk->fops->owner; + ret = -ENXIO ;down (&bdev->bd_sem);if (!bdev->bd_openers) { bdev->bd_disk = disk;
On Sat, 20 Mar 2004 02:13:47 -0800 Ulrich Drepper wrote:
| Opening a non-existing block device currently yields an ENXIO error. | Doing the same for char devices produces the correct error ENODEV. | | The attached patch fixes the symptoms. Somebody with more knowledge | will have to decide whether there are any negative side effects.
(now that this is merged...)
Isn't this going in the wrong direction, or am I just mis-interpreting SUSv3?
Compare LSB bugzilla #115:
http://bugs.linuxbase.org/show_bug.cgi?id=115
open - open a file
...
ERRORS
[ENXIO]O_NONBLOCK is set, the named file is a FIFO, O_WRONLY is set, and no process has the file open for reading.
[ENXIO]
The named file is a character special or block special file, and the device associated with this special file does not exist.
(Note: ENODEV is not listed as a possible return value.)
--
~Randy
"You can't do anything without having to do something else first." -- Belefant's Law
Quoted 4 lines · Randy.Dunlap
[ENXIO]
The named file is a character special or block special file, and the device associated with this special file does not exist.
Ho hum... It's chrdev_open which needs to be converted to return -ENXIO.
25-akpm/fs/block_dev.c | 3 +-- 25-akpm/fs/char_dev.c | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-)
fs/char_dev.c renamed from fs/char_dev.c~chrdev_open-retval-fix +4 -4
@@ -265,7 +265,7 @@ int chrdev_open(struct inode * inode, stspin_unlock (&cdev_lock); kobj =kobj_lookup (cdev_map, inode->i_rdev, &idx);if (!kobj) -return -ENODEV ; +return -ENXIO ; new = container_of(kobj, struct cdev, kobj);spin_lock (&cdev_lock); p = inode->i_cdev;
@@ -275,9 +275,9 @@ int chrdev_open(struct inode * inode, stlist_add (&inode->i_devices, &p->list); new =NULL ; }else if (!cdev_get (p)) - ret = -ENODEV ; + ret = -ENXIO ; }else if (!cdev_get (p)) - ret = -ENODEV ; + ret = -ENXIO ;spin_unlock (&cdev_lock);cdev_put (new);if (ret)
@@ -285,7 +285,7 @@ int chrdev_open(struct inode * inode, st filp->f_op =fops_get (p->ops);if (!filp->f_op) {cdev_put (p); -return -ENODEV ; +return -ENXIO ; }if (filp->f_op->open) {lock_kernel ();
fs/block_dev.c renamed from fs/block_dev.c~chrdev_open-retval-fix +1 -2
@@ -550,7 +550,7 @@ static int do_open(struct block_device * {struct module *owner =NULL ;struct gendisk *disk; -int ret = -ENODEV ; +int ret = -ENXIO ;int part; file->f_mapping = bdev->bd_inode->i_mapping;
@@ -563,7 +563,6 @@ static int do_open(struct block_device * } owner = disk->fops->owner; - ret = -ENXIO ;down (&bdev->bd_sem);if (!bdev->bd_openers) { bdev->bd_disk = disk;
_