2.5.33-bk testing
Subsystems (2)
Quoted 10 lines · Linus Torvalds
In article <[email protected]>,
Quoted 3 lines · Thomas Molina
I've beat on the floppy driver and it seems to work well. I haven't been able to make it hiccup yet.
Really? I was looking at my cleanups, and I'm fairly certain they are buggy. I just pushed an update to the BK tree a few minutes ago that I think should fix it, but since I'm not a floppy user myself I can only go by the source and trying to imagine everything that could go wrong.
I was able to get 2.5.33 (even with your patch) to corrupt data in a few seconds: writes (with dd) put corrupted data on the media, and reads (again with dd) returns data that doesn't match what's on the media.
The patch below is an update of the floppy workarounds patch I've been maintaining since the problems began in 2.5.13. With this patch I'm able to reliably read and write to the raw /dev/fd0 device. I'm not suggesting that my hack to bdev->bd_block_size is the correct fix, but maybe someone who understands the block I/O system can see what's going on and do a proper fix.
There is also a fix to the broken {,un}register_sys_device() calls. The driver forgets to unregister in several cases, leading to data structure corruption.
/Mikael
drivers/block/floppy.c +46 -2
@@ -3710,6 +3710,10 @@UDRS ->fd_ref =0 ; }floppy_release_irq_and_dma (); + +/* undo ++bd_openers in floppy_open() */ + --inode->i_bdev->bd_openers; +return 0 ; }
@@ -3802,6 +3806,44 @@invalidate_buffers (mk_kdev (FLOPPY_MAJOR ,old_dev)); } +/* Problems: +* 1. fs/block_dev.c:do_open() calls bd_set_size() which +* changes bdev's block size after floppy_open() has +* returned. For some reason, this causes data corruption. +* 2. The device size appears to be zero on first access +* sometimes, especially if the first access is a write. +* Workarounds: +* 1. Set bdev block size equal to the hardsect/queue size. +* This seems to cure the data corruption problem for raw +* accesses. VFS accesses to mounted floppies still cause +* data corruption for unknown reasons. +* 2. Fake a constant 1.44MB i_size. +* 1&2. ++bdev->bd_openers to bypass do_open()'s changes. +* floppy_release() does a --bdev->bd_openers. +*/ + { +struct block_device *bdev = inode->i_bdev; +struct backing_dev_info *bdi; +sector_t sect; + + bdev->bd_offset =0 ; + + sect = (1440 *1024 ) >>9 ; + +/* like bd_set_size() but don't mutate block_size */ + bdev->bd_inode->i_size = (loff_t )sect <<9 ; + bdev->bd_block_size =bdev_hardsect_size (bdev); + bdev->bd_inode->i_blkbits =blksize_bits (block_size (bdev)); + + bdi =blk_get_backing_dev_info (bdev); +if (bdi ==NULL ) + bdi = &default_backing_dev_info; + inode->i_data.backing_dev_info = bdi; + bdev->bd_inode->i_data.backing_dev_info = bdi; + + ++bdev->bd_openers; + } +/* Allow ioctls if we have write-permissions even if read-only open. * Needed so that programs such as fdrawcmd still can work on write * protected disks */
@@ -4239,8 +4281,6 @@ {int i,unit,drive; -register_sys_device (&device_floppy); - raw_cmd =NULL ; devfs_handle =devfs_mk_dir (NULL ,"floppy" ,NULL );
@@ -4367,6 +4407,9 @@register_disk (NULL ,mk_kdev (MAJOR_NR ,TOMINOR (drive)+i*4 ),1 , &floppy_fops,0 ); } + +register_sys_device (&device_floppy); +return have_no_fdc; }
@@ -4549,6 +4592,7 @@ {int dummy; +unregister_sys_device (&device_floppy);devfs_unregister (devfs_handle);unregister_blkdev (MAJOR_NR ,"fd" );
Quoted 4 lines · Mikael Pettersson
I was able to get 2.5.33 (even with your patch) to corrupt data in a few seconds: writes (with dd) put corrupted data on the media, and reads (again with dd) returns data that doesn't match what's on the media.
I don't know why I didn't see the corruption the first time around. However, I repeated the tests with Linus' floppy update and saw the same thing you did.
dd if=/dev/fd0 of=floppyimage
produced corrupt output, as did a dd write to floppy command.
Quoted 7 lines
The patch below is an update of the floppy workarounds patch I've been maintaining since the problems began in 2.5.13. With this patch I'm able to reliably read and write to the raw
/dev/fd0device. I'm not suggesting that my hack tobdev->bd_block_sizeis the correct fix, but maybe someone who understands the block I/O system can see what's going on and do a proper fix.
Thanks. Adding your workaround produced correct outputs. I hope we can some other eyes on the code and get it integrated into mainline.
Quoted 8 lines · Mikael Pettersson
The patch below is an update of the floppy workarounds patch I've been maintaining since the problems began in 2.5.13. With this patch I'm able to reliably read and write to the raw
/dev/fd0device. I'm not suggesting that my hack tobdev->bd_block_sizeis the correct fix, but maybe someone who understands the block I/O system can see what's going on and do a proper fix.
It looks like what your fix does is to force a 512-byte blocksize on the floppy.
Which implies to me that the floppy driver is broken for other blocksizes.
Does your patch still leave the floppy driver broken for something like a mounted minix or ext2 filesystem? Those have 1kB blocksizes, and will set it to that. If the non-512B blocksize in the floppy driver is broken, then such mounted filesystems should not work reliably either.
Linus
Quoted 9 lines · Linus Torvalds
It looks like what your fix does is to force a 512-byte blocksize on the floppy.
Which implies to me that the floppy driver is broken for other blocksizes.
Does your patch still leave the floppy driver broken for something like a mounted minix or ext2 filesystem? Those have 1kB blocksizes, and will set it to that. If the non-512B blocksize in the floppy driver is broken, then such mounted filesystems should not work reliably either.
You are correct. Making an ext2 filesystem on the floppy is indeed broken. Attempting to read/write from the resulting filesystem results in the following type errors:
Sep 1 13:18:23 dad kernel: EXT2-fs error (device fd(2,0)): ext2_check_page: bad entry in directory #11: unaligned directory entry - offset=7168, inode=1431634935, rec_len=50, name_len=0 Sep 1 13:20:20 dad kernel: EXT2-fs error (device fd(2,0)): ext2_check_page: bad entry in directory #11: rec_len is smaller than minimal - offset=7168, inode=0, rec_len=0, name_len=0 Sep 1 13:22:29 dad kernel: EXT2-fs warning: mounting fs with errors, running e2fsck is recommended Sep 1 13:23:09 dad kernel: EXT2-fs error (device fd(2,0)): ext2_check_page: bad entry in directory #11: directory entry across blocks - offset=7168, inode=861697588, rec_len=12592, name_len=119 Sep 1 13:24:38 dad kernel: EXT2-fs error (device fd(2,0)):
ext2_check_page: bad entry in directory #11: rec_len is smaller than minimal - offset=7168, inode=0, rec_len=0, name_len=0
Putting a text file on the floppy shows 512 byte chunks of the file being moved around depending on how many times the file is read/written.