Problems with Loop-Block Device in .68

Jeremy A. Gilbert (grath@gryphon.ccs.brandeis.edu)
Fri, 23 Feb 1996 03:57:47 -0500 (EST)


Andries or other linux people:

I have a question regarding the 1.3.68 loopback block device.
Since I am often shuffling around filesytems, it would be very useful to
me to have this feature of the new working. I am running kernel 1.3.68
without any additional patches on a SCSI-based PC.

Since there is apparently no documentation on LOOP_BLOCK_DEV, I
wrote a small C program to use the loop device based on guesses I made
once I looked at linux/drivers/block/loop.[ch]. I concluded that you must
use ioctl to pass a file descriptor into the loop device to link that
block device to a particular file. Since the loop device is major #28 on
my system, I did the following:

mknod /tmp/block b 28 3 # 3 could be whatever
dd if=/dev/zero of=/tmp/disk count=5000

Just to test it, I did a `mke2fs /tmp/disk` and confirmed that
all was happy.

Then I wrote this banal C program:

main()
{
int disk_dev;
int block_dev;

disk_dev = open( "/tmp/disk", O_RDWR );
printf( "disk fd %d\n", disk_dev );
block_dev = open( "/tmp/block", O_RDWR );
printf( "open block fd %d\n", block_dev );
printf( "clearfd: %d\n", ioctl( block_dev, 0x4C01 ));
printf( "setfd: %d\n", ioctl( block_dev, 0x4C00, disk_dev));
perror( "set error would be" );
}

The output was good -- the two ioctls run as they are supposed to
with the right error codes, etc. The first 0x4C01 should clear the file
descriptor left previosly, and the 0x4C00 should set a new one in place. I
checked these commands by making calls to ioctl( LO_GET_STATUS ) with the
address of a loop_device struct and verified that stuff was getting filled
into the record. However, I had some rather severe problems attempting to
use this new block device: For instance, a mke2fs /tmp/block generated a
billion

Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 66
Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 68
Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 70
Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 2
Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 4
Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 6
Feb 23 03:39:47 gryphon kernel: end_request: I/O error, dev 1c:03, sector 8

syslog errors and absolutly nothing was written to the file.
However something right DID happen, since the struct was filled out the
right way. Deleting /tmp/disk outright had no effect -- the I/O errors
continued. Nothing changes even if I let the binary sit in an infinite
loop (does this keep the fd open?!?)

Can anyone please shed some light as to what is going on here?
Any help would be greatly appreciated.

Thanks in advance,

Jeremy Gilbert
grath@cs.brandeis.edu
Brandeis CS Webmaster