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