Put in updated version of bitops header
[reactos.git] / reactos / drivers / fs / vfat / finfo.c
1 /* $Id: finfo.c,v 1.1 1999/12/11 21:14:48 dwelch 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 <wchar.h>
14 #include <internal/string.h>
15 #include <ddk/ntddk.h>
16 #include <ddk/cctypes.h>
17
18 #define NDEBUG
19 #include <internal/debug.h>
20
21 #include "vfat.h"
22
23 /* FUNCTIONS ****************************************************************/
24
25 NTSTATUS FsdGetStandardInformation(PVFATFCB FCB, PDEVICE_OBJECT DeviceObject,
26 PFILE_STANDARD_INFORMATION StandardInfo)
27 /*
28 * FUNCTION: Retrieve the standard file information
29 */
30 {
31 PDEVICE_EXTENSION DeviceExtension;
32 unsigned long AllocSize;
33
34 DeviceExtension = DeviceObject->DeviceExtension;
35 /* PRECONDITION */
36 assert(DeviceExtension != NULL);
37 assert(DeviceExtension->BytesPerCluster != 0);
38 assert(StandardInfo != NULL);
39 assert(FCB != NULL);
40
41 RtlZeroMemory(StandardInfo, sizeof(FILE_STANDARD_INFORMATION));
42
43 /* Make allocsize a rounded up multiple of BytesPerCluster */
44 AllocSize = ((FCB->entry.FileSize + DeviceExtension->BytesPerCluster - 1) /
45 DeviceExtension->BytesPerCluster) *
46 DeviceExtension->BytesPerCluster;
47
48 StandardInfo->AllocationSize = RtlConvertUlongToLargeInteger(AllocSize);
49 StandardInfo->EndOfFile = RtlConvertUlongToLargeInteger(FCB->entry.FileSize);
50 StandardInfo->NumberOfLinks = 0;
51 StandardInfo->DeletePending = FALSE;
52 if((FCB->entry.Attrib & 0x10)>0) {
53 StandardInfo->Directory = TRUE;
54 } else {
55 StandardInfo->Directory = FALSE;
56 }
57
58 return STATUS_SUCCESS;
59 }
60
61 NTSTATUS FsdSetPositionInformation(PFILE_OBJECT FileObject,
62 PVFATFCB FCB,
63 PDEVICE_OBJECT DeviceObject,
64 PFILE_POSITION_INFORMATION PositionInfo)
65 {
66 DPRINT("FsdSetPositionInformation()\n");
67
68 DPRINT("PositionInfo %x\n", PositionInfo);
69 DPRINT("Setting position %d\n", PositionInfo->CurrentByteOffset.u.LowPart);
70 memcpy(&FileObject->CurrentByteOffset,&PositionInfo->CurrentByteOffset,
71 sizeof(LARGE_INTEGER));
72
73 return(STATUS_SUCCESS);
74 }
75
76 NTSTATUS FsdGetPositionInformation(PFILE_OBJECT FileObject,
77 PVFATFCB FCB,
78 PDEVICE_OBJECT DeviceObject,
79 PFILE_POSITION_INFORMATION PositionInfo)
80 {
81 DPRINT("FsdGetPositionInformation()\n");
82
83 memcpy(&PositionInfo->CurrentByteOffset, &FileObject->CurrentByteOffset,
84 sizeof(LARGE_INTEGER));
85 DPRINT("Getting position %x\n", PositionInfo->CurrentByteOffset.u.LowPart);
86 return(STATUS_SUCCESS);
87 }
88
89 NTSTATUS FsdGetBasicInformation(PFILE_OBJECT FileObject,
90 PVFATFCB FCB,
91 PDEVICE_OBJECT DeviceObject,
92 PFILE_BASIC_INFORMATION BasicInfo)
93 {
94 DPRINT("FsdGetBasicInformation()\n");
95
96 FsdDosDateTimeToFileTime(FCB->entry.CreationDate,FCB->entry.CreationTime,
97 &BasicInfo->CreationTime);
98 FsdDosDateTimeToFileTime(FCB->entry.AccessDate,0,
99 &BasicInfo->LastAccessTime);
100 FsdDosDateTimeToFileTime(FCB->entry.UpdateDate,FCB->entry.UpdateTime,
101 &BasicInfo->LastWriteTime);
102 FsdDosDateTimeToFileTime(FCB->entry.UpdateDate,FCB->entry.UpdateTime,
103 &BasicInfo->ChangeTime);
104
105 BasicInfo->FileAttributes = FCB->entry.Attrib;
106
107 DPRINT("Getting attributes %x\n", BasicInfo->FileAttributes);
108
109 return(STATUS_SUCCESS);
110 }
111
112
113 NTSTATUS FsdSetDispositionInformation(PFILE_OBJECT FileObject,
114 PVFATFCB FCB,
115 PDEVICE_OBJECT DeviceObject,
116 PFILE_DISPOSITION_INFORMATION DispositionInfo)
117 {
118 DPRINT("FsdSetDispositionInformation()\n");
119
120 FileObject->DeletePending = DispositionInfo->DeleteFile;
121
122 return(STATUS_SUCCESS);
123 }
124
125
126 NTSTATUS FsdQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
127 /*
128 * FUNCTION: Retrieve the specified file information
129 */
130 {
131 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
132 FILE_INFORMATION_CLASS FileInformationClass =
133 Stack->Parameters.QueryFile.FileInformationClass;
134 PFILE_OBJECT FileObject = NULL;
135 PVFATFCB FCB = NULL;
136 // PVFATCCB CCB = NULL;
137
138 NTSTATUS RC = STATUS_SUCCESS;
139 void *SystemBuffer;
140
141 /* PRECONDITION */
142 assert(DeviceObject != NULL);
143 assert(Irp != NULL);
144
145 /* INITIALIZATION */
146 Stack = IoGetCurrentIrpStackLocation(Irp);
147 FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
148 FileObject = Stack->FileObject;
149 // CCB = (PVFATCCB)(FileObject->FsContext2);
150 // FCB = CCB->Buffer; // Should be CCB->FCB???
151 FCB = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
152
153 // FIXME : determine Buffer for result :
154 if (Irp->MdlAddress)
155 SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
156 else
157 SystemBuffer = Irp->UserBuffer;
158 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
159
160 switch(FileInformationClass) {
161 case FileStandardInformation:
162 RC = FsdGetStandardInformation(FCB, DeviceObject, SystemBuffer);
163 break;
164 case FilePositionInformation:
165 RC = FsdGetPositionInformation(FileObject,
166 FCB,
167 DeviceObject,
168 SystemBuffer);
169 break;
170 case FileBasicInformation:
171 RC = FsdGetBasicInformation(FileObject,
172 FCB,
173 DeviceObject,
174 SystemBuffer);
175 break;
176 default:
177 RC=STATUS_NOT_IMPLEMENTED;
178 }
179
180 Irp->IoStatus.Status = RC;
181 Irp->IoStatus.Information = 0;
182 IoCompleteRequest(Irp, IO_NO_INCREMENT);
183
184 return RC;
185 }
186
187 NTSTATUS VfatSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
188 /*
189 * FUNCTION: Retrieve the specified file information
190 */
191 {
192 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
193 FILE_INFORMATION_CLASS FileInformationClass;
194 PFILE_OBJECT FileObject = NULL;
195 PVFATFCB FCB = NULL;
196 // PVFATCCB CCB = NULL;
197 NTSTATUS RC = STATUS_SUCCESS;
198 PVOID SystemBuffer;
199
200 /* PRECONDITION */
201 assert(DeviceObject != NULL);
202 assert(Irp != NULL);
203
204 DPRINT("FsdSetInformation(DeviceObject %x, Irp %x)\n",
205 DeviceObject,Irp);
206
207 /* INITIALIZATION */
208 Stack = IoGetCurrentIrpStackLocation(Irp);
209 FileInformationClass = Stack->Parameters.SetFile.FileInformationClass;
210 FileObject = Stack->FileObject;
211 FCB = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
212
213 // FIXME : determine Buffer for result :
214 if (Irp->MdlAddress)
215 SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
216 else
217 SystemBuffer = Irp->UserBuffer;
218 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
219
220 DPRINT("FileInformationClass %d\n",FileInformationClass);
221 DPRINT("SystemBuffer %x\n",SystemBuffer);
222
223 switch(FileInformationClass)
224 {
225 case FilePositionInformation:
226 RC = FsdSetPositionInformation(FileObject,
227 FCB,
228 DeviceObject,
229 SystemBuffer);
230 break;
231 case FileDispositionInformation:
232 RC = FsdSetDispositionInformation(FileObject,
233 FCB,
234 DeviceObject,
235 SystemBuffer);
236 break;
237 default:
238 RC = STATUS_NOT_IMPLEMENTED;
239 }
240
241 Irp->IoStatus.Status = RC;
242 Irp->IoStatus.Information = 0;
243 IoCompleteRequest(Irp, IO_NO_INCREMENT);
244
245 return RC;
246 }
247
248
249