Sparse files or memory mapped files in the kernel

Is it possible to create and use a sparse file or a memory mapped file from a device driver?

A sparse file is just an attribute of the file, implemented in the file
system (not all file systems implement this, but I’ll assume you mean
‘NTFS’), so yes you can do so. You’ll need to read up on how to open
files and send FSCTL_SET_SPARSE.

For mapped files, look at the ZwCreateSection/ZwMapViewOfSection APIs.

t.

On Sat, 26 Mar 2011, xxxxx@gmail.com wrote:

Is it possible to create and use a sparse file or a memory mapped file
from a device driver?


NTFSD is sponsored by OSR

For our schedule of debugging and file system seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

On Sat, 26 Mar 2011, xxxxx@gmail.com wrote:

Is it possible to create and use a sparse file or a memory mapped file from a device driver?

After you have created the file you first mark it as sparse and then set
the length:

status = ZwFsControlFile(
device_extension->file_handle,
NULL,
NULL,
NULL,
&Irp->IoStatus,
FSCTL_SET_SPARSE,
NULL,
0,
NULL,
0
);

file_eof.EndOfFile.QuadPart = someting;

status = ZwSetInformationFile(
device_extension->file_handle,
&Irp->IoStatus,
&file_eof,
sizeof(FILE_END_OF_FILE_INFORMATION),
FileEndOfFileInformation
);

ZwFsControlFile does indeed work for FSCTL_SET_SPARSE, thanks for the generous details. The problem I was having is I was using ZwDeviceIoControlFile which did not work. Just for my understanding of the mechanics involved, why does ZwFsControlFile work while DeviceIoControlFile fails? They both take the same parameters and the request is sent to the exact same handle so it is not apparent what the difference is.

The difference I believe is that one sends IRP_MJ_DEVICE_CONTROL vs
IRP_MJ_FILE_SYSTEM_CONTROL.

t.

On Sat, 26 Mar 2011, xxxxx@gmail.com wrote:

ZwFsControlFile does indeed work for FSCTL_SET_SPARSE, thanks for the
generous details. The problem I was having is I was using
ZwDeviceIoControlFile which did not work. Just for my understanding of
the mechanics involved, why does ZwFsControlFile work while
DeviceIoControlFile fails? They both take the same parameters and the
request is sent to the exact same handle so it is not apparent what the
difference is.


NTFSD is sponsored by OSR

For our schedule of debugging and file system seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer