[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: harddisc device drivers, how to read/write data?



Hello Torsten,

>  My simple question is: How should read/write be done on such raw devices? I
> don't have a Linux box or anything else to look how it's done there, but I
> assume the following possibilities:
> 
>  1) Use the DEVDRV read/write calls but watch out that data is always aligned
> to 512 byte boundaries.

	This seems to be the simplest to implement; you could return
some error code (ERANGE maybe?) if the read/write/lseek is not properly
aligned, i.e. if the number of bytes to read/write or the offset isn't a
multiple of 512. But in this case, you should provide some ioctl to get
the exact block size.

(Under Linux, the stat structure contains additional fields st_blksize
and st_blocks, but unless you want to modify the Fstat interface,
appropriate ioctls should be defined to get these fields. But I'll look
more closely at the linux block devices...)

>  2) Use the read/write calls but give the size argument a completely different
> meaning: It doesn't say bytes, but sectors instead. The size of the device
> would therefore not represent the partition size in bytes, but in sectors
> instead.

This is a bad idea, and will break some low-level programs like dd.

>  3) Use ioctl() calls to read/write and make the DEVDRV read/write calls
> become dummies. If so, which ioctl numbers should be used?

Same problem here, it would make dd unusable.

Thierry.