Synchronize with trunk r58606.
[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 if (*BufferLength < sizeof (FILE_FS_ATTRIBUTE_INFORMATION))
90 return STATUS_INFO_LENGTH_MISMATCH;
91
92 if (*BufferLength < (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8))
93 return STATUS_BUFFER_OVERFLOW;
94
95 FsAttributeInfo->FileSystemAttributes =
96 FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK;
97 FsAttributeInfo->MaximumComponentNameLength = 255;
98 FsAttributeInfo->FileSystemNameLength = 8;
99
100 memcpy(FsAttributeInfo->FileSystemName, L"CDFS", 8);
101
102 DPRINT("Finished FsdGetFsAttributeInformation()\n");
103
104 *BufferLength -= (sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 8);
105 DPRINT("BufferLength %lu\n", *BufferLength);
106
107 return(STATUS_SUCCESS);
108 }
109
110
111 static NTSTATUS
112 CdfsGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
113 PFILE_FS_SIZE_INFORMATION FsSizeInfo,
114 PULONG BufferLength)
115 {
116 PDEVICE_EXTENSION DeviceExt;
117 NTSTATUS Status = STATUS_SUCCESS;
118
119 DPRINT("CdfsGetFsSizeInformation()\n");
120 DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
121
122 if (*BufferLength < sizeof(FILE_FS_SIZE_INFORMATION))
123 return(STATUS_BUFFER_OVERFLOW);
124
125 DeviceExt = DeviceObject->DeviceExtension;
126
127 FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
128 FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->CdInfo.VolumeSpaceSize;
129 FsSizeInfo->SectorsPerAllocationUnit = 1;
130 FsSizeInfo->BytesPerSector = BLOCKSIZE;
131
132 DPRINT("Finished FsdGetFsSizeInformation()\n");
133 if (NT_SUCCESS(Status))
134 *BufferLength -= sizeof(FILE_FS_SIZE_INFORMATION);
135
136 return(Status);
137 }
138
139
140 static NTSTATUS
141 CdfsGetFsDeviceInformation
142 (
143 PDEVICE_OBJECT DeviceObject,
144 PFILE_FS_DEVICE_INFORMATION FsDeviceInfo,
145 PULONG BufferLength
146 )
147 {
148 DPRINT("CdfsGetFsDeviceInformation()\n");
149 DPRINT("FsDeviceInfo = %p\n", FsDeviceInfo);
150 DPRINT("BufferLength %lu\n", *BufferLength);
151 DPRINT("Required length %lu\n", sizeof(FILE_FS_DEVICE_INFORMATION));
152
153 if (*BufferLength < sizeof(FILE_FS_DEVICE_INFORMATION))
154 return(STATUS_BUFFER_OVERFLOW);
155
156 FsDeviceInfo->DeviceType = FILE_DEVICE_CD_ROM;
157 FsDeviceInfo->Characteristics = DeviceObject->Characteristics;
158
159 DPRINT("FsdGetFsDeviceInformation() finished.\n");
160
161 *BufferLength -= sizeof(FILE_FS_DEVICE_INFORMATION);
162 DPRINT("BufferLength %lu\n", *BufferLength);
163
164 return(STATUS_SUCCESS);
165 }
166
167
168 NTSTATUS NTAPI
169 CdfsQueryVolumeInformation(PDEVICE_OBJECT DeviceObject,
170 PIRP Irp)
171 {
172 FS_INFORMATION_CLASS FsInformationClass;
173 PIO_STACK_LOCATION Stack;
174 NTSTATUS Status = STATUS_SUCCESS;
175 PVOID SystemBuffer;
176 ULONG BufferLength;
177
178 DPRINT("CdfsQueryVolumeInformation() called\n");
179
180 Stack = IoGetCurrentIrpStackLocation(Irp);
181 FsInformationClass = Stack->Parameters.QueryVolume.FsInformationClass;
182 BufferLength = Stack->Parameters.QueryVolume.Length;
183 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
184
185 DPRINT("FsInformationClass %d\n", FsInformationClass);
186 DPRINT("SystemBuffer %x\n", SystemBuffer);
187
188 switch (FsInformationClass)
189 {
190 case FileFsVolumeInformation:
191 Status = CdfsGetFsVolumeInformation(DeviceObject,
192 SystemBuffer,
193 &BufferLength);
194 break;
195
196 case FileFsAttributeInformation:
197 Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension,
198 SystemBuffer,
199 &BufferLength);
200 break;
201
202 case FileFsSizeInformation:
203 Status = CdfsGetFsSizeInformation(DeviceObject,
204 SystemBuffer,
205 &BufferLength);
206 break;
207
208 case FileFsDeviceInformation:
209 Status = CdfsGetFsDeviceInformation(DeviceObject,
210 SystemBuffer,
211 &BufferLength);
212 break;
213
214 default:
215 Status = STATUS_NOT_SUPPORTED;
216 }
217
218 Irp->IoStatus.Status = Status;
219 if (NT_SUCCESS(Status))
220 Irp->IoStatus.Information =
221 Stack->Parameters.QueryVolume.Length - BufferLength;
222 else
223 Irp->IoStatus.Information = 0;
224 IoCompleteRequest(Irp, IO_NO_INCREMENT);
225
226 return(Status);
227 }
228
229
230 NTSTATUS NTAPI
231 CdfsSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
232 PIRP Irp)
233 {
234 DPRINT("CdfsSetVolumeInformation() called\n");
235
236 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
237 Irp->IoStatus.Information = 0;
238 IoCompleteRequest(Irp, IO_NO_INCREMENT);
239
240 return(STATUS_NOT_SUPPORTED);
241 }
242
243 /* EOF */