Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:43

0001 /**
0002  *  @file
0003  *
0004  *  @ingroup shared_tfs
0005  *
0006  *  @brief Header file for TFS transactions, used by both application and
0007  *  monnitor.
0008  */
0009 
0010 /*  Based upon code from MicroMonitor 1.17 from http://www.umonfw.com/
0011  *  which includes this notice:
0012  *
0013  **************************************************************************
0014  *  General notice:
0015  *  This code is part of a boot-monitor package developed as a generic base
0016  *  platform for embedded system designs.  As such, it is likely to be
0017  *  distributed to various projects beyond the control of the original
0018  *  author.  Please notify the author of any enhancements made or bugs found
0019  *  so that all may benefit from the changes.  In addition, notification back
0020  *  to the author will allow the new user to pick up changes that may have
0021  *  been made by other users after this version of the code was distributed.
0022  *
0023  *  Note1: the majority of this code was edited with 4-space tabs.
0024  *  Note2: as more and more contributions are accepted, the term "author"
0025  *         is becoming a mis-representation of credit.
0026  *
0027  *  Original author:    Ed Sutter
0028  *  Email:              esutter@alcatel-lucent.com
0029  *  Phone:              908-582-2351
0030  **************************************************************************
0031  *
0032  *  Ed Sutter has been informed that this code is being used in RTEMS.
0033  *
0034  *  This code was reformatted by Joel Sherrill from OAR Corporation and
0035  *  Fernando Nicodemos <fgnicodemos@terra.com.br> from NCB - Sistemas
0036  *  Embarcados Ltda. (Brazil) to be more compliant with RTEMS coding
0037  *  standards and to eliminate C++ style comments.
0038  */
0039 
0040 #ifndef _tfs_h
0041 #define _tfs_h
0042 
0043 /**
0044  *  @defgroup shared_tfs TFS Support
0045  *
0046  *  @ingroup shared_umon
0047  *
0048  *  @brief TFS Support Package
0049  */
0050 
0051 #define TFSINFOSIZE     23      /* Max size of info string (mod4-1). */
0052 
0053 #ifndef TFSNAMESIZE             /* This specifies the maximum size of a file */
0054 #define TFSNAMESIZE     23      /* name that can be used in TFS. */
0055 #endif                          /* This MUST be some value mod4 - 1. */
0056 
0057 #ifndef TFS_CHANGELOG_FILE      /* Information used for change-log */
0058 #define TFS_CHANGELOG_SIZE  0   /* facility within tfs. */
0059 #define TFS_CHANGELOG_FILE  ".tfschlog"
0060 #endif
0061 
0062 #ifndef SYMFILE                 /* This specifies the default filename */
0063 #define SYMFILE     "symtbl"    /* used by the monitor for the symbol */
0064 #endif                          /* table. */
0065 
0066 #define MINUSRLEVEL     0       /* Minimum user level supported. */
0067 #define MAXUSRLEVEL     3       /* Maximum user level supported. */
0068 
0069 #ifndef TFS_RESERVED
0070 #define TFS_RESERVED    4       /* Number of "reserved" entries (ulong) */
0071 #endif                          /* in the TFS header. */
0072 
0073 
0074 /* Flags: */
0075 #define TFS_EXEC    0x00000001  /* 'e': Executable script. */
0076 #define TFS_BRUN    0x00000002  /* 'b': To be executed at boot. */
0077 #define TFS_QRYBRUN 0x00000004  /* 'B': To be executed at boot if */
0078                                 /*      query passes. */
0079 #define TFS_SYMLINK 0x00000008  /* 'l': Symbolic link file. */
0080 #define TFS_EBIN    0x00000010  /* 'E': Executable binary (coff/elf/a.out). */
0081 #define TFS_CPRS    0x00000040  /* 'c': File is compressed. */
0082 #define TFS_IPMOD   0x00000080  /* 'i': File is in-place modifiable. */
0083 #define TFS_UNREAD  0x00000100  /* 'u': File is not even readable if the */
0084                                 /*      user-level requirement is not met; */
0085                                 /*      else, it is read-only. */
0086 #define TFS_ULVLMSK 0x00000600  /*  User level mask defines 4 access levels: */
0087 #define TFS_ULVL0   0x00000000  /* '0'  level 0 */
0088 #define TFS_ULVL1   0x00000200  /* '1'  level 1 */
0089 #define TFS_ULVL2   0x00000400  /* '2'  level 2 */
0090 #define TFS_ULVL3   0x00000600  /* '3'  level 3 */
0091 #define TFS_NSTALE  0x00000800  /* File is NOT stale, invisible to user.
0092                                  * When this bit is clear, the file is
0093                                  * considered stale (see notes in tfsadd()).
0094                                  * See notes in tfsclose() for this.
0095                                  */
0096 #define TFS_ACTIVE  0x00008000  /* Used to indicate that file is not deleted. */
0097 
0098 #define TFS_ULVLMAX TFS_ULVL3
0099 #define TFS_USRLVL(f)   ((f->flags & TFS_ULVLMSK) >> 9)
0100 
0101 /* Open modes */
0102 #define TFS_RDONLY      0x00010000  /* File is opened for reading. */
0103 #define TFS_CREATE      0x00020000  /* File is to be created. Error if file */
0104                                     /* with the same name already exists. */
0105 #define TFS_APPEND      0x00040000  /* Append to existing file.  If OR'ed */
0106                                     /* with TFS_CREATE, then create if */
0107                                     /* necessary. */
0108 #define TFS_ALLFFS      0x00080000  /* File is created with all FFs. */
0109 #define TFS_CREATERM    0x00100000  /* File is to be created. If file with */
0110                                     /* same name already exists, then allow */
0111                                     /* tfsadd() to remove it if necessary. */
0112 
0113 /* The function tfsrunrc() will search through the current file set and */
0114 /* if the file defined by TFS_RCFILE exists, it will be executed. */
0115 /* If this file exists, it will NOT be run by tfsrunboot(). */
0116 #define TFS_RCFILE      "monrc"
0117 
0118 /* Requests that can be made to tfsctrl(): */
0119 #define TFS_ERRMSG      1
0120 #define TFS_MEMUSE      2
0121 #define TFS_MEMDEAD     3
0122 #define TFS_DEFRAG      4
0123 #define TFS_TELL        5
0124 #define TFS_UNOPEN      7
0125 #define TFS_FATOB       8
0126 #define TFS_FBTOA       9
0127 #define TFS_MEMAVAIL    10
0128 #define TFS_TIMEFUNCS   11
0129 #define TFS_DOCOMMAND   12
0130 #define TFS_INITDEV     13
0131 #define TFS_CHECKDEV    14
0132 #define TFS_DEFRAGDEV   15
0133 #define TFS_DEFRAGOFF   16
0134 #define TFS_DEFRAGON    17
0135 #define TFS_HEADROOM    18
0136 #define TFS_FCOUNT      19
0137 
0138 /* struct tfshdr:
0139  *  It is in FLASH as part of the file system to record the attributes of
0140  *  the file at the time of creation.
0141  */
0142 struct tfshdr {
0143     unsigned short  hdrsize;        /* Size of this header.                 */
0144     unsigned short  hdrvrsn;        /* Header version #.                    */
0145     long    filsize;                /* Size of the file.                    */
0146     long    flags;                  /* Flags describing the file.           */
0147     unsigned long filcrc;           /* 32 bit CRC of file.                  */
0148     unsigned long hdrcrc;           /* 32 bit CRC of the header.            */
0149     unsigned long   modtime;        /* Time when file was last modified.    */
0150     struct  tfshdr  *next;          /* Pointer to next file in list.        */
0151     char    name[TFSNAMESIZE+1];    /* Name of file.                        */
0152     char    info[TFSINFOSIZE+1];    /* Miscellaneous info field.            */
0153 #if TFS_RESERVED
0154     unsigned long   rsvd[TFS_RESERVED];
0155 #endif
0156 };
0157 
0158 #define TFSHDRSIZ   sizeof(struct tfshdr)
0159 
0160 /* TFS error returns. */
0161 #define TFS_OKAY                0
0162 #define TFSERR_NOFILE           -1
0163 #define TFSERR_NOSLOT           -2
0164 #define TFSERR_EOF              -3
0165 #define TFSERR_BADARG           -4
0166 #define TFSERR_NOTEXEC          -5
0167 #define TFSERR_BADCRC           -6
0168 #define TFSERR_FILEEXISTS       -7
0169 #define TFSERR_FLASHFAILURE     -8
0170 #define TFSERR_WRITEMAX         -9
0171 #define TFSERR_RDONLY           -10
0172 #define TFSERR_BADFD            -11
0173 #define TFSERR_BADHDR           -12
0174 #define TFSERR_CORRUPT          -13
0175 #define TFSERR_MEMFAIL          -14
0176 #define TFSERR_NOTIPMOD         -16
0177 #define TFSERR_MUTEXFAILURE     -17
0178 #define TFSERR_FLASHFULL        -18
0179 #define TFSERR_USERDENIED       -19
0180 #define TFSERR_NAMETOOBIG       -20
0181 #define TFSERR_FILEINUSE        -21
0182 #define TFSERR_NOTCPRS          -22
0183 #define TFSERR_NOTAVAILABLE     -23
0184 #define TFSERR_BADFLAG          -24
0185 #define TFSERR_CLEANOFF         -25
0186 #define TFSERR_FLAKEYSOURCE     -26
0187 #define TFSERR_BADEXTENSION     -27
0188 #define TFSERR_MIN              -100
0189 
0190 /* TFS seek options. */
0191 #define TFS_BEGIN       1
0192 #define TFS_CURRENT     2
0193 #define TFS_END         3
0194 
0195 /* Macros: */
0196 #define TFS_DELETED(fp)     (!((fp)->flags & TFS_ACTIVE))
0197 #define TFS_FILEEXISTS(fp)  ((fp)->flags & TFS_ACTIVE)
0198 #define TFS_ISCPRS(fp)      ((fp)->flags & TFS_CPRS)
0199 #define TFS_ISEXEC(fp)      ((fp)->flags & TFS_EXEC)
0200 #define TFS_ISBOOT(fp)      ((fp)->flags & TFS_BRUN)
0201 #define TFS_ISLINK(fp)      ((fp)->flags & TFS_SYMLINK)
0202 #define TFS_STALE(fp)       (!((fp)->flags & TFS_NSTALE))
0203 #define TFS_FLAGS(fp)       ((fp)->flags)
0204 #define TFS_NAME(fp)        ((fp)->name)
0205 #define TFS_SIZE(fp)        ((fp)->filsize)
0206 #define TFS_TIME(fp)        ((fp)->modtime)
0207 #define TFS_INFO(fp)        ((fp)->info)
0208 #define TFS_NEXT(fp)        ((fp)->next)
0209 #define TFS_CRC(fp)         ((fp)->filcrc)
0210 #define TFS_ENTRY(fp)       ((fp)->entry)
0211 #define TFS_BASE(fp)        ((char *)(fp)+(fp)->hdrsize)
0212 
0213 typedef struct tfshdr TFILE;
0214 #endif