How to do IO across hardsector boundries
Hi There
As part of an assignment I am trying to port a piece of software from FreeBSD to linux. Essentially this software (crypto) makes a virtual blockdevice with "virtual" sectors on top. Under FreeBSD these virtual sectors are just read/written using a simple command:
buf=g_read(dev, offset, len)
error=g_write(dev,offset,buf,len)
In linux however I have only seen the BIO layer which operates on IO on hardsector boundaries.
So my question really is, how do I go about updating for instance the 512 bytes located for at byte 64 to 64+511 on the actual media without getting in trouble regarding the data from offset 0-63 and 64+512->1023?
Regards Thomas
Quoted 3 lines · Thomas S. Iversen
So my question really is, how do I go about updating for instance the 512 bytes located for at byte 64 to 64+511 on the actual media without getting in trouble regarding the data from offset 0-63 and 64+512->1023?
If you want to use the BIO layer then you need to read the two blocks, write to the bits you care about and then write them back. That is what will always have to happen at a lower level for this anyway. In essence you would be implementing the small g_read/g_write equivalent routines.
Quoted 6 lines · Thomas S. Iversen
Hi There
As part of an assignment I am trying to port a piece of software from FreeBSD to linux. Essentially this software (crypto) makes a virtual blockdevice with "virtual" sectors on top. Under FreeBSD these virtual sectors are just read/written using a simple command:
I can recommend that you look at the Device Mapper layer and consider porting your code to that, it's designed to take care of some of the hard work for you for usages like this.
Quoted 10 lines · Thomas S. Iversen
Hi There
As part of an assignment I am trying to port a piece of software from FreeBSD to linux. Essentially this software (crypto) makes a virtual blockdevice with "virtual" sectors on top. Under FreeBSD these virtual sectors are just read/written using a simple command:
buf=g_read(dev, offset, len)
error=g_write(dev,offset,buf,len)
Quoted 8 lines
In linux however I have only seen the BIO layer which operates on IO on hardsector boundaries.
So my question really is, how do I go about updating for instance the 512 bytes located for at byte 64 to 64+511 on the actual media without getting in trouble regarding the data from offset 0-63 and 64+512->1023?
Regards Thomas
There are no hard-sector boundaries in Linux. The geometry of a drive is really ignored. It's just used to determine the size of a disk partition, etc. The stated Heads/cylinders/sectors is a throw-back to the old int 0x13, DOS days where stuff had to fit into registers for access.
If your driver expects to write physical sectors, it's broken. Even physical sectors (on the media) don't really exist anymore. They are now "logical" sectors and they are never really accessed as a single unit (except in floppies). They are "extracted" from a sector-buffer that could contain nearly a whole track.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.