📄 tfs.h
字号:
/* tfs.h:
* Header file for TFS transactions.
*
* General notice:
* This code is part of a boot-monitor package developed as a generic base
* platform for embedded system designs. As such, it is likely to be
* distributed to various projects beyond the control of the original
* author. Please notify the author of any enhancements made or bugs found
* so that all may benefit from the changes. In addition, notification back
* to the author will allow the new user to pick up changes that may have
* been made by other users after this version of the code was distributed.
*
* Author: Ed Sutter
* email: esutter@lucent.com (home: lesutter@worldnet.att.net)
* phone: 908-582-2351 (home: 908-889-5161)
*/
#ifndef _tfs_h
#define _tfs_h
#define SANITY 0xBEEF
#define ERASED16 0xFFFF
#define ERASED32 0xFFFFFFFF
#define TFS_MAXOPEN 10 /* Maximum of 10 open files */
#define TFS_QRYTMOUT 100000 /* Timeout for QRYBRUN */
#define TFS_FSIZEMOD 16 /* File size must be a multiple of this value */
#define MINUSRLEVEL 0 /* Minimum user level supported. */
#define MAXUSRLEVEL 3 /* Maximum user level supported. */
#define TFSINFOSIZE 23 /* Max size of info string (mod4-1). */
#define TFSHDRVERSION 1 /* Increment this if TFS header changes. */
#ifndef TFSNAMESIZE /* This specifies the maximum size of a file */
#define TFSNAMESIZE 23 /* name that can be used in TFS. */
#endif /* This MUST be some value mod4 - 1. */
#ifndef TFS_AUTODEFRAG /* Set to 1 typically, this allows tfsadd() */
#define TFS_AUTODEFRAG 1 /* to automatically do a defrag when it is */
#endif /* adding a file, but needs cleanup first. */
#ifndef TFS_CHANGELOG_FILE /* Information used for change-log */
#define TFS_CHANGELOG_SIZE 0 /* facility within tfs. */
#define TFS_CHANGELOG_FILE ".tfschlog"
#endif
#ifndef DEFRAG_TEST_ENABLED /* Enable testing for tfsclean() by */
#define DEFRAG_TEST_ENABLED 0 /* setting this flag to 1. */
#endif
/* NOTE that the "ifndef" macros above are provided as defaults. If
* there is a need to change any of them, do it in config.h
*/
#if TFS_EBIN_COFF
#define TFS_EBIN_NAME "coff"
#elif TFS_EBIN_AOUT
#define TFS_EBIN_NAME "aout"
#elif TFS_EBIN_ELF
#define TFS_EBIN_NAME "elf"
#else
#define TFS_EBIN_NAME "NA"
#endif
/* Flags: */
#define TFS_EXEC 0x00000001 /* 'e': Executable script. */
#define TFS_BRUN 0x00000002 /* 'b': To be executed at boot. */
#define TFS_QRYBRUN 0x00000004 /* 'B': To be executed at boot if */
/* query passes. */
#define TFS_EBIN 0x00000010 /* 'E': Executable binary (coff/elf/a.out). */
#define TFS_CPRS 0x00000040 /* 'c': File is compressed. */
#define TFS_IPMOD 0x00000080 /* 'i': File is in-place modifiable. */
#define TFS_UNREAD 0x00000100 /* 'u': File is not even readable if the */
/* user-level requirement is not met; */
/* else, it is read-only. */
#define TFS_ULVLMSK 0x00000600 /* User level mask defines 4 access levels: */
#define TFS_ULVL0 0x00000000 /* '0' level 0 */
#define TFS_ULVL1 0x00000200 /* '1' level 1 */
#define TFS_ULVL2 0x00000400 /* '2' level 2 */
#define TFS_ULVL3 0x00000600 /* '3' level 3 */
#define TFS_NSTALE 0x00000800 /* File is NOT stale, invisible to user.
* When this bit is clear, the file is
* considered stale (see notes in tfsadd()).
* See notes in tfsclose() for this.
*/
#define TFS_ACTIVE 0x00008000 /* Used to indicate that file is not deleted. */
#define TFS_ULVLMAX TFS_ULVL3
#define TFS_USRLVL(f) ((f->flags & TFS_ULVLMSK) >> 9)
/* Open modes */
#define TFS_RDONLY 0x00010000 /* File is opened for reading. */
#define TFS_CREATE 0x00020000 /* File is to be created. */
#define TFS_APPEND 0x00040000 /* Append to existing file or */
/* create new file. */
#define TFS_ALLFFS 0x00080000 /* File is created with all FFs. */
/* Masks used to allow flags and modes to be part of the same long word. */
#define TFS_FLAGMASK 0x0000ffff
#define TFS_MODEMASK 0xffff0000
/* Definitions used by the fixup algorithm. */
#define TFSFIXUPDONE 0x00000000
#define TFSFIXUPNA 0xFFFFFFFF
/* Requests that can be made to tfsctrl(): */
#define TFS_ERRMSG 1
#define TFS_MEMUSE 2
#define TFS_MEMDEAD 3
#define TFS_DEFRAG 4
#define TFS_TELL 5
#define TFS_UNOPEN 7
#define TFS_FATOB 8
#define TFS_FBTOA 9
#define TFS_MEMAVAIL 10
#define TFS_TIMEFUNCS 11
#define TFS_DOCOMMAND 12
#define TFS_INITDEV 13
#define TFS_CHECKDEV 14
#define TFS_DEFRAGDEV 15
/* Definitions related to tfslog: */
#define TFSLOG_ADD 0
#define TFSLOG_DEL 1
#define TFSLOG_IPM 2
#define TFSLOG_ON 3
#define TFSLOG_OFF 4
#define TIME_UNDEFINED 0xffffffff
/* Used by tfsscript.. */
#define EXIT_SCRIPT 1
#define REMOVE_SCRIPT 2
/* Macros used for partial-header-copy in defragmentation... */
#define TFS_PHCBITS 0xF0000000
#define TFS_PHCSTARTED 0xE0000000
#define TFS_PHCCOPIED 0xC0000000
#define TFS_PHCDONE 0x80000000
#define PHC_IS_STARTED(x) ((x & TFS_PHCBITS) == TFS_PHCSTARTED)
#define PHC_IS_COPIED(x) ((x & TFS_PHCBITS) == TFS_PHCCOPIED)
#define PHC_IS_DONE(x) ((x & TFS_PHCBITS) == TFS_PHCDONE)
#define GET_PHC_VALUE(x) (x & ~TFS_PHCBITS)
#define SET_PHC_STARTED(x) (GET_PHC_VALUE(x) | TFS_PHCSTARTED)
#define SET_PHC_COPIED(x) (GET_PHC_VALUE(x) | TFS_PHCCOPIED)
#define SET_PHC_DONE(x) (GET_PHC_VALUE(x) | TFS_PHCDONE)
/* struct tfshdr:
* It is in FLASH as part of the file system to record the attributes of
* the file at the time of creation.
*/
struct tfshdr {
unsigned short hdrsize; /* Size of this header. */
unsigned short hdrvrsn; /* Header version #. */
long filsize; /* Size of the file. */
long flags; /* Flags describing the file. */
unsigned long filcrc; /* 32 bit CRC of file. */
unsigned long hdrcrc; /* 32 bit CRC of the header. */
unsigned long modtime; /* Time when file was last modified. */
struct tfshdr *next; /* Pointer to next file in list. */
char name[TFSNAMESIZE+1]; /* Name of file. */
char info[TFSINFOSIZE+1]; /* Miscellaneous info field. */
};
#define TFSHDRSIZ sizeof(struct tfshdr)
/* Device Table structure and definitions:
* The Device table is typically only one entry in length. It is defined
* on a per-target basis in the file tfsdev.h. In the simplest case, the
* table in tfsdev.h has all of the information in it. This is fine as long
* as there is no need to support different devices with the same monitor
* binary. To support the ability to have a device-table that is constructed
* based on the type of flash on-board, the TFS_DEVINFO_DYNAMIC bit must
* be set in the devinfo member of tfsdevtbl (in tfsdev.h). This tells TFS
* to figure out the addresses based on a few assumptions...
* * Regardless of the device type, the start address will be the same.
* * The spare sector starts immediately after the end of TFS storage space.
* In dynamic mode, all that need be specified in the tfsdevtbl of tfsdev.h
* is the prefix, start and devinfo fields. The other fields will be built
* based on information taken from the flash interface.
* One important note: if there is a block of contiguous flash space that
* spans accross multiple flash banks, then the bank # of the last bank in
* that block is what should be specified in the devinfo BANKMASK field.
*/
#define TFSEOT 0xffffffff
#define TDEV struct tfsdev
#define TFS_DEVTYPE_RAM 0x00001000
#define TFS_DEVTYPE_FLASH 0x00002000
#define TFS_DEVTYPE_MASK 0x0000f000
#define TFS_DEVINFO_DYNAMIC 0x00000800
#define TFS_DEVINFO_BANKMASK 0x000007ff
#define TFSDEVTOT ((sizeof(tfsdevtbl))/(sizeof(struct tfsdev)))
struct tfsdev {
char *prefix; /* Device name prefix. */
unsigned long start; /* First location into which TFS can */
/* begin to store files. */
unsigned long end; /* Last address into which TFS can */
/* place file data. This is usually */
/* one unit below the start of the */
/* spare sector. */
unsigned long spare; /* Start address of device spare */
/* sector. */
unsigned long sparesize; /* Size of device spare sector. */
unsigned long sectorcount; /* Number of sectors in this device. */
unsigned long devinfo; /* RAM or FLASH, etc... */
};
/* TFS defragmentation process:
Allocate the last (or first) sector to be dedicated as the SPARE sector.
Save enough space at the end of file system space to support one
defraghdr structure per valid file. Plus about 128 bytes for keeping
track of defragmentation state.
1. Erase SPARE sector.
2. Mark the end of the file system indicating that defragmentation
is in progress.
3. Copy the standard headers of all non-deleted files to a table of
defraghdr structures that is placed at the end of the flash space
allocated to TFS (but not used by the spare sector).
4. For (N=0;N<TFSSECTORS;N++) {
a. copy sector[N] to SPARE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -