📄 fs_int.h
字号:
/*
**********************************************************************
* Micrium, Inc.
* 949 Crestview Circle
* Weston, FL 33327-1848
*
* uC/FS
*
* (c) Copyright 2001 - 2007, Micrium, Inc.
* All rights reserved.
*
***********************************************************************
**** 礐/FS file system for embedded applications ****
礐/FS is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : FS_Int.h
Purpose : Internals used accross different layers of the file system
---------------------------END-OF-HEADER------------------------------
*/
#ifndef _FS_INT_H_ // Avoid multiple/recursive inclusion
#define _FS_INT_H_
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "FS_Types.h"
#include "FS.h"
#include "FS_Debug.h"
#include "FS_ConfDefaults.h" /* FS Configuration */
#include "FS_OS.h"
#if FS_SUPPORT_FAT
#include "FAT.h"
#endif
#if FS_SUPPORT_EFS
#include "EFS.h"
#endif
#if defined(__cplusplus)
extern "C" { /* Make sure we have C-declarations in C++ programs */
#endif
/*********************************************************************
*
* Global defines
*
**********************************************************************
*/
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define ZEROFILL(p, Size) (memset(p, 0, Size))
/*********************************************************************
*
* Data types
*
**********************************************************************
*/
typedef struct {
int TypeMask; /* Combination of FS_SECTOR_TYPE_DATA, FS_SECTOR_TYPE_MAN, FS_SECTOR_TYPE_DIR */
int ModeMask; /* Combination of FS_CACHE_MODE_R, FS_CACHE_MODE_W, FS_CACHE_MODE_D */
} CACHE_MODE;
typedef struct {
int TypeMask; /* Combination of FS_SECTOR_TYPE_DATA, FS_SECTOR_TYPE_MAN, FS_SECTOR_TYPE_DIR */
int NumSectors; /* Number of sectors to use for the type(s) specified */
} CACHE_QUOTA;
typedef struct {
U32 FirstSector;
U32 NumSectors;
} CACHE_FREE;
/*********************************************************************
*
* FS_INFO
*
* The following structures are related:
* The first 3 entries of the structures in the union need to be identical.
*/
struct FS_FAT_INFO {
U32 NumSectors; // RSVD + FAT + ROOT + FATA
U16 BytesPerSec; // 512,1024,2048,4096
U16 ldBytesPerSector; // 9, 10, 11, 12
U32 FirstDataSector;
U32 BytesPerCluster;
U32 FATSize; // Number of FAT sectors
U32 RootDirPos; /* Position of root directory. FAT32: Cluster, FAT12/16: Sector */
U16 RootEntCnt; /* number of root dir entries */
U16 RsvdSecCnt; /* 1 for FAT12 & FAT16 */
U8 SecPerClus; /* sec in allocation unit */
U8 NumFATs; /* Typical value is 2 */
U8 FATType; /* FS_FAT_TYPE_FAT12/16/32 */
U32 NumClusters;
U32 NumFreeClusters; /* Once known, we keep track of the number of free clusters */
U32 NextFreeCluster; /* Once known, we keep track of the next free cluster */
#if FS_FAT_USE_FSINFO_SECTOR
U16 FSInfoSector;
#endif
};
struct FS_EFS_INFO {
U32 NumSectors; // RSVD + EFS alloc table + DATA
U16 BytesPerSector; // 512,1024,2048,4096
U16 ldBytesPerSector; // 9, 10, 11, 12
U32 FirstDataSector; // First data cluster -> First Sector after InfoSector, EFSAllocTable.
U32 BytesPerCluster; // Bytes for each cluster: 512 - 32768
U32 EFSTableSize; // EFS Alloc table size in no. of sectors
U32 RootDirPos; // Cluster that is used for the root directory
U8 SectorsPerCluster; // Number of sectors for a cluster
U32 NumClusters; // Number of available clusters
U32 NumFreeClusters; // Once known, we keep track of the number of free clusters
U32 NextFreeCluster; // Once known, we keep track of the next free cluster
};
typedef union {
FS_FAT_INFO FATInfo;
FS_EFS_INFO EFSInfo;
struct {
U32 NumSectors; // RSVD + EFS alloc table + DATA
U16 BytesPerSector; // 512,1024,2048,4096
U16 ldBytesPerSector; // 9, 10, 11, 12
} Info;
} FS_INFO;
typedef struct {
U8 Unit;
U8 IsInited;
U8 JournalIsActive;
U8 JournalUnit;
#if FS_SUPPORT_CACHE
const FS_CACHE_API * pCacheAPI;
void * pCacheData;
#endif
#if FS_SUPPORT_BUSY_LED
FS_BUSY_LED_CALLBACK * pfSetBusyLED;
#endif
#if FS_SUPPORT_CHECK_MEMORY
FS_MEMORY_IS_ACCESSIBLE_CALLBACK * pfMemoryIsAccessible;
#endif
} FS_DEVICE_DATA;
struct FS_DEVICE {
const FS_DEVICE_TYPE * pType;
FS_DEVICE_DATA Data;
};
struct FS_PARTITION {
FS_DEVICE Device;
U32 StartSector;
U32 NumSectors;
};
typedef void FS_CB_FCLOSE (FS_FILE * pFile);
typedef int FS_CB_CHECKINFOSECTOR(FS_VOLUME * pVolume);
typedef U32 FS_CB_FREAD (FS_FILE * pFile, void * pData, U32 NumBytes);
typedef U32 FS_CB_FWRITE (FS_FILE * pFile, const void * pData, U32 NumBytes);
typedef char FS_CB_FOPEN (const char * pFileName, FS_FILE * pFile, char DoDel, char DoOpen, char DoCreate);
typedef int FS_CB_OPENDIR (const char * pDirName, FS__DIR * pDir);
typedef int FS_CB_CLOSEDIR (FS__DIR * pDir);
typedef int FS_CB_READDIR (FS__DIR * pDir, FS_DIRENTRY_INFO * pDirEntryInfo);
typedef int FS_CB_REMOVEDIR (FS_VOLUME * pVolume, const char * pDirName);
typedef int FS_CB_CREATEDIR (FS_VOLUME * pVolume, const char * pDirName);
typedef int FS_CB_RENAME (const char * sOldName, const char * sNewName, FS_VOLUME * pVolume);
typedef int FS_CB_MOVE (const char * sOldName, const char * sNewName, FS_VOLUME * pVolume);
typedef char FS_CB_SETDIRENTRYINFO(FS_VOLUME * pVolume, const char * sName, const void * p, int Mask);
typedef char FS_CB_GETDIRENTRYINFO(FS_VOLUME * pVolume, const char * sName, void * p, int Mask);
typedef int FS_CB_SET_END_OF_FILE(FS_FILE * pFile);
typedef void FS_CB_UNMOUNT (FS_VOLUME * pVolume);
typedef struct {
FS_CB_CHECKINFOSECTOR * pfCheckInfoSector;
FS_CB_FOPEN * pfFOpen;
FS_CB_FCLOSE * pfFClose;
FS_CB_FREAD * pfFRead;
FS_CB_FWRITE * pfFWrite;
FS_CB_OPENDIR * pfOpenDir;
FS_CB_CLOSEDIR * pfCloseDir;
FS_CB_READDIR * pfReadDir;
FS_CB_REMOVEDIR * pfRemoveDir;
FS_CB_CREATEDIR * pfCreateDir;
FS_CB_RENAME * pfRename;
FS_CB_MOVE * pfMove;
FS_CB_SETDIRENTRYINFO * pfSetDirEntryInfo;
FS_CB_GETDIRENTRYINFO * pfGetDirEntryInfo;
FS_CB_SET_END_OF_FILE * pfSetEndOfFile;
FS_CB_UNMOUNT * pfUnmount;
} FS_FS_API;
struct FS_VOLUME {
FS_PARTITION Partition;
FS_INFO FSInfo;
U8 PartitionIndex;
U8 IsMounted;
U8 AllowAutoMount;
U8 InUse;
#if FS_SUPPORT_MULTIPLE_FS
const FS_FS_API * pFS_API;
#endif
};
/*********************************************************************
*
* Directory types
*/
struct FS_DIR {
FS__DIR Dir;
FS_DIRENT DirEntry;
I16 error; /* error code */
U8 InUse; /* handle in use mark */
};
/*********************************************************************
*
* File types
*/
typedef union {
struct {
U32 CurClusterFile; /* Current cluster within the file. First cluster is 0, next cluster is 1 ... */
U32 CurClusterAbs; /* Current cluster on the medium. This needs to be computed from file cluster, consulting the FAT */
U32 DirEntrySector; /* Sector of directory */
U16 DirEntryIndex; /* Index of directory entry */
U16 NumAdjClusters; /* Number of cluster that are sequentially in chain behind current one */
} Fat;
struct {
U32 DirCluster; /* Start cluster of directory file */
U32 DirEntryPos; /* Offset of directory entry in directory file */
U32 CurClusterFile; /* Current cluster within the file. First cluster is 0, next cluster is 1 ... */
U32 CurClusterAbs; /* Current cluster on the medium. This needs to be computed from file cluster, consulting the FAT */
U16 NumAdjClusters; /* Number of cluster that are sequentially in chain behind current one */
} Efs;
} FS_INT_DATA;
typedef struct { /* Describes the file object structure below the handle */
U32 FirstCluster; /* First cluster used for file */
U32 Size; /* size of file */
FS_VOLUME * pVolume;
U8 UseCnt; /* handle in use mark */
FS_INT_DATA Data;
#if FS_MULTI_HANDLE_SAFE
char acFullFileName[FS_MAX_LEN_FULL_FILE_NAME];
#endif
} FS_FILE_OBJ;
struct FS_FILE { /* Describes the file handle structure */
FS_FILE_OBJ * pFileObj;
U32 FilePos; /* current position in file */
I16 Error; /* error code */
U8 InUse; /* handle in use mark */
U8 AccessFlags;
};
/*********************************************************************
*
* Smart buffer (SB) type, internal
*
*/
struct FS_SB {
U32 SectorNo;
#if FS_MAINTAIN_FAT_COPY
U32 WriteCopyOff; /* Duplicate on write if value is != 0 */
#endif
FS_PARTITION * pPart;
U8 * pBuffer;
char IsDirty;
char HasError;
U8 Type;
U8 Read; /* 1 if data is valid, usually because the sector has been read */
};
/*********************************************************************
*
* Partition related
*/
U32 FS__GetMediaStartSecEx(FS_VOLUME * pVolume, U32 * pNumSectors, U8* pBuffer);
U32 FS__GetMediaStartSec(U8 PartIndex, U8 *pBuffer);
signed char FS__LocatePartition(FS_VOLUME * pVolume);
/*********************************************************************
*
* little endian translation functions, internal
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -