[CDFS]
[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: drivers/filesystems/cdfs/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
38 NTSTATUS
39 CdfsGetFsVolumeInformation(
40 PDEVICE_OBJECT DeviceObject,
41 PFILE_FS_VOLUME_INFORMATION FsVolumeInfo,
42 PULONG BufferLength)
43 {
44 DPRINT("CdfsGetFsVolumeInformation() called\n");
45 DPRINT("FsVolumeInfo = %p\n", FsVolumeInfo);
46 DPRINT("BufferLength %lu\n", *BufferLength);
47
48 DPRINT("Vpb %p\n", DeviceObject->Vpb);
49
50 DPRINT("Required length %lu\n", (sizeof(FILE_FS_VOLUME_INFORMATION) + DeviceObject->Vpb->VolumeLabelLength));
51 DPRINT("LabelLength %hu\n", DeviceObject->Vpb->VolumeLabelLength);
52 DPRINT("Label %*.S\n", DeviceObject->Vpb->VolumeLabelLength / sizeof(WCHAR), DeviceObject->Vpb->VolumeLabel);
53
54 if (*BufferLength < sizeof(FILE_FS_VOLUME_INFORMATION))
55 return STATUS_INFO_LENGTH_MISMATCH;
56
57 if (*BufferLength < (sizeof(FILE_FS_VOLUME_INFORMATION) + DeviceObject->Vpb->VolumeLabelLength))
58 return STATUS_BUFFER_OVERFLOW;
59
60 /* valid entries */
61 FsVolumeInfo->VolumeSerialNumber = DeviceObject->Vpb->SerialNumber;
62 FsVolumeInfo->VolumeLabelLength = DeviceObject->Vpb->VolumeLabelLength;
63 memcpy(FsVolumeInfo->VolumeLabel,
64 DeviceObject->Vpb->VolumeLabel,
65 DeviceObject->Vpb->VolumeLabelLength);
66
67 /* dummy entries */
68 FsVolumeInfo->VolumeCreationTime.QuadPart = 0;
69 FsVolumeInfo->SupportsObjects = FALSE;
70
71 DPRINT("Finished FsdGetFsVolumeInformation()\n");
72
73 *BufferLength -= (sizeof(FILE_FS_VOLUME_INFORMATION) + DeviceObject->Vpb->VolumeLabelLength);
74
75 DPRINT("BufferLength %lu\n", *BufferLength);
76
77 return STATUS_SUCCESS;
78 }
79
80
81 static
82 NTSTATUS
83 CdfsGetFsAttributeInformation(
84 PDEVICE_EXTENSION DeviceExt,
85 PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo,
86 PULONG BufferLength)
87 {
88 DPRINT("CdfsGetFsAttributeInformation()\n");
89 DPRINT("FsAttributeInfo = %p\n", FsAttributeInfo);
90 DPRINT("BufferLength %lu\n", *BufferLength);
91 DPRINT("Required length %lu\n", (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8));
92
93 UNREFERENCED_PARAMETER(DeviceExt);
94
95 if (*BufferLength < sizeof (FILE_FS_ATTRIBUTE_INFORMATION))
96 return STATUS_INFO_LENGTH_MISMATCH;
97
98 if (*BufferLength < (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8))
99 return STATUS_BUFFER_OVERFLOW;
100
101 FsAttributeInfo->FileSystemAttributes =
102 FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK | FILE_READ_ONLY_VOLUME;
103 FsAttributeInfo->MaximumComponentNameLength = 255;
104 FsAttributeInfo->FileSystemNameLength = 8;
105
106 memcpy(FsAttributeInfo->FileSystemName, L"CDFS", 8);
107
108 DPRINT("Finished FsdGetFsAttributeInformation()\n");
109
110 *BufferLength -= (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8);
111 DPRINT("BufferLength %lu\n", *BufferLength);
112
113 return STATUS_SUCCESS;
114 }
115
116
117 static NTSTATUS
118 CdfsGetFsSizeInformation(
119 PDEVICE_OBJECT DeviceObject,
120 PFILE_FS_SIZE_INFORMATION FsSizeInfo,
121 PULONG BufferLength)
122 {
123 PDEVICE_EXTENSION DeviceExt;
124 NTSTATUS Status = STATUS_SUCCESS;
125
126 DPRINT("CdfsGetFsSizeInformation()\n");
127 DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
128
129 if (*BufferLength < sizeof(FILE_FS_SIZE_INFORMATION))
130 return STATUS_BUFFER_OVERFLOW;
131
132 DeviceExt = DeviceObject->DeviceExtension;
133
134 FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
135 FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->CdInfo.VolumeSpaceSize;
136 FsSizeInfo->SectorsPerAllocationUnit = 1;
137 FsSizeInfo->BytesPerSector = BLOCKSIZE;
138
139 DPRINT("Finished FsdGetFsSizeInformation()\n");
140 if (NT_SUCCESS(Status))
141 *BufferLength -= sizeof(FILE_FS_SIZE_INFORMATION);
142
143 return Status;
144 }
145
146
147 static
148 NTSTATUS
149 CdfsGetFsDeviceInformation(
150 PDEVICE_OBJECT DeviceObject,
151 PFILE_FS_DEVICE_INFORMATION FsDeviceInfo,
152 PULONG BufferLength)
153 {
154 DPRINT("CdfsGetFsDeviceInformation()\n");
155 DPRINT("FsDeviceInfo = %p\n", FsDeviceInfo);
156 DPRINT("BufferLength %lu\n", *BufferLength);
157 DPRINT("Required length %lu\n", sizeof(FILE_FS_DEVICE_INFORMATION));
158
159 if (*BufferLength < sizeof(FILE_FS_DEVICE_INFORMATION))
160 return STATUS_BUFFER_OVERFLOW;
161
162 FsDeviceInfo->DeviceType = FILE_DEVICE_CD_ROM;
163 FsDeviceInfo->Characteristics = DeviceObject->Characteristics;
164
165 DPRINT("FsdGetFsDeviceInformation() finished.\n");
166
167 *BufferLength -= sizeof(FILE_FS_DEVICE_INFORMATION);
168 DPRINT("BufferLength %lu\n", *BufferLength);
169
170 return STATUS_SUCCESS;
171 }
172
173
174 NTSTATUS
175 NTAPI
176 CdfsQueryVolumeInformation(
177 PCDFS_IRP_CONTEXT IrpContext)
178 {
179 PIRP Irp;
180 PDEVICE_OBJECT DeviceObject;
181 FS_INFORMATION_CLASS FsInformationClass;
182 PIO_STACK_LOCATION Stack;
183 NTSTATUS Status = STATUS_SUCCESS;
184 PVOID SystemBuffer;
185 ULONG BufferLength;
186
187 DPRINT("CdfsQueryVolumeInformation() called\n");
188
189 ASSERT(IrpContext);
190
191 Irp = IrpContext->Irp;
192 DeviceObject = IrpContext->DeviceObject;
193 Stack = IrpContext->Stack;
194 FsInformationClass = Stack->Parameters.QueryVolume.FsInformationClass;
195 BufferLength = Stack->Parameters.QueryVolume.Length;
196 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
197
198 DPRINT("FsInformationClass %d\n", FsInformationClass);
199 DPRINT("SystemBuffer %p\n", SystemBuffer);
200
201 switch (FsInformationClass)
202 {
203 case FileFsVolumeInformation:
204 Status = CdfsGetFsVolumeInformation(DeviceObject,
205 SystemBuffer,
206 &BufferLength);
207 break;
208
209 case FileFsAttributeInformation:
210 Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension,
211 SystemBuffer,
212 &BufferLength);
213 break;
214
215 case FileFsSizeInformation:
216 Status = CdfsGetFsSizeInformation(DeviceObject,
217 SystemBuffer,
218 &BufferLength);
219 break;
220
221 case FileFsDeviceInformation:
222 Status = CdfsGetFsDeviceInformation(DeviceObject,
223 SystemBuffer,
224 &BufferLength);
225 break;
226
227 default:
228 Status = STATUS_NOT_SUPPORTED;
229 }
230
231 Irp->IoStatus.Status = Status;
232 if (NT_SUCCESS(Status))
233 Irp->IoStatus.Information =
234 Stack->Parameters.QueryVolume.Length - BufferLength;
235 else
236 Irp->IoStatus.Information = 0;
237
238 return Status;
239 }
240
241
242 NTSTATUS
243 NTAPI
244 CdfsSetVolumeInformation(
245 PCDFS_IRP_CONTEXT IrpContext)
246 {
247 PIRP Irp;
248
249 DPRINT("CdfsSetVolumeInformation() called\n");
250
251 ASSERT(IrpContext);
252
253 Irp = IrpContext->Irp;
254 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
255 Irp->IoStatus.Information = 0;
256
257 return STATUS_NOT_SUPPORTED;
258 }
259
260 /* EOF */