changes in IRP for compatibility
[reactos.git] / reactos / drivers / fs / vfat / volume.c
1 /* $Id: volume.c,v 1.4 2000/09/12 10:12:13 jean Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/fs/vfat/volume.c
6 * PURPOSE: VFAT Filesystem
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13 #include <wchar.h>
14 #include <ddk/cctypes.h>
15
16 #define NDEBUG
17 #include <debug.h>
18
19 #include "vfat.h"
20
21 /* FUNCTIONS ****************************************************************/
22
23 NTSTATUS FsdGetFsVolumeInformation(PFILE_OBJECT FileObject,
24 PVFATFCB FCB,
25 PDEVICE_OBJECT DeviceObject,
26 PFILE_FS_VOLUME_INFORMATION FsVolumeInfo)
27 {
28 DPRINT("FsdGetFsVolumeInformation()\n");
29 DPRINT("FsVolumeInfo = %p\n", FsVolumeInfo);
30
31 if (!FsVolumeInfo)
32 return(STATUS_SUCCESS);
33
34
35 /* valid entries */
36 FsVolumeInfo->VolumeSerialNumber = DeviceObject->Vpb->SerialNumber;
37 FsVolumeInfo->VolumeLabelLength = DeviceObject->Vpb->VolumeLabelLength;
38 wcscpy (FsVolumeInfo->VolumeLabel, DeviceObject->Vpb->VolumeLabel);
39
40 /* dummy entries */
41 FsVolumeInfo->VolumeCreationTime.QuadPart = 0;
42 FsVolumeInfo->SupportsObjects = FALSE;
43
44 DPRINT("Finished FsdGetFsVolumeInformation()\n");
45
46 return(STATUS_SUCCESS);
47 }
48
49
50 NTSTATUS FsdGetFsAttributeInformation(PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo)
51 {
52 DPRINT("FsdGetFsAttributeInformation()\n");
53 DPRINT("FsAttributeInfo = %p\n", FsAttributeInfo);
54
55 if (!FsAttributeInfo)
56 return(STATUS_SUCCESS);
57
58 FsAttributeInfo->FileSystemAttributes = FS_CASE_IS_PRESERVED;
59 FsAttributeInfo->MaximumComponentNameLength = 255;
60 FsAttributeInfo->FileSystemNameLength = 3;
61 wcscpy (FsAttributeInfo->FileSystemName, L"FAT");
62
63 DPRINT("Finished FsdGetFsAttributeInformation()\n");
64
65 return(STATUS_SUCCESS);
66 }
67
68 NTSTATUS FsdGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
69 PFILE_FS_SIZE_INFORMATION FsSizeInfo)
70 {
71 PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
72
73 DPRINT("FsdGetFsSizeInformation()\n");
74 DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
75
76 if (!FsSizeInfo)
77 return(STATUS_SUCCESS);
78
79 if (DeviceExt->FatType == FAT32)
80 {
81 struct _BootSector32 *BootSect = (struct _BootSector32 *)DeviceExt->Boot;
82
83 if (BootSect->Sectors)
84 FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
85 else
86 FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
87
88 FsSizeInfo->AvailableAllocationUnits.QuadPart =
89 FAT32CountAvailableClusters(DeviceExt);
90
91 FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
92 FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
93 }
94 else
95 {
96 struct _BootSector *BootSect = (struct _BootSector *)DeviceExt->Boot;
97
98 if (BootSect->Sectors)
99 FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
100 else
101 FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
102
103 if (DeviceExt->FatType == FAT16)
104 FsSizeInfo->AvailableAllocationUnits.QuadPart =
105 FAT16CountAvailableClusters(DeviceExt);
106 else
107 FsSizeInfo->AvailableAllocationUnits.QuadPart =
108 FAT12CountAvailableClusters(DeviceExt);
109
110 FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
111 FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
112 }
113
114 DPRINT("Finished FsdGetFsSizeInformation()\n");
115
116 return(STATUS_SUCCESS);
117 }
118
119
120 NTSTATUS STDCALL VfatQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
121 /*
122 * FUNCTION: Retrieve the specified file information
123 */
124 {
125 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
126 FILE_INFORMATION_CLASS FileInformationClass =
127 Stack->Parameters.QueryVolume.FileInformationClass;
128 PFILE_OBJECT FileObject = NULL;
129 PVFATFCB FCB = NULL;
130 // PVfatCCB CCB = NULL;
131
132 NTSTATUS RC = STATUS_SUCCESS;
133 void *SystemBuffer;
134
135 /* PRECONDITION */
136 assert(DeviceObject != NULL);
137 assert(Irp != NULL);
138
139 DPRINT("FsdQueryVolumeInformation(DeviceObject %x, Irp %x)\n",
140 DeviceObject,Irp);
141
142 /* INITIALIZATION */
143 Stack = IoGetCurrentIrpStackLocation(Irp);
144 FileInformationClass = Stack->Parameters.QueryVolume.FileInformationClass;
145 FileObject = Stack->FileObject;
146 // CCB = (PVfatCCB)(FileObject->FsContext2);
147 // FCB = CCB->Buffer; // Should be CCB->FCB???
148 FCB = ((PVFATCCB)(FileObject->FsContext2))->pFcb;
149
150 // FIXME : determine Buffer for result :
151 if (Irp->MdlAddress)
152 SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
153 else
154 SystemBuffer = Irp->UserBuffer;
155 // SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
156
157 DPRINT("FileInformationClass %d\n",FileInformationClass);
158 DPRINT("SystemBuffer %x\n",SystemBuffer);
159
160 switch (FileInformationClass)
161 {
162 case FileFsVolumeInformation:
163 RC = FsdGetFsVolumeInformation(FileObject,
164 FCB,
165 DeviceObject,
166 SystemBuffer);
167 break;
168
169 case FileFsAttributeInformation:
170 RC = FsdGetFsAttributeInformation(SystemBuffer);
171 break;
172
173 case FileFsSizeInformation:
174 RC = FsdGetFsSizeInformation(DeviceObject, SystemBuffer);
175 break;
176
177 default:
178 RC=STATUS_NOT_IMPLEMENTED;
179 }
180
181 Irp->IoStatus.Status = RC;
182 Irp->IoStatus.Information = 0;
183 IoCompleteRequest(Irp, IO_NO_INCREMENT);
184
185 return RC;
186 }
187
188