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