Sync with trunk r63343.
[reactos.git] / 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 * PROGRAMMER: Eric Kohl
24 */
25
26 /* INCLUDES *****************************************************************/
27
28 #include "ntfs.h"
29
30 #define NDEBUG
31 #include <debug.h>
32
33 /* FUNCTIONS ****************************************************************/
34
35 /*
36 * FUNCTION: Retrieve the standard file information
37 */
38 static
39 NTSTATUS
40 NtfsGetStandardInformation(PNTFS_FCB Fcb,
41 PDEVICE_OBJECT DeviceObject,
42 PFILE_STANDARD_INFORMATION StandardInfo,
43 PULONG BufferLength)
44 {
45 UNREFERENCED_PARAMETER(DeviceObject);
46
47 DPRINT("NtfsGetStandardInformation() called\n");
48
49 if (*BufferLength < sizeof(FILE_STANDARD_INFORMATION))
50 return STATUS_BUFFER_OVERFLOW;
51
52 /* PRECONDITION */
53 ASSERT(StandardInfo != NULL);
54 ASSERT(Fcb != NULL);
55
56 RtlZeroMemory(StandardInfo,
57 sizeof(FILE_STANDARD_INFORMATION));
58
59 StandardInfo->AllocationSize = Fcb->RFCB.AllocationSize;
60 StandardInfo->EndOfFile = Fcb->RFCB.FileSize;
61 StandardInfo->NumberOfLinks = 0;
62 StandardInfo->DeletePending = FALSE;
63 StandardInfo->Directory = NtfsFCBIsDirectory(Fcb);
64
65 *BufferLength -= sizeof(FILE_STANDARD_INFORMATION);
66
67 return STATUS_SUCCESS;
68 }
69
70
71 static
72 NTSTATUS
73 NtfsGetPositionInformation(PFILE_OBJECT FileObject,
74 PFILE_POSITION_INFORMATION PositionInfo,
75 PULONG BufferLength)
76 {
77 UNREFERENCED_PARAMETER(FileObject);
78
79 DPRINT("NtfsGetPositionInformation() called\n");
80
81 if (*BufferLength < sizeof(FILE_POSITION_INFORMATION))
82 return STATUS_BUFFER_OVERFLOW;
83
84 PositionInfo->CurrentByteOffset.QuadPart = 0;
85 // FileObject->CurrentByteOffset.QuadPart;
86
87 DPRINT("Getting position %I64x\n",
88 PositionInfo->CurrentByteOffset.QuadPart);
89
90 *BufferLength -= sizeof(FILE_POSITION_INFORMATION);
91
92 return STATUS_SUCCESS;
93 }
94
95
96 static
97 NTSTATUS
98 NtfsGetBasicInformation(PFILE_OBJECT FileObject,
99 PNTFS_FCB Fcb,
100 PDEVICE_OBJECT DeviceObject,
101 PFILE_BASIC_INFORMATION BasicInfo,
102 PULONG BufferLength)
103 {
104 DPRINT("NtfsGetBasicInformation() called\n");
105
106 if (*BufferLength < sizeof(FILE_BASIC_INFORMATION))
107 return STATUS_BUFFER_OVERFLOW;
108
109 #if 0
110 CdfsDateTimeToFileTime(Fcb,
111 &BasicInfo->CreationTime);
112 CdfsDateTimeToFileTime(Fcb,
113 &BasicInfo->LastAccessTime);
114 CdfsDateTimeToFileTime(Fcb,
115 &BasicInfo->LastWriteTime);
116 CdfsDateTimeToFileTime(Fcb,
117 &BasicInfo->ChangeTime);
118
119 CdfsFileFlagsToAttributes(Fcb,
120 &BasicInfo->FileAttributes);
121 #else
122 UNREFERENCED_PARAMETER(FileObject);
123 UNREFERENCED_PARAMETER(Fcb);
124 UNREFERENCED_PARAMETER(DeviceObject);
125 UNREFERENCED_PARAMETER(BasicInfo);
126 #endif
127
128 *BufferLength -= sizeof(FILE_BASIC_INFORMATION);
129
130 return STATUS_SUCCESS;
131 }
132
133
134 /*
135 * FUNCTION: Retrieve the file name information
136 */
137 static
138 NTSTATUS
139 NtfsGetNameInformation(PFILE_OBJECT FileObject,
140 PNTFS_FCB Fcb,
141 PDEVICE_OBJECT DeviceObject,
142 PFILE_NAME_INFORMATION NameInfo,
143 PULONG BufferLength)
144 {
145 ULONG NameLength;
146
147 UNREFERENCED_PARAMETER(FileObject);
148 UNREFERENCED_PARAMETER(DeviceObject);
149
150 DPRINT("NtfsGetNameInformation() called\n");
151
152 ASSERT(NameInfo != NULL);
153 ASSERT(Fcb != NULL);
154
155 NameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
156 // NameLength = 2;
157 if (*BufferLength < sizeof(FILE_NAME_INFORMATION) + NameLength)
158 return STATUS_BUFFER_OVERFLOW;
159
160 NameInfo->FileNameLength = NameLength;
161 memcpy(NameInfo->FileName,
162 Fcb->PathName,
163 NameLength + sizeof(WCHAR));
164 // wcscpy(NameInfo->FileName, L"\\");
165
166 *BufferLength -= (sizeof(FILE_NAME_INFORMATION) + NameLength + sizeof(WCHAR));
167
168 return STATUS_SUCCESS;
169 }
170
171
172 static
173 NTSTATUS
174 NtfsGetInternalInformation(PNTFS_FCB Fcb,
175 PFILE_INTERNAL_INFORMATION InternalInfo,
176 PULONG BufferLength)
177 {
178 DPRINT("NtfsGetInternalInformation() called\n");
179
180 ASSERT(InternalInfo);
181 ASSERT(Fcb);
182
183 if (*BufferLength < sizeof(FILE_INTERNAL_INFORMATION))
184 return STATUS_BUFFER_OVERFLOW;
185
186 /* FIXME: get a real index, that can be used in a create operation */
187 InternalInfo->IndexNumber.QuadPart = 0;
188
189 *BufferLength -= sizeof(FILE_INTERNAL_INFORMATION);
190
191 return STATUS_SUCCESS;
192 }
193
194
195 /*
196 * FUNCTION: Retrieve the specified file information
197 */
198 NTSTATUS
199 NTAPI
200 NtfsFsdQueryInformation(PDEVICE_OBJECT DeviceObject,
201 PIRP Irp)
202 {
203 FILE_INFORMATION_CLASS FileInformationClass;
204 PIO_STACK_LOCATION Stack;
205 PFILE_OBJECT FileObject;
206 PNTFS_FCB Fcb;
207 PVOID SystemBuffer;
208 ULONG BufferLength;
209 NTSTATUS Status = STATUS_SUCCESS;
210
211 DPRINT("NtfsQueryInformation() called\n");
212
213 Stack = IoGetCurrentIrpStackLocation(Irp);
214 FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
215 FileObject = Stack->FileObject;
216 Fcb = FileObject->FsContext;
217
218 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
219 BufferLength = Stack->Parameters.QueryFile.Length;
220
221 switch (FileInformationClass)
222 {
223 case FileStandardInformation:
224 Status = NtfsGetStandardInformation(Fcb,
225 DeviceObject,
226 SystemBuffer,
227 &BufferLength);
228 break;
229
230 case FilePositionInformation:
231 Status = NtfsGetPositionInformation(FileObject,
232 SystemBuffer,
233 &BufferLength);
234 break;
235
236 case FileBasicInformation:
237 Status = NtfsGetBasicInformation(FileObject,
238 Fcb,
239 DeviceObject,
240 SystemBuffer,
241 &BufferLength);
242 break;
243
244 case FileNameInformation:
245 Status = NtfsGetNameInformation(FileObject,
246 Fcb,
247 DeviceObject,
248 SystemBuffer,
249 &BufferLength);
250 break;
251
252 case FileInternalInformation:
253 Status = NtfsGetInternalInformation(Fcb,
254 SystemBuffer,
255 &BufferLength);
256 break;
257
258 case FileAlternateNameInformation:
259 case FileAllInformation:
260 Status = STATUS_NOT_IMPLEMENTED;
261 break;
262
263 default:
264 DPRINT("Unimplemented information class %u\n", FileInformationClass);
265 Status = STATUS_INVALID_PARAMETER;
266 }
267
268 Irp->IoStatus.Status = Status;
269
270 if (NT_SUCCESS(Status))
271 Irp->IoStatus.Information =
272 Stack->Parameters.QueryFile.Length - BufferLength;
273 else
274 Irp->IoStatus.Information = 0;
275
276 IoCompleteRequest(Irp, IO_NO_INCREMENT);
277
278 return Status;
279 }
280
281 /* EOF */