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

Home NTFSD

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Before Posting...

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

Move data in a file without copying it?

Erik_DabrowskyErik_Dabrowsky Member - All Emails Posts: 35

Hi,

This may not be the correct forum for this question, but I'm asking it here since there is such a wealth of knowledge here.

Lets say I have a 1 TB data file on an NTFS volume consisting of 4, 256GB blocks of data - A, B, C, and D.
I want to delete block C from the file and then move the contents of block D up to where block C is and then truncate the file to 768GB.
The traditional method of doing this would be to read the data from block D and write it to the location where block C was, then call SetEndOfFile() to truncate the file.
This creates a lot of read/write I/O and in the case where you are using SSD/NVME counts against the TBW of the SSD.

Is there a way to logically move block D up to block C without actually reading/writing a bunch of data?
Something like updating file table entries/extents?
Preferably from user mode?

Thanks,
Erik

Comments

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 445
    via Email
    You might be able to do something if you lock the volume and know NTFS
    structures.

    In your case, I think an easier way, though not exactly what you want, is
    to mark that area as SPARSE, set that region as ZERO, which will deallocate
    the range, but it will not move the actual file pointers.
    You would need to be aware of the sparse region and cut your file position
    pointers accordingly when reading/writing beyond the C marker.

    Kind regards, Dejan Maksimovic.
    FS Lead: http://www.alfasp.com
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Internals & Software Drivers 15 November 2021 Live, Online
Writing WDF Drivers TBD Live, Online
Developing Minifilters 7 February 2022 Live, Online
Kernel Debugging 21 March 2022 Live, Online