- Final ROSRTL removal patch. The next patch will remove the actual library and code.
[reactos.git] / reactos / lib / rosrtl / file / sparse.c
1 #if 0
2 #include <windows.h>
3 #include <ddk/ntifs.h>
4 #include <string.h>
5 #include <rosrtl/sparse.h>
6
7 /*
8 * Utility to convert a file to a sparse file
9 *
10 * IN HANDLE hFile -> Handle to the file to be converted
11 *
12 * Returns TRUE on success.
13 * Returns FALSE on failure, use GetLastError() to get extended error information.
14 */
15 BOOL
16 STDCALL
17 SetFileSparse(HANDLE hFile)
18 {
19 DWORD BytesRet;
20 return DeviceIoControl(hFile,
21 FSCTL_SET_SPARSE,
22 NULL,
23 0,
24 NULL,
25 0,
26 &BytesRet,
27 NULL) != 0;
28 }
29
30
31 /*
32 * Utility to fill a specified range of a file with zeroes.
33 *
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.
37 *
38 * Returns TRUE on success.
39 * Returns FALSE on failure, use GetLastError() to get extended error information.
40 */
41 BOOL
42 STDCALL
43 ZeroFileData(HANDLE hFile,
44 PLARGE_INTEGER pliFileOffset,
45 PLARGE_INTEGER pliBeyondFinalZero)
46 {
47 DWORD BytesRet;
48 FILE_ZERO_DATA_INFORMATION fzdi;
49
50 if(!pliFileOffset || !pliBeyondFinalZero)
51 {
52 SetLastError(ERROR_INVALID_PARAMETER);
53 return FALSE;
54 }
55
56 fzdi.FileOffset = *pliFileOffset;
57 fzdi.BeyondFinalZero = *pliBeyondFinalZero;
58
59 return DeviceIoControl(hFile,
60 FSCTL_SET_ZERO_DATA,
61 &fzdi,
62 sizeof(FILE_ZERO_DATA_INFORMATION),
63 NULL,
64 0,
65 &BytesRet,
66 NULL) != 0;
67 }
68
69
70 /*
71 * Utility to determine the allocated ranges of a sparse file
72 *
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.
78 *
79 * Returns a nonzero value on success.
80 * Returns zero on failure, use GetLastError() to get extended error information.
81 */
82 DWORD
83 STDCALL
84 QueryAllocatedFileRanges(HANDLE hFile,
85 PLARGE_INTEGER pliFileOffset,
86 PLARGE_INTEGER pliLength,
87 PFILE_ALLOCATED_RANGE_BUFFER lpAllocatedRanges,
88 DWORD dwBufferSize)
89 {
90 DWORD BytesRet;
91 FILE_ALLOCATED_RANGE_BUFFER farb;
92
93 if(!pliFileOffset || !pliLength || !lpAllocatedRanges || !dwBufferSize)
94 {
95 SetLastError(ERROR_INVALID_PARAMETER);
96 return FALSE;
97 }
98
99 farb.FileOffset = *pliFileOffset;
100 farb.Length = *pliLength;
101
102 if(DeviceIoControl(hFile,
103 FSCTL_QUERY_ALLOCATED_RANGES,
104 &farb,
105 sizeof(FILE_ALLOCATED_RANGE_BUFFER),
106 lpAllocatedRanges,
107 dwBufferSize,
108 &BytesRet,
109 NULL) != 0)
110 {
111 return BytesRet;
112 }
113
114 return 0;
115 }
116
117 #endif