All I/Os must be correctly aligned in memory and on disk:
they must start at a sector offset on disk, they must be
an exact number of sectors long, and the data buffer in
virtual memory must also be aligned to a multiple of the
sector size. The sector size is 512 bytes for most
devices.
Is anyone working on an user space library to making porting programs to
Linux raw devices easier? RAWfs did not require data alignment and INN's
current CNFS implimentation does not attempt to do data alignment. I
wondered if there is something that would allow for a quick and dirty
port.
Take for example the following code:
fd = open("/dev/raw/raw1", O_RDWR);
lseek(fd, 700, SEEK_SET);
read(fd, buf1, 1200);
write(fd, buf2, 1500);
close(fd);
I would like to be able to replace open, seek, read, write and close
with calls to rawopen, rawseek, rawread, rawwrite and rawclose where the
arguments are left the same and the drop in replacements handle data align
such that the resulting system calls would become something along the
lines of:
lseek(fd, 512, SEEK_SET);
// additional 188 byte offset kept in a variable
read(fd, alternatebuf, 1536);
// discard first 188 bytes, discard last 148 bytes and copy into buf1
lseek(fd, 1536, SEEK_SET);
read(fd, rewritebuffer, 512);
// copy 148 bytes of buf2 into the end of rewritebuffer
lseek(fd, 1536, SEEK_SET);
write(fd, rewritebuffer, 512);
// skip 148 bytes and copy 1024 bytes of buf2 into alternatebuf
write(fd, alternatebuf, 1024);
read(fd, rewritebuffer, 512);
// copy last 328 bytes of buf2 into beginning of rewritebuffer
lseek(fd, 3072, SEEK_SET);
write(fd, rewritebuffer, 512);
Is anyone working on such a library as I described above? Or is there
an easier method?
Thanks
References:
[1] ftp://ftp.cistron.nl/pub/people/miquels/kernel/
[2] http://www.isc.org/products/INN/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/