[NTFS] Update headers
[reactos.git] / reactos / drivers / filesystems / ntfs / finfo.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/dirctl.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMERS: Eric Kohl
24 * Hervé Poussineau (hpoussin@reactos.org)
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "ntfs.h"
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /* FUNCTIONS ****************************************************************/
35
36 /*
37 * FUNCTION: Retrieve the standard file information
38 */
39 static
40 NTSTATUS
41 NtfsGetStandardInformation(PNTFS_FCB Fcb,
42 PDEVICE_OBJECT DeviceObject,
43 PFILE_STANDARD_INFORMATION StandardInfo,
44 PULONG BufferLength)
45 {
46 UNREFERENCED_PARAMETER(DeviceObject);
47
48 DPRINT("NtfsGetStandardInformation() called\n");
49
50 if (*BufferLength < sizeof(FILE_STANDARD_INFORMATION))
51 return STATUS_BUFFER_OVERFLOW;
52
53 /* PRECONDITION */
54 ASSERT(StandardInfo != NULL);
55 ASSERT(Fcb != NULL);
56
57 RtlZeroMemory(StandardInfo,
58 sizeof(FILE_STANDARD_INFORMATION));
59
60 StandardInfo->AllocationSize = Fcb->RFCB.AllocationSize;
61 StandardInfo->EndOfFile = Fcb->RFCB.FileSize;
62 StandardInfo->NumberOfLinks = 0;
63 StandardInfo->DeletePending = FALSE;
64 StandardInfo->Directory = NtfsFCBIsDirectory(Fcb);
65
66 *BufferLength -= sizeof(FILE_STANDARD_INFORMATION);
67
68 return STATUS_SUCCESS;
69 }
70
71
72 static
73 NTSTATUS
74 NtfsGetPositionInformation(PFILE_OBJECT FileObject,
75 PFILE_POSITION_INFORMATION PositionInfo,
76 PULONG BufferLength)
77 {
78 UNREFERENCED_PARAMETER(FileObject);
79
80 DPRINT("NtfsGetPositionInformation() called\n");
81
82 if (*BufferLength < sizeof(FILE_POSITION_INFORMATION))
83 return STATUS_BUFFER_OVERFLOW;
84
85 PositionInfo->CurrentByteOffset.QuadPart = 0;
86 // FileObject->CurrentByteOffset.QuadPart;
87
88 DPRINT("Getting position %I64x\n",
89 PositionInfo->CurrentByteOffset.QuadPart);
90
91 *BufferLength -= sizeof(FILE_POSITION_INFORMATION);
92
93 return STATUS_SUCCESS;
94 }
95
96
97 static
98 NTSTATUS
99 NtfsGetBasicInformation(PFILE_OBJECT FileObject,
100 PNTFS_FCB Fcb,
101 PDEVICE_OBJECT DeviceObject,
102 PFILE_BASIC_INFORMATION BasicInfo,
103 PULONG BufferLength)
104 {
105 DPRINT("NtfsGetBasicInformation() called\n");
106
107 if (*BufferLength < sizeof(FILE_BASIC_INFORMATION))
108 return STATUS_BUFFER_OVERFLOW;
109
110 #if 0
111 CdfsDateTimeToFileTime(Fcb,
112 &BasicInfo->CreationTime);
113 CdfsDateTimeToFileTime(Fcb,
114 &BasicInfo->LastAccessTime);
115 CdfsDateTimeToFileTime(Fcb,
116 &BasicInfo->LastWriteTime);
117 CdfsDateTimeToFileTime(Fcb,
118 &BasicInfo->ChangeTime);
119
120 CdfsFileFlagsToAttributes(Fcb,
121 &BasicInfo->FileAttributes);
122 #else
123 UNREFERENCED_PARAMETER(FileObject);
124 UNREFERENCED_PARAMETER(Fcb);
125 UNREFERENCED_PARAMETER(DeviceObject);
126 UNREFERENCED_PARAMETER(BasicInfo);
127 #endif
128
129 *BufferLength -= sizeof(FILE_BASIC_INFORMATION);
130
131 return STATUS_SUCCESS;
132 }
133
134
135 /*
136 * FUNCTION: Retrieve the file name information
137 */
138 static
139 NTSTATUS
140 NtfsGetNameInformation(PFILE_OBJECT FileObject,
141 PNTFS_FCB Fcb,
142 PDEVICE_OBJECT DeviceObject,
143 PFILE_NAME_INFORMATION NameInfo,
144 PULONG BufferLength)
145 {
146 ULONG NameLength;
147
148 UNREFERENCED_PARAMETER(FileObject);
149 UNREFERENCED_PARAMETER(DeviceObject);
150
151 DPRINT("NtfsGetNameInformation() called\n");
152
153 ASSERT(NameInfo != NULL);
154 ASSERT(Fcb != NULL);
155
156 NameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
157 // NameLength = 2;
158 if (*BufferLength < sizeof(FILE_NAME_INFORMATION) + NameLength)
159 return STATUS_BUFFER_OVERFLOW;
160
161 NameInfo->FileNameLength = NameLength;
162 memcpy(NameInfo->FileName,
163 Fcb->PathName,
164 NameLength + sizeof(WCHAR));
165 // wcscpy(NameInfo->FileName, L"\\");
166
167 *BufferLength -= (sizeof(FILE_NAME_INFORMATION) + NameLength + sizeof(WCHAR));
168
169 return STATUS_SUCCESS;
170 }
171
172
173 static
174 NTSTATUS
175 NtfsGetInternalInformation(PNTFS_FCB Fcb,
176 PFILE_INTERNAL_INFORMATION InternalInfo,
177 PULONG BufferLength)
178 {
179 DPRINT("NtfsGetInternalInformation() called\n");
180
181 ASSERT(InternalInfo);
182 ASSERT(Fcb);
183
184 if (*BufferLength < sizeof(FILE_INTERNAL_INFORMATION))
185 return STATUS_BUFFER_OVERFLOW;
186
187 /* FIXME: get a real index, that can be used in a create operation */
188 InternalInfo->IndexNumber.QuadPart = 0;
189
190 *BufferLength -= sizeof(FILE_INTERNAL_INFORMATION);
191
192 return STATUS_SUCCESS;
193 }
194
195
196 /*
197 * FUNCTION: Retrieve the specified file information
198 */
199 NTSTATUS
200 NTAPI
201 NtfsFsdQueryInformation(PDEVICE_OBJECT DeviceObject,
202 PIRP Irp)
203 {
204 FILE_INFORMATION_CLASS FileInformationClass;
205 PIO_STACK_LOCATION Stack;
206 PFILE_OBJECT FileObject;
207 PNTFS_FCB Fcb;
208 PVOID SystemBuffer;
209 ULONG BufferLength;
210 NTSTATUS Status = STATUS_SUCCESS;
211
212 DPRINT("NtfsQueryInformation() called\n");
213
214 Stack = IoGetCurrentIrpStackLocation(Irp);
215 FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
216 FileObject = Stack->FileObject;
217 Fcb = FileObject->FsContext;
218
219 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
220 BufferLength = Stack->Parameters.QueryFile.Length;
221
222 switch (FileInformationClass)
223 {
224 case FileStandardInformation:
225 Status = NtfsGetStandardInformation(Fcb,
226 DeviceObject,
227 SystemBuffer,
228 &BufferLength);
229 break;
230
231 case FilePositionInformation:
232 Status = NtfsGetPositionInformation(FileObject,
233 SystemBuffer,
234 &BufferLength);
235 break;
236
237 case FileBasicInformation:
238 Status = NtfsGetBasicInformation(FileObject,
239 Fcb,
240 DeviceObject,
241 SystemBuffer,
242 &BufferLength);
243 break;
244
245 case FileNameInformation:
246 Status = NtfsGetNameInformation(FileObject,
247 Fcb,
248 DeviceObject,
249 SystemBuffer,
250 &BufferLength);
251 break;
252
253 case FileInternalInformation:
254 Status = NtfsGetInternalInformation(Fcb,
255 SystemBuffer,
256 &BufferLength);
257 break;
258
259 case FileAlternateNameInformation:
260 case FileAllInformation:
261 Status = STATUS_NOT_IMPLEMENTED;
262 break;
263
264 default:
265 DPRINT("Unimplemented information class %u\n", FileInformationClass);
266 Status = STATUS_INVALID_PARAMETER;
267 }
268
269 Irp->IoStatus.Status = Status;
270
271 if (NT_SUCCESS(Status))
272 Irp->IoStatus.Information =
273 Stack->Parameters.QueryFile.Length - BufferLength;
274 else
275 Irp->IoStatus.Information = 0;
276
277 IoCompleteRequest(Irp, IO_NO_INCREMENT);
278
279 return Status;
280 }
281
282 /* EOF */