2 * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18 * nor the names of their contributors may be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission from Kernel Drivers, LLC and Your File System, Inc.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // File: AFSVolumeInfo.cpp
39 #include "AFSCommon.h"
42 AFSQueryVolumeInfo( IN PDEVICE_OBJECT LibDeviceObject,
46 NTSTATUS ntStatus = STATUS_SUCCESS;
47 AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
48 IO_STACK_LOCATION *pIrpSp;
49 FS_INFORMATION_CLASS FsInformationClass;
52 BOOLEAN bReleaseResource = FALSE;
54 AFSVolumeCB *pVolumeCB = NULL;
56 pIrpSp = IoGetCurrentIrpStackLocation( Irp);
61 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
66 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
67 AFS_TRACE_LEVEL_ERROR,
68 "AFSQueryVolumeInfo Failing request with NULL Fcb\n");
70 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
73 pVolumeCB = pFcb->ObjectInformation->VolumeCB;
75 ASSERT( pVolumeCB->ObjectInformation.FileType == AFS_FILE_TYPE_DIRECTORY &&
76 pVolumeCB->ObjectInformation.FileId.Vnode == 1);
78 ulLength = pIrpSp->Parameters.QueryVolume.Length;
79 FsInformationClass = pIrpSp->Parameters.QueryVolume.FsInformationClass;
80 pBuffer = Irp->AssociatedIrp.SystemBuffer;
82 AFSAcquireExcl( pVolumeCB->VolumeLock,
85 bReleaseResource = TRUE;
88 // Don't allow requests against IOCtl nodes
91 if( pFcb->Header.NodeTypeCode == AFS_IOCTL_FCB)
94 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
95 AFS_TRACE_LEVEL_ERROR,
96 "AFSQueryVolumeInfo Failing request against PIOCtl Fcb\n");
98 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
100 else if( pFcb->Header.NodeTypeCode == AFS_SPECIAL_SHARE_FCB)
103 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
104 AFS_TRACE_LEVEL_ERROR,
105 "AFSQueryVolumeInfo Failing request against SpecialShare Fcb\n");
107 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
111 // Process the request
114 switch( FsInformationClass)
117 case FileFsVolumeInformation:
120 ntStatus = AFSQueryFsVolumeInfo( &pVolumeCB->VolumeInformation,
121 (PFILE_FS_VOLUME_INFORMATION)pBuffer,
127 case FileFsSizeInformation:
130 ntStatus = AFSQueryFsSizeInfo( &pVolumeCB->VolumeInformation,
131 (PFILE_FS_SIZE_INFORMATION)pBuffer,
137 case FileFsDeviceInformation:
140 ntStatus = AFSQueryFsDeviceInfo( &pVolumeCB->VolumeInformation,
141 (PFILE_FS_DEVICE_INFORMATION)pBuffer,
147 case FileFsAttributeInformation:
150 ntStatus = AFSQueryFsAttributeInfo( &pVolumeCB->VolumeInformation,
151 (PFILE_FS_ATTRIBUTE_INFORMATION)pBuffer,
157 case FileFsFullSizeInformation:
160 ntStatus = AFSQueryFsFullSizeInfo( &pVolumeCB->VolumeInformation,
161 (PFILE_FS_FULL_SIZE_INFORMATION)pBuffer,
169 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
170 AFS_TRACE_LEVEL_WARNING,
171 "AFSQueryVolumeInfo Invalid class %d\n",
174 ntStatus = STATUS_INVALID_PARAMETER;
182 // Setup the Irp's information field to what we actually copied in.
185 Irp->IoStatus.Information = pIrpSp->Parameters.QueryVolume.Length - ulLength;
187 if( bReleaseResource)
190 AFSReleaseResource( pVolumeCB->VolumeLock);
193 AFSCompleteRequest( Irp,
197 __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
202 "EXCEPTION - AFSQueryVolumeInfo\n");
209 AFSSetVolumeInfo( IN PDEVICE_OBJECT DeviceObject,
213 NTSTATUS ntStatus = STATUS_SUCCESS;
214 IO_STACK_LOCATION *pIrpSp;
216 pIrpSp = IoGetCurrentIrpStackLocation( Irp);
221 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
222 AFS_TRACE_LEVEL_WARNING,
223 "AFSSetVolumeInfo Entry for FO %08lX\n", pIrpSp->FileObject);
225 AFSCompleteRequest( Irp,
229 __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
234 "EXCEPTION - AFSSetVolumeInfo\n");
241 AFSQueryFsVolumeInfo( IN AFSVolumeInfoCB *VolumeInfo,
242 IN PFILE_FS_VOLUME_INFORMATION Buffer,
243 IN OUT PULONG Length)
247 NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
250 RtlZeroMemory( Buffer,
253 if( *Length >= (ULONG)sizeof( FILE_FS_VOLUME_INFORMATION))
256 if( *Length >= (ULONG)(FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel) + (LONG)VolumeInfo->VolumeLabelLength))
259 ulCopyLength = (LONG)VolumeInfo->VolumeLabelLength;
261 ntStatus = STATUS_SUCCESS;
266 ulCopyLength = *Length - FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel);
268 ntStatus = STATUS_BUFFER_OVERFLOW;
271 Buffer->VolumeCreationTime.QuadPart = VolumeInfo->VolumeCreationTime.QuadPart;
273 Buffer->VolumeSerialNumber = VolumeInfo->VolumeID;
275 Buffer->VolumeLabelLength = VolumeInfo->VolumeLabelLength;
277 Buffer->SupportsObjects = FALSE;
279 *Length -= FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel);
281 if( ulCopyLength > 0)
284 RtlCopyMemory( Buffer->VolumeLabel,
285 VolumeInfo->VolumeLabel,
288 *Length -= ulCopyLength;
296 AFSQueryFsSizeInfo( IN AFSVolumeInfoCB *VolumeInfo,
297 IN PFILE_FS_SIZE_INFORMATION Buffer,
298 IN OUT PULONG Length)
301 NTSTATUS ntStatus = STATUS_SUCCESS;
303 RtlZeroMemory( Buffer,
306 if( *Length >= sizeof( FILE_FS_SIZE_INFORMATION))
309 Buffer->TotalAllocationUnits.QuadPart = VolumeInfo->TotalAllocationUnits.QuadPart;
311 Buffer->AvailableAllocationUnits.QuadPart = VolumeInfo->AvailableAllocationUnits.QuadPart;
313 Buffer->SectorsPerAllocationUnit = VolumeInfo->SectorsPerAllocationUnit;
315 Buffer->BytesPerSector = VolumeInfo->BytesPerSector;
317 *Length -= sizeof( FILE_FS_SIZE_INFORMATION);
322 ntStatus = STATUS_BUFFER_TOO_SMALL;
329 AFSQueryFsDeviceInfo( IN AFSVolumeInfoCB *VolumeInfo,
330 IN PFILE_FS_DEVICE_INFORMATION Buffer,
331 IN OUT PULONG Length)
333 NTSTATUS ntStatus = STATUS_SUCCESS;
335 RtlZeroMemory( Buffer,
338 if( *Length >= (LONG)sizeof( FILE_FS_DEVICE_INFORMATION))
341 Buffer->DeviceType = FILE_DEVICE_DISK;
343 Buffer->Characteristics = VolumeInfo->Characteristics;
345 *Length -= sizeof( FILE_FS_DEVICE_INFORMATION);
350 ntStatus = STATUS_BUFFER_TOO_SMALL;
357 AFSQueryFsAttributeInfo( IN AFSVolumeInfoCB *VolumeInfo,
358 IN PFILE_FS_ATTRIBUTE_INFORMATION Buffer,
359 IN OUT PULONG Length)
361 NTSTATUS ntStatus = STATUS_SUCCESS;
363 RtlZeroMemory( Buffer,
366 if( *Length >= (LONG)(sizeof( FILE_FS_ATTRIBUTE_INFORMATION)))
369 Buffer->FileSystemAttributes = (FILE_CASE_PRESERVED_NAMES |
370 FILE_UNICODE_ON_DISK |
371 FILE_SUPPORTS_REPARSE_POINTS);
373 Buffer->MaximumComponentNameLength = 255;
375 Buffer->FileSystemNameLength = 18;
377 *Length -= FIELD_OFFSET( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName);
382 RtlCopyMemory( Buffer->FileSystemName,
391 ntStatus = STATUS_BUFFER_OVERFLOW;
397 ntStatus = STATUS_BUFFER_TOO_SMALL;
404 AFSQueryFsFullSizeInfo( IN AFSVolumeInfoCB *VolumeInfo,
405 IN PFILE_FS_FULL_SIZE_INFORMATION Buffer,
406 IN OUT PULONG Length)
409 NTSTATUS ntStatus = STATUS_SUCCESS;
411 RtlZeroMemory( Buffer,
414 if( *Length >= sizeof( FILE_FS_FULL_SIZE_INFORMATION))
417 Buffer->TotalAllocationUnits.QuadPart = VolumeInfo->TotalAllocationUnits.QuadPart;
419 Buffer->CallerAvailableAllocationUnits.QuadPart = VolumeInfo->AvailableAllocationUnits.QuadPart;
421 Buffer->ActualAvailableAllocationUnits.QuadPart = VolumeInfo->AvailableAllocationUnits.QuadPart;
423 Buffer->SectorsPerAllocationUnit = VolumeInfo->SectorsPerAllocationUnit;
425 Buffer->BytesPerSector = VolumeInfo->BytesPerSector;
427 *Length -= sizeof( FILE_FS_FULL_SIZE_INFORMATION);
432 ntStatus = STATUS_BUFFER_TOO_SMALL;