From ad566c4411ff859f7b35571fa763b2fe0bcd2aba Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 12 Dec 2013 13:51:50 +0000 Subject: [PATCH] [FASTFAT] Fix coding style and indentation in remaining files. No code changes! svn path=/trunk/; revision=61261 --- reactos/drivers/filesystems/fastfat/create.c | 12 +- reactos/drivers/filesystems/fastfat/fsctl.c | 1003 ++++++++-------- reactos/drivers/filesystems/fastfat/misc.c | 4 +- reactos/drivers/filesystems/fastfat/vfat.h | 1104 ++++++++++-------- 4 files changed, 1157 insertions(+), 966 deletions(-) diff --git a/reactos/drivers/filesystems/fastfat/create.c b/reactos/drivers/filesystems/fastfat/create.c index 04d0c0d3452..e3d026c5478 100644 --- a/reactos/drivers/filesystems/fastfat/create.c +++ b/reactos/drivers/filesystems/fastfat/create.c @@ -272,7 +272,7 @@ FindFile( return Status; } - while(TRUE) + while (TRUE) { Status = DeviceExt->GetNextDirEntry(&Context, &Page, Parent, DirContext, First); First = FALSE; @@ -380,7 +380,7 @@ VfatOpenFile( FALSE); if (!NT_SUCCESS(Status)) { - DPRINT ("Status %lx\n", Status); + DPRINT("Status %lx\n", Status); *ParentFcb = NULL; return Status; } @@ -395,14 +395,14 @@ VfatOpenFile( DPRINT("Checking for existing FCB in memory\n"); Status = vfatGetFCBForFile(DeviceExt, ParentFcb, &Fcb, PathNameU); - if (!NT_SUCCESS (Status)) + if (!NT_SUCCESS(Status)) { DPRINT ("Could not make a new FCB, status: %x\n", Status); return Status; } if (Fcb->Flags & FCB_DELETE_PENDING) { - vfatReleaseFCB (DeviceExt, Fcb); + vfatReleaseFCB(DeviceExt, Fcb); return STATUS_DELETE_PENDING; } @@ -418,7 +418,7 @@ VfatOpenFile( Status = vfatAttachFCBToFileObject(DeviceExt, Fcb, FileObject); if (!NT_SUCCESS(Status)) { - vfatReleaseFCB (DeviceExt, Fcb); + vfatReleaseFCB(DeviceExt, Fcb); } return Status; } @@ -446,7 +446,7 @@ VfatCreateFile( ULONG Attributes; /* Unpack the various parameters. */ - Stack = IoGetCurrentIrpStackLocation (Irp); + Stack = IoGetCurrentIrpStackLocation(Irp); RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff); RequestedOptions = Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS; PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE; diff --git a/reactos/drivers/filesystems/fastfat/fsctl.c b/reactos/drivers/filesystems/fastfat/fsctl.c index 47d0e29d2c6..efc4bec2572 100644 --- a/reactos/drivers/filesystems/fastfat/fsctl.c +++ b/reactos/drivers/filesystems/fastfat/fsctl.c @@ -338,557 +338,578 @@ VfatHasFileSystem( return Status; } -static NTSTATUS -VfatMountDevice(PDEVICE_EXTENSION DeviceExt, - PDEVICE_OBJECT DeviceToMount) /* * FUNCTION: Mounts the device */ +static +NTSTATUS +VfatMountDevice( + PDEVICE_EXTENSION DeviceExt, + PDEVICE_OBJECT DeviceToMount) { - NTSTATUS Status; - BOOLEAN RecognizedFS; - - DPRINT("Mounting VFAT device...\n"); + NTSTATUS Status; + BOOLEAN RecognizedFS; - Status = VfatHasFileSystem(DeviceToMount, &RecognizedFS, &DeviceExt->FatInfo); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - DPRINT("MountVfatdev %u, PAGE_SIZE = %d\n", DeviceExt->FatInfo.BytesPerCluster, PAGE_SIZE); + DPRINT("Mounting VFAT device...\n"); + Status = VfatHasFileSystem(DeviceToMount, &RecognizedFS, &DeviceExt->FatInfo); + if (!NT_SUCCESS(Status)) + { + return Status; + } + DPRINT("MountVfatdev %u, PAGE_SIZE = %d\n", DeviceExt->FatInfo.BytesPerCluster, PAGE_SIZE); - return(STATUS_SUCCESS); + return STATUS_SUCCESS; } -static NTSTATUS -VfatMount (PVFAT_IRP_CONTEXT IrpContext) /* * FUNCTION: Mount the filesystem */ +static +NTSTATUS +VfatMount( + PVFAT_IRP_CONTEXT IrpContext) { - PDEVICE_OBJECT DeviceObject = NULL; - PDEVICE_EXTENSION DeviceExt = NULL; - BOOLEAN RecognizedFS; - NTSTATUS Status; - PVFATFCB Fcb = NULL; - PVFATFCB VolumeFcb = NULL; - PVFATCCB Ccb = NULL; - PDEVICE_OBJECT DeviceToMount; - PVPB Vpb; - UNICODE_STRING NameU = RTL_CONSTANT_STRING(L"\\$$Fat$$"); - UNICODE_STRING VolumeNameU = RTL_CONSTANT_STRING(L"\\$$Volume$$"); - ULONG HashTableSize; - ULONG eocMark; - FATINFO FatInfo; - - DPRINT("VfatMount(IrpContext %p)\n", IrpContext); - - ASSERT(IrpContext); - - if (IrpContext->DeviceObject != VfatGlobalData->DeviceObject) - { - Status = STATUS_INVALID_DEVICE_REQUEST; - goto ByeBye; - } - - DeviceToMount = IrpContext->Stack->Parameters.MountVolume.DeviceObject; - Vpb = IrpContext->Stack->Parameters.MountVolume.Vpb; - - Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS, &FatInfo); - if (!NT_SUCCESS(Status)) - { - goto ByeBye; - } - - if (RecognizedFS == FALSE) - { - DPRINT("VFAT: Unrecognized Volume\n"); - Status = STATUS_UNRECOGNIZED_VOLUME; - goto ByeBye; - } - - /* Use prime numbers for the table size */ - if (FatInfo.FatType == FAT12) - { - HashTableSize = 4099; // 4096 = 4 * 1024 - } - else if (FatInfo.FatType == FAT16 || - FatInfo.FatType == FATX16) - { - HashTableSize = 16411; // 16384 = 16 * 1024 - } - else - { - HashTableSize = 65537; // 65536 = 64 * 1024; - } - HashTableSize = FCB_HASH_TABLE_SIZE; - DPRINT("VFAT: Recognized volume\n"); - Status = IoCreateDevice(VfatGlobalData->DriverObject, - ROUND_UP(sizeof (DEVICE_EXTENSION), sizeof(ULONG)) + sizeof(HASHENTRY*) * HashTableSize, - NULL, - FILE_DEVICE_DISK_FILE_SYSTEM, - DeviceToMount->Characteristics, - FALSE, - &DeviceObject); - if (!NT_SUCCESS(Status)) - { - goto ByeBye; - } - - DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO; - DeviceExt = (PVOID) DeviceObject->DeviceExtension; - RtlZeroMemory(DeviceExt, ROUND_UP(sizeof(DEVICE_EXTENSION), sizeof(ULONG)) + sizeof(HASHENTRY*) * HashTableSize); - DeviceExt->FcbHashTable = (HASHENTRY**)((ULONG_PTR)DeviceExt + ROUND_UP(sizeof(DEVICE_EXTENSION), sizeof(ULONG))); - DeviceExt->HashTableSize = HashTableSize; - - /* use same vpb as device disk */ - DeviceObject->Vpb = Vpb; - DeviceToMount->Vpb = Vpb; - - Status = VfatMountDevice(DeviceExt, DeviceToMount); - if (!NT_SUCCESS(Status)) - { - /* FIXME: delete device object */ - goto ByeBye; - } - - DPRINT("BytesPerSector: %u\n", DeviceExt->FatInfo.BytesPerSector); - DPRINT("SectorsPerCluster: %u\n", DeviceExt->FatInfo.SectorsPerCluster); - DPRINT("FATCount: %u\n", DeviceExt->FatInfo.FATCount); - DPRINT("FATSectors: %u\n", DeviceExt->FatInfo.FATSectors); - DPRINT("RootStart: %u\n", DeviceExt->FatInfo.rootStart); - DPRINT("DataStart: %u\n", DeviceExt->FatInfo.dataStart); - if (DeviceExt->FatInfo.FatType == FAT32) - { - DPRINT("RootCluster: %u\n", DeviceExt->FatInfo.RootCluster); - } - - switch (DeviceExt->FatInfo.FatType) - { - case FAT12: - DeviceExt->GetNextCluster = FAT12GetNextCluster; - DeviceExt->FindAndMarkAvailableCluster = FAT12FindAndMarkAvailableCluster; - DeviceExt->WriteCluster = FAT12WriteCluster; - DeviceExt->CleanShutBitMask = 0; - break; - - case FAT16: - case FATX16: - DeviceExt->GetNextCluster = FAT16GetNextCluster; - DeviceExt->FindAndMarkAvailableCluster = FAT16FindAndMarkAvailableCluster; - DeviceExt->WriteCluster = FAT16WriteCluster; - DeviceExt->CleanShutBitMask = 0x8000; - break; - - case FAT32: - case FATX32: - DeviceExt->GetNextCluster = FAT32GetNextCluster; - DeviceExt->FindAndMarkAvailableCluster = FAT32FindAndMarkAvailableCluster; - DeviceExt->WriteCluster = FAT32WriteCluster; - DeviceExt->CleanShutBitMask = 0x80000000; - break; - } - - if (DeviceExt->FatInfo.FatType == FATX16 - || DeviceExt->FatInfo.FatType == FATX32) - { - DeviceExt->Flags |= VCB_IS_FATX; - DeviceExt->GetNextDirEntry = FATXGetNextDirEntry; - DeviceExt->BaseDateYear = 2000; - } - else - { - DeviceExt->GetNextDirEntry = FATGetNextDirEntry; - DeviceExt->BaseDateYear = 1980; - } - - DeviceExt->StorageDevice = DeviceToMount; - DeviceExt->StorageDevice->Vpb->DeviceObject = DeviceObject; - DeviceExt->StorageDevice->Vpb->RealDevice = DeviceExt->StorageDevice; - DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED; - DeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1; - DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; - - DPRINT("FsDeviceObject %p\n", DeviceObject); - - /* Initialize this resource early ... it's used in VfatCleanup */ - ExInitializeResourceLite(&DeviceExt->DirResource); - - DeviceExt->FATFileObject = IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice); - Fcb = vfatNewFCB(DeviceExt, &NameU); - if (Fcb == NULL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - goto ByeBye; - } - Ccb = ExAllocateFromNPagedLookasideList(&VfatGlobalData->CcbLookasideList); - if (Ccb == NULL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - goto ByeBye; - } - - RtlZeroMemory(Ccb, sizeof (VFATCCB)); - DeviceExt->FATFileObject->FsContext = Fcb; - DeviceExt->FATFileObject->FsContext2 = Ccb; - DeviceExt->FATFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers; - DeviceExt->FATFileObject->PrivateCacheMap = NULL; - DeviceExt->FATFileObject->Vpb = DeviceObject->Vpb; - Fcb->FileObject = DeviceExt->FATFileObject; - - Fcb->Flags |= FCB_IS_FAT; - - Fcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector; - Fcb->RFCB.ValidDataLength = Fcb->RFCB.FileSize; - Fcb->RFCB.AllocationSize = Fcb->RFCB.FileSize; - - CcInitializeCacheMap(DeviceExt->FATFileObject, - (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize), - TRUE, - &VfatGlobalData->CacheMgrCallbacks, - Fcb); - - DeviceExt->LastAvailableCluster = 2; - ExInitializeResourceLite(&DeviceExt->FatResource); - - InitializeListHead(&DeviceExt->FcbListHead); - - VolumeFcb = vfatNewFCB(DeviceExt, &VolumeNameU); - if (VolumeFcb == NULL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - goto ByeBye; - } - VolumeFcb->Flags = FCB_IS_VOLUME; - VolumeFcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.Sectors * DeviceExt->FatInfo.BytesPerSector; - VolumeFcb->RFCB.ValidDataLength = VolumeFcb->RFCB.FileSize; - VolumeFcb->RFCB.AllocationSize = VolumeFcb->RFCB.FileSize; - DeviceExt->VolumeFcb = VolumeFcb; - - ExAcquireResourceExclusiveLite(&VfatGlobalData->VolumeListLock, TRUE); - InsertHeadList(&VfatGlobalData->VolumeListHead, &DeviceExt->VolumeListEntry); - ExReleaseResourceLite(&VfatGlobalData->VolumeListLock); - - /* read serial number */ - DeviceObject->Vpb->SerialNumber = DeviceExt->FatInfo.VolumeID; - - /* read volume label */ - ReadVolumeLabel(DeviceExt, DeviceObject->Vpb); - - /* read clean shutdown bit status */ - Status = GetNextCluster(DeviceExt, 1, &eocMark); - if (NT_SUCCESS(Status)) - { - if (eocMark & DeviceExt->CleanShutBitMask) - { - /* unset clean shutdown bit */ - eocMark &= ~DeviceExt->CleanShutBitMask; - WriteCluster(DeviceExt, 1, eocMark); - VolumeFcb->Flags |= VCB_CLEAR_DIRTY; - } - } - VolumeFcb->Flags |= VCB_IS_DIRTY; - - FsRtlNotifyVolumeEvent(DeviceExt->FATFileObject, FSRTL_VOLUME_MOUNT); - - Status = STATUS_SUCCESS; + PDEVICE_OBJECT DeviceObject = NULL; + PDEVICE_EXTENSION DeviceExt = NULL; + BOOLEAN RecognizedFS; + NTSTATUS Status; + PVFATFCB Fcb = NULL; + PVFATFCB VolumeFcb = NULL; + PVFATCCB Ccb = NULL; + PDEVICE_OBJECT DeviceToMount; + PVPB Vpb; + UNICODE_STRING NameU = RTL_CONSTANT_STRING(L"\\$$Fat$$"); + UNICODE_STRING VolumeNameU = RTL_CONSTANT_STRING(L"\\$$Volume$$"); + ULONG HashTableSize; + ULONG eocMark; + FATINFO FatInfo; + + DPRINT("VfatMount(IrpContext %p)\n", IrpContext); + + ASSERT(IrpContext); + + if (IrpContext->DeviceObject != VfatGlobalData->DeviceObject) + { + Status = STATUS_INVALID_DEVICE_REQUEST; + goto ByeBye; + } + + DeviceToMount = IrpContext->Stack->Parameters.MountVolume.DeviceObject; + Vpb = IrpContext->Stack->Parameters.MountVolume.Vpb; + + Status = VfatHasFileSystem(DeviceToMount, &RecognizedFS, &FatInfo); + if (!NT_SUCCESS(Status)) + { + goto ByeBye; + } + + if (RecognizedFS == FALSE) + { + DPRINT("VFAT: Unrecognized Volume\n"); + Status = STATUS_UNRECOGNIZED_VOLUME; + goto ByeBye; + } + + /* Use prime numbers for the table size */ + if (FatInfo.FatType == FAT12) + { + HashTableSize = 4099; // 4096 = 4 * 1024 + } + else if (FatInfo.FatType == FAT16 || + FatInfo.FatType == FATX16) + { + HashTableSize = 16411; // 16384 = 16 * 1024 + } + else + { + HashTableSize = 65537; // 65536 = 64 * 1024; + } + HashTableSize = FCB_HASH_TABLE_SIZE; + DPRINT("VFAT: Recognized volume\n"); + Status = IoCreateDevice(VfatGlobalData->DriverObject, + ROUND_UP(sizeof (DEVICE_EXTENSION), sizeof(ULONG)) + sizeof(HASHENTRY*) * HashTableSize, + NULL, + FILE_DEVICE_DISK_FILE_SYSTEM, + DeviceToMount->Characteristics, + FALSE, + &DeviceObject); + if (!NT_SUCCESS(Status)) + { + goto ByeBye; + } + + DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO; + DeviceExt = (PVOID) DeviceObject->DeviceExtension; + RtlZeroMemory(DeviceExt, ROUND_UP(sizeof(DEVICE_EXTENSION), sizeof(ULONG)) + sizeof(HASHENTRY*) * HashTableSize); + DeviceExt->FcbHashTable = (HASHENTRY**)((ULONG_PTR)DeviceExt + ROUND_UP(sizeof(DEVICE_EXTENSION), sizeof(ULONG))); + DeviceExt->HashTableSize = HashTableSize; + + /* use same vpb as device disk */ + DeviceObject->Vpb = Vpb; + DeviceToMount->Vpb = Vpb; + + Status = VfatMountDevice(DeviceExt, DeviceToMount); + if (!NT_SUCCESS(Status)) + { + /* FIXME: delete device object */ + goto ByeBye; + } + + DPRINT("BytesPerSector: %u\n", DeviceExt->FatInfo.BytesPerSector); + DPRINT("SectorsPerCluster: %u\n", DeviceExt->FatInfo.SectorsPerCluster); + DPRINT("FATCount: %u\n", DeviceExt->FatInfo.FATCount); + DPRINT("FATSectors: %u\n", DeviceExt->FatInfo.FATSectors); + DPRINT("RootStart: %u\n", DeviceExt->FatInfo.rootStart); + DPRINT("DataStart: %u\n", DeviceExt->FatInfo.dataStart); + if (DeviceExt->FatInfo.FatType == FAT32) + { + DPRINT("RootCluster: %u\n", DeviceExt->FatInfo.RootCluster); + } + + switch (DeviceExt->FatInfo.FatType) + { + case FAT12: + DeviceExt->GetNextCluster = FAT12GetNextCluster; + DeviceExt->FindAndMarkAvailableCluster = FAT12FindAndMarkAvailableCluster; + DeviceExt->WriteCluster = FAT12WriteCluster; + DeviceExt->CleanShutBitMask = 0; + break; + + case FAT16: + case FATX16: + DeviceExt->GetNextCluster = FAT16GetNextCluster; + DeviceExt->FindAndMarkAvailableCluster = FAT16FindAndMarkAvailableCluster; + DeviceExt->WriteCluster = FAT16WriteCluster; + DeviceExt->CleanShutBitMask = 0x8000; + break; + + case FAT32: + case FATX32: + DeviceExt->GetNextCluster = FAT32GetNextCluster; + DeviceExt->FindAndMarkAvailableCluster = FAT32FindAndMarkAvailableCluster; + DeviceExt->WriteCluster = FAT32WriteCluster; + DeviceExt->CleanShutBitMask = 0x80000000; + break; + } + + if (DeviceExt->FatInfo.FatType == FATX16 || + DeviceExt->FatInfo.FatType == FATX32) + { + DeviceExt->Flags |= VCB_IS_FATX; + DeviceExt->GetNextDirEntry = FATXGetNextDirEntry; + DeviceExt->BaseDateYear = 2000; + } + else + { + DeviceExt->GetNextDirEntry = FATGetNextDirEntry; + DeviceExt->BaseDateYear = 1980; + } + + DeviceExt->StorageDevice = DeviceToMount; + DeviceExt->StorageDevice->Vpb->DeviceObject = DeviceObject; + DeviceExt->StorageDevice->Vpb->RealDevice = DeviceExt->StorageDevice; + DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED; + DeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1; + DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; + + DPRINT("FsDeviceObject %p\n", DeviceObject); + + /* Initialize this resource early ... it's used in VfatCleanup */ + ExInitializeResourceLite(&DeviceExt->DirResource); + + DeviceExt->FATFileObject = IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice); + Fcb = vfatNewFCB(DeviceExt, &NameU); + if (Fcb == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto ByeBye; + } + + Ccb = ExAllocateFromNPagedLookasideList(&VfatGlobalData->CcbLookasideList); + if (Ccb == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto ByeBye; + } + + RtlZeroMemory(Ccb, sizeof (VFATCCB)); + DeviceExt->FATFileObject->FsContext = Fcb; + DeviceExt->FATFileObject->FsContext2 = Ccb; + DeviceExt->FATFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers; + DeviceExt->FATFileObject->PrivateCacheMap = NULL; + DeviceExt->FATFileObject->Vpb = DeviceObject->Vpb; + Fcb->FileObject = DeviceExt->FATFileObject; + + Fcb->Flags |= FCB_IS_FAT; + + Fcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector; + Fcb->RFCB.ValidDataLength = Fcb->RFCB.FileSize; + Fcb->RFCB.AllocationSize = Fcb->RFCB.FileSize; + + CcInitializeCacheMap(DeviceExt->FATFileObject, + (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize), + TRUE, + &VfatGlobalData->CacheMgrCallbacks, + Fcb); + + DeviceExt->LastAvailableCluster = 2; + ExInitializeResourceLite(&DeviceExt->FatResource); + + InitializeListHead(&DeviceExt->FcbListHead); + + VolumeFcb = vfatNewFCB(DeviceExt, &VolumeNameU); + if (VolumeFcb == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto ByeBye; + } + + VolumeFcb->Flags = FCB_IS_VOLUME; + VolumeFcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.Sectors * DeviceExt->FatInfo.BytesPerSector; + VolumeFcb->RFCB.ValidDataLength = VolumeFcb->RFCB.FileSize; + VolumeFcb->RFCB.AllocationSize = VolumeFcb->RFCB.FileSize; + DeviceExt->VolumeFcb = VolumeFcb; + + ExAcquireResourceExclusiveLite(&VfatGlobalData->VolumeListLock, TRUE); + InsertHeadList(&VfatGlobalData->VolumeListHead, &DeviceExt->VolumeListEntry); + ExReleaseResourceLite(&VfatGlobalData->VolumeListLock); + + /* read serial number */ + DeviceObject->Vpb->SerialNumber = DeviceExt->FatInfo.VolumeID; + + /* read volume label */ + ReadVolumeLabel(DeviceExt, DeviceObject->Vpb); + + /* read clean shutdown bit status */ + Status = GetNextCluster(DeviceExt, 1, &eocMark); + if (NT_SUCCESS(Status)) + { + if (eocMark & DeviceExt->CleanShutBitMask) + { + /* unset clean shutdown bit */ + eocMark &= ~DeviceExt->CleanShutBitMask; + WriteCluster(DeviceExt, 1, eocMark); + VolumeFcb->Flags |= VCB_CLEAR_DIRTY; + } + } + + VolumeFcb->Flags |= VCB_IS_DIRTY; + + FsRtlNotifyVolumeEvent(DeviceExt->FATFileObject, FSRTL_VOLUME_MOUNT); + + Status = STATUS_SUCCESS; + ByeBye: + if (!NT_SUCCESS(Status)) + { + /* Cleanup */ + if (DeviceExt && DeviceExt->FATFileObject) + ObDereferenceObject (DeviceExt->FATFileObject); + if (Fcb) + vfatDestroyFCB(Fcb); + if (Ccb) + vfatDestroyCCB(Ccb); + if (DeviceObject) + IoDeleteDevice(DeviceObject); + if (VolumeFcb) + vfatDestroyFCB(VolumeFcb); + } - if (!NT_SUCCESS(Status)) - { - // cleanup - if (DeviceExt && DeviceExt->FATFileObject) - ObDereferenceObject (DeviceExt->FATFileObject); - if (Fcb) - vfatDestroyFCB(Fcb); - if (Ccb) - vfatDestroyCCB(Ccb); - if (DeviceObject) - IoDeleteDevice(DeviceObject); - if (VolumeFcb) - vfatDestroyFCB(VolumeFcb); - } - return Status; + return Status; } -static NTSTATUS -VfatVerify (PVFAT_IRP_CONTEXT IrpContext) /* * FUNCTION: Verify the filesystem */ +static +NTSTATUS +VfatVerify( + PVFAT_IRP_CONTEXT IrpContext) { - PDEVICE_OBJECT DeviceToVerify; - NTSTATUS Status = STATUS_SUCCESS; - FATINFO FatInfo; - BOOLEAN RecognizedFS; - PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt; - - DPRINT("VfatVerify(IrpContext %p)\n", IrpContext); - - DeviceToVerify = IrpContext->Stack->Parameters.VerifyVolume.DeviceObject; - Status = VfatBlockDeviceIoControl(DeviceToVerify, - IOCTL_DISK_CHECK_VERIFY, - NULL, - 0, - NULL, - 0, - TRUE); - DeviceToVerify->Flags &= ~DO_VERIFY_VOLUME; - if (!NT_SUCCESS(Status) && Status != STATUS_VERIFY_REQUIRED) - { - DPRINT("VfatBlockDeviceIoControl() failed (Status %lx)\n", Status); - Status = STATUS_WRONG_VOLUME; - } - else - { - Status = VfatHasFileSystem(DeviceToVerify, &RecognizedFS, &FatInfo); - if (!NT_SUCCESS(Status) || RecognizedFS == FALSE) + PDEVICE_OBJECT DeviceToVerify; + NTSTATUS Status = STATUS_SUCCESS; + FATINFO FatInfo; + BOOLEAN RecognizedFS; + PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt; + + DPRINT("VfatVerify(IrpContext %p)\n", IrpContext); + + DeviceToVerify = IrpContext->Stack->Parameters.VerifyVolume.DeviceObject; + Status = VfatBlockDeviceIoControl(DeviceToVerify, + IOCTL_DISK_CHECK_VERIFY, + NULL, + 0, + NULL, + 0, + TRUE); + DeviceToVerify->Flags &= ~DO_VERIFY_VOLUME; + if (!NT_SUCCESS(Status) && Status != STATUS_VERIFY_REQUIRED) + { + DPRINT("VfatBlockDeviceIoControl() failed (Status %lx)\n", Status); + Status = STATUS_WRONG_VOLUME; + } + else + { + Status = VfatHasFileSystem(DeviceToVerify, &RecognizedFS, &FatInfo); + if (!NT_SUCCESS(Status) || RecognizedFS == FALSE) { - Status = STATUS_WRONG_VOLUME; + Status = STATUS_WRONG_VOLUME; } - else if (sizeof(FATINFO) == RtlCompareMemory(&FatInfo, &DeviceExt->FatInfo, sizeof(FATINFO))) + else if (sizeof(FATINFO) == RtlCompareMemory(&FatInfo, &DeviceExt->FatInfo, sizeof(FATINFO))) { - /* - * FIXME: - * Preformated floppy disks have very often a serial number of 0000:0000. - * We should calculate a crc sum over the sectors from the root directory as secondary volume number. - * Each write to the root directory must update this crc sum. - */ - + /* + * FIXME: + * Preformated floppy disks have very often a serial number of 0000:0000. + * We should calculate a crc sum over the sectors from the root directory as secondary volume number. + * Each write to the root directory must update this crc sum. + */ } - else + else { - Status = STATUS_WRONG_VOLUME; + Status = STATUS_WRONG_VOLUME; } - } + } - return Status; + return Status; } -static NTSTATUS -VfatGetVolumeBitmap(PVFAT_IRP_CONTEXT IrpContext) +static +NTSTATUS +VfatGetVolumeBitmap( + PVFAT_IRP_CONTEXT IrpContext) { - DPRINT("VfatGetVolumeBitmap (IrpContext %p)\n", IrpContext); - - return STATUS_INVALID_DEVICE_REQUEST; + DPRINT("VfatGetVolumeBitmap (IrpContext %p)\n", IrpContext); + return STATUS_INVALID_DEVICE_REQUEST; } -static NTSTATUS -VfatGetRetrievalPointers(PVFAT_IRP_CONTEXT IrpContext) +static +NTSTATUS +VfatGetRetrievalPointers( + PVFAT_IRP_CONTEXT IrpContext) { - PIO_STACK_LOCATION Stack; - LARGE_INTEGER Vcn; - PRETRIEVAL_POINTERS_BUFFER RetrievalPointers; - PFILE_OBJECT FileObject; - ULONG MaxExtentCount; - PVFATFCB Fcb; - PDEVICE_EXTENSION DeviceExt; - ULONG FirstCluster; - ULONG CurrentCluster; - ULONG LastCluster; - NTSTATUS Status; - - DPRINT("VfatGetRetrievalPointers(IrpContext %p)\n", IrpContext); - - DeviceExt = IrpContext->DeviceExt; - FileObject = IrpContext->FileObject; - Stack = IrpContext->Stack; - if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(STARTING_VCN_INPUT_BUFFER) || - Stack->Parameters.DeviceIoControl.Type3InputBuffer == NULL) - { - return STATUS_INVALID_PARAMETER; - } - if (IrpContext->Irp->UserBuffer == NULL || - Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(RETRIEVAL_POINTERS_BUFFER)) - { - return STATUS_BUFFER_TOO_SMALL; - } - - Fcb = FileObject->FsContext; - - ExAcquireResourceSharedLite(&Fcb->MainResource, TRUE); - - Vcn = ((PSTARTING_VCN_INPUT_BUFFER)Stack->Parameters.DeviceIoControl.Type3InputBuffer)->StartingVcn; - RetrievalPointers = IrpContext->Irp->UserBuffer; - - MaxExtentCount = ((Stack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(RetrievalPointers->ExtentCount) - sizeof(RetrievalPointers->StartingVcn)) / sizeof(RetrievalPointers->Extents[0])); - - - if (Vcn.QuadPart >= Fcb->RFCB.AllocationSize.QuadPart / DeviceExt->FatInfo.BytesPerCluster) - { - Status = STATUS_INVALID_PARAMETER; - goto ByeBye; - } - - CurrentCluster = FirstCluster = vfatDirEntryGetFirstCluster(DeviceExt, &Fcb->entry); - Status = OffsetToCluster(DeviceExt, FirstCluster, - Vcn.u.LowPart * DeviceExt->FatInfo.BytesPerCluster, - &CurrentCluster, FALSE); - if (!NT_SUCCESS(Status)) - { - goto ByeBye; - } - - RetrievalPointers->StartingVcn = Vcn; - RetrievalPointers->ExtentCount = 0; - RetrievalPointers->Extents[0].Lcn.u.HighPart = 0; - RetrievalPointers->Extents[0].Lcn.u.LowPart = CurrentCluster - 2; - LastCluster = 0; - while (CurrentCluster != 0xffffffff && RetrievalPointers->ExtentCount < MaxExtentCount) - { - - LastCluster = CurrentCluster; - Status = NextCluster(DeviceExt, CurrentCluster, &CurrentCluster, FALSE); - Vcn.QuadPart++; - if (!NT_SUCCESS(Status)) - { - goto ByeBye; - } - - if (LastCluster + 1 != CurrentCluster) - { - RetrievalPointers->Extents[RetrievalPointers->ExtentCount].NextVcn = Vcn; - RetrievalPointers->ExtentCount++; - if (RetrievalPointers->ExtentCount < MaxExtentCount) - { - RetrievalPointers->Extents[RetrievalPointers->ExtentCount].Lcn.u.HighPart = 0; - RetrievalPointers->Extents[RetrievalPointers->ExtentCount].Lcn.u.LowPart = CurrentCluster - 2; - } - } - } - - IrpContext->Irp->IoStatus.Information = sizeof(RETRIEVAL_POINTERS_BUFFER) + (sizeof(RetrievalPointers->Extents[0]) * (RetrievalPointers->ExtentCount - 1)); - Status = STATUS_SUCCESS; + PIO_STACK_LOCATION Stack; + LARGE_INTEGER Vcn; + PRETRIEVAL_POINTERS_BUFFER RetrievalPointers; + PFILE_OBJECT FileObject; + ULONG MaxExtentCount; + PVFATFCB Fcb; + PDEVICE_EXTENSION DeviceExt; + ULONG FirstCluster; + ULONG CurrentCluster; + ULONG LastCluster; + NTSTATUS Status; + + DPRINT("VfatGetRetrievalPointers(IrpContext %p)\n", IrpContext); + + DeviceExt = IrpContext->DeviceExt; + FileObject = IrpContext->FileObject; + Stack = IrpContext->Stack; + if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(STARTING_VCN_INPUT_BUFFER) || + Stack->Parameters.DeviceIoControl.Type3InputBuffer == NULL) + { + return STATUS_INVALID_PARAMETER; + } + + if (IrpContext->Irp->UserBuffer == NULL || + Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(RETRIEVAL_POINTERS_BUFFER)) + { + return STATUS_BUFFER_TOO_SMALL; + } + + Fcb = FileObject->FsContext; + + ExAcquireResourceSharedLite(&Fcb->MainResource, TRUE); + + Vcn = ((PSTARTING_VCN_INPUT_BUFFER)Stack->Parameters.DeviceIoControl.Type3InputBuffer)->StartingVcn; + RetrievalPointers = IrpContext->Irp->UserBuffer; + + MaxExtentCount = ((Stack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(RetrievalPointers->ExtentCount) - sizeof(RetrievalPointers->StartingVcn)) / sizeof(RetrievalPointers->Extents[0])); + + if (Vcn.QuadPart >= Fcb->RFCB.AllocationSize.QuadPart / DeviceExt->FatInfo.BytesPerCluster) + { + Status = STATUS_INVALID_PARAMETER; + goto ByeBye; + } + + CurrentCluster = FirstCluster = vfatDirEntryGetFirstCluster(DeviceExt, &Fcb->entry); + Status = OffsetToCluster(DeviceExt, FirstCluster, + Vcn.u.LowPart * DeviceExt->FatInfo.BytesPerCluster, + &CurrentCluster, FALSE); + if (!NT_SUCCESS(Status)) + { + goto ByeBye; + } + + RetrievalPointers->StartingVcn = Vcn; + RetrievalPointers->ExtentCount = 0; + RetrievalPointers->Extents[0].Lcn.u.HighPart = 0; + RetrievalPointers->Extents[0].Lcn.u.LowPart = CurrentCluster - 2; + LastCluster = 0; + while (CurrentCluster != 0xffffffff && RetrievalPointers->ExtentCount < MaxExtentCount) + { + LastCluster = CurrentCluster; + Status = NextCluster(DeviceExt, CurrentCluster, &CurrentCluster, FALSE); + Vcn.QuadPart++; + if (!NT_SUCCESS(Status)) + { + goto ByeBye; + } + + if (LastCluster + 1 != CurrentCluster) + { + RetrievalPointers->Extents[RetrievalPointers->ExtentCount].NextVcn = Vcn; + RetrievalPointers->ExtentCount++; + if (RetrievalPointers->ExtentCount < MaxExtentCount) + { + RetrievalPointers->Extents[RetrievalPointers->ExtentCount].Lcn.u.HighPart = 0; + RetrievalPointers->Extents[RetrievalPointers->ExtentCount].Lcn.u.LowPart = CurrentCluster - 2; + } + } + } + + IrpContext->Irp->IoStatus.Information = sizeof(RETRIEVAL_POINTERS_BUFFER) + (sizeof(RetrievalPointers->Extents[0]) * (RetrievalPointers->ExtentCount - 1)); + Status = STATUS_SUCCESS; ByeBye: - ExReleaseResourceLite(&Fcb->MainResource); + ExReleaseResourceLite(&Fcb->MainResource); - return Status; + return Status; } -static NTSTATUS -VfatMoveFile(PVFAT_IRP_CONTEXT IrpContext) +static +NTSTATUS +VfatMoveFile( + PVFAT_IRP_CONTEXT IrpContext) { - DPRINT("VfatMoveFile(IrpContext %p)\n", IrpContext); - - return STATUS_INVALID_DEVICE_REQUEST; + DPRINT("VfatMoveFile(IrpContext %p)\n", IrpContext); + return STATUS_INVALID_DEVICE_REQUEST; } -static NTSTATUS -VfatIsVolumeDirty(PVFAT_IRP_CONTEXT IrpContext) +static +NTSTATUS +VfatIsVolumeDirty( + PVFAT_IRP_CONTEXT IrpContext) { - PULONG Flags; + PULONG Flags; - DPRINT("VfatIsVolumeDirty(IrpContext %p)\n", IrpContext); + DPRINT("VfatIsVolumeDirty(IrpContext %p)\n", IrpContext); - if (IrpContext->Stack->Parameters.FileSystemControl.OutputBufferLength != sizeof(ULONG)) - return STATUS_INVALID_BUFFER_SIZE; - else if (!IrpContext->Irp->AssociatedIrp.SystemBuffer) - return STATUS_INVALID_USER_BUFFER; + if (IrpContext->Stack->Parameters.FileSystemControl.OutputBufferLength != sizeof(ULONG)) + return STATUS_INVALID_BUFFER_SIZE; + else if (!IrpContext->Irp->AssociatedIrp.SystemBuffer) + return STATUS_INVALID_USER_BUFFER; - Flags = (PULONG)IrpContext->Irp->AssociatedIrp.SystemBuffer; - *Flags = 0; + Flags = (PULONG)IrpContext->Irp->AssociatedIrp.SystemBuffer; + *Flags = 0; - if (IrpContext->DeviceExt->VolumeFcb->Flags & VCB_IS_DIRTY - && !(IrpContext->DeviceExt->VolumeFcb->Flags & VCB_CLEAR_DIRTY)) - { - *Flags |= VOLUME_IS_DIRTY; - } + if ((IrpContext->DeviceExt->VolumeFcb->Flags & VCB_IS_DIRTY) && + !(IrpContext->DeviceExt->VolumeFcb->Flags & VCB_CLEAR_DIRTY)) + { + *Flags |= VOLUME_IS_DIRTY; + } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } -static NTSTATUS -VfatMarkVolumeDirty(PVFAT_IRP_CONTEXT IrpContext) +static +NTSTATUS +VfatMarkVolumeDirty( + PVFAT_IRP_CONTEXT IrpContext) { - ULONG eocMark; - PDEVICE_EXTENSION DeviceExt; - NTSTATUS Status = STATUS_SUCCESS; - - DPRINT("VfatMarkVolumeDirty(IrpContext %p)\n", IrpContext); - DeviceExt = IrpContext->DeviceExt; - - if (!(DeviceExt->VolumeFcb->Flags & VCB_IS_DIRTY)) - { - Status = GetNextCluster(DeviceExt, 1, &eocMark); - if (NT_SUCCESS(Status)) - { - /* unset clean shutdown bit */ - eocMark &= ~DeviceExt->CleanShutBitMask; - Status = WriteCluster(DeviceExt, 1, eocMark); - } - } - - DeviceExt->VolumeFcb->Flags &= ~VCB_CLEAR_DIRTY; - - return Status; + ULONG eocMark; + PDEVICE_EXTENSION DeviceExt; + NTSTATUS Status = STATUS_SUCCESS; + + DPRINT("VfatMarkVolumeDirty(IrpContext %p)\n", IrpContext); + DeviceExt = IrpContext->DeviceExt; + + if (!(DeviceExt->VolumeFcb->Flags & VCB_IS_DIRTY)) + { + Status = GetNextCluster(DeviceExt, 1, &eocMark); + if (NT_SUCCESS(Status)) + { + /* unset clean shutdown bit */ + eocMark &= ~DeviceExt->CleanShutBitMask; + Status = WriteCluster(DeviceExt, 1, eocMark); + } + } + + DeviceExt->VolumeFcb->Flags &= ~VCB_CLEAR_DIRTY; + + return Status; } -NTSTATUS VfatFileSystemControl(PVFAT_IRP_CONTEXT IrpContext) /* * FUNCTION: File system control */ +NTSTATUS +VfatFileSystemControl( + PVFAT_IRP_CONTEXT IrpContext) { + NTSTATUS Status; + + DPRINT("VfatFileSystemControl(IrpContext %p)\n", IrpContext); + + ASSERT(IrpContext); + ASSERT(IrpContext->Irp); + ASSERT(IrpContext->Stack); + + IrpContext->Irp->IoStatus.Information = 0; + + switch (IrpContext->MinorFunction) + { + case IRP_MN_KERNEL_CALL: + case IRP_MN_USER_FS_REQUEST: + switch(IrpContext->Stack->Parameters.DeviceIoControl.IoControlCode) + { + case FSCTL_GET_VOLUME_BITMAP: + Status = VfatGetVolumeBitmap(IrpContext); + break; + + case FSCTL_GET_RETRIEVAL_POINTERS: + Status = VfatGetRetrievalPointers(IrpContext); + break; - NTSTATUS Status; - - DPRINT("VfatFileSystemControl(IrpContext %p)\n", IrpContext); - - ASSERT(IrpContext); - ASSERT(IrpContext->Irp); - ASSERT(IrpContext->Stack); - - IrpContext->Irp->IoStatus.Information = 0; - - switch (IrpContext->MinorFunction) - { - case IRP_MN_KERNEL_CALL: - case IRP_MN_USER_FS_REQUEST: - switch(IrpContext->Stack->Parameters.DeviceIoControl.IoControlCode) - { - case FSCTL_GET_VOLUME_BITMAP: - Status = VfatGetVolumeBitmap(IrpContext); - break; - case FSCTL_GET_RETRIEVAL_POINTERS: - Status = VfatGetRetrievalPointers(IrpContext); - break; - case FSCTL_MOVE_FILE: - Status = VfatMoveFile(IrpContext); - break; - case FSCTL_IS_VOLUME_DIRTY: - Status = VfatIsVolumeDirty(IrpContext); - break; - case FSCTL_MARK_VOLUME_DIRTY: - Status = VfatMarkVolumeDirty(IrpContext); - break; - default: - Status = STATUS_INVALID_DEVICE_REQUEST; - } - break; - - case IRP_MN_MOUNT_VOLUME: - Status = VfatMount(IrpContext); - break; - - case IRP_MN_VERIFY_VOLUME: - DPRINT("VFATFS: IRP_MN_VERIFY_VOLUME\n"); - Status = VfatVerify(IrpContext); - break; - - default: - DPRINT("VFAT FSC: MinorFunction %u\n", IrpContext->MinorFunction); - Status = STATUS_INVALID_DEVICE_REQUEST; - break; - } - - IrpContext->Irp->IoStatus.Status = Status; - - IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT); - VfatFreeIrpContext(IrpContext); - return (Status); + case FSCTL_MOVE_FILE: + Status = VfatMoveFile(IrpContext); + break; + + case FSCTL_IS_VOLUME_DIRTY: + Status = VfatIsVolumeDirty(IrpContext); + break; + + case FSCTL_MARK_VOLUME_DIRTY: + Status = VfatMarkVolumeDirty(IrpContext); + break; + + default: + Status = STATUS_INVALID_DEVICE_REQUEST; + } + break; + + case IRP_MN_MOUNT_VOLUME: + Status = VfatMount(IrpContext); + break; + + case IRP_MN_VERIFY_VOLUME: + DPRINT("VFATFS: IRP_MN_VERIFY_VOLUME\n"); + Status = VfatVerify(IrpContext); + break; + + default: + DPRINT("VFAT FSC: MinorFunction %u\n", IrpContext->MinorFunction); + Status = STATUS_INVALID_DEVICE_REQUEST; + break; + } + + IrpContext->Irp->IoStatus.Status = Status; + + IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT); + VfatFreeIrpContext(IrpContext); + return Status; } diff --git a/reactos/drivers/filesystems/fastfat/misc.c b/reactos/drivers/filesystems/fastfat/misc.c index 1435ae5ad77..0d678f85e79 100644 --- a/reactos/drivers/filesystems/fastfat/misc.c +++ b/reactos/drivers/filesystems/fastfat/misc.c @@ -159,12 +159,12 @@ VfatBuildRequest( { Status = STATUS_INSUFFICIENT_RESOURCES; Irp->IoStatus.Status = Status; - IoCompleteRequest (Irp, IO_NO_INCREMENT); + IoCompleteRequest(Irp, IO_NO_INCREMENT); } else { FsRtlEnterFileSystem(); - Status = VfatDispatchRequest (IrpContext); + Status = VfatDispatchRequest(IrpContext); FsRtlExitFileSystem(); } return Status; diff --git a/reactos/drivers/filesystems/fastfat/vfat.h b/reactos/drivers/filesystems/fastfat/vfat.h index 5d45a4dd1f4..33b225f570c 100644 --- a/reactos/drivers/filesystems/fastfat/vfat.h +++ b/reactos/drivers/filesystems/fastfat/vfat.h @@ -15,94 +15,94 @@ #include struct _BootSector { - unsigned char magic0, res0, magic1; - unsigned char OEMName[8]; - unsigned short BytesPerSector; - unsigned char SectorsPerCluster; - unsigned short ReservedSectors; - unsigned char FATCount; - unsigned short RootEntries, Sectors; - unsigned char Media; - unsigned short FATSectors, SectorsPerTrack, Heads; - unsigned long HiddenSectors, SectorsHuge; - unsigned char Drive, Res1, Sig; - unsigned long VolumeID; - unsigned char VolumeLabel[11], SysType[8]; - unsigned char Res2[448]; - unsigned short Signatur1; + unsigned char magic0, res0, magic1; + unsigned char OEMName[8]; + unsigned short BytesPerSector; + unsigned char SectorsPerCluster; + unsigned short ReservedSectors; + unsigned char FATCount; + unsigned short RootEntries, Sectors; + unsigned char Media; + unsigned short FATSectors, SectorsPerTrack, Heads; + unsigned long HiddenSectors, SectorsHuge; + unsigned char Drive, Res1, Sig; + unsigned long VolumeID; + unsigned char VolumeLabel[11], SysType[8]; + unsigned char Res2[448]; + unsigned short Signatur1; }; struct _BootSector32 { - unsigned char magic0, res0, magic1; // 0 - unsigned char OEMName[8]; // 3 - unsigned short BytesPerSector; // 11 - unsigned char SectorsPerCluster; // 13 - unsigned short ReservedSectors; // 14 - unsigned char FATCount; // 16 - unsigned short RootEntries, Sectors; // 17 - unsigned char Media; // 21 - unsigned short FATSectors, SectorsPerTrack, Heads; // 22 - unsigned long HiddenSectors, SectorsHuge; // 28 - unsigned long FATSectors32; // 36 - unsigned short ExtFlag; // 40 - unsigned short FSVersion; // 42 - unsigned long RootCluster; // 44 - unsigned short FSInfoSector; // 48 - unsigned short BootBackup; // 50 - unsigned char Res3[12]; // 52 - unsigned char Drive; // 64 - unsigned char Res4; // 65 - unsigned char ExtBootSignature; // 66 - unsigned long VolumeID; // 67 - unsigned char VolumeLabel[11], SysType[8]; // 71 - unsigned char Res2[420]; // 90 - unsigned short Signature1; // 510 + unsigned char magic0, res0, magic1; // 0 + unsigned char OEMName[8]; // 3 + unsigned short BytesPerSector; // 11 + unsigned char SectorsPerCluster; // 13 + unsigned short ReservedSectors; // 14 + unsigned char FATCount; // 16 + unsigned short RootEntries, Sectors; // 17 + unsigned char Media; // 21 + unsigned short FATSectors, SectorsPerTrack, Heads; // 22 + unsigned long HiddenSectors, SectorsHuge; // 28 + unsigned long FATSectors32; // 36 + unsigned short ExtFlag; // 40 + unsigned short FSVersion; // 42 + unsigned long RootCluster; // 44 + unsigned short FSInfoSector; // 48 + unsigned short BootBackup; // 50 + unsigned char Res3[12]; // 52 + unsigned char Drive; // 64 + unsigned char Res4; // 65 + unsigned char ExtBootSignature; // 66 + unsigned long VolumeID; // 67 + unsigned char VolumeLabel[11], SysType[8]; // 71 + unsigned char Res2[420]; // 90 + unsigned short Signature1; // 510 }; struct _BootSectorFatX { - unsigned char SysType[4]; // 0 - unsigned long VolumeID; // 4 - unsigned long SectorsPerCluster; // 8 - unsigned short FATCount; // 12 - unsigned long Unknown; // 14 - unsigned char Unused[4078]; // 18 + unsigned char SysType[4]; // 0 + unsigned long VolumeID; // 4 + unsigned long SectorsPerCluster; // 8 + unsigned short FATCount; // 12 + unsigned long Unknown; // 14 + unsigned char Unused[4078]; // 18 }; struct _FsInfoSector { - unsigned long ExtBootSignature2; // 0 - unsigned char Res6[480]; // 4 - unsigned long FSINFOSignature; // 484 - unsigned long FreeCluster; // 488 - unsigned long NextCluster; // 492 - unsigned char Res7[12]; // 496 - unsigned long Signatur2; // 508 + unsigned long ExtBootSignature2; // 0 + unsigned char Res6[480]; // 4 + unsigned long FSINFOSignature; // 484 + unsigned long FreeCluster; // 488 + unsigned long NextCluster; // 492 + unsigned char Res7[12]; // 496 + unsigned long Signatur2; // 508 }; typedef struct _BootSector BootSector; struct _FATDirEntry { - union - { - struct { unsigned char Filename[8], Ext[3]; }; - unsigned char ShortName[11]; - }; - unsigned char Attrib; - unsigned char lCase; - unsigned char CreationTimeMs; - unsigned short CreationTime,CreationDate,AccessDate; - union - { - unsigned short FirstClusterHigh; // FAT32 - unsigned short ExtendedAttributes; // FAT12/FAT16 - }; - unsigned short UpdateTime; //time create/update - unsigned short UpdateDate; //date create/update - unsigned short FirstCluster; - unsigned long FileSize; + union + { + struct { unsigned char Filename[8], Ext[3]; }; + unsigned char ShortName[11]; + }; + unsigned char Attrib; + unsigned char lCase; + unsigned char CreationTimeMs; + unsigned short CreationTime,CreationDate,AccessDate; + union + { + unsigned short FirstClusterHigh; // FAT32 + unsigned short ExtendedAttributes; // FAT12/FAT16 + }; + unsigned short UpdateTime; //time create/update + unsigned short UpdateDate; //date create/update + unsigned short FirstCluster; + unsigned long FileSize; }; #define FAT_EAFILE "EA DATA. SF" @@ -111,62 +111,62 @@ typedef struct _EAFileHeader FAT_EA_FILE_HEADER, *PFAT_EA_FILE_HEADER; struct _EAFileHeader { - unsigned short Signature; // ED - unsigned short Unknown[15]; - unsigned short EASetTable[240]; + unsigned short Signature; // ED + unsigned short Unknown[15]; + unsigned short EASetTable[240]; }; typedef struct _EASetHeader FAT_EA_SET_HEADER, *PFAT_EA_SET_HEADER; struct _EASetHeader { - unsigned short Signature; // EA - unsigned short Offset; // relative offset, same value as in the EASetTable - unsigned short Unknown1[2]; - char TargetFileName[12]; - unsigned short Unknown2[3]; - unsigned int EALength; - // EA Header + unsigned short Signature; // EA + unsigned short Offset; // relative offset, same value as in the EASetTable + unsigned short Unknown1[2]; + char TargetFileName[12]; + unsigned short Unknown2[3]; + unsigned int EALength; + // EA Header }; typedef struct _EAHeader FAT_EA_HEADER, *PFAT_EA_HEADER; struct _EAHeader { - unsigned char Unknown; - unsigned char EANameLength; - unsigned short EAValueLength; - // Name Data - // Value Data + unsigned char Unknown; + unsigned char EANameLength; + unsigned short EAValueLength; + // Name Data + // Value Data }; typedef struct _FATDirEntry FAT_DIR_ENTRY, *PFAT_DIR_ENTRY; struct _FATXDirEntry { - unsigned char FilenameLength; // 0 - unsigned char Attrib; // 1 - unsigned char Filename[42]; // 2 - unsigned long FirstCluster; // 44 - unsigned long FileSize; // 48 - unsigned short UpdateTime; // 52 - unsigned short UpdateDate; // 54 - unsigned short CreationTime; // 56 - unsigned short CreationDate; // 58 - unsigned short AccessTime; // 60 - unsigned short AccessDate; // 62 + unsigned char FilenameLength; // 0 + unsigned char Attrib; // 1 + unsigned char Filename[42]; // 2 + unsigned long FirstCluster; // 44 + unsigned long FileSize; // 48 + unsigned short UpdateTime; // 52 + unsigned short UpdateDate; // 54 + unsigned short CreationTime; // 56 + unsigned short CreationDate; // 58 + unsigned short AccessTime; // 60 + unsigned short AccessDate; // 62 }; struct _slot { - unsigned char id; // sequence number for slot - WCHAR name0_4[5]; // first 5 characters in name - unsigned char attr; // attribute byte - unsigned char reserved; // always 0 - unsigned char alias_checksum; // checksum for 8.3 alias - WCHAR name5_10[6]; // 6 more characters in name - unsigned char start[2]; // starting cluster number - WCHAR name11_12[2]; // last 2 characters in name + unsigned char id; // sequence number for slot + WCHAR name0_4[5]; // first 5 characters in name + unsigned char attr; // attribute byte + unsigned char reserved; // always 0 + unsigned char alias_checksum; // checksum for 8.3 alias + WCHAR name5_10[6]; // 6 more characters in name + unsigned char start[2]; // starting cluster number + WCHAR name11_12[2]; // last 2 characters in name }; typedef struct _slot slot; @@ -199,8 +199,8 @@ typedef struct _FATXDirEntry FATX_DIR_ENTRY, *PFATX_DIR_ENTRY; union _DIR_ENTRY { - FAT_DIR_ENTRY Fat; - FATX_DIR_ENTRY FatX; + FAT_DIR_ENTRY Fat; + FATX_DIR_ENTRY FatX; }; typedef union _DIR_ENTRY DIR_ENTRY, *PDIR_ENTRY; @@ -221,21 +221,21 @@ typedef union _DIR_ENTRY DIR_ENTRY, *PDIR_ENTRY; typedef struct { - ULONG VolumeID; - ULONG FATStart; - ULONG FATCount; - ULONG FATSectors; - ULONG rootDirectorySectors; - ULONG rootStart; - ULONG dataStart; - ULONG RootCluster; - ULONG SectorsPerCluster; - ULONG BytesPerSector; - ULONG BytesPerCluster; - ULONG NumberOfClusters; - ULONG FatType; - ULONG Sectors; - BOOLEAN FixedMedia; + ULONG VolumeID; + ULONG FATStart; + ULONG FATCount; + ULONG FATSectors; + ULONG rootDirectorySectors; + ULONG rootStart; + ULONG dataStart; + ULONG RootCluster; + ULONG SectorsPerCluster; + ULONG BytesPerSector; + ULONG BytesPerCluster; + ULONG NumberOfClusters; + ULONG FatType; + ULONG Sectors; + BOOLEAN FixedMedia; } FATINFO, *PFATINFO; struct _VFATFCB; @@ -243,9 +243,9 @@ struct _VFAT_DIRENTRY_CONTEXT; typedef struct _HASHENTRY { - ULONG Hash; - struct _VFATFCB* self; - struct _HASHENTRY* next; + ULONG Hash; + struct _VFATFCB* self; + struct _HASHENTRY* next; } HASHENTRY; @@ -261,49 +261,49 @@ typedef NTSTATUS (*PGET_NEXT_DIR_ENTRY)(PVOID*,PVOID*,struct _VFATFCB*,struct _V typedef struct DEVICE_EXTENSION { - ERESOURCE DirResource; - ERESOURCE FatResource; - - KSPIN_LOCK FcbListLock; - LIST_ENTRY FcbListHead; - ULONG HashTableSize; - struct _HASHENTRY** FcbHashTable; - - PDEVICE_OBJECT StorageDevice; - PFILE_OBJECT FATFileObject; - FATINFO FatInfo; - ULONG LastAvailableCluster; - ULONG AvailableClusters; - BOOLEAN AvailableClustersValid; - ULONG Flags; - struct _VFATFCB * VolumeFcb; - - /* Pointers to functions for manipulating FAT. */ - PGET_NEXT_CLUSTER GetNextCluster; - PFIND_AND_MARK_AVAILABLE_CLUSTER FindAndMarkAvailableCluster; - PWRITE_CLUSTER WriteCluster; - ULONG CleanShutBitMask; - - /* Pointers to functions for manipulating directory entries. */ - PGET_NEXT_DIR_ENTRY GetNextDirEntry; - - ULONG BaseDateYear; - - LIST_ENTRY VolumeListEntry; + ERESOURCE DirResource; + ERESOURCE FatResource; + + KSPIN_LOCK FcbListLock; + LIST_ENTRY FcbListHead; + ULONG HashTableSize; + struct _HASHENTRY **FcbHashTable; + + PDEVICE_OBJECT StorageDevice; + PFILE_OBJECT FATFileObject; + FATINFO FatInfo; + ULONG LastAvailableCluster; + ULONG AvailableClusters; + BOOLEAN AvailableClustersValid; + ULONG Flags; + struct _VFATFCB *VolumeFcb; + + /* Pointers to functions for manipulating FAT. */ + PGET_NEXT_CLUSTER GetNextCluster; + PFIND_AND_MARK_AVAILABLE_CLUSTER FindAndMarkAvailableCluster; + PWRITE_CLUSTER WriteCluster; + ULONG CleanShutBitMask; + + /* Pointers to functions for manipulating directory entries. */ + PGET_NEXT_DIR_ENTRY GetNextDirEntry; + + ULONG BaseDateYear; + + LIST_ENTRY VolumeListEntry; } DEVICE_EXTENSION, VCB, *PVCB; typedef struct { - PDRIVER_OBJECT DriverObject; - PDEVICE_OBJECT DeviceObject; - ULONG Flags; - ERESOURCE VolumeListLock; - LIST_ENTRY VolumeListHead; - NPAGED_LOOKASIDE_LIST FcbLookasideList; - NPAGED_LOOKASIDE_LIST CcbLookasideList; - NPAGED_LOOKASIDE_LIST IrpContextLookasideList; - FAST_IO_DISPATCH FastIoDispatch; - CACHE_MANAGER_CALLBACKS CacheMgrCallbacks; + PDRIVER_OBJECT DriverObject; + PDEVICE_OBJECT DeviceObject; + ULONG Flags; + ERESOURCE VolumeListLock; + LIST_ENTRY VolumeListHead; + NPAGED_LOOKASIDE_LIST FcbLookasideList; + NPAGED_LOOKASIDE_LIST CcbLookasideList; + NPAGED_LOOKASIDE_LIST IrpContextLookasideList; + FAST_IO_DISPATCH FastIoDispatch; + CACHE_MANAGER_CALLBACKS CacheMgrCallbacks; } VFAT_GLOBAL_DATA, *PVFAT_GLOBAL_DATA; extern PVFAT_GLOBAL_DATA VfatGlobalData; @@ -318,90 +318,90 @@ extern PVFAT_GLOBAL_DATA VfatGlobalData; typedef struct _VFATFCB { - /* FCB header required by ROS/NT */ - FSRTL_COMMON_FCB_HEADER RFCB; - SECTION_OBJECT_POINTERS SectionObjectPointers; - ERESOURCE MainResource; - ERESOURCE PagingIoResource; - /* end FCB header required by ROS/NT */ + /* FCB header required by ROS/NT */ + FSRTL_COMMON_FCB_HEADER RFCB; + SECTION_OBJECT_POINTERS SectionObjectPointers; + ERESOURCE MainResource; + ERESOURCE PagingIoResource; + /* end FCB header required by ROS/NT */ - /* directory entry for this file or directory */ - DIR_ENTRY entry; + /* directory entry for this file or directory */ + DIR_ENTRY entry; - /* Pointer to attributes in entry */ - PUCHAR Attributes; + /* Pointer to attributes in entry */ + PUCHAR Attributes; - /* long file name, points into PathNameBuffer */ - UNICODE_STRING LongNameU; + /* long file name, points into PathNameBuffer */ + UNICODE_STRING LongNameU; - /* short file name */ - UNICODE_STRING ShortNameU; + /* short file name */ + UNICODE_STRING ShortNameU; - /* directory name, points into PathNameBuffer */ - UNICODE_STRING DirNameU; + /* directory name, points into PathNameBuffer */ + UNICODE_STRING DirNameU; - /* path + long file name 260 max*/ - UNICODE_STRING PathNameU; + /* path + long file name 260 max*/ + UNICODE_STRING PathNameU; - /* buffer for PathNameU */ - PWCHAR PathNameBuffer; + /* buffer for PathNameU */ + PWCHAR PathNameBuffer; - /* buffer for ShortNameU */ - WCHAR ShortNameBuffer[13]; + /* buffer for ShortNameU */ + WCHAR ShortNameBuffer[13]; - /* */ - LONG RefCount; + /* */ + LONG RefCount; - /* List of FCB's for this volume */ - LIST_ENTRY FcbListEntry; + /* List of FCB's for this volume */ + LIST_ENTRY FcbListEntry; - /* pointer to the parent fcb */ - struct _VFATFCB* parentFcb; + /* pointer to the parent fcb */ + struct _VFATFCB *parentFcb; - /* Flags for the fcb */ - ULONG Flags; + /* Flags for the fcb */ + ULONG Flags; - /* pointer to the file object which has initialized the fcb */ - PFILE_OBJECT FileObject; + /* pointer to the file object which has initialized the fcb */ + PFILE_OBJECT FileObject; - /* Directory index for the short name entry */ - ULONG dirIndex; + /* Directory index for the short name entry */ + ULONG dirIndex; - /* Directory index where the long name starts */ - ULONG startIndex; + /* Directory index where the long name starts */ + ULONG startIndex; - /* Share access for the file object */ - SHARE_ACCESS FCBShareAccess; + /* Share access for the file object */ + SHARE_ACCESS FCBShareAccess; - /* Incremented on IRP_MJ_CREATE, decremented on IRP_MJ_CLEANUP */ - ULONG OpenHandleCount; + /* Incremented on IRP_MJ_CREATE, decremented on IRP_MJ_CLEANUP */ + ULONG OpenHandleCount; - /* Entry into the hash table for the path + long name */ - HASHENTRY Hash; + /* Entry into the hash table for the path + long name */ + HASHENTRY Hash; - /* Entry into the hash table for the path + short name */ - HASHENTRY ShortHash; + /* Entry into the hash table for the path + short name */ + HASHENTRY ShortHash; - /* List of byte-range locks for this file */ - FILE_LOCK FileLock; + /* List of byte-range locks for this file */ + FILE_LOCK FileLock; - /* - * Optimalization: caching of last read/write cluster+offset pair. Can't - * be in VFATCCB because it must be reset everytime the allocated clusters - * change. - */ - FAST_MUTEX LastMutex; - ULONG LastCluster; - ULONG LastOffset; + /* + * Optimalization: caching of last read/write cluster+offset pair. Can't + * be in VFATCCB because it must be reset everytime the allocated clusters + * change. + */ + FAST_MUTEX LastMutex; + ULONG LastCluster; + ULONG LastOffset; } VFATFCB, *PVFATFCB; typedef struct _VFATCCB { - LARGE_INTEGER CurrentByteOffset; - /* for DirectoryControl */ - ULONG Entry; - /* for DirectoryControl */ - UNICODE_STRING SearchPattern; + LARGE_INTEGER CurrentByteOffset; + /* for DirectoryControl */ + ULONG Entry; + /* for DirectoryControl */ + UNICODE_STRING SearchPattern; } VFATCCB, *PVFATCCB; #define TAG_CCB 'BCCV' @@ -413,17 +413,17 @@ typedef struct _VFATCCB typedef struct __DOSTIME { - USHORT Second:5; - USHORT Minute:6; - USHORT Hour:5; + USHORT Second:5; + USHORT Minute:6; + USHORT Hour:5; } DOSTIME, *PDOSTIME; typedef struct __DOSDATE { - USHORT Day:5; - USHORT Month:4; - USHORT Year:7; + USHORT Day:5; + USHORT Month:4; + USHORT Year:7; } DOSDATE, *PDOSDATE; @@ -432,352 +432,522 @@ DOSDATE, *PDOSDATE; typedef struct { - PIRP Irp; - PDEVICE_OBJECT DeviceObject; - PDEVICE_EXTENSION DeviceExt; - ULONG Flags; - WORK_QUEUE_ITEM WorkQueueItem; - PIO_STACK_LOCATION Stack; - UCHAR MajorFunction; - UCHAR MinorFunction; - PFILE_OBJECT FileObject; - ULONG RefCount; - KEVENT Event; + PIRP Irp; + PDEVICE_OBJECT DeviceObject; + PDEVICE_EXTENSION DeviceExt; + ULONG Flags; + WORK_QUEUE_ITEM WorkQueueItem; + PIO_STACK_LOCATION Stack; + UCHAR MajorFunction; + UCHAR MinorFunction; + PFILE_OBJECT FileObject; + ULONG RefCount; + KEVENT Event; } VFAT_IRP_CONTEXT, *PVFAT_IRP_CONTEXT; typedef struct _VFAT_DIRENTRY_CONTEXT { - ULONG StartIndex; - ULONG DirIndex; - DIR_ENTRY DirEntry; - UNICODE_STRING LongNameU; - UNICODE_STRING ShortNameU; + ULONG StartIndex; + ULONG DirIndex; + DIR_ENTRY DirEntry; + UNICODE_STRING LongNameU; + UNICODE_STRING ShortNameU; } VFAT_DIRENTRY_CONTEXT, *PVFAT_DIRENTRY_CONTEXT; -/* ------------------------------------------------------ shutdown.c */ +/* blockdev.c */ -DRIVER_DISPATCH VfatShutdown; -NTSTATUS NTAPI VfatShutdown (PDEVICE_OBJECT DeviceObject, - PIRP Irp); +NTSTATUS +VfatReadDisk( + IN PDEVICE_OBJECT pDeviceObject, + IN PLARGE_INTEGER ReadOffset, + IN ULONG ReadLength, + IN PUCHAR Buffer, + IN BOOLEAN Override); -/* -------------------------------------------------------- volume.c */ +NTSTATUS +VfatReadDiskPartial( + IN PVFAT_IRP_CONTEXT IrpContext, + IN PLARGE_INTEGER ReadOffset, + IN ULONG ReadLength, + IN ULONG BufferOffset, + IN BOOLEAN Wait); -NTSTATUS VfatQueryVolumeInformation (PVFAT_IRP_CONTEXT IrpContext); +NTSTATUS +VfatWriteDiskPartial( + IN PVFAT_IRP_CONTEXT IrpContext, + IN PLARGE_INTEGER WriteOffset, + IN ULONG WriteLength, + IN ULONG BufferOffset, + IN BOOLEAN Wait); + +NTSTATUS +VfatBlockDeviceIoControl( + IN PDEVICE_OBJECT DeviceObject, + IN ULONG CtlCode, + IN PVOID InputBuffer, + IN ULONG InputBufferSize, + IN OUT PVOID OutputBuffer, + IN OUT PULONG pOutputBufferSize, + IN BOOLEAN Override); -NTSTATUS VfatSetVolumeInformation (PVFAT_IRP_CONTEXT IrpContext); +/* cleanup.c */ -/* ------------------------------------------------------ blockdev.c */ +NTSTATUS +VfatCleanup( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, - IN PLARGE_INTEGER ReadOffset, - IN ULONG ReadLength, - IN PUCHAR Buffer, - IN BOOLEAN Override); +/* close.c */ -NTSTATUS VfatReadDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, - IN PLARGE_INTEGER ReadOffset, - IN ULONG ReadLength, - IN ULONG BufferOffset, - IN BOOLEAN Wait); +NTSTATUS +VfatClose( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS VfatWriteDiskPartial(IN PVFAT_IRP_CONTEXT IrpContext, - IN PLARGE_INTEGER WriteOffset, - IN ULONG WriteLength, - IN ULONG BufferOffset, - IN BOOLEAN Wait); +NTSTATUS +VfatCloseFile( + PDEVICE_EXTENSION DeviceExt, + PFILE_OBJECT FileObject); -NTSTATUS VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject, - IN ULONG CtlCode, - IN PVOID InputBuffer, - IN ULONG InputBufferSize, - IN OUT PVOID OutputBuffer, - IN OUT PULONG pOutputBufferSize, - IN BOOLEAN Override); +/* create.c */ -/* ----------------------------------------------------------- dir.c */ +NTSTATUS +VfatCreate( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS VfatDirectoryControl (PVFAT_IRP_CONTEXT); +NTSTATUS +FindFile( + PDEVICE_EXTENSION DeviceExt, + PVFATFCB Parent, + PUNICODE_STRING FileToFindU, + PVFAT_DIRENTRY_CONTEXT DirContext, + BOOLEAN First); -BOOLEAN FsdDosDateTimeToSystemTime (PDEVICE_EXTENSION DeviceExt, - USHORT DosDate, - USHORT DosTime, - PLARGE_INTEGER SystemTime); +VOID +vfat8Dot3ToString( + PFAT_DIR_ENTRY pEntry, + PUNICODE_STRING NameU); -BOOLEAN FsdSystemTimeToDosDateTime (PDEVICE_EXTENSION DeviceExt, - PLARGE_INTEGER SystemTime, - USHORT *pDosDate, - USHORT *pDosTime); +NTSTATUS +ReadVolumeLabel( + PDEVICE_EXTENSION DeviceExt, + PVPB Vpb); -/* -------------------------------------------------------- create.c */ +/* dir.c */ -NTSTATUS VfatCreate (PVFAT_IRP_CONTEXT IrpContext); +NTSTATUS +VfatDirectoryControl( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS FindFile (PDEVICE_EXTENSION DeviceExt, - PVFATFCB Parent, - PUNICODE_STRING FileToFindU, - PVFAT_DIRENTRY_CONTEXT DirContext, - BOOLEAN First); +BOOLEAN +FsdDosDateTimeToSystemTime( + PDEVICE_EXTENSION DeviceExt, + USHORT DosDate, + USHORT DosTime, + PLARGE_INTEGER SystemTime); -VOID vfat8Dot3ToString (PFAT_DIR_ENTRY pEntry, - PUNICODE_STRING NameU); +BOOLEAN +FsdSystemTimeToDosDateTime( + PDEVICE_EXTENSION DeviceExt, + PLARGE_INTEGER SystemTime, + USHORT *pDosDate, + USHORT *pDosTime); -NTSTATUS ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, - PVPB Vpb); +/* direntry.c */ -/* --------------------------------------------------------- close.c */ +ULONG +vfatDirEntryGetFirstCluster( + PDEVICE_EXTENSION pDeviceExt, + PDIR_ENTRY pDirEntry); -NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext); +BOOLEAN +VfatIsDirectoryEmpty( + PVFATFCB Fcb); -NTSTATUS VfatCloseFile(PDEVICE_EXTENSION DeviceExt, - PFILE_OBJECT FileObject); +NTSTATUS +FATGetNextDirEntry( + PVOID *pContext, + PVOID *pPage, + IN PVFATFCB pDirFcb, + IN PVFAT_DIRENTRY_CONTEXT DirContext, + BOOLEAN First); -/* ------------------------------------------------------- cleanup.c */ +NTSTATUS +FATXGetNextDirEntry( + PVOID *pContext, + PVOID *pPage, + IN PVFATFCB pDirFcb, + IN PVFAT_DIRENTRY_CONTEXT DirContext, + BOOLEAN First); -NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext); +/* dirwr.c */ -/* --------------------------------------------------------- fastio.c */ +NTSTATUS +VfatAddEntry( + PDEVICE_EXTENSION DeviceExt, + PUNICODE_STRING PathNameU, + PVFATFCB* Fcb, + PVFATFCB ParentFcb, + ULONG RequestedOptions, + UCHAR ReqAttr); -VOID -VfatInitFastIoRoutines(PFAST_IO_DISPATCH FastIoDispatch); +NTSTATUS +VfatUpdateEntry( + PVFATFCB pFcb); + +NTSTATUS +VfatDelEntry( + PDEVICE_EXTENSION, + PVFATFCB); + +BOOLEAN +vfatFindDirSpace( + PDEVICE_EXTENSION DeviceExt, + PVFATFCB pDirFcb, + ULONG nbSlots, + PULONG start); -BOOLEAN NTAPI -VfatAcquireForLazyWrite(IN PVOID Context, - IN BOOLEAN Wait); +/* ea.h */ -VOID NTAPI -VfatReleaseFromLazyWrite(IN PVOID Context); +NTSTATUS +VfatSetExtendedAttributes( + PFILE_OBJECT FileObject, + PVOID Ea, + ULONG EaLength); -BOOLEAN NTAPI -VfatAcquireForReadAhead(IN PVOID Context, - IN BOOLEAN Wait); +/* fastio.c */ -VOID NTAPI -VfatReleaseFromReadAhead(IN PVOID Context); +VOID +VfatInitFastIoRoutines( + PFAST_IO_DISPATCH FastIoDispatch); -/* --------------------------------------------------------- fsctl.c */ +BOOLEAN +NTAPI +VfatAcquireForLazyWrite( + IN PVOID Context, + IN BOOLEAN Wait); -NTSTATUS VfatFileSystemControl (PVFAT_IRP_CONTEXT IrpContext); +VOID +NTAPI +VfatReleaseFromLazyWrite( + IN PVOID Context); -/* --------------------------------------------------------- finfo.c */ +BOOLEAN +NTAPI +VfatAcquireForReadAhead( + IN PVOID Context, + IN BOOLEAN Wait); -NTSTATUS VfatQueryInformation (PVFAT_IRP_CONTEXT IrpContext); +VOID +NTAPI +VfatReleaseFromReadAhead( + IN PVOID Context); -NTSTATUS VfatSetInformation (PVFAT_IRP_CONTEXT IrpContext); +/* fat.c */ NTSTATUS -VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject, - PVFATFCB Fcb, - PDEVICE_EXTENSION DeviceExt, - PLARGE_INTEGER AllocationSize); +FAT12GetNextCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG CurrentCluster, + PULONG NextCluster); -/* --------------------------------------------------------- iface.c */ +NTSTATUS +FAT12FindAndMarkAvailableCluster( + PDEVICE_EXTENSION DeviceExt, + PULONG Cluster); -NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, - PUNICODE_STRING RegistryPath); +NTSTATUS +FAT12WriteCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG ClusterToWrite, + ULONG NewValue, + PULONG OldValue); -/* --------------------------------------------------------- dirwr.c */ +NTSTATUS +FAT16GetNextCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG CurrentCluster, + PULONG NextCluster); -NTSTATUS VfatAddEntry (PDEVICE_EXTENSION DeviceExt, - PUNICODE_STRING PathNameU, - PVFATFCB* Fcb, - PVFATFCB ParentFcb, - ULONG RequestedOptions, - UCHAR ReqAttr); +NTSTATUS +FAT16FindAndMarkAvailableCluster( + PDEVICE_EXTENSION DeviceExt, + PULONG Cluster); -NTSTATUS VfatUpdateEntry (PVFATFCB pFcb); +NTSTATUS +FAT16WriteCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG ClusterToWrite, + ULONG NewValue, + PULONG OldValue); -NTSTATUS VfatDelEntry(PDEVICE_EXTENSION, PVFATFCB); +NTSTATUS +FAT32GetNextCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG CurrentCluster, + PULONG NextCluster); -BOOLEAN -vfatFindDirSpace(PDEVICE_EXTENSION DeviceExt, - PVFATFCB pDirFcb, - ULONG nbSlots, - PULONG start); +NTSTATUS +FAT32FindAndMarkAvailableCluster( + PDEVICE_EXTENSION DeviceExt, + PULONG Cluster); -/* -------------------------------------------------------- string.c */ +NTSTATUS +FAT32WriteCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG ClusterToWrite, + ULONG NewValue, + PULONG OldValue); -VOID -vfatSplitPathName(PUNICODE_STRING PathNameU, - PUNICODE_STRING DirNameU, - PUNICODE_STRING FileNameU); +NTSTATUS +OffsetToCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG FirstCluster, + ULONG FileOffset, + PULONG Cluster, + BOOLEAN Extend); + +ULONGLONG +ClusterToSector( + PDEVICE_EXTENSION DeviceExt, + ULONG Cluster); -BOOLEAN vfatIsLongIllegal(WCHAR c); +NTSTATUS +GetNextCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG CurrentCluster, + PULONG NextCluster); -BOOLEAN wstrcmpjoki (PWSTR s1, - PWSTR s2); +NTSTATUS +GetNextClusterExtend( + PDEVICE_EXTENSION DeviceExt, + ULONG CurrentCluster, + PULONG NextCluster); -/* ----------------------------------------------------------- fat.c */ +NTSTATUS +CountAvailableClusters( + PDEVICE_EXTENSION DeviceExt, + PLARGE_INTEGER Clusters); -NTSTATUS FAT12GetNextCluster(PDEVICE_EXTENSION DeviceExt, - ULONG CurrentCluster, - PULONG NextCluster); +NTSTATUS +WriteCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG ClusterToWrite, + ULONG NewValue); -NTSTATUS FAT12FindAndMarkAvailableCluster(PDEVICE_EXTENSION DeviceExt, - PULONG Cluster); +/* fcb.c */ -NTSTATUS FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt, - ULONG ClusterToWrite, - ULONG NewValue, - PULONG OldValue); +PVFATFCB +vfatNewFCB( + PDEVICE_EXTENSION pVCB, + PUNICODE_STRING pFileNameU); -NTSTATUS FAT16GetNextCluster(PDEVICE_EXTENSION DeviceExt, - ULONG CurrentCluster, - PULONG NextCluster); +VOID +vfatDestroyFCB( + PVFATFCB pFCB); -NTSTATUS FAT16FindAndMarkAvailableCluster(PDEVICE_EXTENSION DeviceExt, - PULONG Cluster); +VOID +vfatDestroyCCB( + PVFATCCB pCcb); -NTSTATUS FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt, - ULONG ClusterToWrite, - ULONG NewValue, - PULONG OldValue); +VOID +vfatGrabFCB( + PDEVICE_EXTENSION pVCB, + PVFATFCB pFCB); -NTSTATUS FAT32GetNextCluster(PDEVICE_EXTENSION DeviceExt, - ULONG CurrentCluster, - PULONG NextCluster); +VOID +vfatReleaseFCB( + PDEVICE_EXTENSION pVCB, + PVFATFCB pFCB); -NTSTATUS FAT32FindAndMarkAvailableCluster(PDEVICE_EXTENSION DeviceExt, - PULONG Cluster); +VOID +vfatAddFCBToTable( + PDEVICE_EXTENSION pVCB, + PVFATFCB pFCB); -NTSTATUS FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt, - ULONG ClusterToWrite, - ULONG NewValue, - PULONG OldValue); +PVFATFCB +vfatGrabFCBFromTable( + PDEVICE_EXTENSION pDeviceExt, + PUNICODE_STRING pFileNameU); -NTSTATUS OffsetToCluster (PDEVICE_EXTENSION DeviceExt, - ULONG FirstCluster, - ULONG FileOffset, - PULONG Cluster, - BOOLEAN Extend); +PVFATFCB +vfatMakeRootFCB( + PDEVICE_EXTENSION pVCB); -ULONGLONG ClusterToSector (PDEVICE_EXTENSION DeviceExt, - ULONG Cluster); +PVFATFCB +vfatOpenRootFCB( + PDEVICE_EXTENSION pVCB); -NTSTATUS GetNextCluster (PDEVICE_EXTENSION DeviceExt, - ULONG CurrentCluster, - PULONG NextCluster); +BOOLEAN +vfatFCBIsDirectory( + PVFATFCB FCB); -NTSTATUS GetNextClusterExtend (PDEVICE_EXTENSION DeviceExt, - ULONG CurrentCluster, - PULONG NextCluster); +BOOLEAN +vfatFCBIsRoot( + PVFATFCB FCB); -NTSTATUS CountAvailableClusters (PDEVICE_EXTENSION DeviceExt, - PLARGE_INTEGER Clusters); +NTSTATUS +vfatAttachFCBToFileObject( + PDEVICE_EXTENSION vcb, + PVFATFCB fcb, + PFILE_OBJECT fileObject); NTSTATUS -WriteCluster(PDEVICE_EXTENSION DeviceExt, - ULONG ClusterToWrite, - ULONG NewValue); +vfatDirFindFile( + PDEVICE_EXTENSION pVCB, + PVFATFCB parentFCB, + PUNICODE_STRING FileToFindU, + PVFATFCB *fileFCB); -/* ------------------------------------------------------ direntry.c */ +NTSTATUS +vfatGetFCBForFile( + PDEVICE_EXTENSION pVCB, + PVFATFCB *pParentFCB, + PVFATFCB *pFCB, + PUNICODE_STRING pFileNameU); -ULONG vfatDirEntryGetFirstCluster (PDEVICE_EXTENSION pDeviceExt, - PDIR_ENTRY pDirEntry); +NTSTATUS +vfatMakeFCBFromDirEntry( + PVCB vcb, + PVFATFCB directoryFCB, + PVFAT_DIRENTRY_CONTEXT DirContext, + PVFATFCB *fileFCB); -BOOLEAN VfatIsDirectoryEmpty(PVFATFCB Fcb); +/* finfo.c */ -NTSTATUS FATGetNextDirEntry(PVOID * pContext, - PVOID * pPage, - IN PVFATFCB pDirFcb, - IN PVFAT_DIRENTRY_CONTEXT DirContext, - BOOLEAN First); +NTSTATUS +VfatQueryInformation( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS FATXGetNextDirEntry(PVOID * pContext, - PVOID * pPage, - IN PVFATFCB pDirFcb, - IN PVFAT_DIRENTRY_CONTEXT DirContext, - BOOLEAN First); +NTSTATUS +VfatSetInformation( + PVFAT_IRP_CONTEXT IrpContext); -/* ----------------------------------------------------------- fcb.c */ +NTSTATUS +VfatSetAllocationSizeInformation( + PFILE_OBJECT FileObject, + PVFATFCB Fcb, + PDEVICE_EXTENSION DeviceExt, + PLARGE_INTEGER AllocationSize); -PVFATFCB vfatNewFCB (PDEVICE_EXTENSION pVCB, - PUNICODE_STRING pFileNameU); +/* flush.c */ -VOID vfatDestroyFCB (PVFATFCB pFCB); +NTSTATUS +VfatFlush( + PVFAT_IRP_CONTEXT IrpContext); -VOID vfatDestroyCCB(PVFATCCB pCcb); +NTSTATUS +VfatFlushVolume( + PDEVICE_EXTENSION DeviceExt, + PVFATFCB VolumeFcb); -VOID vfatGrabFCB (PDEVICE_EXTENSION pVCB, - PVFATFCB pFCB); +/* fsctl.c */ -VOID vfatReleaseFCB (PDEVICE_EXTENSION pVCB, - PVFATFCB pFCB); +NTSTATUS +VfatFileSystemControl( + PVFAT_IRP_CONTEXT IrpContext); -VOID vfatAddFCBToTable (PDEVICE_EXTENSION pVCB, - PVFATFCB pFCB); +/* iface.c */ -PVFATFCB vfatGrabFCBFromTable (PDEVICE_EXTENSION pDeviceExt, - PUNICODE_STRING pFileNameU); +NTSTATUS +NTAPI +DriverEntry( + PDRIVER_OBJECT DriverObject, + PUNICODE_STRING RegistryPath); -PVFATFCB vfatMakeRootFCB (PDEVICE_EXTENSION pVCB); -PVFATFCB vfatOpenRootFCB (PDEVICE_EXTENSION pVCB); +/* misc.c */ -BOOLEAN vfatFCBIsDirectory (PVFATFCB FCB); +NTSTATUS +VfatQueueRequest( + PVFAT_IRP_CONTEXT IrpContext); -BOOLEAN vfatFCBIsRoot(PVFATFCB FCB); +PVFAT_IRP_CONTEXT +VfatAllocateIrpContext( + PDEVICE_OBJECT DeviceObject, + PIRP Irp); -NTSTATUS vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb, - PVFATFCB fcb, - PFILE_OBJECT fileObject); +VOID +VfatFreeIrpContext( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS vfatDirFindFile (PDEVICE_EXTENSION pVCB, - PVFATFCB parentFCB, - PUNICODE_STRING FileToFindU, - PVFATFCB * fileFCB); +DRIVER_DISPATCH +VfatBuildRequest; -NTSTATUS vfatGetFCBForFile (PDEVICE_EXTENSION pVCB, - PVFATFCB *pParentFCB, - PVFATFCB *pFCB, - PUNICODE_STRING pFileNameU); +NTSTATUS +NTAPI +VfatBuildRequest( + PDEVICE_OBJECT DeviceObject, + PIRP Irp); -NTSTATUS vfatMakeFCBFromDirEntry (PVCB vcb, - PVFATFCB directoryFCB, - PVFAT_DIRENTRY_CONTEXT DirContext, - PVFATFCB * fileFCB); +PVOID +VfatGetUserBuffer( + IN PIRP); -/* ------------------------------------------------------------ rw.c */ +NTSTATUS +VfatLockUserBuffer( + IN PIRP, + IN ULONG, + IN LOCK_OPERATION); -NTSTATUS VfatRead (PVFAT_IRP_CONTEXT IrpContext); +/* pnp.c */ -NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext); +NTSTATUS +VfatPnp( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, - ULONG FirstCluster, - PULONG CurrentCluster, - BOOLEAN Extend); +/* rw.c */ -/* ----------------------------------------------------------- misc.c */ +NTSTATUS +VfatRead( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS VfatQueueRequest(PVFAT_IRP_CONTEXT IrpContext); +NTSTATUS +VfatWrite( + PVFAT_IRP_CONTEXT IrpContext); -PVFAT_IRP_CONTEXT VfatAllocateIrpContext(PDEVICE_OBJECT DeviceObject, - PIRP Irp); +NTSTATUS +NextCluster( + PDEVICE_EXTENSION DeviceExt, + ULONG FirstCluster, + PULONG CurrentCluster, + BOOLEAN Extend); -VOID VfatFreeIrpContext(PVFAT_IRP_CONTEXT IrpContext); +/* shutdown.c */ -DRIVER_DISPATCH VfatBuildRequest; -NTSTATUS NTAPI VfatBuildRequest (PDEVICE_OBJECT DeviceObject, - PIRP Irp); +DRIVER_DISPATCH +VfatShutdown; -PVOID VfatGetUserBuffer(IN PIRP); +NTSTATUS +NTAPI +VfatShutdown( + PDEVICE_OBJECT DeviceObject, + PIRP Irp); -NTSTATUS VfatLockUserBuffer(IN PIRP, IN ULONG, - IN LOCK_OPERATION); +/* string.c */ -NTSTATUS -VfatSetExtendedAttributes(PFILE_OBJECT FileObject, - PVOID Ea, - ULONG EaLength); -/* ------------------------------------------------------------- flush.c */ +VOID +vfatSplitPathName( + PUNICODE_STRING PathNameU, + PUNICODE_STRING DirNameU, + PUNICODE_STRING FileNameU); -NTSTATUS VfatFlush(PVFAT_IRP_CONTEXT IrpContext); +BOOLEAN +vfatIsLongIllegal( + WCHAR c); -NTSTATUS VfatFlushVolume(PDEVICE_EXTENSION DeviceExt, PVFATFCB VolumeFcb); +BOOLEAN +wstrcmpjoki( + PWSTR s1, + PWSTR s2); + +/* volume.c */ -/* --------------------------------------------------------------- pnp.c */ +NTSTATUS +VfatQueryVolumeInformation( + PVFAT_IRP_CONTEXT IrpContext); -NTSTATUS VfatPnp(PVFAT_IRP_CONTEXT IrpContext); +NTSTATUS +VfatSetVolumeInformation( + PVFAT_IRP_CONTEXT IrpContext); /* EOF */ -- 2.17.1