RTEMS  5.1
tfs.h
Go to the documentation of this file.
1 
10 /* Based upon code from MicroMonitor 1.17 from http://www.umonfw.com/
11  * which includes this notice:
12  *
13  **************************************************************************
14  * General notice:
15  * This code is part of a boot-monitor package developed as a generic base
16  * platform for embedded system designs. As such, it is likely to be
17  * distributed to various projects beyond the control of the original
18  * author. Please notify the author of any enhancements made or bugs found
19  * so that all may benefit from the changes. In addition, notification back
20  * to the author will allow the new user to pick up changes that may have
21  * been made by other users after this version of the code was distributed.
22  *
23  * Note1: the majority of this code was edited with 4-space tabs.
24  * Note2: as more and more contributions are accepted, the term "author"
25  * is becoming a mis-representation of credit.
26  *
27  * Original author: Ed Sutter
28  * Email: esutter@alcatel-lucent.com
29  * Phone: 908-582-2351
30  **************************************************************************
31  *
32  * Ed Sutter has been informed that this code is being used in RTEMS.
33  *
34  * This code was reformatted by Joel Sherrill from OAR Corporation and
35  * Fernando Nicodemos <fgnicodemos@terra.com.br> from NCB - Sistemas
36  * Embarcados Ltda. (Brazil) to be more compliant with RTEMS coding
37  * standards and to eliminate C++ style comments.
38  */
39 
40 #ifndef _tfs_h
41 #define _tfs_h
42 
51 #define TFSINFOSIZE 23 /* Max size of info string (mod4-1). */
52 
53 #ifndef TFSNAMESIZE /* This specifies the maximum size of a file */
54 #define TFSNAMESIZE 23 /* name that can be used in TFS. */
55 #endif /* This MUST be some value mod4 - 1. */
56 
57 #ifndef TFS_CHANGELOG_FILE /* Information used for change-log */
58 #define TFS_CHANGELOG_SIZE 0 /* facility within tfs. */
59 #define TFS_CHANGELOG_FILE ".tfschlog"
60 #endif
61 
62 #ifndef SYMFILE /* This specifies the default filename */
63 #define SYMFILE "symtbl" /* used by the monitor for the symbol */
64 #endif /* table. */
65 
66 #define MINUSRLEVEL 0 /* Minimum user level supported. */
67 #define MAXUSRLEVEL 3 /* Maximum user level supported. */
68 
69 #ifndef TFS_RESERVED
70 #define TFS_RESERVED 4 /* Number of "reserved" entries (ulong) */
71 #endif /* in the TFS header. */
72 
73 
74 /* Flags: */
75 #define TFS_EXEC 0x00000001 /* 'e': Executable script. */
76 #define TFS_BRUN 0x00000002 /* 'b': To be executed at boot. */
77 #define TFS_QRYBRUN 0x00000004 /* 'B': To be executed at boot if */
78  /* query passes. */
79 #define TFS_SYMLINK 0x00000008 /* 'l': Symbolic link file. */
80 #define TFS_EBIN 0x00000010 /* 'E': Executable binary (coff/elf/a.out). */
81 #define TFS_CPRS 0x00000040 /* 'c': File is compressed. */
82 #define TFS_IPMOD 0x00000080 /* 'i': File is in-place modifiable. */
83 #define TFS_UNREAD 0x00000100 /* 'u': File is not even readable if the */
84  /* user-level requirement is not met; */
85  /* else, it is read-only. */
86 #define TFS_ULVLMSK 0x00000600 /* User level mask defines 4 access levels: */
87 #define TFS_ULVL0 0x00000000 /* '0' level 0 */
88 #define TFS_ULVL1 0x00000200 /* '1' level 1 */
89 #define TFS_ULVL2 0x00000400 /* '2' level 2 */
90 #define TFS_ULVL3 0x00000600 /* '3' level 3 */
91 #define TFS_NSTALE 0x00000800 /* File is NOT stale, invisible to user.
92  * When this bit is clear, the file is
93  * considered stale (see notes in tfsadd()).
94  * See notes in tfsclose() for this.
95  */
96 #define TFS_ACTIVE 0x00008000 /* Used to indicate that file is not deleted. */
97 
98 #define TFS_ULVLMAX TFS_ULVL3
99 #define TFS_USRLVL(f) ((f->flags & TFS_ULVLMSK) >> 9)
100 
101 /* Open modes */
102 #define TFS_RDONLY 0x00010000 /* File is opened for reading. */
103 #define TFS_CREATE 0x00020000 /* File is to be created. Error if file */
104  /* with the same name already exists. */
105 #define TFS_APPEND 0x00040000 /* Append to existing file. If OR'ed */
106  /* with TFS_CREATE, then create if */
107  /* necessary. */
108 #define TFS_ALLFFS 0x00080000 /* File is created with all FFs. */
109 #define TFS_CREATERM 0x00100000 /* File is to be created. If file with */
110  /* same name already exists, then allow */
111  /* tfsadd() to remove it if necessary. */
112 
113 /* The function tfsrunrc() will search through the current file set and */
114 /* if the file defined by TFS_RCFILE exists, it will be executed. */
115 /* If this file exists, it will NOT be run by tfsrunboot(). */
116 #define TFS_RCFILE "monrc"
117 
118 /* Requests that can be made to tfsctrl(): */
119 #define TFS_ERRMSG 1
120 #define TFS_MEMUSE 2
121 #define TFS_MEMDEAD 3
122 #define TFS_DEFRAG 4
123 #define TFS_TELL 5
124 #define TFS_UNOPEN 7
125 #define TFS_FATOB 8
126 #define TFS_FBTOA 9
127 #define TFS_MEMAVAIL 10
128 #define TFS_TIMEFUNCS 11
129 #define TFS_DOCOMMAND 12
130 #define TFS_INITDEV 13
131 #define TFS_CHECKDEV 14
132 #define TFS_DEFRAGDEV 15
133 #define TFS_DEFRAGOFF 16
134 #define TFS_DEFRAGON 17
135 #define TFS_HEADROOM 18
136 #define TFS_FCOUNT 19
137 
138 /* struct tfshdr:
139  * It is in FLASH as part of the file system to record the attributes of
140  * the file at the time of creation.
141  */
142 struct tfshdr {
143  unsigned short hdrsize; /* Size of this header. */
144  unsigned short hdrvrsn; /* Header version #. */
145  long filsize; /* Size of the file. */
146  long flags; /* Flags describing the file. */
147  unsigned long filcrc; /* 32 bit CRC of file. */
148  unsigned long hdrcrc; /* 32 bit CRC of the header. */
149  unsigned long modtime; /* Time when file was last modified. */
150  struct tfshdr *next; /* Pointer to next file in list. */
151  char name[TFSNAMESIZE+1]; /* Name of file. */
152  char info[TFSINFOSIZE+1]; /* Miscellaneous info field. */
153 #if TFS_RESERVED
154  unsigned long rsvd[TFS_RESERVED];
155 #endif
156 };
157 
158 #define TFSHDRSIZ sizeof(struct tfshdr)
159 
160 /* TFS error returns. */
161 #define TFS_OKAY 0
162 #define TFSERR_NOFILE -1
163 #define TFSERR_NOSLOT -2
164 #define TFSERR_EOF -3
165 #define TFSERR_BADARG -4
166 #define TFSERR_NOTEXEC -5
167 #define TFSERR_BADCRC -6
168 #define TFSERR_FILEEXISTS -7
169 #define TFSERR_FLASHFAILURE -8
170 #define TFSERR_WRITEMAX -9
171 #define TFSERR_RDONLY -10
172 #define TFSERR_BADFD -11
173 #define TFSERR_BADHDR -12
174 #define TFSERR_CORRUPT -13
175 #define TFSERR_MEMFAIL -14
176 #define TFSERR_NOTIPMOD -16
177 #define TFSERR_MUTEXFAILURE -17
178 #define TFSERR_FLASHFULL -18
179 #define TFSERR_USERDENIED -19
180 #define TFSERR_NAMETOOBIG -20
181 #define TFSERR_FILEINUSE -21
182 #define TFSERR_NOTCPRS -22
183 #define TFSERR_NOTAVAILABLE -23
184 #define TFSERR_BADFLAG -24
185 #define TFSERR_CLEANOFF -25
186 #define TFSERR_FLAKEYSOURCE -26
187 #define TFSERR_BADEXTENSION -27
188 #define TFSERR_MIN -100
189 
190 /* TFS seek options. */
191 #define TFS_BEGIN 1
192 #define TFS_CURRENT 2
193 #define TFS_END 3
194 
195 /* Macros: */
196 #define TFS_DELETED(fp) (!((fp)->flags & TFS_ACTIVE))
197 #define TFS_FILEEXISTS(fp) ((fp)->flags & TFS_ACTIVE)
198 #define TFS_ISCPRS(fp) ((fp)->flags & TFS_CPRS)
199 #define TFS_ISEXEC(fp) ((fp)->flags & TFS_EXEC)
200 #define TFS_ISBOOT(fp) ((fp)->flags & TFS_BRUN)
201 #define TFS_ISLINK(fp) ((fp)->flags & TFS_SYMLINK)
202 #define TFS_STALE(fp) (!((fp)->flags & TFS_NSTALE))
203 #define TFS_FLAGS(fp) ((fp)->flags)
204 #define TFS_NAME(fp) ((fp)->name)
205 #define TFS_SIZE(fp) ((fp)->filsize)
206 #define TFS_TIME(fp) ((fp)->modtime)
207 #define TFS_INFO(fp) ((fp)->info)
208 #define TFS_NEXT(fp) ((fp)->next)
209 #define TFS_CRC(fp) ((fp)->filcrc)
210 #define TFS_ENTRY(fp) ((fp)->entry)
211 #define TFS_BASE(fp) ((char *)(fp)+(fp)->hdrsize)
212 
213 typedef struct tfshdr TFILE;
214 #endif
Definition: tfs.h:142