From c1d76231a4a37b64c9510c8dfa2f589b0462ad23 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Mon, 28 Sep 2009 18:04:31 +0000 Subject: [PATCH] [fastfat_new] - Create root DCB when mounting a volume. svn path=/trunk/; revision=43207 --- reactos/drivers/filesystems/fastfat_new/dir.c | 103 ++++++++++++++++++ .../drivers/filesystems/fastfat_new/fastfat.h | 4 + .../filesystems/fastfat_new/fatstruc.h | 35 +++++- .../drivers/filesystems/fastfat_new/fsctl.c | 3 + 4 files changed, 139 insertions(+), 6 deletions(-) diff --git a/reactos/drivers/filesystems/fastfat_new/dir.c b/reactos/drivers/filesystems/fastfat_new/dir.c index ce858c70e18..4cd4e0064c8 100644 --- a/reactos/drivers/filesystems/fastfat_new/dir.c +++ b/reactos/drivers/filesystems/fastfat_new/dir.c @@ -21,4 +21,107 @@ FatDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp) return STATUS_NOT_IMPLEMENTED; } +VOID +NTAPI +FatCreateRootDcb(IN PFAT_IRP_CONTEXT IrpContext, + IN PVCB Vcb) +{ + PFCB Dcb; + + /* Make sure it's not already created */ + ASSERT(!Vcb->RootDcb); + + /* Allocate the DCB */ + Dcb = FsRtlAllocatePoolWithTag(NonPagedPool, + sizeof(FCB), + TAG_FCB); + + /* Zero it */ + RtlZeroMemory(Dcb, sizeof(FCB)); + + /* Assign it to the VCB */ + Vcb->RootDcb = Dcb; + + /* Set its header */ + Dcb->Header.NodeTypeCode = FAT_NTC_ROOT_DCB; + Dcb->Header.NodeByteSize = sizeof(FCB); + + /* FCB is in a good condition */ + Dcb->Condition = FcbGood; + + /* Initialize FCB's resource */ + Dcb->Header.Resource = &Dcb->Resource; + ExInitializeResourceLite(&Dcb->Resource); + + /* Initialize Paging Io resource*/ + Dcb->Header.PagingIoResource = &Dcb->PagingIoResource; + ExInitializeResourceLite(&Dcb->PagingIoResource); + + /* Initialize a list of parent DCBs*/ + InitializeListHead(&Dcb->ParentDcbLinks); + + /* Set VCB */ + Dcb->Vcb = Vcb; + + /* Initialize parent's DCB list */ + InitializeListHead(&Dcb->Dcb.ParentDcbList); + + /* Initialize the full file name */ + Dcb->FullFileName.Buffer = L"\\"; + Dcb->FullFileName.Length = 1 * sizeof(WCHAR); + Dcb->FullFileName.MaximumLength = 2 * sizeof(WCHAR); + + Dcb->FileName.Name.Ansi.Buffer = "\\"; + Dcb->FileName.Name.Ansi.Length = 1; + Dcb->FileName.Name.Ansi.MaximumLength = 2 * sizeof(CHAR); + + /* Fill dirent attribute byte copy */ + Dcb->DirentFatFlags = FILE_ATTRIBUTE_DIRECTORY; + + /* Initialize advanced FCB header fields */ + ExInitializeFastMutex(&Dcb->HeaderMutex); + FsRtlSetupAdvancedHeader(&Dcb->Header, &Dcb->HeaderMutex); + + /* Initialize MCB */ + FsRtlInitializeLargeMcb(&Dcb->Mcb, NonPagedPool); + + /* Set up first cluster field depending on FAT type */ + if (TRUE/*FatIsFat32(Vcb)*/) + { + /* First cluster is really the first cluster of this volume */ + Dcb->FirstClusterOfFile = Vcb->Bpb.RootDirFirstCluster; + + /* Calculate size of FAT32 root dir */ + Dcb->Header.AllocationSize.LowPart = 0xFFFFFFFF; + //FatLookupFileAllocationSize(IrpContext, Dcb); + DPRINT1("Calculation of a size of a root dir is missing!\n"); + + Dcb->Header.FileSize.QuadPart = Dcb->Header.AllocationSize.QuadPart; + } + else + { +#if 0 + /* Add MCB entry */ + FatAddMcbEntry(Vcb, + &Dcb->Mcb, + 0, + FatRootDirectoryLbo(&Vcb->Bpb), + FatRootDirectorySize(&Vcb->Bpb)); + + /* Set a real size of the root directory */ + Dcb->Header.FileSize.QuadPart = FatRootDirectorySize(&Vcb->Bpb); + Dcb->Header.AllocationSize.QuadPart = Dcb->Header.FileSize.QuadPart; +#endif + UNIMPLEMENTED; + } + + /* Initialize free dirent bitmap */ + RtlInitializeBitMap(&Dcb->Dcb.FreeBitmap, NULL, 0); + + /* Fill the dirent bitmap */ + DPRINT1("Filling the free dirent bitmap is missing\n"); + //FatCheckFreeDirentBitmap( IrpContext, Dcb ); +} + + /* EOF */ diff --git a/reactos/drivers/filesystems/fastfat_new/fastfat.h b/reactos/drivers/filesystems/fastfat_new/fastfat.h index 32f090b394b..e19627f1a65 100644 --- a/reactos/drivers/filesystems/fastfat_new/fastfat.h +++ b/reactos/drivers/filesystems/fastfat_new/fastfat.h @@ -72,6 +72,10 @@ FatMapUserBuffer( NTSTATUS NTAPI FatDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); +VOID NTAPI +FatCreateRootDcb(IN PFAT_IRP_CONTEXT IrpContext, + IN PVCB Vcb); + /* -------------------------------------------------------- create.c */ NTSTATUS NTAPI diff --git a/reactos/drivers/filesystems/fastfat_new/fatstruc.h b/reactos/drivers/filesystems/fastfat_new/fatstruc.h index 7b739c6a0ff..1524e4fe947 100644 --- a/reactos/drivers/filesystems/fastfat_new/fatstruc.h +++ b/reactos/drivers/filesystems/fastfat_new/fatstruc.h @@ -215,10 +215,21 @@ enum _FCB_NAME_TYPE { typedef struct _FCB_NAME_LINK { RTL_SPLAY_LINKS Links; - UNICODE_STRING String; + union + { + OEM_STRING Ansi; + UNICODE_STRING String; + } Name; UCHAR Type; } FCB_NAME_LINK, *PFCB_NAME_LINK; +typedef enum _FCB_CONDITION +{ + FcbGood, + FcbBad, + FcbNeedsToBeVerified +} FCB_CONDITION; + typedef struct _FCB { FSRTL_ADVANCED_FCB_HEADER Header; @@ -228,35 +239,47 @@ typedef struct _FCB * FCB into paged and non paged parts * (as it is done in MS implementation */ - FAST_MUTEX HeaderMutex; + FAST_MUTEX HeaderMutex; // nonpaged! SECTION_OBJECT_POINTERS SectionObjectPointers; - ERESOURCE Resource; - ERESOURCE PagingIoResource; + ERESOURCE Resource; // nonpaged! + ERESOURCE PagingIoResource; // nonpaged! FILE_LOCK Lock; + /* First cluster in the fat allocation chain */ + ULONG FirstClusterOfFile; + /* A list of all FCBs of that DCB */ + LIST_ENTRY ParentDcbLinks; /* Reference to the Parent Dcb*/ struct _FCB *ParentFcb; /* Pointer to a Vcb */ PVCB Vcb; + /* Fcb state */ + ULONG State; + /* Fcb condition */ + FCB_CONDITION Condition; /* Mcb mapping Vbo->Lbo */ LARGE_MCB Mcb; ULONG FirstCluster; /* Links into FCB Trie */ - FCB_NAME_LINK FileName[0x2]; + FCB_NAME_LINK FileName; /* Buffer for the short name */ WCHAR ShortNameBuffer[0xc]; /* Full file name */ UNICODE_STRING FullFileName; + /* A copy of fat attribute byte */ + UCHAR DirentFatFlags; /* File basic info */ FILE_BASIC_INFORMATION BasicInfo; union { struct { + /* A list of all FCBs/DCBs opened under this DCB */ + LIST_ENTRY ParentDcbList; /* Directory data stream (just handy to have it). */ PFILE_OBJECT StreamFileObject; /* Bitmap to search for free dirents. */ - /* RTL_BITMAP Bitmap; */ + RTL_BITMAP FreeBitmap; PRTL_SPLAY_LINKS SplayLinks; } Dcb; }; diff --git a/reactos/drivers/filesystems/fastfat_new/fsctl.c b/reactos/drivers/filesystems/fastfat_new/fsctl.c index be5edc6293b..5ddb4d8de3b 100644 --- a/reactos/drivers/filesystems/fastfat_new/fsctl.c +++ b/reactos/drivers/filesystems/fastfat_new/fsctl.c @@ -124,6 +124,9 @@ FatMountVolume(PFAT_IRP_CONTEXT IrpContext, Status = FatInitializeVcb(IrpContext, &VolumeDevice->Vcb, TargetDeviceObject, Vpb); if (!NT_SUCCESS(Status)) goto FatMountVolumeCleanup; + /* Create root DCB for it */ + FatCreateRootDcb(IrpContext, &VolumeDevice->Vcb); + /* Keep trace of media changes */ VolumeDevice->Vcb.MediaChangeCount = MediaChangeCount; -- 2.17.1