views:

389

answers:

2

Is there a Windows equivalent to Linux's readahead syscall?

EDIT:

I would like a full function signature if possible, showing the equivalent offset/count parameters (or lower/upper).

Eg: The Linux function signature is:

ssize_t readahead(int fd, off64_t *offset, size_t count);

and an example of it's use is

readahead(file, 100, 500);

Where "file" is a file descriptor previously set by a function like mmap. This call is reading 500 bytes at index 100.

EDIT 2: Please read this if you are unsure what readahead does: http://linux.die.net/man/2/readahead

+7  A: 

Yes. It is FileSystemControl FSCTL_FILE_PREFETCH.

It is used in Windows Vista and above for prefetching both when an application starts and at boot time.

It is also used by the SuperFetch technology that uses heuristics to load applications at approximately the times of day you generally use them.

FSCTL_FILE_PREFETCH itself is not documented on MSDN, but it is easy to figure out the parameter format by examining the DeviceIoControl calls made on app startup: Just start an application in the debugger that already has a .pf file in the c:\Windows\Prefetch directory and break on DeviceIoControl (or if you're using a kernel debugger, break when the NTFS driver receives its first FSCTL_FILE_PREFETCH). Examine the buffer passed in and compare it with the .pf file and the range actually used later. I did this once out of curiosity but didn't record the details.

In case you are unfamiliar with DeviceIoControl and IRP_MJ_FILESYSTEM_CONTROL, here are some links to look at:

Ray Burns
It's a good answer, but I am a little confused.The Linux syscall has the signature:readahead(int fd, off64_t *offset, size_t count);eg:readahead(file, 100, 500);Which I assume will read 500 bytes at offset 100 of the file with the file descriptor "file".What would be something equivalent in Windows?
joemoe
Got a link for where those are documented, or a demonstration of how they're used? Right now I have no idea how to interpret this answer.
Rob Kennedy
Still not sure I understand. What I am looking for is a function signature and an example demonstrating it's use. See my edited question for an example.
joemoe
A: 
tommieb75
No this is not what I am looking for. I'm looking for a function that is functionally equivalent to "readahead" in Linux.
joemoe