]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commit
[SCSI] sr.c: Fix getting wrong size
authorPete Zaitcev <zaitcev@redhat.com>
Wed, 6 Jul 2005 01:18:08 +0000 (18:18 -0700)
committerJames Bottomley <jejb@titanic.(none)>
Sun, 28 Aug 2005 16:14:12 +0000 (11:14 -0500)
commit51490c89f95b8581782e9baa855da166441852be
tree3be27d5e30c114d5d69fe21a4a079a64f2016354
parent8224bfa84d510630b40ea460b2bb380c91acb8ae
[SCSI] sr.c: Fix getting wrong size

Here's the problem. Try to do this on 2.6.12:
- Kill udev and HAL
- Insert a CD-ROM into a SCSI or USB CD-ROM drive
- Run dd if=/dev/scd0
- cat /sys/block/sr0/size
- Eject the CD, insert a different one
- Run dd if=/dev/scd0
This is likely to do "access beyond the end of device", if you let it
- cat /sys/block/sr0/size
This shows the size of a previous CD, even though dd was supposed
to revalidate the device.
- Run dd if=/dev/scd0
The second run of dd works correctly!

The bug was introduced in 2.5.31, when Al fixes the recursive opens
in partitioning. Before, the code worked like this:
- Block layer called cdrom_open directly
- cdrom_open called sr_open
- sr_open called check_disk_change
- check_disk_change called sr_media_change
- sr_media_change did cd->needs_disk_change=1
- before returning sr_open tested cd->needs_disk_change
  and called get_sector_size.

In 2.6.12, the check_disk_change is called from cdrom_open only. Thus:
- Block layer calls sr_bd_open
- sr_bd_open calls cdrom_open
- cdrom_open calls sr_open
- sr_open tests cd->needs_disk_change, which wasn't set yet; returns
- cdrom_open calls check_disk_change
- check_disk_change calls sr_media_change
- sr_media_change does cd->needs_disk_change=1, but nobody cares

Acked by: Alexander Viro <aviro@redhat.com>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
drivers/scsi/sr.c
drivers/scsi/sr.h