Included Files
- #include <nut/include/fs/fs.h>
- #include <nut/include/sys/nutdebug.h>
- #include <nut/include/stdio.h>
- #include <nut/include/fcntl.h>
- #include <nut/include/sys/stat.h>
- #include <nut/include/include2/string.h>
- #include <nut/include/errno.h>
- #include <nut/include/dirent.h>
- #include <nut/include/dev/spi_at45dib.h>
- #include <nut/include/fs/uflashfs.h>
Preprocessor definitions
#define UFLASH_MAX_BLOCKS 8192
#define UFLASH_BLOCK_UNITS 4
#define UFLASH_ENTRIES 128
#define UFLASH_USAGE_CACHE 32
#define UFLASH_MAX_PATH 0
#define UFLASH_BLOCK_INVALID
#define UFLASH_VOLF_FIXED 0x80
typedef uint16_t blknum_t
typedef uint_fast16_t blknum_fast_t
typedef struct _BLOCK_USAGE BLOCK_USAGE
struct _BLOCK_USAGE
|
|
{
|
|
uint8_t use_cnt;
|
|
blknum_t use_phyblk;
|
|
}
|
|
typedef struct _BLOCKHEAD BLOCKHEAD
struct _BLOCKHEAD
|
|
{
|
|
blknum_t bh_logblk;
|
|
blknum_t bh_version;
|
|
blknum_t bh_entblk;
|
|
blknum_t bh_entseq;
|
|
}
|
|
typedef struct _BLOCKFOOT BLOCKFOOT
struct _BLOCKFOOT
|
|
{
|
|
uint8_t bf_wear;
|
|
}
|
|
typedef struct _ENTRYHEAD ENTRYHEAD
struct _ENTRYHEAD
|
|
{
|
|
uint8_t eh_attr;
|
|
uint8_t eh_nlen;
|
|
}
|
|
typedef struct _UFLASHENTRY UFLASHENTRY
struct _UFLASHENTRY
|
|
{
|
|
blknum_t ent_id;
|
|
uint32_t ent_pos;
|
|
blknum_t ent_bidx;
|
|
uint16_t ent_sidx;
|
|
uint16_t ent_uidx;
|
|
uint16_t ent_upos;
|
|
uint32_t ent_mode;
|
|
uint8_t ent_attr;
|
|
uint8_t ent_namlen;
|
|
uint32_t ent_size;
|
|
uint16_t ent_eoff;
|
|
}
|
|
typedef struct _UFLASHVOLUME UFLASHVOLUME
struct _UFLASHVOLUME
struct _UFLASHVOLUME
|
|
{
|
|
NUTSERIALFLASH* vol_ifc;
|
|
HANDLE vol_mutex;
|
|
uint8_t vol_attrib;
|
|
blknum_t vol_blocks;
|
|
blknum_t* vol_l2p;
|
|
}
|
|
typedef struct _UFLASHFIND UFLASHFIND
struct _UFLASHFIND
|
|
{
|
|
blknum_t uff_lbe;
|
|
char* uff_path;
|
|
}
|
|
NUTDEVICE devUFlash0
NUTDEVICE devUFlash1
Local Variables
min_used
static BLOCK_USAGE min_used[32]
int UFlashAttach ( NUTDEVICE* dev, NUTSERIALFLASH* sfi, NUTSPIBUS* bus )
void UFlashDetach ( NUTDEVICE* dev )
int UFlashFormat ( NUTDEVICE* dev, NUTSERIALFLASH* sfi, NUTSPIBUS* bus )
static void CollectLeastUsed ( UFLASHVOLUME* vol, uint8_t* usage )
static int EntryCreate ( UFLASHVOLUME* vol, blknum_t lbe, ENTRYHEAD* eh, const char* name )
static void EntryPosInc ( NUTFILE* nfp, int step )
static void EntryPosSet ( NUTFILE* nfp, long pos )
static long EntryScan ( UFLASHVOLUME* vol, blknum_t lbe, time_t* mod )
static int EntrySearch ( UFLASHVOLUME* vol, const char* name, ENTRYHEAD* eh )
static int EntrySearchNext ( UFLASHVOLUME* vol, const char* name, ENTRYHEAD* eh, blknum_t lbs )
static blknum_t EntrySeek ( UFLASHVOLUME* vol, blknum_t lbe, blknum_t seq )
static int EntryTruncate ( UFLASHVOLUME* vol, blknum_t lbe )
static int EntryTruncateSeq ( UFLASHVOLUME* vol, int lbe )
static int FlashBlockCmpEntryName ( NUTSERIALFLASH* ifc, blknum_t b, const char* name, uint8_t len )
static int FlashCheckBlock ( NUTSERIALFLASH* ifc, blknum_t b )
static int FlashEraseBlockData ( NUTSERIALFLASH* ifc, blknum_t b )
static int FlashEraseBlocks ( NUTSERIALFLASH* ifc, int n )
static int FlashEraseEntry ( NUTSERIALFLASH* ifc, blknum_t b )
static int FlashReadBlockFoot ( NUTSERIALFLASH* ifc, blknum_t b, BLOCKFOOT* bf )
static int FlashReadBlockHead ( NUTSERIALFLASH* ifc, blknum_t b, BLOCKHEAD* bh )
static int FlashReadEntry ( NUTSERIALFLASH* ifc, blknum_t b, ENTRYHEAD* eh, char** name )
static void FlashUnitCommit ( NUTSERIALFLASH* ifc, blknum_t b, sf_unit_t unit )
static int FlashUnitCopy ( NUTSERIALFLASH* ifc, blknum_t b_src, blknum_t b_dst, sf_unit_t unit )
static int FlashUnitRead ( NUTSERIALFLASH* ifc, blknum_t b, sf_unit_t unit, int upos, void* data, int len )
static int FlashUnitWrite ( NUTSERIALFLASH* ifc, blknum_t b, sf_unit_t unit, int upos, const void* data, int len )
static int FlashWriteBlockFoot ( NUTSERIALFLASH* ifc, blknum_t b, BLOCKFOOT* bf )
static int FlashWriteBlockHead ( NUTSERIALFLASH* ifc, blknum_t b, BLOCKHEAD* bh )
static int FlashWriteEntry ( NUTSERIALFLASH* ifc, blknum_t b, const ENTRYHEAD* eh, const char* name )
static blknum_t LogBlkAllocate ( UFLASHVOLUME* vol, blknum_t lb )
static blknum_t LogBlkReallocate ( UFLASHVOLUME* vol, blknum_t lb )
static int LogBlkRelease ( UFLASHVOLUME* vol, blknum_t lb )
static blknum_t PhysBlkAllocate ( UFLASHVOLUME* vol, int level )
static int PhysBlkMove ( UFLASHVOLUME* vol, blknum_t src, blknum_t dst )
static int PhysBlkRequest ( UFLASHVOLUME* vol, int level, blknum_t n )
static blknum_t PhysBlkUnused ( UFLASHVOLUME* vol )
static int UFlashDirClose ( NUTFILE* ndp )
static NUTFILE* UFlashDirOpen ( NUTDEVICE* dev, const char* dpath )
static int UFlashDirRead ( DIR* dir )
static int UFlashFileClose ( NUTFILE* nfp )
static NUTFILE* UFlashFileOpen ( NUTDEVICE* dev, const char* path, int mode, int acc )
static int UFlashFileRead ( NUTFILE* nfp, void* data, int size )
static int UFlashFileRemove ( NUTDEVICE* dev, const char* name )
static int UFlashFileRename ( NUTDEVICE* dev, const char* old_path, const char* new_path )
static int UFlashFileSeek ( NUTFILE* nfp, long* pos, int whence )
static long UFlashFileSize ( NUTFILE* nfp )
static int UFlashFileStatus ( NUTDEVICE* dev, const char* name, struct stat* st )
static int UFlashFileWrite ( NUTFILE* nfp, const void* data, int len )
static int UFlashFileWrite_P ( NUTFILE* nfp, const char* buffer, int len )
static int UFlashIOCtl ( NUTDEVICE* dev, int req, void* conf )
static int UFlashInit ( NUTDEVICE* dev )
static int UFlashMount ( NUTDEVICE* dev )
static int UFlashUnmount ( NUTDEVICE* dev )