Added "support" for the 64 bit data structures of EHCI in appendix B, in case the...
[cake.git] / tools / adflib / adf_env.c
blobaf5b059fe501498599290a82219747c988077f2c
1 /*
2 * ADF Library
4 * adf_env.c
6 */
8 #include<stdio.h>
9 #include<stdlib.h>
11 #include"adf_defs.h"
12 #include"adf_str.h"
13 #include"adf_nativ.h"
14 #include"adf_env.h"
16 #include"defendian.h"
18 union u{
19 long l;
20 char c[4];
23 ENV_DECLARATION;
25 void rwHeadAccess(SECTNUM physical, SECTNUM logical, BOOL write)
27 /* display the physical sector, the logical block, and if the access is read or write */
29 fprintf(stderr, "phy %ld / log %ld : %c\n", physical, logical, write ? 'W' : 'R');
32 void progressBar(int perCentDone)
34 fprintf(stderr,"%d %% done\n",perCentDone);
37 void Warning(char* msg) {
38 fprintf(stderr,"Warning <%s>\n",msg);
41 void Error(char* msg) {
42 fprintf(stderr,"Error <%s>\n",msg);
43 // exit(1);
46 void Verbose(char* msg) {
47 fprintf(stderr,"Verbose <%s>\n",msg);
50 void Changed(SECTNUM nSect, int changedType)
52 /* switch(changedType) {
53 case ST_FILE:
54 fprintf(stderr,"Notification : sector %ld (FILE)\n",nSect);
55 break;
56 case ST_DIR:
57 fprintf(stderr,"Notification : sector %ld (DIR)\n",nSect);
58 break;
59 case ST_ROOT:
60 fprintf(stderr,"Notification : sector %ld (ROOT)\n",nSect);
61 break;
62 default:
63 fprintf(stderr,"Notification : sector %ld (???)\n",nSect);
65 */}
68 * adfInitEnv
71 void adfEnvInitDefault()
73 // char str[80];
74 union u val;
76 /* internal checking */
78 if (sizeof(short)!=2)
79 { fprintf(stderr,"Compilation error : sizeof(short)!=2\n"); exit(1); }
80 if (sizeof(long)!=4)
81 { fprintf(stderr,"Compilation error : sizeof(short)!=2\n"); exit(1); }
82 if (sizeof(struct bEntryBlock)!=512)
83 { fprintf(stderr,"Internal error : sizeof(struct bEntryBlock)!=512\n"); exit(1); }
84 if (sizeof(struct bRootBlock)!=512)
85 { fprintf(stderr,"Internal error : sizeof(struct bRootBlock)!=512\n"); exit(1); }
86 if (sizeof(struct bDirBlock)!=512)
87 { fprintf(stderr,"Internal error : sizeof(struct bDirBlock)!=512\n"); exit(1); }
88 if (sizeof(struct bBootBlock)!=1024)
89 { fprintf(stderr,"Internal error : sizeof(struct bBootBlock)!=1024\n"); exit(1); }
90 if (sizeof(struct bFileHeaderBlock)!=512)
91 { fprintf(stderr,"Internal error : sizeof(struct bFileHeaderBlock)!=512\n"); exit(1); }
92 if (sizeof(struct bFileExtBlock)!=512)
93 { fprintf(stderr,"Internal error : sizeof(struct bFileExtBlock)!=512\n"); exit(1); }
94 if (sizeof(struct bOFSDataBlock)!=512)
95 { fprintf(stderr,"Internal error : sizeof(struct bOFSDataBlock)!=512\n"); exit(1); }
96 if (sizeof(struct bBitmapBlock)!=512)
97 { fprintf(stderr,"Internal error : sizeof(struct bBitmapBlock)!=512\n"); exit(1); }
98 if (sizeof(struct bBitmapExtBlock)!=512)
99 { fprintf(stderr,"Internal error : sizeof(struct bBitmapExtBlock)!=512\n"); exit(1); }
100 if (sizeof(struct bLinkBlock)!=512)
101 { fprintf(stderr,"Internal error : sizeof(struct bLinkBlock)!=512\n"); exit(1); }
103 val.l=1L;
104 /* if LITT_ENDIAN not defined : must be BIG endian */
105 #ifndef LITT_ENDIAN
106 if (val.c[3]!=1) /* little endian : LITT_ENDIAN must be defined ! */
107 { fprintf(stderr,"Compilation error : #define LITT_ENDIAN must exist\n"); exit(1); }
108 #else
109 if (val.c[3]==1) /* big endian : LITT_ENDIAN must not be defined ! */
110 { fprintf(stderr,"Compilation error : #define LITT_ENDIAN must not exist\n"); exit(1); }
111 #endif
113 adfEnv.wFct = Warning;
114 adfEnv.eFct = Error;
115 adfEnv.vFct = Verbose;
116 adfEnv.notifyFct = Changed;
117 adfEnv.rwhAccess = rwHeadAccess;
118 adfEnv.progressBar = progressBar;
120 adfEnv.useDirCache = FALSE;
121 adfEnv.useRWAccess = FALSE;
122 adfEnv.useNotify = FALSE;
123 adfEnv.useProgressBar = FALSE;
125 /* sprintf(str,"ADFlib %s (%s)",adfGetVersionNumber(),adfGetVersionDate());
126 (*adfEnv.vFct)(str);
128 adfEnv.nativeFct=(struct nativeFunctions*)malloc(sizeof(struct nativeFunctions));
129 if (!adfEnv.nativeFct) (*adfEnv.wFct)("adfInitDefaultEnv : malloc");
131 adfInitNativeFct();
136 * adfEnvCleanUp
139 void adfEnvCleanUp()
141 free(adfEnv.nativeFct);
146 * adfChgEnvProp
149 void adfChgEnvProp(int prop, void *new)
151 BOOL *newBool;
152 // int *newInt;
154 switch(prop) {
155 case PR_VFCT:
156 adfEnv.vFct = (void(*)(char*))new;
157 break;
158 case PR_WFCT:
159 adfEnv.wFct = (void(*)(char*))new;
160 break;
161 case PR_EFCT:
162 adfEnv.eFct = (void(*)(char*))new;
163 break;
164 case PR_NOTFCT:
165 adfEnv.notifyFct = (void(*)(SECTNUM,int))new;
166 break;
167 case PR_USE_NOTFCT:
168 newBool = (BOOL*)new;
169 adfEnv.useNotify = *newBool;
170 break;
171 case PR_PROGBAR:
172 adfEnv.progressBar = (void(*)(int))new;
173 break;
174 case PR_USE_PROGBAR:
175 newBool = (BOOL*)new;
176 adfEnv.useProgressBar = *newBool;
177 break;
178 case PR_USE_RWACCESS:
179 newBool = (BOOL*)new;
180 adfEnv.useRWAccess = *newBool;
181 break;
182 case PR_RWACCESS:
183 adfEnv.rwhAccess = (void(*)(SECTNUM,SECTNUM,BOOL))new;
184 break;
185 case PR_USEDIRC:
186 newBool = (BOOL*)new;
187 adfEnv.useDirCache = *newBool;
188 break;
193 * adfSetEnv
196 void adfSetEnvFct( void(*eFct)(char*), void(*wFct)(char*), void(*vFct)(char*),
197 void(*notFct)(SECTNUM,int) )
199 if (*eFct!=0)
200 adfEnv.eFct = *eFct;
201 if (*wFct!=0)
202 adfEnv.wFct = *wFct;
203 if (*vFct!=0)
204 adfEnv.vFct = *vFct;
205 if (*notFct!=0)
206 adfEnv.notifyFct = *notFct;
211 * adfGetVersionNumber
214 char* adfGetVersionNumber()
216 return(ADFLIB_VERSION);
221 * adfGetVersionDate
224 char* adfGetVersionDate()
226 return(ADFLIB_DATE);
232 /*##################################################################################*/