utils.c
来自「ST5518机顶盒系统文件系统源代码!绝对超值!」· C语言 代码 · 共 522 行 · 第 1/2 页
C
522 行
{ Error = ThisError; } } /* Clear the unused entries */ stavfs_ClearUnusedMasterCAT(Device_p, LocalCat_p); /* Write the Master CAT back tp disk */ if (ST_NO_ERROR != stavfs_FlushCat (Device_p)) { Error = STAVFS_ERROR_UNWRITABLE_DISK; } return (Error);}/******************************************************************************Function Name : stavfs_OpenCheck Description : Check files open for write (or being deleted). Parameters :******************************************************************************/static ST_ErrorCode_t stavfs_OpenCheck(stavfs_Device_t *Device_p, U32 * Flags_p){ ST_ErrorCode_t Error = ST_NO_ERROR; /* Walk through the directories */ Error = stavfs_CheckOpenInDir(Device_p, NULL, Flags_p); return (Error);}/******************************************************************************Function Name : stavfs_CheckOpenInDir Description : Check the directory for files open for write (or being deleted). Parameters :******************************************************************************/static ST_ErrorCode_t stavfs_CheckOpenInDir(stavfs_Device_t *Device_p, stavfs_DirEntry_t *Dir_p, U32 * Flags_p){ ST_ErrorCode_t Error = ST_NO_ERROR; ST_ErrorCode_t ThisError = ST_NO_ERROR; stavfs_DirEntry_t *Entry_p = NULL; assert(Device_p != NULL); assert(Flags_p != NULL); /* Walk through the directories */ do { if (ST_NO_ERROR != stavfs_NextEntry(Device_p, Dir_p, &Entry_p)) { Error = STAVFS_ERROR_UNREADABLE_DISK; } else if (Entry_p != NULL) { if (Entry_p->Flags & FILE_FLAG_DIRECTORY) { /* Sub-directory */ STTBX_Print(("Sub-directory [%s]\n", Entry_p->Name)); if (ST_NO_ERROR != (ThisError = stavfs_CheckOpenInDir(Device_p, Entry_p, Flags_p))) { Error = ThisError; } } else if (Entry_p->Flags & (FILE_FLAG_BEING_DELETED | FILE_FLAG_OPEN_FOR_WRITE)) { /* Open for write or delete */ U64 ThisLBA; U32 Count = 0; if (Entry_p->Flags & FILE_FLAG_BEING_DELETED) { /* * If we crash while deleting a file the chain may have been * removed but the Master CAT not updated. With no chain, we * don't know which MCAT entries need correcting, so we have * to rebuild it all from scratch. We only need to this if it * has not been done already */ if (!(*Flags_p & STAVFS_FSCK_REBUILD_MCAT)) { *Flags_p |= STAVFS_FSCK_REBUILD_MCAT; if (ST_NO_ERROR != (ThisError = stavfs_CATCheck(Device_p, *Flags_p))) { Error = ThisError; } } } /* Set the start point */ #ifdef STAVFS_CHECK_ALLOC_SIZE ThisLBA = Entry_p->StartLBA;#else ThisLBA = Entry_p->EndLBA;#endif /* Check to see if there is a chain */ if (INT_I64_AreEqual(ThisLBA, NullLBA) || INT_I64_AreEqual(ThisLBA, InvalidLBA)) { /* No chain - remove the entry */ Entry_p->Flags = FILE_FLAG_ENTRY_UNUSED; stavfs_ModifyDirEntry(Device_p, Entry_p); } else { /* Check the first cluster */ U32 ThisClusterBlockId = 0; U32 ThisClusterIdx = 0; stavfs_LocalCatCache_t *ThisLocalCat_p = NULL; stavfs_GetClusterIdx(Device_p, &ThisClusterBlockId, &ThisClusterIdx, &ThisLBA); if (ST_NO_ERROR != (ThisError = stavfs_GetLocalCat(Device_p, ThisClusterBlockId, &ThisLocalCat_p))) { Error = ThisError; } else { /* Is the cluster allocated */ if (INT_I64_AreEqual(ThisLocalCat_p->Data.Cat[ThisClusterIdx].NextLBA, InvalidLBA) || INT_I64_AreEqual(ThisLocalCat_p->Data.Cat[ThisClusterIdx].PrevLBA, InvalidLBA)) { /* Cluster not allocated (eg crash at end of file delete) */ /* No chain - remove the entry. */ Entry_p->Flags = FILE_FLAG_ENTRY_UNUSED; stavfs_ModifyDirEntry(Device_p, Entry_p); } else { /* Cluster allocated */ /* Walk the chain */ ThisError = stavfs_WalkTheChain(Device_p, TRUE, &ThisLBA, &Count); if (ThisError != ST_NO_ERROR) { Error = ThisError; } /* Correct the end pointers */ if (INT_I64_AreNotEqual(ThisLBA, Entry_p->EndLBA)) { STTBX_Print(("Correct the directory end pointer\n")); stavfs_ModifyDirEntry(Device_p, Entry_p); Entry_p->EndLBA = ThisLBA; if (INT_I64_AreEqual(ThisLBA, NullLBA)) { STTBX_Print(("Correct the directory start pointer\n")); Entry_p->StartLBA = ThisLBA; } } /* Correct the alloc size */ #ifdef STAVFS_CHECK_ALLOC_SIZE if (Count != Entry_p->AllocSize.LSW) { STTBX_Print(("Correct the allocation size\n")); stavfs_ModifyDirEntry(Device_p, Entry_p); INT_I64_SetValue (Count, 0, Entry_p->AllocSize); }#else if (Count > 1) { STTBX_Print(("Correct the allocation size\n")); stavfs_ModifyDirEntry(Device_p, Entry_p); INT_I64_AddLit(Entry_p->AllocSize, Count-1, Entry_p->AllocSize) }#endif } ThisError = stavfs_RebuildLocalCAT(Device_p, ThisLocalCat_p, FALSE); if (ThisError != ST_NO_ERROR) { Error = ThisError; } /* Update master CAT incase any LCAT writes were not propagated before crash */ stavfs_UpdateMasterCAT(Device_p, ThisClusterBlockId, ThisLocalCat_p); /* Release the local cat */ stavfs_ReleaseLocalCat(ThisLocalCat_p); } } /* Finish deleting */ if (Entry_p->Flags & FILE_FLAG_BEING_DELETED) { /* Free up the allocated space */ STTBX_Print(("Complete an interrupted deletion\n")); while ((0 != stavfs_FreeClusterChain(Device_p, &ThisLBA)) && INT_I64_AreNotEqual(ThisLBA, NullLBA)) { } if (INT_I64_AreNotEqual(ThisLBA, NullLBA)) { /* We have failed to release the chain */ stavfs_SetClusterNext(Device_p, &ThisLBA, &NullLBA); Error = ST_ERROR_BAD_PARAMETER; } else { Entry_p->Flags = FILE_FLAG_ENTRY_UNUSED; stavfs_ModifyDirEntry(Device_p, Entry_p); } } /* Clear the open for write flag */ Entry_p->Flags &= ~FILE_FLAG_OPEN_FOR_WRITE; } } } while (Entry_p != NULL); /* Write the Master CAT back to disk before we flush directory entries saying it is okay */ if (ST_NO_ERROR != stavfs_FlushCat (Device_p)) { Error = STAVFS_ERROR_UNWRITABLE_DISK; } /* Write the directory */ if (ST_NO_ERROR != stavfs_FlushDir(Device_p, Dir_p)) { Error = STAVFS_ERROR_UNWRITABLE_DISK; } return (Error);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?