REVISION
Definition in file EAR_main.c.
#include "../SYSTEM/sys_hardware.h"
#include "../SYSTEM/sys_main.h"
#include "../MENU/tmplt.h"
#include "ear.h"
Include dependency graph for EAR_main.c:

Go to the source code of this file.
Functions | |
| BOOL | EAR_init (const char *drive) |
| Function initializes EAR module and checks to create the EAR file. | |
| BOOL | EAR_put (const char *drive, D2PEAR_ID id, PEAR_DATA pData, USHORT dataLen, long diskSpace) |
| Function adds an EAR entry to the EAR file. | |
| BOOL | EAR_getFirst (const char *drive, PEAR_DATA earData, BOOL bP2W) |
| Function gets the first EAR from the EAR file if available. | |
| BOOL | EAR_getNext (PEAR_DATA earData) |
| Function gets the next EAR from EAR file if there is any. | |
| void | EAR_getClose (void) |
| Function closes the EAR file. | |
| USHORT | EAR_checkSum (PEAR_DATA pData, USHORT dataLen, D2PEAR_ID id) |
| Function generates EAR entry checksum. | |
|
||||||||||||||||
|
Function generates EAR entry checksum.
Definition at line 312 of file EAR_main.c. Referenced by EAR_getNext(), and EAR_put(). 00313 {
00314 USHORT checkSum = dataLen + 3;
00315 USHORT tmp;
00316
00317 tmp = (checkSum & 0x0001)? 0x8000 : 0;
00318
00319 checkSum >>= 1;
00320
00321 checkSum += tmp + id;
00322
00323 /* Following to implement an unsigned short integer rotate right. */
00324 for(; dataLen != 0; dataLen--)
00325 {
00326 tmp = (checkSum & 0x0001)? 0x8000 : 0;
00327
00328 checkSum >>= 1;
00329
00330 checkSum += tmp + (*pData++);
00331 }
00332
00333 return checkSum;
00334 }
|
|
||||||||||||||||
|
Function gets the first EAR from the EAR file if available. This function shall open the EAR file and do all signature check.
Definition at line 207 of file EAR_main.c. References EAR_getNext(), FAT_cd(), FAT_fclose(), FAT_fopen(), FAT_fread(), and rb. Referenced by EAR_put(), and UI_processEAR(). 00208 {
00209 char strSYNCDIR[16];
00210 char strPC2WOIDEAR[16];
00211 st_EARHEADER earHeader;
00212
00213 GEN_readXstr((ULONG)text_syncDir, (USHORT*)strSYNCDIR, 16);
00214 if(TRUE == bP2W)
00215 GEN_readXstr((ULONG)text_pc2neurosEar, (USHORT*)strPC2WOIDEAR, 16);
00216 else
00217 GEN_readXstr((ULONG)text_neuros2pcEar, (USHORT*)strPC2WOIDEAR, 16);
00218
00219 FAT_cd(drive);
00220
00221 // If woid sync directory does not exist, no EAR is pending.
00222 if(FAT_cd(strSYNCDIR) == FALSE ) return FALSE;
00223
00224 // Check to see if EAR file exists.
00225 if( (_earfile = FAT_fopen(strPC2WOIDEAR, rb) ) == NULL ) return FALSE;
00226
00227 // Read EAR header.
00228 if(FAT_fread(_earfile, (USHORT *)&earHeader, sizeof(st_EARHEADER))
00229 == sizeof(st_EARHEADER) )
00230 {
00231 // Verify EAR header.
00232 if( (earHeader.manufactID == EAR_MANUFACTURE_ID ) &&
00233 (earHeader.signature == EAR_SIGNATURE) )
00234 {
00235 // Verifications all pass, try to fetch the first EAR.
00236 if( EAR_getNext(earData) == TRUE ) return TRUE;
00237 }
00238 }
00239
00240 // Close EAR file and reports error.
00241 FAT_fclose(_earfile);
00242
00243 return FALSE;
00244 }
|
Here is the call graph for this function:

|
|
Function gets the next EAR from EAR file if there is any.
Definition at line 256 of file EAR_main.c. References D2PEAR_ID, EAR_checkSum(), FAT_fread(), FAT_fseek(), File::ptr, and SEEK_HEAD. Referenced by EAR_getFirst(), EAR_put(), and UI_processEAR(). 00257 {
00258 unsigned long startOffset = _earfile->ptr;
00259 unsigned short tmp;
00260 unsigned short length;
00261
00262 while(1)
00263 {
00264 if(FAT_fread(_earfile, &tmp, 1) != 1) break;
00265
00266 if( tmp != EAR_SYNC_ID ) continue;
00267
00268 if(FAT_fread(_earfile, &length, 1) != 1) break;
00269
00270 if(length == 0) break;
00271
00272 // Read potential EAR ID, data and checksum.
00273 if(FAT_fread(_earfile, (unsigned short *)earData, length-1)
00274 != length-1) break;
00275
00276 // Check data checksum.
00277 if(earData[length-2] == EAR_checkSum( earData + 1,
00278 length - 3,
00279 (D2PEAR_ID)earData[0]) ) return TRUE;
00280
00281 // Checksum failed, start from next word.
00282 if( FAT_fseek( _earfile,
00283 startOffset + 1,
00284 SEEK_HEAD) == FALSE) break;
00285 }
00286
00287 return FALSE;
00288 }
|
Here is the call graph for this function:

|
|
Function initializes EAR module and checks to create the EAR file.
Definition at line 44 of file EAR_main.c. References st_EARHEADER::DIOSversion, FAT_cd(), FAT_fclose(), FAT_fopen(), FAT_fwrite(), FAT_mkdir(), GEN_zeroOut(), st_EARHEADER::manufactID, st_EARHEADER::pendingDiskSpace, st_EARHEADER::productID, rb, st_EARHEADER::reserved, st_EARHEADER::signature, st_EARHEADER::syncCtl, and wb. Referenced by EAR_put(). 00045 {
00046 File * file;
00047 st_EARHEADER earHeader;
00048 char strSYNCDIR[16];
00049 char strWOID2PCEAR[16];
00050
00051 GEN_readXstr((ULONG)text_syncDir, (USHORT*)strSYNCDIR, 16);
00052 GEN_readXstr((ULONG)text_neuros2pcEar, (USHORT*)strWOID2PCEAR, 16);
00053
00054 FAT_cd(drive);
00055 if(FAT_cd(strSYNCDIR) == FALSE)
00056 {
00057 if(FAT_mkdir(strSYNCDIR) == FALSE) return FALSE;
00058 if(FAT_cd(strSYNCDIR) == FALSE) return FALSE;
00059 }
00060
00061 file = FAT_fopen(strWOID2PCEAR, rb);
00062 if( file == NULL )
00063 {
00064 /* File does not exist, create new file and generate header. */
00065 file = FAT_fopen(strWOID2PCEAR, wb);
00066
00067 /* Form the EAR file header. */
00068 earHeader.manufactID = EAR_MANUFACTURE_ID;
00069
00070 earHeader.productID = EAR_PRODUCT_ID;
00071
00072 _versionStr2ASCII( (ULONG)text_OSversion,
00073 &earHeader.DIOSversion);
00074
00075 earHeader.syncCtl = (SYS_isHDDpresent())?1:0;
00076
00077 earHeader.pendingDiskSpace = 0L;
00078
00079 GEN_zeroOut((UINT *)earHeader.reserved, 7);
00080
00081 earHeader.signature = EAR_SIGNATURE;
00082
00083 FAT_fwrite(file, (USHORT *)&earHeader, sizeof(st_EARHEADER));
00084 }
00085
00086 /* Close EAR file. */
00087 return(FAT_fclose(file));
00088 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||
|
Function adds an EAR entry to the EAR file.
Definition at line 108 of file EAR_main.c. References ab, D2PEAR_ID, EAR_checkSum(), EAR_DATA, EAR_getClose(), EAR_getFirst(), EAR_getNext(), EAR_init(), FAT_fclose(), FAT_fopen(), FAT_fread(), FAT_fseek(), FAT_fwrite(), PEAR_DATA, st_SYNCLOG::pending, r_b, SEEK_HEAD, and st_SYSPARAM::synclog. Referenced by UI_earPut(). 00113 {
00114 File * file;
00115 USHORT tmp;
00116 char strWOID2PCEAR[16];
00117 EAR_DATA earData[MAX_DEVICE_EAR_LENGTH];
00118 EAR_DATA * pE;
00119 EAR_DATA * pD;
00120 long lTmp;
00121
00122 GEN_readXstr((ULONG)text_neuros2pcEar, (USHORT*)strWOID2PCEAR, 16);
00123
00124 if(EAR_init(drive) == FALSE) return FALSE;
00125
00126 // Check if EAR already exists.
00127 if(EAR_getFirst(drive, earData, FALSE) == TRUE)
00128 {
00129 do
00130 {
00131 pE = &earData[0];
00132 pD = pData;
00133 if(*pE++ == id)
00134 {
00135 USHORT ii;
00136
00137 for(ii = 0; ii<dataLen; ii++)
00138 {
00139 if(*pE++ != *pD++) break;
00140 }
00141 if(ii == dataLen)
00142 {
00143 EAR_getClose();
00144 return TRUE;
00145 }
00146 }
00147 } while( EAR_getNext(earData) == TRUE );
00148
00149 EAR_getClose();
00150 }
00151
00152 file = FAT_fopen(strWOID2PCEAR, ab);
00153
00154 /* Put EAR sync ID. */
00155 tmp = EAR_SYNC_ID;
00156 FAT_fwrite(file, &tmp, 1);
00157
00158 // Put EAR entry length = data length + actID cell
00159 // + length cell + checksum cell.
00160 tmp = dataLen + 3;
00161
00162 FAT_fwrite(file, &tmp, 1);
00163
00164 /* Put EAR action ID. */
00165 FAT_fwrite(file, (unsigned short *)&id, 1);
00166
00167 /* Put entry data. */
00168 FAT_fwrite(file, pData, dataLen);
00169
00170 /* Calculate checksum. */
00171 tmp = EAR_checkSum(pData, dataLen, id);
00172
00173 /* Put checksum. */
00174 FAT_fwrite(file, &tmp, 1);
00175
00176 sysParam.synclog.pending++;
00177
00178 /* Close EAR file. */
00179 FAT_fclose(file);
00180
00181 // Modify pending disk space field if needed.
00182 file = FAT_fopen(strWOID2PCEAR, r_b);
00183 FAT_fseek(file, 5, SEEK_HEAD);
00184 FAT_fread(file, (USHORT*)&lTmp, 2);
00185 FAT_fseek(file, 5, SEEK_HEAD);
00186 lTmp += diskSpace;
00187 FAT_fwrite(file, (USHORT*)&lTmp, 2);
00188 FAT_fclose(file);
00189
00190 return TRUE;
00191 }
|
Here is the call graph for this function:

1.3.9.1