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

📄 backup.c

📁 ST5518机顶盒系统文件系统源代码!绝对超值!
💻 C
字号:
/******************************************************************************    File Name   : backup.c    Description : This API implements the backup on write policy for file                  system data. The backup on write policy is intended to                  ensure that is any file system write becomes corrupted then                  it can be recovered.******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <assert.h>#include <string.h>#include "backup.h"#include "root.h"#include "hal.h"#include "sttbx.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- *//* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- *//* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : stavfs_BOWRead  Description : Do a BOW Read. Read the specified file system data automaticaly                recovering on error.   Parameters :******************************************************************************/ST_ErrorCode_t stavfs_BOWRead(stavfs_Device_t *Device, U64 *LBA, U16 Sectors, U8 *Data){    ST_ErrorCode_t Error = ST_NO_ERROR;    #ifndef STAVFS_NO_BACKUP_ON_WRITE    U32 CRC;#endif        assert (NULL != Data);    assert (NULL != LBA);    assert (NULL != Device);    /* Read the partition's first sector (root sector) */    if (ST_NO_ERROR != stavfs_HalRead(Device->HALData, LBA, Sectors, (char*)Data, FALSE))    {	 STTBX_Print(("Unable to read the root sector\n"));         Error = STAVFS_ERROR_UNREADABLE_DISK;    }#ifndef STAVFS_NO_BACKUP_ON_WRITE    else    {        /* If the CRC is wrong then read the back up */        CRC = 0XFFFFFFFF;        stavfs_DoBufferCRC((char*)Data +sizeof(U64),                           Sectors*DISK_SECTOR_SIZE -sizeof(U64),                           &CRC);        if (CRC != 0)        {            U64 BackupLBA;                        stavfs_GetBackupLBA(Device, LBA, &BackupLBA);             if (ST_NO_ERROR != stavfs_HalRead(Device->HALData, &BackupLBA, Sectors, (char*)Data, FALSE))            {                 STTBX_Print(("Unable to read the root sector\n"));                 Error = STAVFS_ERROR_UNREADABLE_DISK;            }                        /* Check the LBA addess for the backup data */                        else if (INT_I64_AreNotEqual(*LBA, *((U64*)Data)))            {                 STTBX_Print(("Backup invalid for this read\n"));                 Error = STAVFS_ERROR_CORRUPT_DISK;            }            else            {                /* Check for corrupt backup data */                                CRC = 0XFFFFFFFF;                stavfs_DoBufferCRC((char*)Data +sizeof(U64),                                   Sectors*DISK_SECTOR_SIZE -sizeof(U64),                                   &CRC);                 if (CRC != 0)                {                     STTBX_Print(("Root sector corrupt\n"));                     Error = STAVFS_ERROR_CORRUPT_DISK;                }                else                {                    /* Write back the restored data */                                        if (ST_NO_ERROR != stavfs_HalWrite(Device->HALData, LBA, Sectors, (char*)Data, FALSE))                    {                         STTBX_Print(("Unable to read the root sector\n"));                         Error = STAVFS_ERROR_CORRUPT_DISK;                    }                }            }        }    }#endif          return (Error);}/******************************************************************************Function Name : stavfs_BOWWrite  Description : Do a BOW Write. Write the specified file system data automaticaly                making a backup.   Parameters :******************************************************************************/ST_ErrorCode_t stavfs_BOWWrite(stavfs_Device_t *Device, U64 *LBA, U16 Sectors, U8 *Data){    ST_ErrorCode_t Error = ST_NO_ERROR;    #ifndef STAVFS_NO_BACKUP_ON_WRITE    U64 BackupLBA;    U32 CRC;#endif        assert (NULL != Data);    assert (NULL != LBA);    assert (NULL != Device);            #ifndef STAVFS_NO_BACKUP_ON_WRITE    stavfs_GetBackupLBA(Device, LBA, &BackupLBA);        /* Set the LBA feild */        *((U64*)Data) = *LBA;        /* Set the CRC */    CRC = 0XFFFFFFFF;    stavfs_DoBufferCRC((char*)Data +sizeof(U64),                       Sectors*DISK_SECTOR_SIZE-sizeof(CRC)-sizeof(U64),                       &CRC);        /* The CRC goes in the last four bytes of the Data */    /* Copy the CRC with byte swap for big-endian to little-endian */    *((U32*)(Data +Sectors*DISK_SECTOR_SIZE-sizeof(CRC))) =            (CRC >> 24) | (CRC << 24) | ((CRC >> 8) & 0X0000FF00) | ((CRC << 8) & 0X00FF0000);        /* Write the backup data to the second sector of the partition (root sector) */        if (ST_NO_ERROR != stavfs_HalWrite(Device->HALData, &BackupLBA, Sectors, (char*)Data, FALSE))    {	 STTBX_Print(("Unable to write the back up sector\n"));         Error = STAVFS_ERROR_UNWRITABLE_DISK;    }#endif          /* Write the data to the first sector of the partition (root sector) */       if (ST_NO_ERROR != stavfs_HalWrite(Device->HALData, LBA, Sectors, (char*)Data, FALSE))    {	 STTBX_Print(("Unable to write the root sector\n"));         Error = STAVFS_ERROR_UNWRITABLE_DISK;    }    return (Error);}

⌨️ 快捷键说明

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