1 /* $Id: finfo.c,v 1.6 2001/03/06 23:36:35 cnettel Exp $
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)
11 /* INCLUDES *****************************************************************/
13 #include <ddk/ntddk.h>
21 /* FUNCTIONS ****************************************************************/
24 VfatGetStandardInformation (PVFATFCB FCB
, PDEVICE_OBJECT DeviceObject
,
25 PFILE_STANDARD_INFORMATION StandardInfo
)
27 * FUNCTION: Retrieve the standard file information
30 PDEVICE_EXTENSION DeviceExtension
;
31 unsigned long AllocSize
;
33 DeviceExtension
= DeviceObject
->DeviceExtension
;
35 assert (DeviceExtension
!= NULL
);
36 assert (DeviceExtension
->BytesPerCluster
!= 0);
37 assert (StandardInfo
!= NULL
);
40 RtlZeroMemory (StandardInfo
, sizeof (FILE_STANDARD_INFORMATION
));
42 /* Make allocsize a rounded up multiple of BytesPerCluster */
43 AllocSize
= ((FCB
->entry
.FileSize
+ DeviceExtension
->BytesPerCluster
- 1) /
44 DeviceExtension
->BytesPerCluster
) *
45 DeviceExtension
->BytesPerCluster
;
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)
54 StandardInfo
->Directory
= TRUE
;
58 StandardInfo
->Directory
= FALSE
;
61 return STATUS_SUCCESS
;
65 VfatSetPositionInformation (PFILE_OBJECT FileObject
,
67 PDEVICE_OBJECT DeviceObject
,
68 PFILE_POSITION_INFORMATION PositionInfo
)
70 DPRINT ("FsdSetPositionInformation()\n");
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
));
77 return (STATUS_SUCCESS
);
81 VfatGetPositionInformation (PFILE_OBJECT FileObject
,
83 PDEVICE_OBJECT DeviceObject
,
84 PFILE_POSITION_INFORMATION PositionInfo
)
86 DPRINT ("VfatGetPositionInformation()\n");
88 memcpy (&PositionInfo
->CurrentByteOffset
, &FileObject
->CurrentByteOffset
,
89 sizeof (LARGE_INTEGER
));
90 DPRINT ("Getting position %x\n", PositionInfo
->CurrentByteOffset
.u
.LowPart
);
91 return (STATUS_SUCCESS
);
95 VfatGetBasicInformation (PFILE_OBJECT FileObject
,
97 PDEVICE_OBJECT DeviceObject
,
98 PFILE_BASIC_INFORMATION BasicInfo
)
100 DPRINT ("VfatGetBasicInformation()\n");
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
);
111 BasicInfo
->FileAttributes
= FCB
->entry
.Attrib
;
113 DPRINT ("Getting attributes %x\n", BasicInfo
->FileAttributes
);
115 return (STATUS_SUCCESS
);
120 VfatSetDispositionInformation (PFILE_OBJECT FileObject
,
122 PDEVICE_OBJECT DeviceObject
,
123 PFILE_DISPOSITION_INFORMATION DispositionInfo
)
125 DPRINT ("FsdSetDispositionInformation()\n");
127 FileObject
->DeletePending
= DispositionInfo
->DoDeleteFile
;
129 return (STATUS_SUCCESS
);
133 VfatGetNameInformation (PFILE_OBJECT FileObject
, PVFATFCB FCB
, PDEVICE_OBJECT DeviceObject
,
134 PFILE_NAME_INFORMATION NameInfo
)
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.
140 assert (NameInfo
!= NULL
);
141 assert (FCB
!= NULL
);
143 NameInfo
->FileNameLength
= wcslen(FCB
->PathName
);
144 memcpy(NameInfo
->FileName
, FCB
->PathName
, sizeof(WCHAR
)*(NameInfo
->FileNameLength
+1));
146 return STATUS_SUCCESS
;
152 VfatQueryInformation (PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
154 * FUNCTION: Retrieve the specified file information
157 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation (Irp
);
158 FILE_INFORMATION_CLASS FileInformationClass
=
159 Stack
->Parameters
.QueryFile
.FileInformationClass
;
160 PFILE_OBJECT FileObject
= NULL
;
162 // PVFATCCB CCB = NULL;
164 NTSTATUS RC
= STATUS_SUCCESS
;
168 assert (DeviceObject
!= NULL
);
169 assert (Irp
!= NULL
);
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
;
179 // FIXME : determine Buffer for result :
181 SystemBuffer
= MmGetSystemAddressForMdl (Irp
->MdlAddress
);
183 SystemBuffer
= Irp
->UserBuffer
;
184 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
186 switch (FileInformationClass
)
188 case FileStandardInformation
:
189 RC
= VfatGetStandardInformation (FCB
, DeviceObject
, SystemBuffer
);
191 case FilePositionInformation
:
192 RC
= VfatGetPositionInformation (FileObject
,
193 FCB
, DeviceObject
, SystemBuffer
);
195 case FileBasicInformation
:
196 RC
= VfatGetBasicInformation (FileObject
,
197 FCB
, DeviceObject
, SystemBuffer
);
199 case FileNameInformation
:
200 RC
= VfatGetNameInformation (FileObject
,
201 FCB
, DeviceObject
, SystemBuffer
);
204 RC
= STATUS_NOT_IMPLEMENTED
;
207 Irp
->IoStatus
.Status
= RC
;
208 Irp
->IoStatus
.Information
= 0;
209 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);
215 VfatSetInformation (PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
217 * FUNCTION: Retrieve the specified file information
220 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation (Irp
);
221 FILE_INFORMATION_CLASS FileInformationClass
;
222 PFILE_OBJECT FileObject
= NULL
;
224 // PVFATCCB CCB = NULL;
225 NTSTATUS RC
= STATUS_SUCCESS
;
229 assert (DeviceObject
!= NULL
);
230 assert (Irp
!= NULL
);
232 DPRINT ("VfatSetInformation(DeviceObject %x, Irp %x)\n", DeviceObject
, Irp
);
235 Stack
= IoGetCurrentIrpStackLocation (Irp
);
236 FileInformationClass
= Stack
->Parameters
.SetFile
.FileInformationClass
;
237 FileObject
= Stack
->FileObject
;
238 FCB
= ((PVFATCCB
) (FileObject
->FsContext2
))->pFcb
;
240 // FIXME : determine Buffer for result :
242 SystemBuffer
= MmGetSystemAddressForMdl (Irp
->MdlAddress
);
244 SystemBuffer
= Irp
->UserBuffer
;
245 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
247 DPRINT ("FileInformationClass %d\n", FileInformationClass
);
248 DPRINT ("SystemBuffer %x\n", SystemBuffer
);
250 switch (FileInformationClass
)
252 case FilePositionInformation
:
253 RC
= VfatSetPositionInformation (FileObject
,
254 FCB
, DeviceObject
, SystemBuffer
);
256 case FileDispositionInformation
:
257 RC
= VfatSetDispositionInformation (FileObject
,
258 FCB
, DeviceObject
, SystemBuffer
);
261 RC
= STATUS_NOT_IMPLEMENTED
;
264 Irp
->IoStatus
.Status
= RC
;
265 Irp
->IoStatus
.Information
= 0;
266 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);