📄 avdevice.c
字号:
/****************************************************************************** File Name : avdevice.c Description : Generic device functions. These fuctions are related to the layout of data in the files system.******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <assert.h>#include <string.h>#include "root.h"#include "avdevice.h"#include "hal.h"#include "cat.h"#include "sttbx.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- *//* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- *//* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : stavfs_GetBackupLBA Description : Locate the backup area for any given LBA address in the partition (The root sector is handled separatly as a special case). Parameters :******************************************************************************/void stavfs_GetBackupLBA(stavfs_Device_t *Device_p, U64 const *LBA_p, U64 *BackupLBA_p){ assert (Device_p != NULL); assert (LBA_p != NULL); assert (BackupLBA_p != NULL); if (INT_I64_AreEqual(*LBA_p, Device_p->RootSectorLBA)) { *BackupLBA_p = Device_p->RootSectorLBA; INT_I64_AddLit(*BackupLBA_p, 1, *BackupLBA_p); } else if (INT_I64_IsGreaterOrEqual(*LBA_p, Device_p->DataStartLBA)) { U64 Offset; U64 Modulus; /* File data - find the Block and its backup LBA */ INT_I64_SetValue(0, 0, *BackupLBA_p); /* Find the LBA offset */ INT_I64_Sub(*LBA_p, Device_p->DataStartLBA, Offset); /* Reset to the start of block */ INT_I64_ModLit(Offset, CLUSTER_BLOCK_SIZE(Device_p), Modulus); INT_I64_Sub (Offset, Modulus, Offset); /* Get the absolute LBA address */ INT_I64_Add(Device_p->DataStartLBA, Offset, *BackupLBA_p); } else { /* Non-File data - Return the default backup */ /* Default backup area is the first section of the Master CAT */ /* Which starts immediatly after the root sector area */ *BackupLBA_p = Device_p->RootSectorLBA; INT_I64_AddLit(*BackupLBA_p, ROOT_SECTOR_AREA_SIZE, *BackupLBA_p); }}/******************************************************************************Function Name : stavfs_GetBackupLBA Description : Locate the backup area for any given LBA address in the partition (The root sector is handled separatly as a special case). Parameters :******************************************************************************/void stavfs_GetLocalCatLBA(stavfs_Device_t *Device_p, U64 const *LBA_p, U64 *CatLBA_p){ U64 Modulus; assert (Device_p != NULL); assert (LBA_p != NULL); assert (CatLBA_p != NULL); if (!INT_I64_IsGreaterOrEqual(*LBA_p, Device_p->DataStartLBA)) { /* Not in the file data area */ /* Use the first Local CAT */ INT_I64_SetValue(CLUSTER_BLOCK_SIZE(Device_p) - LOCAL_CAT_SIZE, 0, *CatLBA_p); } else { /* Find the LBA offset */ INT_I64_SetValue(0, 0, *CatLBA_p); INT_I64_Sub(*LBA_p, Device_p->DataStartLBA, *CatLBA_p); /* Reset to the start of block */ INT_I64_ModLit(*CatLBA_p, CLUSTER_BLOCK_SIZE(Device_p), Modulus); INT_I64_Sub (*CatLBA_p, Modulus, *CatLBA_p); /* Add in the offset within the File Block */ INT_I64_AddLit(*CatLBA_p, CLUSTER_BLOCK_SIZE(Device_p) - LOCAL_CAT_SIZE, *CatLBA_p); } /* Get the absolute LBA address */ INT_I64_Add(Device_p->DataStartLBA, *CatLBA_p, *CatLBA_p);}/******************************************************************************Function Name : stavfs_GetClusterIdx Description : Get the Cluster Block index for this LBA Parameters :******************************************************************************/void stavfs_GetClusterIdx(stavfs_Device_t *Device_p, U32 *BlockId_p, U32 *Idx_p, U64 const *LBA_p){ if (!INT_I64_IsGreaterOrEqual(*LBA_p, Device_p->DataStartLBA)) { /* Not in the file data area */ /* Default to the first Block */ *BlockId_p = 0; *Idx_p = 0; } else { U64 Offset; U64 Idx; U64 Mod; /* Find the LBA offset */ INT_I64_Sub(*LBA_p, Device_p->DataStartLBA, Offset); /* Find the index */ INT_I64_DivLit(Offset, CLUSTER_BLOCK_SIZE(Device_p), Idx); INT_I64_ModLit(Offset, CLUSTER_BLOCK_SIZE(Device_p), Mod); INT_I64_SubLit(Mod, FILE_BACKUP_SIZE(Device_p), Mod); INT_I64_DivLit(Mod, Device_p->ClusterSize, Mod); *BlockId_p = Idx.LSW; *Idx_p = Mod.LSW; /* Check that it is in the file area */ if (*BlockId_p >= Device_p->NumClusterBlock) { *BlockId_p = Device_p->NumClusterBlock-1; *Idx_p = CLUSTERS_PER_BLOCK(Device_p); } }}/******************************************************************************Function Name : stavfs_GetClusterLBA Description : LBA for the Cluster in the Cluster Block Parameters :******************************************************************************/void stavfs_GetClusterLBA (stavfs_Device_t *Device_p, U32 BlockId, U8 Idx, U64 *LBA_p){ /* Find the indexed LBA address */ INT_I64_SetValue(BlockId, 0, *LBA_p); INT_I64_MulLit (*LBA_p, CLUSTER_BLOCK_SIZE(Device_p), *LBA_p); INT_I64_AddLit(*LBA_p, FILE_BACKUP_SIZE(Device_p), *LBA_p); INT_I64_AddLit(*LBA_p, Idx*Device_p->ClusterSize, *LBA_p); INT_I64_Add(*LBA_p, Device_p->DataStartLBA, *LBA_p);}/******************************************************************************Function Name : stavfs_GetLCatLBA Description : LBA for the Local CAT in the Cluster Block Parameters :******************************************************************************/void stavfs_GetLCatLBA(stavfs_Device_t *Device_p, U32 BlockId, U64 *LBA_p){ /* Find the indexed LBA address */ INT_I64_SetValue(BlockId, 0, *LBA_p); INT_I64_MulLit (*LBA_p, CLUSTER_BLOCK_SIZE(Device_p), *LBA_p); INT_I64_AddLit(*LBA_p, FILE_BACKUP_SIZE(Device_p), *LBA_p); INT_I64_AddLit(*LBA_p, CLUSTERS_PER_BLOCK(Device_p)*Device_p->ClusterSize, *LBA_p); INT_I64_Add(*LBA_p, Device_p->DataStartLBA, *LBA_p);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -