Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

Sparse files or memory mapped files in the kernel

Bob_KroeterBob_Kroeter Member Posts: 65
Is it possible to create and use a sparse file or a memory mapped file from a device driver?

Comments

  • Tracy_CampTracy_Camp Member - All Emails Posts: 82
    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
    >
  • Bo_BranténBo_Brantén Member Posts: 92
    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
    );
  • Bob_KroeterBob_Kroeter Member Posts: 65
    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.
  • Tracy_CampTracy_Camp Member - All Emails Posts: 82
    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
    >
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA