By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

NTFS5 sparse file creation w/Win32 and .NET 1.1 (long)

P: n/a
I've just recently read several articles that state that the only way to
write "sparse zeros" to an NTFS5 sparse file is to use Win32 DeviceIoControl
with FSCTL_SET_ZERO_DATA in order to specify what ranges in the file are
sparse zeros.

However, it appears that the following steps also work when creating a new
sparse file. First, using Win32 (via .NET 1.1 pinvoke), I ...

CreateFile (returns a handle)

DeviceIoControl (handle, FSCTL_SET_SPARSE, ...)

SetFilePointerEX (handle, filesize, ...) [filesize is set to the maximum
"virtual" size my app would ever need - 2GB]

SetEndOfFile (handle)

CloseHandle (handle)

Then, in .NET 1.1 (in the same app) I open the newly-created file with a
..NET Filestream, write to it using FS.Write, then close it.

---> NOTICE THAT I NEVER USED FSCTL_SET_ZERO_DATA !

I've confirmed that when I write zero values to the filestream, they are
treated by NTFS as "sparse zeros" ... the size-on-disk varies - in 64KB
chunks - when I write more/fewer zero values to the Filestream.

So is what I'm doing somehow exempt from the documented "requirement" to
explicitly define the sparse-zero areas in the file using FSCTL_SET_ZERO_DATA?

Or is my app depending on some loop-hole that might get closed ....?

Thanks,

D

Feb 8 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.