⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 ST5518机顶盒系统文件系统源代码!绝对超值!
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************    File Name   : utils.c    Description : Driver functions that may optionally be used in the final system.******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <assert.h>#include "stddefs.h"#include "stavfs.h"#include "sttbx.h"#include "cat.h"#include "dir.h"#include "root.h"#include "diskpart.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- */static U64 const InvalidLBA = {INVALID_LBA, INVALID_LBA};static U64 const NullLBA    = {NULL_LBA,    NULL_LBA};/* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- */#define STAVFS_CHECK_ALLOC_SIZE  /* Check the file allocation size *//* Private Function Prototypes --------------------------------------------- */static ST_ErrorCode_t stavfs_FSCheck       (stavfs_Device_t *Device_p, U32 Flags);static ST_ErrorCode_t stavfs_CATCheck      (stavfs_Device_t *Device_p, U32 Flags);static ST_ErrorCode_t stavfs_OpenCheck     (stavfs_Device_t *Device_p, U32 * Flags_p);static ST_ErrorCode_t stavfs_CheckOpenInDir(stavfs_Device_t *Device_p,                                            stavfs_DirEntry_t *Dir_p, U32 * Flags_p);/* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : STAVFS_FileSystemCheck  Description : Check/fix any file system errors.   Parameters :******************************************************************************/ST_ErrorCode_t STAVFS_FileSystemCheck (ST_DeviceName_t Name, U32 Flags){    ST_ErrorCode_t   Error    = ST_NO_ERROR;    stavfs_Device_t *Device_p = NULL;    if (Name == NULL || (Device_p = stavfs_GetDevice(Name)) == NULL)    {        Error = ST_ERROR_UNKNOWN_DEVICE;    }    else    {        /* Lock the device */        semaphore_wait (&(Device_p->DeviceLock));                if (Device_p->OpenHandles > 0)        {            Error = ST_ERROR_OPEN_HANDLE;        }        else        {            stavfs_DiskPartitionTable_t PartitionInfo;                        /* re-read the partiton table because a FormatPartition function               may have been called since Intitialising */                        if (ST_NO_ERROR != (Error = stavfs_ReadPartitionTable (Device_p, &PartitionInfo)))            {            }            /* Make sure partition is AVFS */            else if (PartitionInfo.Type != AVFS_PARTITION)            {                Error = STAVFS_ERROR_NOT_AVFS_PARTITION;            }            else            {                stavfs_RootSector_t RootSector;                I64_SetValue (PartitionInfo.StartLBA, 0, Device_p->RootSectorLBA);                              /* Read the partitions root sector to set up device */                if (ST_NO_ERROR != (Error = stavfs_ReadRootSector (Device_p, &RootSector)))                {                    /* Error Reading Root Sector */                }                else if (RootSector.Version != ROOT_PARTITION_VERSION)                {                    Error = STAVFS_ERROR_BAD_AVFS_VERSION;                }                else if ((Flags & STAVFS_FSCK_FORCE) ||                         (RootSector.StateFlags & (ROOT_PARTITION_FLAG_INUSE |                                                   ROOT_PARTITION_FLAG_BAD)))                {                    U64 TmpSize;                                        /* Set up the device */                                RootSector.StateFlags |= ROOT_PARTITION_FLAG_INUSE;                    stavfs_WriteRootSector(Device_p, &RootSector);                    Device_p->RootDirLBA      = RootSector.DirStart;                    Device_p->ClusterSize     = RootSector.ClusterSize;                    Device_p->DataSize        = RootSector.DataSize;                    Device_p->DataStartLBA    = RootSector.DataStart;                                        INT_I64_DivLit(RootSector.DataSize, CLUSTER_BLOCK_SIZE(Device_p), TmpSize);                    Device_p->NumClusterBlock = TmpSize.LSW;                                        /* Read in the root directory */                                        if (ST_NO_ERROR != (Error = stavfs_OpenRootDir(Device_p)))                    {                        STTBX_Print (("Failed to open the root directory.\n"));                    }                                        /* Read the Master CAT */                                        else if (ST_NO_ERROR != (Error = stavfs_OpenCat(Device_p)))                    {                        Error  = stavfs_InitCat(Device_p);                        Flags |= STAVFS_FSCK_REBUILD_MCAT;                    }                                         /* Do a file system check */                        if (Error == ST_NO_ERROR)                    {                        Error = stavfs_FSCheck(Device_p, Flags);                    }                                        if (Error == ST_NO_ERROR)                    {                        /* Clear the file system */                                                RootSector.StateFlags &= ~(ROOT_PARTITION_FLAG_INUSE |                                                   ROOT_PARTITION_FLAG_BAD);                        Error = stavfs_WriteRootSector(Device_p, &RootSector);                    }                }            }        }            /* Release the device */        semaphore_signal (&(Device_p->DeviceLock));    }    return (Error);}/******************************************************************************Function Name: DefragPartition  Description: Simple defrag routine   Parameters:******************************************************************************/ST_ErrorCode_t STAVFS_FileSystemDefragmentation (STAVFS_Handle_t Handle){    return (ST_NO_ERROR);}/******************************************************************************Function Name : STAVFS_Abort  Description : Abort the current operation.   Parameters :******************************************************************************/ST_ErrorCode_t STAVFS_Abort (STAVFS_Handle_t Handle){    return (ST_ERROR_FEATURE_NOT_SUPPORTED);}/******************************************************************************Function Name : stavfs_FSCheck  Description : Check/fix any file system errors.   Parameters :******************************************************************************/static ST_ErrorCode_t stavfs_FSCheck(stavfs_Device_t *Device_p, U32 Flags){    ST_ErrorCode_t Error = ST_NO_ERROR;        /* Do a full Local CAT check */        if (Flags & STAVFS_FSCK_REBUILD_MCAT)    {        /*         * We must do this before stavfs_OpenCheck() because if the         * STAVFS_FSCK_REBUILD_MCAT flag is set it assumes the Master         * CAT has already been rebuilt, and won't do it a second time.         */                 Error = stavfs_CATCheck(Device_p, Flags);    }        /* Check file open for write */        if (Error == ST_NO_ERROR)    {        Error = stavfs_OpenCheck(Device_p, &Flags);    }        return (Error);}/******************************************************************************Function Name : stavfs_CATCheck  Description : Check all the CAT's.   Parameters :******************************************************************************/static ST_ErrorCode_t stavfs_CATCheck(stavfs_Device_t *Device_p, U32 Flags){    ST_ErrorCode_t Error = ST_NO_ERROR;    stavfs_LocalCatCache_t *LocalCat_p;    U32 i;        for (i = 0; (i < Device_p->NumClusterBlock); i++)    {        ST_ErrorCode_t ThisError = ST_NO_ERROR;                /* Read and check the local CAT */                if (ST_NO_ERROR == (ThisError = stavfs_GetLocalCat(Device_p, i, &LocalCat_p)))        {               /* Check the entries */                        ThisError = stavfs_RebuildLocalCAT(Device_p, LocalCat_p, TRUE);                        /* Update the Master CAT */                        stavfs_UpdateMasterCAT(Device_p, i, LocalCat_p);                        /* Free up the cached Local CAT */                        if (ST_NO_ERROR != stavfs_ReleaseLocalCat(LocalCat_p))            {                ThisError = STAVFS_ERROR_UNWRITABLE_DISK;              }                    }                /* Log any errors */                if (ThisError != ST_NO_ERROR)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -