6ff2e48700b288ff59eb00152dbdc6a8fc2cb5e7
[reactos.git] / reactos / drivers / filesystems / cdfs / volinfo.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: services/fs/vfat/volume.c
23 * PURPOSE: CDROM (ISO 9660) filesystem driver
24 * PROGRAMMER: Art Yerkes
25 * Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include "cdfs.h"
31
32 #define NDEBUG
33 #include <debug.h>
34
35 /* FUNCTIONS ****************************************************************/
36
37 static NTSTATUS
38 CdfsGetFsVolumeInformation(PDEVICE_OBJECT DeviceObject,
39 PFILE_FS_VOLUME_INFORMATION FsVolumeInfo,
40 PULONG BufferLength)
41 {
42 DPRINT("CdfsGetFsVolumeInformation() called\n");
43 DPRINT("FsVolumeInfo = %p\n", FsVolumeInfo);
44 DPRINT("BufferLength %lu\n", *BufferLength);
45
46 DPRINT("Vpb %p\n", DeviceObject->Vpb);
47
48 DPRINT("Required length %lu\n", (sizeof(FILE_FS_VOLUME_INFORMATION) + DeviceObject->Vpb->VolumeLabelLength));
49 DPRINT("LabelLength %hu\n", DeviceObject->Vpb->VolumeLabelLength);
50 DPRINT("Label %*.S\n", DeviceObject->Vpb->VolumeLabelLength / sizeof(WCHAR), DeviceObject->Vpb->VolumeLabel);
51
52 if (*BufferLength < sizeof(FILE_FS_VOLUME_INFORMATION))
53 return STATUS_INFO_LENGTH_MISMATCH;
54
55 if (*BufferLength < (sizeof(FILE_FS_VOLUME_INFORMATION) + DeviceObject->Vpb->VolumeLabelLength))
56 return STATUS_BUFFER_OVERFLOW;
57
58 /* valid entries */
59 FsVolumeInfo->VolumeSerialNumber = DeviceObject->Vpb->SerialNumber;
60 FsVolumeInfo->VolumeLabelLength = DeviceObject->Vpb->VolumeLabelLength;
61 memcpy(FsVolumeInfo->VolumeLabel,
62 DeviceObject->Vpb->VolumeLabel,
63 DeviceObject->Vpb->VolumeLabelLength);
64
65 /* dummy entries */
66 FsVolumeInfo->VolumeCreationTime.QuadPart = 0;
67 FsVolumeInfo->SupportsObjects = FALSE;
68
69 DPRINT("Finished FsdGetFsVolumeInformation()\n");
70
71 *BufferLength -= (sizeof(FILE_FS_VOLUME_INFORMATION) + DeviceObject->Vpb->VolumeLabelLength);
72
73 DPRINT("BufferLength %lu\n", *BufferLength);
74
75 return(STATUS_SUCCESS);
76 }
77
78
79 static NTSTATUS
80 CdfsGetFsAttributeInformation(PDEVICE_EXTENSION DeviceExt,
81 PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo,
82 PULONG BufferLength)
83 {
84 DPRINT("CdfsGetFsAttributeInformation()\n");
85 DPRINT("FsAttributeInfo = %p\n", FsAttributeInfo);
86 DPRINT("BufferLength %lu\n", *BufferLength);
87 DPRINT("Required length %lu\n", (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8));
88
89 UNREFERENCED_PARAMETER(DeviceExt);
90
91 if (*BufferLength < sizeof (FILE_FS_ATTRIBUTE_INFORMATION))
92 return STATUS_INFO_LENGTH_MISMATCH;
93
94 if (*BufferLength < (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8))
95 return STATUS_BUFFER_OVERFLOW;
96
97 FsAttributeInfo->FileSystemAttributes =
98 FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK | FILE_READ_ONLY_VOLUME;
99 FsAttributeInfo->MaximumComponentNameLength = 255;
100 FsAttributeInfo->FileSystemNameLength = 8;
101
102 memcpy(FsAttributeInfo->FileSystemName, L"CDFS", 8);
103
104 DPRINT("Finished FsdGetFsAttributeInformation()\n");
105
106 *BufferLength -= (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8);
107 DPRINT("BufferLength %lu\n", *BufferLength);
108
109 return(STATUS_SUCCESS);
110 }
111
112
113 static NTSTATUS
114 CdfsGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
115 PFILE_FS_SIZE_INFORMATION FsSizeInfo,
116 PULONG BufferLength)
117 {
118 PDEVICE_EXTENSION DeviceExt;
119 NTSTATUS Status = STATUS_SUCCESS;
120
121 DPRINT("CdfsGetFsSizeInformation()\n");
122 DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
123
124 if (*BufferLength < sizeof(FILE_FS_SIZE_INFORMATION))
125 return(STATUS_BUFFER_OVERFLOW);
126
127 DeviceExt = DeviceObject->DeviceExtension;
128
129 FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
130 FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->CdInfo.VolumeSpaceSize;
131 FsSizeInfo->SectorsPerAllocationUnit = 1;
132 FsSizeInfo->BytesPerSector = BLOCKSIZE;
133
134 DPRINT("Finished FsdGetFsSizeInformation()\n");
135 if (NT_SUCCESS(Status))
136 *BufferLength -= sizeof(FILE_FS_SIZE_INFORMATION);
137
138 return(Status);
139 }
140
141
142 static NTSTATUS
143 CdfsGetFsDeviceInformation
144 (
145 PDEVICE_OBJECT DeviceObject,
146 PFILE_FS_DEVICE_INFORMATION FsDeviceInfo,
147 PULONG BufferLength
148 )
149 {
150 DPRINT("CdfsGetFsDeviceInformation()\n");
151 DPRINT("FsDeviceInfo = %p\n", FsDeviceInfo);
152 DPRINT("BufferLength %lu\n", *BufferLength);
153 DPRINT("Required length %lu\n", sizeof(FILE_FS_DEVICE_INFORMATION));
154
155 if (*BufferLength < sizeof(FILE_FS_DEVICE_INFORMATION))
156 return(STATUS_BUFFER_OVERFLOW);
157
158 FsDeviceInfo->DeviceType = FILE_DEVICE_CD_ROM;
159 FsDeviceInfo->Characteristics = DeviceObject->Characteristics;
160
161 DPRINT("FsdGetFsDeviceInformation() finished.\n");
162
163 *BufferLength -= sizeof(FILE_FS_DEVICE_INFORMATION);
164 DPRINT("BufferLength %lu\n", *BufferLength);
165
166 return(STATUS_SUCCESS);
167 }
168
169
170 NTSTATUS NTAPI
171 CdfsQueryVolumeInformation(
172 PCDFS_IRP_CONTEXT IrpContext)
173 {
174 PIRP Irp;
175 PDEVICE_OBJECT DeviceObject;
176 FS_INFORMATION_CLASS FsInformationClass;
177 PIO_STACK_LOCATION Stack;
178 NTSTATUS Status = STATUS_SUCCESS;
179 PVOID SystemBuffer;
180 ULONG BufferLength;
181
182 DPRINT("CdfsQueryVolumeInformation() called\n");
183
184 ASSERT(IrpContext);
185
186 Irp = IrpContext->Irp;
187 DeviceObject = IrpContext->DeviceObject;
188 Stack = IrpContext->Stack;
189 FsInformationClass = Stack->Parameters.QueryVolume.FsInformationClass;
190 BufferLength = Stack->Parameters.QueryVolume.Length;
191 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
192
193 DPRINT("FsInformationClass %d\n", FsInformationClass);
194 DPRINT("SystemBuffer %p\n", SystemBuffer);
195
196 switch (FsInformationClass)
197 {
198 case FileFsVolumeInformation:
199 Status = CdfsGetFsVolumeInformation(DeviceObject,
200 SystemBuffer,
201 &BufferLength);
202 break;
203
204 case FileFsAttributeInformation:
205 Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension,
206 SystemBuffer,
207 &BufferLength);
208 break;
209
210 case FileFsSizeInformation:
211 Status = CdfsGetFsSizeInformation(DeviceObject,
212 SystemBuffer,
213 &BufferLength);
214 break;
215
216 case FileFsDeviceInformation:
217 Status = CdfsGetFsDeviceInformation(DeviceObject,
218 SystemBuffer,
219 &BufferLength);
220 break;
221
222 default:
223 Status = STATUS_NOT_SUPPORTED;
224 }
225
226 Irp->IoStatus.Status = Status;
227 if (NT_SUCCESS(Status))
228 Irp->IoStatus.Information =
229 Stack->Parameters.QueryVolume.Length - BufferLength;
230 else
231 Irp->IoStatus.Information = 0;
232
233 return(Status);
234 }
235
236
237 NTSTATUS NTAPI
238 CdfsSetVolumeInformation(
239 PCDFS_IRP_CONTEXT IrpContext)
240 {
241 PIRP Irp;
242
243 DPRINT("CdfsSetVolumeInformation() called\n");
244
245 ASSERT(IrpContext);
246
247 Irp = IrpContext->Irp;
248 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
249 Irp->IoStatus.Information = 0;
250
251 return(STATUS_NOT_SUPPORTED);
252 }
253
254 /* EOF */