当用户删除文件时,就会通过ReactOS@H_502_2@的API@H_502_2@调用IO@H_502_2@管理器函数,然后创建IRP@H_502_2@包发送到文件系统驱动程序来,然后就调用下面函数来把文件分配的簇从FAT@H_502_2@分配表时删除。具体实现的代码如下:
#001 @H_502_2@static NTSTATUS@H_502_2@
#002 @H_502_2@FATDelEntry(@H_502_2@
#003 @H_502_2@IN PDEVICE_EXTENSION DeviceExt,@H_502_2@
#004 @H_502_2@IN PVFATFCB pFcb)@H_502_2@
#006 @H_502_2@ULONG CurrentCluster = 0,NextCluster,i;@H_502_2@
#007 @H_502_2@PVOID Context = NULL;@H_502_2@
#008 @H_502_2@LARGE_INTEGER Offset;@H_502_2@
#009 @H_502_2@PFAT_DIR_ENTRY pDirEntry;@H_502_2@
#011 @H_502_2@ASSERT(pFcb);@H_502_2@
#012 @H_502_2@ASSERT(pFcb->parentFcb);@H_502_2@
#014 @H_502_2@DPRINT("delEntry PathName /'%wZ/'/n",&pFcb->PathNameU);@H_502_2@
#015 @H_502_2@DPRINT("delete entry: %d to %d/n",pFcb->startIndex,pFcb->dirIndex);@H_502_2@
@H_502_2@
下面开始从目录项里找到首簇开始位置。@H_502_2@@H_502_2@
#016 @H_502_2@Offset.u.HighPart = 0;@H_502_2@
#017 @H_502_2@for (i = pFcb->startIndex; i <= pFcb->dirIndex; i++)@H_502_2@
#019 @H_502_2@if (Context == NULL || ((i * sizeof(FAT_DIR_ENTRY)) % PAGE_SIZE) == 0)@H_502_2@
#021 @H_502_2@if (Context)@H_502_2@
#023 @H_502_2@CcSetDirtyPinnedData(Context,NULL);@H_502_2@
#024 @H_502_2@CcUnpinData(Context);@H_502_2@
#026 @H_502_2@Offset.u.LowPart = (i * sizeof(FAT_DIR_ENTRY) / PAGE_SIZE) * PAGE_SIZE;@H_502_2@
#027 @H_502_2@CcPinRead(pFcb->parentFcb->FileObject,&Offset,PAGE_SIZE,TRUE,@H_502_2@
#028 @H_502_2@&Context,(PVOID*)&pDirEntry);@H_502_2@
@H_502_2@
#030 @H_502_2@pDirEntry[i % (PAGE_SIZE / sizeof(FAT_DIR_ENTRY))].Filename[0] = 0xe5;@H_502_2@
@H_502_2@
#031 @H_502_2@if (i == pFcb->dirIndex)@H_502_2@
#033 @H_502_2@CurrentCluster =@H_502_2@
#034 @H_502_2@vfatDirEntryGetFirstCluster(DeviceExt,@H_502_2@
#035 @H_502_2@(PDIR_ENTRY)&pDirEntry[i % (PAGE_SIZE / sizeof(FAT_DIR_ENTRY))]);@H_502_2@
#038 @H_502_2@if (Context)@H_502_2@
#040 @H_502_2@CcSetDirtyPinnedData(Context,NULL);@H_502_2@
#041 @H_502_2@CcUnpinData(Context);@H_502_2@
@H_502_2@
下面开始删除所有使用的簇,也就是把FAT@H_502_2@表上标记为0.@H_502_2@@H_502_2@
#044 @H_502_2@while (CurrentCluster && CurrentCluster != 0xffffffff)@H_502_2@
#046 @H_502_2@GetNextCluster(DeviceExt,CurrentCluster,&NextCluster);@H_502_2@
#047 @H_502_2@/* FIXME: check status */@H_502_2@
#048 @H_502_2@WriteCluster(DeviceExt,0);@H_502_2@
#049 @H_502_2@CurrentCluster = NextCluster;@H_502_2@
#051 @H_502_2@return STATUS_SUCCESS;@H_502_2@
#052}@H_502_2@
原文链接:https://www.f2er.com/react/308385.html