PATCH: open()ing non-existant partitions on IDE devices, 2.3.35

jpranevich@Lycos.com
Mon, 3 Jan 2000 06:19:15 +0200


--0__=b6i1KlJAuNgWBIdkZQ02NFpDKGRlFdEL5PAQMxuudikJJrz9ikR8RuMJ
Content-type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,

While coding up a utility for myself that uses the IDE ioctls() to get
information that would be much easier to get from /proc, I stumbled on what
appears to be a bug in the ide driver's open code (ide_open()).

I noticed that it appears perfectly legal to open() a partition (/dev/hda4, for
instance) when no such partition actually exists. You can't actually write to it
(it's a zero-byte read-only file, it seems) but you can open it.

According to the manpage for open():

ENXIO
O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and no process
has the file open for reading. Or, the file is a device special file and no
corresponding device exists.

Unless I misunderstand, we should be returning ENXIO as there is no device that
cooresponds to that node. (Admittably, this is a gray area. The
device exists (/dev/hda) but there is no partition at that location.) The
problem is that ide_open only checks to see if the major number is a valid
device,
and no check is performed at that level to see if there is a matching partition
(minor number). I correct this by looking in the partition table and checking to
see
if the number of sectors in the selected partition is zero, in which case I
assume that there is no matching partition in the table. (This is a bug in my
patch, it is
possible in many partition systems to have a zero byte partition, it just isn't
very useful.)

(See attached file: ide.patch)

I have attached the patch, please let me know if this is valid or if I am
misunderstanding the situation. The patch is against 2.3.35.

Joe

--0__=b6i1KlJAuNgWBIdkZQ02NFpDKGRlFdEL5PAQMxuudikJJrz9ikR8RuMJ
Content-type: application/octet-stream;
name="ide.patch"
Content-Disposition: attachment; filename="ide.patch"
Content-transfer-encoding: base64

LS0tIGlkZS5jLm9sZAlTdW4gSmFuICAyIDEzOjAzOjA3IDIwMDAKKysrIGlkZS5jCVN1biBKYW4g
IDIgMTY6NDM6MjUgMjAwMApAQCAtMTYwOCw2ICsxNjA4LDcgQEAKIGlkZV9kcml2ZV90ICpnZXRf
aW5mb19wdHIgKGtkZXZfdCBpX3JkZXYpCiB7CiAJaW50CQltYWpvciA9IE1BSk9SKGlfcmRldik7
CisJaW50CQltaW5vciA9IE1JTk9SKGlfcmRldikgJiBQQVJUTl9NQVNLOyAKIAl1bnNpZ25lZCBp
bnQJaDsKIAogCWZvciAoaCA9IDA7IGggPCBNQVhfSFdJRlM7ICsraCkgewpAQCAtMTYxNiw3ICsx
NjE3LDcgQEAKIAkJCXVuc2lnbmVkIHVuaXQgPSBERVZJQ0VfTlIoaV9yZGV2KTsKIAkJCWlmICh1
bml0IDwgTUFYX0RSSVZFUykgewogCQkJCWlkZV9kcml2ZV90ICpkcml2ZSA9ICZod2lmLT5kcml2
ZXNbdW5pdF07Ci0JCQkJaWYgKGRyaXZlLT5wcmVzZW50KQorCQkJCWlmICgoZHJpdmUtPnByZXNl
bnQpICYmIChkcml2ZS0+cGFydFttaW5vcl0ubnJfc2VjdHMpKQogCQkJCQlyZXR1cm4gZHJpdmU7
CiAJCQl9CiAJCQlicmVhazsK

--0__=b6i1KlJAuNgWBIdkZQ02NFpDKGRlFdEL5PAQMxuudikJJrz9ikR8RuMJ--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/