FILE_NAME_INFORMATION, returning correct casing thanks to changes in create.c
[reactos.git] / reactos / drivers / fs / vfat / finfo.c
1 /* $Id: finfo.c,v 1.6 2001/03/06 23:36:35 cnettel Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/fs/vfat/finfo.c
6 * PURPOSE: VFAT Filesystem
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
8 *
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <wchar.h>
15
16 #define NDEBUG
17 #include <debug.h>
18
19 #include "vfat.h"
20
21 /* FUNCTIONS ****************************************************************/
22
23 NTSTATUS
24 VfatGetStandardInformation (PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
25 PFILE_STANDARD_INFORMATION StandardInfo)
26 /*
27 * FUNCTION: Retrieve the standard file information
28 */
29 {
30 PDEVICE_EXTENSION DeviceExtension;
31 unsigned long AllocSize;
32
33 DeviceExtension = DeviceObject->DeviceExtension;
34 /* PRECONDITION */
35 assert (DeviceExtension != NULL);
36 assert (DeviceExtension->BytesPerCluster != 0);
37 assert (StandardInfo != NULL);
38 assert (FCB != NULL);
39
40 RtlZeroMemory (StandardInfo, sizeof (FILE_STANDARD_INFORMATION));
41
42 /* Make allocsize a rounded up multiple of BytesPerCluster */
43 AllocSize = ((FCB->entry.FileSize + DeviceExtension->BytesPerCluster - 1) /
44 DeviceExtension->BytesPerCluster) *
45 DeviceExtension->BytesPerCluster;
46
47 StandardInfo->AllocationSize = RtlConvertUlongToLargeInteger (AllocSize);
48 StandardInfo->EndOfFile =
49 RtlConvertUlongToLargeInteger (FCB->entry.FileSize);
50 StandardInfo->NumberOfLinks = 0;
51 StandardInfo->DeletePending = FALSE;
52 if ((FCB->entry.Attrib & 0x10) > 0)
53 {
54 StandardInfo->Directory = TRUE;
55 }
56 else
57 {
58 StandardInfo->Directory = FALSE;
59 }
60
61 return STATUS_SUCCESS;
62 }
63
64 NTSTATUS
65 VfatSetPositionInformation (PFILE_OBJECT FileObject,
66 PVFATFCB FCB,
67 PDEVICE_OBJECT DeviceObject,
68 PFILE_POSITION_INFORMATION PositionInfo)
69 {
70 DPRINT ("FsdSetPositionInformation()\n");
71
72 DPRINT ("PositionInfo %x\n", PositionInfo);
73 DPRINT ("Setting position %d\n", PositionInfo->CurrentByteOffset.u.LowPart);
74 memcpy (&FileObject->CurrentByteOffset, &PositionInfo->CurrentByteOffset,
75 sizeof (LARGE_INTEGER));
76
77 return (STATUS_SUCCESS);
78 }
79
80 NTSTATUS
81 VfatGetPositionInformation (PFILE_OBJECT FileObject,
82 PVFATFCB FCB,
83 PDEVICE_OBJECT DeviceObject,
84 PFILE_POSITION_INFORMATION PositionInfo)
85 {
86 DPRINT ("VfatGetPositionInformation()\n");
87
88 memcpy (&PositionInfo->CurrentByteOffset, &FileObject->CurrentByteOffset,
89 sizeof (LARGE_INTEGER));
90 DPRINT ("Getting position %x\n", PositionInfo->CurrentByteOffset.u.LowPart);
91 return (STATUS_SUCCESS);
92 }
93
94 NTSTATUS
95 VfatGetBasicInformation (PFILE_OBJECT FileObject,
96 PVFATFCB FCB,
97 PDEVICE_OBJECT DeviceObject,
98 PFILE_BASIC_INFORMATION BasicInfo)
99 {
100 DPRINT ("VfatGetBasicInformation()\n");
101
102 FsdDosDateTimeToFileTime (FCB->entry.CreationDate, FCB->entry.CreationTime,
103 &BasicInfo->CreationTime);
104 FsdDosDateTimeToFileTime (FCB->entry.AccessDate, 0,
105 &BasicInfo->LastAccessTime);
106 FsdDosDateTimeToFileTime (FCB->entry.UpdateDate, FCB->entry.UpdateTime,
107 &BasicInfo->LastWriteTime);
108 FsdDosDateTimeToFileTime (FCB->entry.UpdateDate, FCB->entry.UpdateTime,
109 &BasicInfo->ChangeTime);
110
111 BasicInfo->FileAttributes = FCB->entry.Attrib;
112
113 DPRINT ("Getting attributes %x\n", BasicInfo->FileAttributes);
114
115 return (STATUS_SUCCESS);
116 }
117
118
119 NTSTATUS
120 VfatSetDispositionInformation (PFILE_OBJECT FileObject,
121 PVFATFCB FCB,
122 PDEVICE_OBJECT DeviceObject,
123 PFILE_DISPOSITION_INFORMATION DispositionInfo)
124 {
125 DPRINT ("FsdSetDispositionInformation()\n");
126
127 FileObject->DeletePending = DispositionInfo->DoDeleteFile;
128
129 return (STATUS_SUCCESS);
130 }
131
132 NTSTATUS
133 VfatGetNameInformation (PFILE_OBJECT FileObject, PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
134 PFILE_NAME_INFORMATION NameInfo)
135 /*
136 * FUNCTION: Retrieve the file name information
137 * FIXME: We would need the IRP to check the length of the passed buffer. Now, it can cause overflows.
138 */
139 {
140 assert (NameInfo != NULL);
141 assert (FCB != NULL);
142
143 NameInfo->FileNameLength = wcslen(FCB->PathName);
144 memcpy(NameInfo->FileName, FCB->PathName, sizeof(WCHAR)*(NameInfo->FileNameLength+1));
145
146 return STATUS_SUCCESS;
147 }
148
149
150
151 NTSTATUS STDCALL
152 VfatQueryInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
153 /*
154 * FUNCTION: Retrieve the specified file information
155 */
156 {
157 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
158 FILE_INFORMATION_CLASS FileInformationClass =
159 Stack->Parameters.QueryFile.FileInformationClass;
160 PFILE_OBJECT FileObject = NULL;
161 PVFATFCB FCB = NULL;
162 // PVFATCCB CCB = NULL;
163
164 NTSTATUS RC = STATUS_SUCCESS;
165 void *SystemBuffer;
166
167 /* PRECONDITION */
168 assert (DeviceObject != NULL);
169 assert (Irp != NULL);
170
171 /* INITIALIZATION */
172 Stack = IoGetCurrentIrpStackLocation (Irp);
173 FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
174 FileObject = Stack->FileObject;
175 // CCB = (PVFATCCB)(FileObject->FsContext2);
176 // FCB = CCB->Buffer; // Should be CCB->FCB???
177 FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
178
179 // FIXME : determine Buffer for result :
180 if (Irp->MdlAddress)
181 SystemBuffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
182 else
183 SystemBuffer = Irp->UserBuffer;
184 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
185
186 switch (FileInformationClass)
187 {
188 case FileStandardInformation:
189 RC = VfatGetStandardInformation (FCB, DeviceObject, SystemBuffer);
190 break;
191 case FilePositionInformation:
192 RC = VfatGetPositionInformation (FileObject,
193 FCB, DeviceObject, SystemBuffer);
194 break;
195 case FileBasicInformation:
196 RC = VfatGetBasicInformation (FileObject,
197 FCB, DeviceObject, SystemBuffer);
198 break;
199 case FileNameInformation:
200 RC = VfatGetNameInformation (FileObject,
201 FCB, DeviceObject, SystemBuffer);
202 break;
203 default:
204 RC = STATUS_NOT_IMPLEMENTED;
205 }
206
207 Irp->IoStatus.Status = RC;
208 Irp->IoStatus.Information = 0;
209 IoCompleteRequest (Irp, IO_NO_INCREMENT);
210
211 return RC;
212 }
213
214 NTSTATUS STDCALL
215 VfatSetInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
216 /*
217 * FUNCTION: Retrieve the specified file information
218 */
219 {
220 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
221 FILE_INFORMATION_CLASS FileInformationClass;
222 PFILE_OBJECT FileObject = NULL;
223 PVFATFCB FCB = NULL;
224 // PVFATCCB CCB = NULL;
225 NTSTATUS RC = STATUS_SUCCESS;
226 PVOID SystemBuffer;
227
228 /* PRECONDITION */
229 assert (DeviceObject != NULL);
230 assert (Irp != NULL);
231
232 DPRINT ("VfatSetInformation(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
233
234 /* INITIALIZATION */
235 Stack = IoGetCurrentIrpStackLocation (Irp);
236 FileInformationClass = Stack->Parameters.SetFile.FileInformationClass;
237 FileObject = Stack->FileObject;
238 FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
239
240 // FIXME : determine Buffer for result :
241 if (Irp->MdlAddress)
242 SystemBuffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
243 else
244 SystemBuffer = Irp->UserBuffer;
245 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
246
247 DPRINT ("FileInformationClass %d\n", FileInformationClass);
248 DPRINT ("SystemBuffer %x\n", SystemBuffer);
249
250 switch (FileInformationClass)
251 {
252 case FilePositionInformation:
253 RC = VfatSetPositionInformation (FileObject,
254 FCB, DeviceObject, SystemBuffer);
255 break;
256 case FileDispositionInformation:
257 RC = VfatSetDispositionInformation (FileObject,
258 FCB, DeviceObject, SystemBuffer);
259 break;
260 default:
261 RC = STATUS_NOT_IMPLEMENTED;
262 }
263
264 Irp->IoStatus.Status = RC;
265 Irp->IoStatus.Information = 0;
266 IoCompleteRequest (Irp, IO_NO_INCREMENT);
267
268 return RC;
269 }