* Sync up to trunk head (r65353).
[reactos.git] / 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;
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(PDEVICE_OBJECT DeviceObject,
172 PIRP Irp)
173 {
174 FS_INFORMATION_CLASS FsInformationClass;
175 PIO_STACK_LOCATION Stack;
176 NTSTATUS Status = STATUS_SUCCESS;
177 PVOID SystemBuffer;
178 ULONG BufferLength;
179
180 DPRINT("CdfsQueryVolumeInformation() called\n");
181
182 Stack = IoGetCurrentIrpStackLocation(Irp);
183 FsInformationClass = Stack->Parameters.QueryVolume.FsInformationClass;
184 BufferLength = Stack->Parameters.QueryVolume.Length;
185 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
186
187 DPRINT("FsInformationClass %d\n", FsInformationClass);
188 DPRINT("SystemBuffer %p\n", SystemBuffer);
189
190 switch (FsInformationClass)
191 {
192 case FileFsVolumeInformation:
193 Status = CdfsGetFsVolumeInformation(DeviceObject,
194 SystemBuffer,
195 &BufferLength);
196 break;
197
198 case FileFsAttributeInformation:
199 Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension,
200 SystemBuffer,
201 &BufferLength);
202 break;
203
204 case FileFsSizeInformation:
205 Status = CdfsGetFsSizeInformation(DeviceObject,
206 SystemBuffer,
207 &BufferLength);
208 break;
209
210 case FileFsDeviceInformation:
211 Status = CdfsGetFsDeviceInformation(DeviceObject,
212 SystemBuffer,
213 &BufferLength);
214 break;
215
216 default:
217 Status = STATUS_NOT_SUPPORTED;
218 }
219
220 Irp->IoStatus.Status = Status;
221 if (NT_SUCCESS(Status))
222 Irp->IoStatus.Information =
223 Stack->Parameters.QueryVolume.Length - BufferLength;
224 else
225 Irp->IoStatus.Information = 0;
226 IoCompleteRequest(Irp, IO_NO_INCREMENT);
227
228 return(Status);
229 }
230
231
232 NTSTATUS NTAPI
233 CdfsSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
234 PIRP Irp)
235 {
236 DPRINT("CdfsSetVolumeInformation() called\n");
237
238 UNREFERENCED_PARAMETER(DeviceObject);
239
240 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
241 Irp->IoStatus.Information = 0;
242 IoCompleteRequest(Irp, IO_NO_INCREMENT);
243
244 return(STATUS_NOT_SUPPORTED);
245 }
246
247 /* EOF */