vfatMakeRootFCB函数是用来创建FAT文件系统的根目录,实现代码如下:
#001 PVFATFCB
#002 vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
#003 {
#004 PVFATFCB FCB;
#005 ULONG FirstCluster,CurrentCluster,Size = 0;
#006 NTSTATUS Status = STATUS_SUCCESS;
设置根目录名称。
#007 UNICODE_STRING NameU = RTL_CONSTANT_STRING(L"//");
#008
#009 FCB = vfatNewFCB(pVCB,&NameU);
#010 if (FCB->Flags & FCB_IS_FATX_ENTRY)
#011 {
如果扩展的FAT入口,就进行相应的扩展的FAT属性设置。
#012 memset(FCB->entry.FatX.Filename,' ',42);
设置FAT最大的文件大小。
#013 FCB->entry.FatX.FileSize = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
设置当前控制块为目录属性。
#014 FCB->entry.FatX.Attrib = FILE_ATTRIBUTE_DIRECTORY;
设置为第一簇。
#015 FCB->entry.FatX.FirstCluster = 1;
#016 Size = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
#017 }
#018 else
#019 {
设置FAT的属性。
#020 memset(FCB->entry.Fat.ShortName,11);
#021 FCB->entry.Fat.FileSize = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
#022 FCB->entry.Fat.Attrib = FILE_ATTRIBUTE_DIRECTORY;
#023 if (pVCB->FatInfo.FatType == FAT32)
#024 {
#025 CurrentCluster = FirstCluster = pVCB->FatInfo.RootCluster;
#026 FCB->entry.Fat.FirstCluster = (unsigned short)(FirstCluster & 0xffff);
#027 FCB->entry.Fat.FirstClusterHigh = (unsigned short)(FirstCluster >> 16);
#028
#029 while (CurrentCluster != 0xffffffff && NT_SUCCESS(Status))
#030 {
#031 Size += pVCB->FatInfo.BytesPerCluster;
#032 Status = NextCluster (pVCB,FirstCluster,&CurrentCluster,FALSE);
#033 }
#034 }
#035 else
#036 {
设置FAT16和FAT12的属性。
#037 FCB->entry.Fat.FirstCluster = 1;
#038 Size = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
#039 }
#040 }
#041 FCB->ShortHash.Hash = FCB->Hash.Hash;
#042 FCB->RefCount = 2;
#043 FCB->dirIndex = 0;
#044 FCB->RFCB.FileSize.QuadPart = Size;
#045 FCB->RFCB.ValidDataLength.QuadPart = Size;
#046 FCB->RFCB.AllocationSize.QuadPart = Size;
#047 FCB->RFCB.IsFastIoPossible = FastIoIsNotPossible;
#048
为文件控制块创建缓存。
#049 vfatFCBInitializeCacheFromVolume(pVCB,FCB);
#050 vfatAddFCBToTable(pVCB,FCB);
#051
#052 return(FCB);
#053}
原文链接:https://www.f2er.com/react/308394.html