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