2005-08-24 18:29:45 +00:00
|
|
|
/*
|
2022-09-24 13:24:08 +00:00
|
|
|
* PROJECT: VFAT Filesystem
|
|
|
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
|
|
|
* PURPOSE: Volume routines
|
|
|
|
* COPYRIGHT: Copyright 1998 Jason Filby <jasonfilby@yahoo.com>
|
|
|
|
* Copyright 2004-2022 Hervé Poussineau <hpoussin@reactos.org>
|
1999-12-11 21:14:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include "vfat.h"
|
|
|
|
|
2013-12-19 16:20:28 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
FsdGetFsVolumeInformation(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_FS_VOLUME_INFORMATION FsVolumeInfo,
|
|
|
|
PULONG BufferLength)
|
1999-12-11 21:14:49 +00:00
|
|
|
{
|
2015-06-17 19:19:39 +00:00
|
|
|
NTSTATUS Status;
|
2013-11-29 14:05:43 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsdGetFsVolumeInformation()\n");
|
|
|
|
DPRINT("FsVolumeInfo = %p\n", FsVolumeInfo);
|
|
|
|
DPRINT("BufferLength %lu\n", *BufferLength);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
DPRINT("Required length %lu\n", FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + DeviceObject->Vpb->VolumeLabelLength);
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("LabelLength %hu\n", DeviceObject->Vpb->VolumeLabelLength);
|
2017-06-20 00:45:07 +00:00
|
|
|
DPRINT("Label %.*S\n", DeviceObject->Vpb->VolumeLabelLength / sizeof(WCHAR), DeviceObject->Vpb->VolumeLabel);
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
ASSERT(*BufferLength >= sizeof(FILE_FS_VOLUME_INFORMATION));
|
|
|
|
*BufferLength -= FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 14:05:43 +00:00
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
/* valid entries */
|
|
|
|
FsVolumeInfo->VolumeSerialNumber = DeviceObject->Vpb->SerialNumber;
|
|
|
|
FsVolumeInfo->VolumeLabelLength = DeviceObject->Vpb->VolumeLabelLength;
|
2015-06-17 19:19:39 +00:00
|
|
|
if (*BufferLength < DeviceObject->Vpb->VolumeLabelLength)
|
|
|
|
{
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
RtlCopyMemory(FsVolumeInfo->VolumeLabel,
|
|
|
|
DeviceObject->Vpb->VolumeLabel,
|
|
|
|
*BufferLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
RtlCopyMemory(FsVolumeInfo->VolumeLabel,
|
|
|
|
DeviceObject->Vpb->VolumeLabel,
|
|
|
|
FsVolumeInfo->VolumeLabelLength);
|
|
|
|
*BufferLength -= DeviceObject->Vpb->VolumeLabelLength;
|
|
|
|
}
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2017-02-17 21:24:12 +00:00
|
|
|
if (vfatVolumeIsFatX(DeviceExt))
|
2013-11-29 14:05:43 +00:00
|
|
|
{
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
DeviceExt->VolumeFcb->entry.FatX.CreationDate,
|
|
|
|
DeviceExt->VolumeFcb->entry.FatX.CreationTime,
|
|
|
|
&FsVolumeInfo->VolumeCreationTime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FsdDosDateTimeToSystemTime(DeviceExt,
|
|
|
|
DeviceExt->VolumeFcb->entry.Fat.CreationDate,
|
|
|
|
DeviceExt->VolumeFcb->entry.Fat.CreationTime,
|
|
|
|
&FsVolumeInfo->VolumeCreationTime);
|
|
|
|
}
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsVolumeInfo->SupportsObjects = FALSE;
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("Finished FsdGetFsVolumeInformation()\n");
|
|
|
|
DPRINT("BufferLength %lu\n", *BufferLength);
|
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
return Status;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
FsdGetFsAttributeInformation(
|
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
|
|
|
PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo,
|
|
|
|
PULONG BufferLength)
|
1999-12-11 21:14:49 +00:00
|
|
|
{
|
2015-06-17 19:19:39 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PCWSTR pName;
|
|
|
|
ULONG Length;
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsdGetFsAttributeInformation()\n");
|
|
|
|
DPRINT("FsAttributeInfo = %p\n", FsAttributeInfo);
|
|
|
|
DPRINT("BufferLength %lu\n", *BufferLength);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
ASSERT(*BufferLength >= sizeof(FILE_FS_ATTRIBUTE_INFORMATION));
|
|
|
|
*BufferLength -= FIELD_OFFSET(FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName);
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2022-09-13 21:15:27 +00:00
|
|
|
switch (DeviceExt->FatInfo.FatType)
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
2022-09-13 21:15:27 +00:00
|
|
|
case FAT12: pName = L"FAT"; break;
|
|
|
|
case FAT16: pName = L"FAT"; break;
|
|
|
|
case FAT32: pName = L"FAT32"; break;
|
|
|
|
case FATX16: pName = L"FATX"; break;
|
|
|
|
case FATX32: pName = L"FATX"; break;
|
|
|
|
default: return STATUS_NOT_SUPPORTED;
|
2013-11-29 11:03:34 +00:00
|
|
|
}
|
2003-07-20 18:36:53 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
Length = wcslen(pName) * sizeof(WCHAR);
|
|
|
|
DPRINT("Required length %lu\n", (FIELD_OFFSET(FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName) + Length));
|
2004-08-01 21:57:18 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
if (*BufferLength < Length)
|
|
|
|
{
|
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
Length = *BufferLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsAttributeInfo->FileSystemAttributes =
|
|
|
|
FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK;
|
2003-07-20 18:36:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsAttributeInfo->MaximumComponentNameLength = 255;
|
2003-07-20 18:36:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsAttributeInfo->FileSystemNameLength = Length;
|
2003-07-20 18:36:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
RtlCopyMemory(FsAttributeInfo->FileSystemName, pName, Length);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("Finished FsdGetFsAttributeInformation()\n");
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
*BufferLength -= Length;
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("BufferLength %lu\n", *BufferLength);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
return Status;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
FsdGetFsSizeInformation(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_FS_SIZE_INFORMATION FsSizeInfo,
|
|
|
|
PULONG BufferLength)
|
1999-12-11 21:14:49 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
NTSTATUS Status;
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsdGetFsSizeInformation()\n");
|
|
|
|
DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
ASSERT(*BufferLength >= sizeof(FILE_FS_SIZE_INFORMATION));
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
Status = CountAvailableClusters(DeviceExt, &FsSizeInfo->AvailableAllocationUnits);
|
2001-07-28 10:12:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->FatInfo.NumberOfClusters;
|
|
|
|
FsSizeInfo->SectorsPerAllocationUnit = DeviceExt->FatInfo.SectorsPerCluster;
|
|
|
|
FsSizeInfo->BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("Finished FsdGetFsSizeInformation()\n");
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
*BufferLength -= sizeof(FILE_FS_SIZE_INFORMATION);
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
return Status;
|
2001-06-12 12:35:42 +00:00
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
FsdGetFsDeviceInformation(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_FS_DEVICE_INFORMATION FsDeviceInfo,
|
|
|
|
PULONG BufferLength)
|
2001-06-12 12:35:42 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsdGetFsDeviceInformation()\n");
|
|
|
|
DPRINT("FsDeviceInfo = %p\n", FsDeviceInfo);
|
|
|
|
DPRINT("BufferLength %lu\n", *BufferLength);
|
|
|
|
DPRINT("Required length %lu\n", sizeof(FILE_FS_DEVICE_INFORMATION));
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
ASSERT(*BufferLength >= sizeof(FILE_FS_DEVICE_INFORMATION));
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsDeviceInfo->DeviceType = FILE_DEVICE_DISK;
|
|
|
|
FsDeviceInfo->Characteristics = DeviceObject->Characteristics;
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsdGetFsDeviceInformation() finished.\n");
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
*BufferLength -= sizeof(FILE_FS_DEVICE_INFORMATION);
|
|
|
|
DPRINT("BufferLength %lu\n", *BufferLength);
|
2001-11-01 10:41:53 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
return STATUS_SUCCESS;
|
2001-06-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-02 09:08:33 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
FsdGetFsFullSizeInformation(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_FS_FULL_SIZE_INFORMATION FsSizeInfo,
|
|
|
|
PULONG BufferLength)
|
|
|
|
{
|
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
DPRINT("FsdGetFsFullSizeInformation()\n");
|
|
|
|
DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
|
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
ASSERT(*BufferLength >= sizeof(FILE_FS_FULL_SIZE_INFORMATION));
|
2015-06-02 09:08:33 +00:00
|
|
|
|
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
Status = CountAvailableClusters(DeviceExt, &FsSizeInfo->CallerAvailableAllocationUnits);
|
|
|
|
|
|
|
|
FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->FatInfo.NumberOfClusters;
|
|
|
|
FsSizeInfo->ActualAvailableAllocationUnits.QuadPart = FsSizeInfo->CallerAvailableAllocationUnits.QuadPart;
|
|
|
|
FsSizeInfo->SectorsPerAllocationUnit = DeviceExt->FatInfo.SectorsPerCluster;
|
|
|
|
FsSizeInfo->BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
|
|
|
|
|
|
|
|
DPRINT("Finished FsdGetFsFullSizeInformation()\n");
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
*BufferLength -= sizeof(FILE_FS_FULL_SIZE_INFORMATION);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
FsdSetFsLabelInformation(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PFILE_FS_LABEL_INFORMATION FsLabelInfo)
|
2001-06-11 19:52:22 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
PVOID Context = NULL;
|
|
|
|
ULONG DirIndex = 0;
|
|
|
|
PDIR_ENTRY Entry;
|
|
|
|
PVFATFCB pRootFcb;
|
|
|
|
LARGE_INTEGER FileOffset;
|
|
|
|
BOOLEAN LabelFound = FALSE;
|
|
|
|
DIR_ENTRY VolumeLabelDirEntry;
|
|
|
|
ULONG VolumeLabelDirIndex;
|
|
|
|
ULONG LabelLen;
|
|
|
|
NTSTATUS Status = STATUS_UNSUCCESSFUL;
|
|
|
|
OEM_STRING StringO;
|
|
|
|
UNICODE_STRING StringW;
|
|
|
|
CHAR cString[43];
|
|
|
|
ULONG SizeDirEntry;
|
|
|
|
ULONG EntriesPerPage;
|
2017-02-18 21:37:56 +00:00
|
|
|
BOOLEAN IsFatX;
|
2013-11-29 11:03:34 +00:00
|
|
|
|
|
|
|
DPRINT("FsdSetFsLabelInformation()\n");
|
|
|
|
|
|
|
|
DeviceExt = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2017-02-18 21:37:56 +00:00
|
|
|
IsFatX = vfatVolumeIsFatX(DeviceExt);
|
2013-11-29 11:03:34 +00:00
|
|
|
|
|
|
|
if (sizeof(DeviceObject->Vpb->VolumeLabel) < FsLabelInfo->VolumeLabelLength)
|
2010-12-22 00:13:03 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
return STATUS_NAME_TOO_LONG;
|
2010-12-22 00:13:03 +00:00
|
|
|
}
|
2013-11-29 11:03:34 +00:00
|
|
|
|
2017-02-18 21:37:56 +00:00
|
|
|
if (IsFatX)
|
2010-12-22 00:13:03 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
if (FsLabelInfo->VolumeLabelLength / sizeof(WCHAR) > 42)
|
|
|
|
return STATUS_NAME_TOO_LONG;
|
|
|
|
|
|
|
|
SizeDirEntry = sizeof(FATX_DIR_ENTRY);
|
|
|
|
EntriesPerPage = FATX_ENTRIES_PER_PAGE;
|
2010-12-22 00:13:03 +00:00
|
|
|
}
|
2013-11-29 11:03:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FsLabelInfo->VolumeLabelLength / sizeof(WCHAR) > 11)
|
|
|
|
return STATUS_NAME_TOO_LONG;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
SizeDirEntry = sizeof(FAT_DIR_ENTRY);
|
|
|
|
EntriesPerPage = FAT_ENTRIES_PER_PAGE;
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
/* Create Volume label dir entry */
|
|
|
|
LabelLen = FsLabelInfo->VolumeLabelLength / sizeof(WCHAR);
|
|
|
|
RtlZeroMemory(&VolumeLabelDirEntry, SizeDirEntry);
|
|
|
|
StringW.Buffer = FsLabelInfo->VolumeLabel;
|
|
|
|
StringW.Length = StringW.MaximumLength = (USHORT)FsLabelInfo->VolumeLabelLength;
|
|
|
|
StringO.Buffer = cString;
|
|
|
|
StringO.Length = 0;
|
|
|
|
StringO.MaximumLength = 42;
|
|
|
|
Status = RtlUnicodeStringToOemString(&StringO, &StringW, FALSE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
2017-02-18 21:37:56 +00:00
|
|
|
if (IsFatX)
|
2004-12-05 16:31:51 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
RtlCopyMemory(VolumeLabelDirEntry.FatX.Filename, cString, LabelLen);
|
|
|
|
memset(&VolumeLabelDirEntry.FatX.Filename[LabelLen], ' ', 42 - LabelLen);
|
|
|
|
VolumeLabelDirEntry.FatX.Attrib = _A_VOLID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(VolumeLabelDirEntry.Fat.Filename, cString, max(sizeof(VolumeLabelDirEntry.Fat.Filename), LabelLen));
|
|
|
|
if (LabelLen > sizeof(VolumeLabelDirEntry.Fat.Filename))
|
|
|
|
{
|
|
|
|
memset(VolumeLabelDirEntry.Fat.Ext, ' ', sizeof(VolumeLabelDirEntry.Fat.Ext));
|
|
|
|
RtlCopyMemory(VolumeLabelDirEntry.Fat.Ext, cString + sizeof(VolumeLabelDirEntry.Fat.Filename), LabelLen - sizeof(VolumeLabelDirEntry.Fat.Filename));
|
|
|
|
}
|
|
|
|
else
|
2010-08-30 11:51:17 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
memset(&VolumeLabelDirEntry.Fat.Filename[LabelLen], ' ', sizeof(VolumeLabelDirEntry.Fat.Filename) - LabelLen);
|
2010-08-30 11:51:17 +00:00
|
|
|
}
|
2013-11-29 11:03:34 +00:00
|
|
|
VolumeLabelDirEntry.Fat.Attrib = _A_VOLID;
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
2013-11-29 11:03:34 +00:00
|
|
|
|
|
|
|
pRootFcb = vfatOpenRootFCB(DeviceExt);
|
2018-05-26 08:12:00 +00:00
|
|
|
Status = vfatFCBInitializeCacheFromVolume(DeviceExt, pRootFcb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2013-11-29 11:03:34 +00:00
|
|
|
|
|
|
|
/* Search existing volume entry on disk */
|
|
|
|
FileOffset.QuadPart = 0;
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcPinRead(pRootFcb->FileObject, &FileOffset, SizeDirEntry, PIN_WAIT, &Context, (PVOID*)&Entry);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
2004-12-05 16:31:51 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
while (TRUE)
|
|
|
|
{
|
2017-02-18 21:37:56 +00:00
|
|
|
if (ENTRY_VOLUME(IsFatX, Entry))
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
|
|
|
/* Update entry */
|
|
|
|
LabelFound = TRUE;
|
|
|
|
RtlCopyMemory(Entry, &VolumeLabelDirEntry, SizeDirEntry);
|
|
|
|
CcSetDirtyPinnedData(Context, NULL);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-02-18 21:37:56 +00:00
|
|
|
if (ENTRY_END(IsFatX, Entry))
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DirIndex++;
|
|
|
|
Entry = (PDIR_ENTRY)((ULONG_PTR)Entry + SizeDirEntry);
|
|
|
|
if ((DirIndex % EntriesPerPage) == 0)
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
FileOffset.u.LowPart += PAGE_SIZE;
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcPinRead(pRootFcb->FileObject, &FileOffset, SizeDirEntry, PIN_WAIT, &Context, (PVOID*)&Entry);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
|
|
|
Context = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Context)
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
2013-11-29 11:03:34 +00:00
|
|
|
|
|
|
|
if (!LabelFound)
|
2004-12-05 16:31:51 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
/* Add new entry for label */
|
|
|
|
if (!vfatFindDirSpace(DeviceExt, pRootFcb, 1, &VolumeLabelDirIndex))
|
|
|
|
Status = STATUS_DISK_FULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileOffset.u.HighPart = 0;
|
|
|
|
FileOffset.u.LowPart = VolumeLabelDirIndex * SizeDirEntry;
|
2016-07-10 17:14:33 +00:00
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcPinRead(pRootFcb->FileObject, &FileOffset, SizeDirEntry, PIN_WAIT, &Context, (PVOID*)&Entry);
|
2013-11-29 11:03:34 +00:00
|
|
|
}
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
|
|
|
RtlCopyMemory(Entry, &VolumeLabelDirEntry, SizeDirEntry);
|
|
|
|
CcSetDirtyPinnedData(Context, NULL);
|
|
|
|
CcUnpinData(Context);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
vfatReleaseFCB(DeviceExt, pRootFcb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
/* Update volume label in memory */
|
|
|
|
DeviceObject->Vpb->VolumeLabelLength = (USHORT)FsLabelInfo->VolumeLabelLength;
|
|
|
|
RtlCopyMemory(DeviceObject->Vpb->VolumeLabel, FsLabelInfo->VolumeLabel, DeviceObject->Vpb->VolumeLabelLength);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
return Status;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-06-11 19:52:22 +00:00
|
|
|
* FUNCTION: Retrieve the specified volume information
|
1999-12-11 21:14:49 +00:00
|
|
|
*/
|
2013-12-09 10:35:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
VfatQueryVolumeInformation(
|
|
|
|
PVFAT_IRP_CONTEXT IrpContext)
|
1999-12-11 21:14:49 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
FS_INFORMATION_CLASS FsInformationClass;
|
|
|
|
NTSTATUS RC = STATUS_SUCCESS;
|
|
|
|
PVOID SystemBuffer;
|
|
|
|
ULONG BufferLength;
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
/* PRECONDITION */
|
|
|
|
ASSERT(IrpContext);
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("VfatQueryVolumeInformation(IrpContext %p)\n", IrpContext);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
if (!ExAcquireResourceSharedLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource,
|
2015-05-25 17:30:01 +00:00
|
|
|
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
2015-05-15 16:03:29 +00:00
|
|
|
DPRINT1("DirResource failed!\n");
|
|
|
|
return VfatMarkIrpContextForQueue(IrpContext);
|
2013-11-29 11:03:34 +00:00
|
|
|
}
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
/* INITIALIZATION */
|
|
|
|
FsInformationClass = IrpContext->Stack->Parameters.QueryVolume.FsInformationClass;
|
|
|
|
BufferLength = IrpContext->Stack->Parameters.QueryVolume.Length;
|
|
|
|
SystemBuffer = IrpContext->Irp->AssociatedIrp.SystemBuffer;
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsInformationClass %d\n", FsInformationClass);
|
|
|
|
DPRINT("SystemBuffer %p\n", SystemBuffer);
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2020-09-11 12:51:35 +00:00
|
|
|
RtlZeroMemory(SystemBuffer, BufferLength);
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
switch (FsInformationClass)
|
2000-12-29 23:17:12 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
case FileFsVolumeInformation:
|
|
|
|
RC = FsdGetFsVolumeInformation(IrpContext->DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsAttributeInformation:
|
|
|
|
RC = FsdGetFsAttributeInformation(IrpContext->DeviceObject->DeviceExtension,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsSizeInformation:
|
|
|
|
RC = FsdGetFsSizeInformation(IrpContext->DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsDeviceInformation:
|
|
|
|
RC = FsdGetFsDeviceInformation(IrpContext->DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
2015-06-02 09:08:33 +00:00
|
|
|
case FileFsFullSizeInformation:
|
|
|
|
RC = FsdGetFsFullSizeInformation(IrpContext->DeviceObject,
|
|
|
|
SystemBuffer,
|
|
|
|
&BufferLength);
|
|
|
|
break;
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
default:
|
|
|
|
RC = STATUS_NOT_SUPPORTED;
|
2000-12-29 23:17:12 +00:00
|
|
|
}
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
ExReleaseResourceLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource);
|
2015-05-15 16:03:29 +00:00
|
|
|
|
2015-06-17 19:19:39 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information =
|
|
|
|
IrpContext->Stack->Parameters.QueryVolume.Length - BufferLength;
|
1999-12-11 21:14:49 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
return RC;
|
1999-12-11 21:14:49 +00:00
|
|
|
}
|
2001-06-11 19:52:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: Set the specified volume information
|
|
|
|
*/
|
2013-12-09 10:35:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
VfatSetVolumeInformation(
|
|
|
|
PVFAT_IRP_CONTEXT IrpContext)
|
2001-06-11 19:52:22 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
FS_INFORMATION_CLASS FsInformationClass;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PVOID SystemBuffer;
|
|
|
|
ULONG BufferLength;
|
|
|
|
PIO_STACK_LOCATION Stack = IrpContext->Stack;
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
/* PRECONDITION */
|
|
|
|
ASSERT(IrpContext);
|
2001-11-02 22:47:36 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("VfatSetVolumeInformation(IrpContext %p)\n", IrpContext);
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
if (!ExAcquireResourceExclusiveLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource,
|
2015-05-25 17:30:01 +00:00
|
|
|
BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
|
2013-11-29 11:03:34 +00:00
|
|
|
{
|
2015-05-15 16:03:29 +00:00
|
|
|
return VfatMarkIrpContextForQueue(IrpContext);
|
2013-11-29 11:03:34 +00:00
|
|
|
}
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
FsInformationClass = Stack->Parameters.SetVolume.FsInformationClass;
|
|
|
|
BufferLength = Stack->Parameters.SetVolume.Length;
|
|
|
|
SystemBuffer = IrpContext->Irp->AssociatedIrp.SystemBuffer;
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
DPRINT("FsInformationClass %d\n", FsInformationClass);
|
|
|
|
DPRINT("BufferLength %u\n", BufferLength);
|
|
|
|
DPRINT("SystemBuffer %p\n", SystemBuffer);
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
switch (FsInformationClass)
|
2001-07-20 08:00:21 +00:00
|
|
|
{
|
2013-11-29 11:03:34 +00:00
|
|
|
case FileFsLabelInformation:
|
|
|
|
Status = FsdSetFsLabelInformation(IrpContext->DeviceObject,
|
|
|
|
SystemBuffer);
|
|
|
|
break;
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
default:
|
|
|
|
Status = STATUS_NOT_SUPPORTED;
|
2001-07-20 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
ExReleaseResourceLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource);
|
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
2001-07-20 08:00:21 +00:00
|
|
|
|
2013-11-29 11:03:34 +00:00
|
|
|
return Status;
|
2001-06-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|