Assist for sector aligned writing/reading needed
Posted on 2006-05-02
I would like to receive some assistance (pls. code) on how to write/read on sector boundaries.
I need to create file without caching -> FILE_FLAG_NO_BUFFERING
hHardTotalsFile = CreateFile((LPCTSTR)szInternalFileName,
GENERIC_READ | GENERIC_WRITE, //read + write
0, //no sharing
NULL, //default security
OPEN_ALWAYS, //Opens a file, always.
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING,
MSDN states :
" An application must meet certain requirements when working with files that are opened with FILE_FLAG_NO_BUFFERING:
File access must begin at byte offsets within a file that are integer multiples of the volume sector size.
File access must be for numbers of bytes that are integer multiples of the volume sector size. For example, if the sector size is 512 bytes, an application can request reads and writes of 512, 1024, 1536, or 2048 bytes, but not of 335, 981, or 7171 bytes.
Buffer addresses for read and write operations should be sector aligned, which means aligned on addresses in memory that are integer multiples of the volume sector size. Depending on the disk, this requirement may not be enforced."
How should I do this allocation (VirtualAlloc??) and alignement for writing/reading when sectorsize=512?
Thanks in advance.