PRB: Unexpected Result of SetFilePointer() with DevicesLast reviewed: November 2, 1995Article ID: Q98892 |
The information in this article applies to:
SYMPTOMSOpen a floppy drive with CreateFile():
h = CreateFile( "\\\\.\\a:", ... );Use SetFilePointer() to advance the file pointer associated with the file handle returned from CreateFile():
SetFilePointer( h, // file handle 5, // distance (in bytes) to move file pointer NULL, // optional high 32-bits of distance FILE_BEGIN // specifies the starting point );If the offset is not a multiple of the sector size of the floppy drive, the function will return success; however, the pointer will not be exactly where requested. The pointer value is rounded down to the beginning of the sector that the pointer value is in.
CAUSEThe behavior of this application programming interface (API) is by design for the following reasons:
RESOLUTIONWhen using SetFilePointer() with a handle that represents a floppy drive, the offset must be a multiple of the sector size for the floppy drive in order for the function to perform as expected.
MORE INFORMATIONThink of a file pointer as merely a stored value, which is where the next read or write will take place. In fact, it is possible to override this value on either the read or write itself, using certain APIs, by supplying a different location. The new pointer location is remembered after the operation. Therefore, the operation of "setting a file pointer" merely means to go store a large integer in a cell in the system's data structures, for possible use in the next file operation. In the case of a handle to a device, the file pointer must be on a sector boundary. In a similar way, ReadFile() only reads amounts that are multiples of the sector size if it is passed a handle that represents a floppy drive.
|
Additional reference words: 3.10 ntddkstorage
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |