5 #include <rosrtl/sparse.h>
8 * Utility to convert a file to a sparse file
10 * IN HANDLE hFile -> Handle to the file to be converted
12 * Returns TRUE on success.
13 * Returns FALSE on failure, use GetLastError() to get extended error information.
17 SetFileSparse(HANDLE hFile
)
20 return DeviceIoControl(hFile
,
32 * Utility to fill a specified range of a file with zeroes.
34 * IN HANDLE hFile -> Handle to the file.
35 * IN PLARGE_INTEGER pliFileOffset -> Points to a LARGE_INTEGER structure that indicates the file offset of the start of the range in bytes.
36 * IN PLARGE_INTEGER pliBeyondFinalZero -> Points to a LARGE_INTEGER structure that indicates the the offset to the first byte beyond the last zeroed byte.
38 * Returns TRUE on success.
39 * Returns FALSE on failure, use GetLastError() to get extended error information.
43 ZeroFileData(HANDLE hFile
,
44 PLARGE_INTEGER pliFileOffset
,
45 PLARGE_INTEGER pliBeyondFinalZero
)
48 FILE_ZERO_DATA_INFORMATION fzdi
;
50 if(!pliFileOffset
|| !pliBeyondFinalZero
)
52 SetLastError(ERROR_INVALID_PARAMETER
);
56 fzdi
.FileOffset
= *pliFileOffset
;
57 fzdi
.BeyondFinalZero
= *pliBeyondFinalZero
;
59 return DeviceIoControl(hFile
,
62 sizeof(FILE_ZERO_DATA_INFORMATION
),
71 * Utility to determine the allocated ranges of a sparse file
73 * IN HANDLE hFile -> Handle to the file.
74 * IN PLARGE_INTEGER pliFileOffset -> Points to a LARGE_INTEGER structure that indicates the portion of the file to search for allocated ranges.
75 * IN PLARGE_INTEGER pliLength -> Points to a LARGE_INTEGER structure that indicates it's size.
76 * OUT PFILE_ALLOCATED_RANGE_BUFFER lpAllocatedRanges -> Points to a buffer that receives an array of FILE_ALLOCATED_RANGE_BUFFER structures.
77 * IN DWORD dwBufferSize -> Size of the output buffer.
79 * Returns a nonzero value on success.
80 * Returns zero on failure, use GetLastError() to get extended error information.
84 QueryAllocatedFileRanges(HANDLE hFile
,
85 PLARGE_INTEGER pliFileOffset
,
86 PLARGE_INTEGER pliLength
,
87 PFILE_ALLOCATED_RANGE_BUFFER lpAllocatedRanges
,
91 FILE_ALLOCATED_RANGE_BUFFER farb
;
93 if(!pliFileOffset
|| !pliLength
|| !lpAllocatedRanges
|| !dwBufferSize
)
95 SetLastError(ERROR_INVALID_PARAMETER
);
99 farb
.FileOffset
= *pliFileOffset
;
100 farb
.Length
= *pliLength
;
102 if(DeviceIoControl(hFile
,
103 FSCTL_QUERY_ALLOCATED_RANGES
,
105 sizeof(FILE_ALLOCATED_RANGE_BUFFER
),