1*12720SWyllys.Ingersoll@Sun.COM /*
2*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER START
3*12720SWyllys.Ingersoll@Sun.COM *
4*12720SWyllys.Ingersoll@Sun.COM * The contents of this file are subject to the terms of the
5*12720SWyllys.Ingersoll@Sun.COM * Common Development and Distribution License (the "License").
6*12720SWyllys.Ingersoll@Sun.COM * You may not use this file except in compliance with the License.
7*12720SWyllys.Ingersoll@Sun.COM *
8*12720SWyllys.Ingersoll@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12720SWyllys.Ingersoll@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*12720SWyllys.Ingersoll@Sun.COM * See the License for the specific language governing permissions
11*12720SWyllys.Ingersoll@Sun.COM * and limitations under the License.
12*12720SWyllys.Ingersoll@Sun.COM *
13*12720SWyllys.Ingersoll@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*12720SWyllys.Ingersoll@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12720SWyllys.Ingersoll@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*12720SWyllys.Ingersoll@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*12720SWyllys.Ingersoll@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*12720SWyllys.Ingersoll@Sun.COM *
19*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER END
20*12720SWyllys.Ingersoll@Sun.COM */
21*12720SWyllys.Ingersoll@Sun.COM
22*12720SWyllys.Ingersoll@Sun.COM /*
23*12720SWyllys.Ingersoll@Sun.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*12720SWyllys.Ingersoll@Sun.COM */
25*12720SWyllys.Ingersoll@Sun.COM
26*12720SWyllys.Ingersoll@Sun.COM /**
27*12720SWyllys.Ingersoll@Sun.COM * \file direct.h
28*12720SWyllys.Ingersoll@Sun.COM *
29*12720SWyllys.Ingersoll@Sun.COM * This file is included in KMSAgentStorage.cpp to provide file handling
30*12720SWyllys.Ingersoll@Sun.COM * hooks. It also contains our EEPROM file handling functions.
31*12720SWyllys.Ingersoll@Sun.COM *
32*12720SWyllys.Ingersoll@Sun.COM * HISTORY:
33*12720SWyllys.Ingersoll@Sun.COM * 8/6/07 BJB Added code for 9840D encryption sectors
34*12720SWyllys.Ingersoll@Sun.COM * 4/7/08 BJB Changed to remove 'file is junk' message - EVT
35*12720SWyllys.Ingersoll@Sun.COM * didn't like it.
36*12720SWyllys.Ingersoll@Sun.COM * 4/24/08 BJB Added function call back to T10000/9840D code
37*12720SWyllys.Ingersoll@Sun.COM * to lookup eeprom address -
38*12720SWyllys.Ingersoll@Sun.COM * so it isn't a hardcoded value.
39*12720SWyllys.Ingersoll@Sun.COM * 05/09/08 BJB Added being more conservative about EEPROM so as to change
40*12720SWyllys.Ingersoll@Sun.COM * frequency of 32CA problems
41*12720SWyllys.Ingersoll@Sun.COM *
42*12720SWyllys.Ingersoll@Sun.COM */
43*12720SWyllys.Ingersoll@Sun.COM
44*12720SWyllys.Ingersoll@Sun.COM
45*12720SWyllys.Ingersoll@Sun.COM #ifndef KMSAGENT_DIRECT_H
46*12720SWyllys.Ingersoll@Sun.COM #define KMSAGENT_DIRECT_H
47*12720SWyllys.Ingersoll@Sun.COM
48*12720SWyllys.Ingersoll@Sun.COM #include <stdio.h>
49*12720SWyllys.Ingersoll@Sun.COM #include <string.h>
50*12720SWyllys.Ingersoll@Sun.COM
51*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32
52*12720SWyllys.Ingersoll@Sun.COM #include <direct.h>
53*12720SWyllys.Ingersoll@Sun.COM #endif
54*12720SWyllys.Ingersoll@Sun.COM
55*12720SWyllys.Ingersoll@Sun.COM #define my_unlink(a) unlink(a)
56*12720SWyllys.Ingersoll@Sun.COM #define my_rmdir(a) rmdir(a)
57*12720SWyllys.Ingersoll@Sun.COM
58*12720SWyllys.Ingersoll@Sun.COM #ifndef METAWARE
59*12720SWyllys.Ingersoll@Sun.COM
60*12720SWyllys.Ingersoll@Sun.COM #define myFILE FILE
61*12720SWyllys.Ingersoll@Sun.COM
62*12720SWyllys.Ingersoll@Sun.COM #else // METAWARE
63*12720SWyllys.Ingersoll@Sun.COM
64*12720SWyllys.Ingersoll@Sun.COM #include "SYSCommon.h"
65*12720SWyllys.Ingersoll@Sun.COM #include "debug.h"
66*12720SWyllys.Ingersoll@Sun.COM #include <snprintf.h>
67*12720SWyllys.Ingersoll@Sun.COM
68*12720SWyllys.Ingersoll@Sun.COM extern "C" void ecpt_trace_msg(ECPT_TRACE_ENTRY*,const char*,...);
69*12720SWyllys.Ingersoll@Sun.COM
70*12720SWyllys.Ingersoll@Sun.COM extern char st[256];
71*12720SWyllys.Ingersoll@Sun.COM
72*12720SWyllys.Ingersoll@Sun.COM
73*12720SWyllys.Ingersoll@Sun.COM #ifndef I_KNOW_REAL_NAMES
74*12720SWyllys.Ingersoll@Sun.COM #undef fopen
75*12720SWyllys.Ingersoll@Sun.COM #undef fclose
76*12720SWyllys.Ingersoll@Sun.COM #undef fputs
77*12720SWyllys.Ingersoll@Sun.COM #undef fgets
78*12720SWyllys.Ingersoll@Sun.COM #undef fwrite
79*12720SWyllys.Ingersoll@Sun.COM #undef fread
80*12720SWyllys.Ingersoll@Sun.COM #undef unlink
81*12720SWyllys.Ingersoll@Sun.COM #undef rmdir
82*12720SWyllys.Ingersoll@Sun.COM
83*12720SWyllys.Ingersoll@Sun.COM #define fopen my_eeprom_fopen
84*12720SWyllys.Ingersoll@Sun.COM #define fclose my_eeprom_fclose
85*12720SWyllys.Ingersoll@Sun.COM #define fputs my_eeprom_fputs
86*12720SWyllys.Ingersoll@Sun.COM #define fwrite my_eeprom_fwrite
87*12720SWyllys.Ingersoll@Sun.COM #define fread my_eeprom_fread
88*12720SWyllys.Ingersoll@Sun.COM #define fgets my_eeprom_fgets
89*12720SWyllys.Ingersoll@Sun.COM #define unlink my_eeprom_unlink
90*12720SWyllys.Ingersoll@Sun.COM #define rmdir my_eeprom_rmdir
91*12720SWyllys.Ingersoll@Sun.COM
92*12720SWyllys.Ingersoll@Sun.COM #define my_eeprom_rmdir(a) (1)
93*12720SWyllys.Ingersoll@Sun.COM
94*12720SWyllys.Ingersoll@Sun.COM #endif
95*12720SWyllys.Ingersoll@Sun.COM
96*12720SWyllys.Ingersoll@Sun.COM
97*12720SWyllys.Ingersoll@Sun.COM #include "KMSClientProfile.h"
98*12720SWyllys.Ingersoll@Sun.COM extern char KMSAgent_Version[KMS_MAX_VERSION_LENGTH];
99*12720SWyllys.Ingersoll@Sun.COM
100*12720SWyllys.Ingersoll@Sun.COM unsigned char volatile* eeprom_addr_lookup_FILESYSTEM_START_ADDR(void);
101*12720SWyllys.Ingersoll@Sun.COM unsigned int EEPROM_Sector_size(void);
102*12720SWyllys.Ingersoll@Sun.COM
103*12720SWyllys.Ingersoll@Sun.COM #define FILESYSTEM_SECTOR (eeprom_addr_lookup_FILESYSTEM_START_ADDR())
104*12720SWyllys.Ingersoll@Sun.COM // was ((unsigned char volatile*)0xf20000) on 9840
105*12720SWyllys.Ingersoll@Sun.COM // was ((unsigned char volatile*)0x41dc0000) on T10000
106*12720SWyllys.Ingersoll@Sun.COM
107*12720SWyllys.Ingersoll@Sun.COM #define FILESYSTEM_SECTOR_SIZE (EEPROM_Sector_size())
108*12720SWyllys.Ingersoll@Sun.COM // was hardcoded 0x20000
109*12720SWyllys.Ingersoll@Sun.COM
110*12720SWyllys.Ingersoll@Sun.COM #define EEPROM_ERASED_BYTE 0xFF
111*12720SWyllys.Ingersoll@Sun.COM
112*12720SWyllys.Ingersoll@Sun.COM /* size of a file allowed (not counting the name) */
113*12720SWyllys.Ingersoll@Sun.COM #define EEPROM_FILE_SECT_SIZE 0x1800
114*12720SWyllys.Ingersoll@Sun.COM
115*12720SWyllys.Ingersoll@Sun.COM /* size of a file name allowed (+ the null) */
116*12720SWyllys.Ingersoll@Sun.COM #define EEPROM_FNAME_SIZE 0x80
117*12720SWyllys.Ingersoll@Sun.COM
118*12720SWyllys.Ingersoll@Sun.COM // 1000h = 4096d
119*12720SWyllys.Ingersoll@Sun.COM #define EEPROM_BLOCK_SIZE (EEPROM_FILE_SECT_SIZE - EEPROM_FNAME_SIZE - 4)
120*12720SWyllys.Ingersoll@Sun.COM
121*12720SWyllys.Ingersoll@Sun.COM /* number of 'files' available */
122*12720SWyllys.Ingersoll@Sun.COM #define FTABLE_SIZE 0x5
123*12720SWyllys.Ingersoll@Sun.COM
124*12720SWyllys.Ingersoll@Sun.COM
125*12720SWyllys.Ingersoll@Sun.COM #define UCHAR8 unsigned char
126*12720SWyllys.Ingersoll@Sun.COM #define UINT32 unsigned long
127*12720SWyllys.Ingersoll@Sun.COM
128*12720SWyllys.Ingersoll@Sun.COM
129*12720SWyllys.Ingersoll@Sun.COM extern "C" unsigned long
130*12720SWyllys.Ingersoll@Sun.COM EEPROM_Sector_Erase( unsigned char volatile *sector_address );
131*12720SWyllys.Ingersoll@Sun.COM
132*12720SWyllys.Ingersoll@Sun.COM extern "C" unsigned long
133*12720SWyllys.Ingersoll@Sun.COM Flash_Write( UCHAR8 *destinationP,
134*12720SWyllys.Ingersoll@Sun.COM UCHAR8 *sourceP,
135*12720SWyllys.Ingersoll@Sun.COM UINT32 byteCount);
136*12720SWyllys.Ingersoll@Sun.COM
137*12720SWyllys.Ingersoll@Sun.COM extern "C" unsigned long
138*12720SWyllys.Ingersoll@Sun.COM Flash_Read( UCHAR8 *dstP,
139*12720SWyllys.Ingersoll@Sun.COM UCHAR8 *srcP,
140*12720SWyllys.Ingersoll@Sun.COM UINT32 byteCount);
141*12720SWyllys.Ingersoll@Sun.COM
142*12720SWyllys.Ingersoll@Sun.COM /* a eeprom file */
143*12720SWyllys.Ingersoll@Sun.COM struct eepromBlockStruct
144*12720SWyllys.Ingersoll@Sun.COM {
145*12720SWyllys.Ingersoll@Sun.COM unsigned long fsize;
146*12720SWyllys.Ingersoll@Sun.COM char fname[EEPROM_FNAME_SIZE];
147*12720SWyllys.Ingersoll@Sun.COM unsigned char fdata[EEPROM_BLOCK_SIZE];
148*12720SWyllys.Ingersoll@Sun.COM };
149*12720SWyllys.Ingersoll@Sun.COM
150*12720SWyllys.Ingersoll@Sun.COM
151*12720SWyllys.Ingersoll@Sun.COM struct fileSystem
152*12720SWyllys.Ingersoll@Sun.COM {
153*12720SWyllys.Ingersoll@Sun.COM struct eepromBlockStruct ftable[FTABLE_SIZE];
154*12720SWyllys.Ingersoll@Sun.COM /* what level of toolkit wrote this - for
155*12720SWyllys.Ingersoll@Sun.COM future compatibility */
156*12720SWyllys.Ingersoll@Sun.COM char writingversion[KMS_MAX_VERSION_LENGTH+1];
157*12720SWyllys.Ingersoll@Sun.COM };
158*12720SWyllys.Ingersoll@Sun.COM
159*12720SWyllys.Ingersoll@Sun.COM
160*12720SWyllys.Ingersoll@Sun.COM #define MODE_WRITE 0x01
161*12720SWyllys.Ingersoll@Sun.COM #define MODE_READ 0x02
162*12720SWyllys.Ingersoll@Sun.COM
163*12720SWyllys.Ingersoll@Sun.COM #define MYFILE_CLOSED 0x0
164*12720SWyllys.Ingersoll@Sun.COM #define MYFILE_OPEN_READ 0x1
165*12720SWyllys.Ingersoll@Sun.COM #define MYFILE_OPEN_WRITE 0x2
166*12720SWyllys.Ingersoll@Sun.COM
167*12720SWyllys.Ingersoll@Sun.COM
168*12720SWyllys.Ingersoll@Sun.COM /* an open file */
169*12720SWyllys.Ingersoll@Sun.COM typedef struct fileStruct
170*12720SWyllys.Ingersoll@Sun.COM {
171*12720SWyllys.Ingersoll@Sun.COM unsigned char *readptr;
172*12720SWyllys.Ingersoll@Sun.COM unsigned long readsize;
173*12720SWyllys.Ingersoll@Sun.COM unsigned char *writeptr;
174*12720SWyllys.Ingersoll@Sun.COM struct eepromBlockStruct *memptr;
175*12720SWyllys.Ingersoll@Sun.COM unsigned long mode;
176*12720SWyllys.Ingersoll@Sun.COM unsigned long file_number;
177*12720SWyllys.Ingersoll@Sun.COM } myFILE;
178*12720SWyllys.Ingersoll@Sun.COM
179*12720SWyllys.Ingersoll@Sun.COM
180*12720SWyllys.Ingersoll@Sun.COM extern "C" myFILE *my_eeprom_fopen (const char *filename, const char *mode);
181*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fclose (myFILE *stream);
182*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fputs (const char *s, myFILE *stream);
183*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fwrite (const char *s, int size, int nobj, myFILE *f);
184*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fread (char *s, int size, int nobj, myFILE *f);
185*12720SWyllys.Ingersoll@Sun.COM extern "C" char *my_eeprom_fgets (char *s, int n, myFILE *stream);
186*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_unlink (const char *filename);
187*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fsys_erase(void);
188*12720SWyllys.Ingersoll@Sun.COM
189*12720SWyllys.Ingersoll@Sun.COM #ifndef FALSE
190*12720SWyllys.Ingersoll@Sun.COM #define FALSE 0
191*12720SWyllys.Ingersoll@Sun.COM #endif
192*12720SWyllys.Ingersoll@Sun.COM #ifndef TRUE
193*12720SWyllys.Ingersoll@Sun.COM #define TRUE 1
194*12720SWyllys.Ingersoll@Sun.COM #endif
195*12720SWyllys.Ingersoll@Sun.COM
196*12720SWyllys.Ingersoll@Sun.COM #ifdef DEFINE_STORAGE
197*12720SWyllys.Ingersoll@Sun.COM /* ram copy of the file system */
198*12720SWyllys.Ingersoll@Sun.COM struct fileSystem ramFileSystem;
199*12720SWyllys.Ingersoll@Sun.COM int file_read = FALSE;
200*12720SWyllys.Ingersoll@Sun.COM
201*12720SWyllys.Ingersoll@Sun.COM /* file state - open/closed/etc */
202*12720SWyllys.Ingersoll@Sun.COM unsigned long fstate[FTABLE_SIZE] = {MYFILE_CLOSED,
203*12720SWyllys.Ingersoll@Sun.COM MYFILE_CLOSED,
204*12720SWyllys.Ingersoll@Sun.COM MYFILE_CLOSED,
205*12720SWyllys.Ingersoll@Sun.COM MYFILE_CLOSED,
206*12720SWyllys.Ingersoll@Sun.COM MYFILE_CLOSED};
207*12720SWyllys.Ingersoll@Sun.COM #else
208*12720SWyllys.Ingersoll@Sun.COM /* ram copy of the file system */
209*12720SWyllys.Ingersoll@Sun.COM extern struct fileSystem ramFileSystem;
210*12720SWyllys.Ingersoll@Sun.COM extern int file_read;
211*12720SWyllys.Ingersoll@Sun.COM
212*12720SWyllys.Ingersoll@Sun.COM /* file state - open/closed/etc */
213*12720SWyllys.Ingersoll@Sun.COM extern unsigned long fstate[FTABLE_SIZE];
214*12720SWyllys.Ingersoll@Sun.COM
215*12720SWyllys.Ingersoll@Sun.COM #endif
216*12720SWyllys.Ingersoll@Sun.COM
217*12720SWyllys.Ingersoll@Sun.COM
218*12720SWyllys.Ingersoll@Sun.COM
219*12720SWyllys.Ingersoll@Sun.COM #ifdef DEFINE_STORAGE
220*12720SWyllys.Ingersoll@Sun.COM
221*12720SWyllys.Ingersoll@Sun.COM
222*12720SWyllys.Ingersoll@Sun.COM extern "C" unsigned long
223*12720SWyllys.Ingersoll@Sun.COM
224*12720SWyllys.Ingersoll@Sun.COM
225*12720SWyllys.Ingersoll@Sun.COM /* UNIT TEST */
226*12720SWyllys.Ingersoll@Sun.COM int TESTV = 0;
227*12720SWyllys.Ingersoll@Sun.COM
228*12720SWyllys.Ingersoll@Sun.COM /* UNIT TEST */
229*12720SWyllys.Ingersoll@Sun.COM #define MY_FLASH_READ(a,b,c) \
230*12720SWyllys.Ingersoll@Sun.COM Flash_Read(a,b,c); \
231*12720SWyllys.Ingersoll@Sun.COM if (TESTV++ < 5) { \
232*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[0].fname[0] = EEPROM_ERASED_BYTE; \
233*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[1].fsize = EEPROM_BLOCK_SIZE+1; \
234*12720SWyllys.Ingersoll@Sun.COM }
235*12720SWyllys.Ingersoll@Sun.COM
236*12720SWyllys.Ingersoll@Sun.COM
237*12720SWyllys.Ingersoll@Sun.COM
238*12720SWyllys.Ingersoll@Sun.COM /**
239*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fopen()
240*12720SWyllys.Ingersoll@Sun.COM * my filesystem fileopen
241*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fopen(const char * filename,const char * mode)242*12720SWyllys.Ingersoll@Sun.COM extern "C" myFILE *my_eeprom_fopen(const char *filename, const char *mode)
243*12720SWyllys.Ingersoll@Sun.COM {
244*12720SWyllys.Ingersoll@Sun.COM int i;
245*12720SWyllys.Ingersoll@Sun.COM myFILE *file;
246*12720SWyllys.Ingersoll@Sun.COM int open_for_write = TRUE;
247*12720SWyllys.Ingersoll@Sun.COM static int Firsttime = TRUE;
248*12720SWyllys.Ingersoll@Sun.COM int retries = 100;
249*12720SWyllys.Ingersoll@Sun.COM
250*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
251*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fopen ) ;
252*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg( trace, "file %s", (char*)filename);
253*12720SWyllys.Ingersoll@Sun.COM
254*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(filename);
255*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(mode);
256*12720SWyllys.Ingersoll@Sun.COM
257*12720SWyllys.Ingersoll@Sun.COM if ( (strcmp(mode,"wb") == 0) ||
258*12720SWyllys.Ingersoll@Sun.COM (strcmp(mode,"w") == 0))
259*12720SWyllys.Ingersoll@Sun.COM {
260*12720SWyllys.Ingersoll@Sun.COM // write
261*12720SWyllys.Ingersoll@Sun.COM open_for_write = TRUE;
262*12720SWyllys.Ingersoll@Sun.COM }
263*12720SWyllys.Ingersoll@Sun.COM else if ( (strcmp(mode,"r") == 0) ||
264*12720SWyllys.Ingersoll@Sun.COM (strcmp(mode,"rb") == 0) )
265*12720SWyllys.Ingersoll@Sun.COM {
266*12720SWyllys.Ingersoll@Sun.COM // read binary
267*12720SWyllys.Ingersoll@Sun.COM open_for_write = FALSE;
268*12720SWyllys.Ingersoll@Sun.COM }
269*12720SWyllys.Ingersoll@Sun.COM else
270*12720SWyllys.Ingersoll@Sun.COM {
271*12720SWyllys.Ingersoll@Sun.COM FATAL_APPLICATION_STATE("my_eeprom_fopen : Illegal mode");
272*12720SWyllys.Ingersoll@Sun.COM }
273*12720SWyllys.Ingersoll@Sun.COM
274*12720SWyllys.Ingersoll@Sun.COM /* read the file table from eeprom? */
275*12720SWyllys.Ingersoll@Sun.COM if (!file_read)
276*12720SWyllys.Ingersoll@Sun.COM {
277*12720SWyllys.Ingersoll@Sun.COM RETRY:
278*12720SWyllys.Ingersoll@Sun.COM
279*12720SWyllys.Ingersoll@Sun.COM MY_FLASH_READ((unsigned char *)&ramFileSystem,
280*12720SWyllys.Ingersoll@Sun.COM (unsigned char *)FILESYSTEM_SECTOR,
281*12720SWyllys.Ingersoll@Sun.COM sizeof(ramFileSystem));
282*12720SWyllys.Ingersoll@Sun.COM
283*12720SWyllys.Ingersoll@Sun.COM /* Audit the filesystem - if it looks junked, reclaim bad files */
284*12720SWyllys.Ingersoll@Sun.COM
285*12720SWyllys.Ingersoll@Sun.COM for (i=0; i < FTABLE_SIZE; i++)
286*12720SWyllys.Ingersoll@Sun.COM {
287*12720SWyllys.Ingersoll@Sun.COM if ( (ramFileSystem.ftable[i].fname[0] == EEPROM_ERASED_BYTE) ||
288*12720SWyllys.Ingersoll@Sun.COM (ramFileSystem.ftable[i].fsize > EEPROM_BLOCK_SIZE) )
289*12720SWyllys.Ingersoll@Sun.COM {
290*12720SWyllys.Ingersoll@Sun.COM /* if this looks bad, don't accept this outcome until
291*12720SWyllys.Ingersoll@Sun.COM 100 retries */
292*12720SWyllys.Ingersoll@Sun.COM if (retries-- > 0)
293*12720SWyllys.Ingersoll@Sun.COM {
294*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg( trace, "file was junk - retrying %s", (char*)filename);
295*12720SWyllys.Ingersoll@Sun.COM log_error_printf(
296*12720SWyllys.Ingersoll@Sun.COM "KMSAgent_direct::fopen file %d is junk - (name %x, "
297*12720SWyllys.Ingersoll@Sun.COM "size %x, data %x) RETRYING \n",
298*12720SWyllys.Ingersoll@Sun.COM i,
299*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fname[0],
300*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize ,
301*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fdata[0]);
302*12720SWyllys.Ingersoll@Sun.COM
303*12720SWyllys.Ingersoll@Sun.COM goto RETRY;
304*12720SWyllys.Ingersoll@Sun.COM }
305*12720SWyllys.Ingersoll@Sun.COM else
306*12720SWyllys.Ingersoll@Sun.COM {
307*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg( trace, "file was junk - formatting %s", (char*)filename);
308*12720SWyllys.Ingersoll@Sun.COM log_error_printf(
309*12720SWyllys.Ingersoll@Sun.COM "KMSAgent_direct::fopen file %d is junk - (name %x, "
310*12720SWyllys.Ingersoll@Sun.COM "size %x, data %x) formatting it\n",
311*12720SWyllys.Ingersoll@Sun.COM i,
312*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fname[0],
313*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize ,
314*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fdata[0]);
315*12720SWyllys.Ingersoll@Sun.COM
316*12720SWyllys.Ingersoll@Sun.COM /* set data to reasonable starting values */
317*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fname[0] = 0;
318*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize = 0;
319*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fdata[0] = 0;
320*12720SWyllys.Ingersoll@Sun.COM }
321*12720SWyllys.Ingersoll@Sun.COM
322*12720SWyllys.Ingersoll@Sun.COM }
323*12720SWyllys.Ingersoll@Sun.COM
324*12720SWyllys.Ingersoll@Sun.COM } /* for */
325*12720SWyllys.Ingersoll@Sun.COM
326*12720SWyllys.Ingersoll@Sun.COM file_read = TRUE;
327*12720SWyllys.Ingersoll@Sun.COM
328*12720SWyllys.Ingersoll@Sun.COM } /* !file read */
329*12720SWyllys.Ingersoll@Sun.COM
330*12720SWyllys.Ingersoll@Sun.COM /* read the file table */
331*12720SWyllys.Ingersoll@Sun.COM for (i=0; i < FTABLE_SIZE; i++)
332*12720SWyllys.Ingersoll@Sun.COM {
333*12720SWyllys.Ingersoll@Sun.COM /* compare filename to ram copy filename */
334*12720SWyllys.Ingersoll@Sun.COM if (strcmp(filename, (const char *)ramFileSystem.ftable[i].fname) == 0)
335*12720SWyllys.Ingersoll@Sun.COM {
336*12720SWyllys.Ingersoll@Sun.COM
337*12720SWyllys.Ingersoll@Sun.COM if (fstate[i] != MYFILE_CLOSED)
338*12720SWyllys.Ingersoll@Sun.COM {
339*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_direct::fopen FN=%s file matches, "
340*12720SWyllys.Ingersoll@Sun.COM "FILE %d WAS ALREADY OPEN for %s with mode %s"
341*12720SWyllys.Ingersoll@Sun.COM "file size is %d \n",
342*12720SWyllys.Ingersoll@Sun.COM filename,
343*12720SWyllys.Ingersoll@Sun.COM i,
344*12720SWyllys.Ingersoll@Sun.COM (fstate[i] == MYFILE_OPEN_WRITE ? "WRITE": "READ"),
345*12720SWyllys.Ingersoll@Sun.COM mode,
346*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize);
347*12720SWyllys.Ingersoll@Sun.COM }
348*12720SWyllys.Ingersoll@Sun.COM
349*12720SWyllys.Ingersoll@Sun.COM /* create a new ramfile handle */
350*12720SWyllys.Ingersoll@Sun.COM file = malloc(sizeof(myFILE));
351*12720SWyllys.Ingersoll@Sun.COM
352*12720SWyllys.Ingersoll@Sun.COM /* since file is being rewritten, it is now size 0 */
353*12720SWyllys.Ingersoll@Sun.COM if (open_for_write)
354*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize = 0;
355*12720SWyllys.Ingersoll@Sun.COM
356*12720SWyllys.Ingersoll@Sun.COM /* remember the file is open */
357*12720SWyllys.Ingersoll@Sun.COM fstate[i]= open_for_write ? MYFILE_OPEN_WRITE : MYFILE_OPEN_READ;
358*12720SWyllys.Ingersoll@Sun.COM
359*12720SWyllys.Ingersoll@Sun.COM
360*12720SWyllys.Ingersoll@Sun.COM /* if filename matches, set file pointers to it */
361*12720SWyllys.Ingersoll@Sun.COM file->writeptr = file->readptr = ramFileSystem.ftable[i].fdata;
362*12720SWyllys.Ingersoll@Sun.COM file->memptr = &ramFileSystem.ftable[i];
363*12720SWyllys.Ingersoll@Sun.COM file->readsize = 0;
364*12720SWyllys.Ingersoll@Sun.COM file->mode = open_for_write ? MODE_WRITE : MODE_READ;
365*12720SWyllys.Ingersoll@Sun.COM file->file_number = i;
366*12720SWyllys.Ingersoll@Sun.COM
367*12720SWyllys.Ingersoll@Sun.COM
368*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_direct::fopen FN=%s file matches, "
369*12720SWyllys.Ingersoll@Sun.COM "opening existing file number %d with mode %s"
370*12720SWyllys.Ingersoll@Sun.COM "file size is %d \n",
371*12720SWyllys.Ingersoll@Sun.COM filename,
372*12720SWyllys.Ingersoll@Sun.COM i,
373*12720SWyllys.Ingersoll@Sun.COM mode,
374*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize);
375*12720SWyllys.Ingersoll@Sun.COM
376*12720SWyllys.Ingersoll@Sun.COM break;
377*12720SWyllys.Ingersoll@Sun.COM }
378*12720SWyllys.Ingersoll@Sun.COM
379*12720SWyllys.Ingersoll@Sun.COM }
380*12720SWyllys.Ingersoll@Sun.COM
381*12720SWyllys.Ingersoll@Sun.COM /* if no existing entry was found, assign a new entry to this filename */
382*12720SWyllys.Ingersoll@Sun.COM if (i == FTABLE_SIZE)
383*12720SWyllys.Ingersoll@Sun.COM {
384*12720SWyllys.Ingersoll@Sun.COM /* couldn't find an old file and opened for read so return NULL */
385*12720SWyllys.Ingersoll@Sun.COM if (open_for_write == FALSE)
386*12720SWyllys.Ingersoll@Sun.COM {
387*12720SWyllys.Ingersoll@Sun.COM
388*12720SWyllys.Ingersoll@Sun.COM
389*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_direct::fopen FN=%s no file match, "
390*12720SWyllys.Ingersoll@Sun.COM "file opened for read so return NULL %d\n",
391*12720SWyllys.Ingersoll@Sun.COM filename,
392*12720SWyllys.Ingersoll@Sun.COM i);
393*12720SWyllys.Ingersoll@Sun.COM
394*12720SWyllys.Ingersoll@Sun.COM
395*12720SWyllys.Ingersoll@Sun.COM return NULL;
396*12720SWyllys.Ingersoll@Sun.COM }
397*12720SWyllys.Ingersoll@Sun.COM
398*12720SWyllys.Ingersoll@Sun.COM /* find a free file pointer */
399*12720SWyllys.Ingersoll@Sun.COM for (i=0; i < FTABLE_SIZE ; i++)
400*12720SWyllys.Ingersoll@Sun.COM {
401*12720SWyllys.Ingersoll@Sun.COM /* empty data will be 0xffffffff since it was copied
402*12720SWyllys.Ingersoll@Sun.COM straight from EEPROM */
403*12720SWyllys.Ingersoll@Sun.COM if (ramFileSystem.ftable[i].fname[0] == '\0')
404*12720SWyllys.Ingersoll@Sun.COM {
405*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_direct::fopen FN=%s no file match, "
406*12720SWyllys.Ingersoll@Sun.COM "opening new file %d\n",
407*12720SWyllys.Ingersoll@Sun.COM filename,
408*12720SWyllys.Ingersoll@Sun.COM i);
409*12720SWyllys.Ingersoll@Sun.COM
410*12720SWyllys.Ingersoll@Sun.COM /* give it a filename - marks this as in use */
411*12720SWyllys.Ingersoll@Sun.COM strcpy ((char *)ramFileSystem.ftable[i].fname, filename);
412*12720SWyllys.Ingersoll@Sun.COM
413*12720SWyllys.Ingersoll@Sun.COM /* set filesize to zero */
414*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize = 0;
415*12720SWyllys.Ingersoll@Sun.COM
416*12720SWyllys.Ingersoll@Sun.COM /* remember the file is open */
417*12720SWyllys.Ingersoll@Sun.COM fstate[i]= open_for_write ? MYFILE_OPEN_WRITE : MYFILE_OPEN_READ;
418*12720SWyllys.Ingersoll@Sun.COM
419*12720SWyllys.Ingersoll@Sun.COM
420*12720SWyllys.Ingersoll@Sun.COM /* create a new ramfile handle */
421*12720SWyllys.Ingersoll@Sun.COM file = malloc(sizeof(myFILE));
422*12720SWyllys.Ingersoll@Sun.COM
423*12720SWyllys.Ingersoll@Sun.COM /* if filename matches, set file pointers to it */
424*12720SWyllys.Ingersoll@Sun.COM file->writeptr = file->readptr = ramFileSystem.ftable[i].fdata;
425*12720SWyllys.Ingersoll@Sun.COM file->memptr = &ramFileSystem.ftable[i];
426*12720SWyllys.Ingersoll@Sun.COM file->readsize = 0;
427*12720SWyllys.Ingersoll@Sun.COM file->mode = open_for_write ? MODE_WRITE : MODE_READ;
428*12720SWyllys.Ingersoll@Sun.COM file->file_number = i;
429*12720SWyllys.Ingersoll@Sun.COM
430*12720SWyllys.Ingersoll@Sun.COM break;
431*12720SWyllys.Ingersoll@Sun.COM }
432*12720SWyllys.Ingersoll@Sun.COM
433*12720SWyllys.Ingersoll@Sun.COM }
434*12720SWyllys.Ingersoll@Sun.COM
435*12720SWyllys.Ingersoll@Sun.COM if (i == FTABLE_SIZE)
436*12720SWyllys.Ingersoll@Sun.COM {
437*12720SWyllys.Ingersoll@Sun.COM log_error_printf("KMSAgent_direct::fopen FN=%s no free files \n",
438*12720SWyllys.Ingersoll@Sun.COM filename);
439*12720SWyllys.Ingersoll@Sun.COM /* no free entries - bail */
440*12720SWyllys.Ingersoll@Sun.COM return NULL;
441*12720SWyllys.Ingersoll@Sun.COM }
442*12720SWyllys.Ingersoll@Sun.COM
443*12720SWyllys.Ingersoll@Sun.COM }
444*12720SWyllys.Ingersoll@Sun.COM
445*12720SWyllys.Ingersoll@Sun.COM /* return pointer to the myFILE struct created */
446*12720SWyllys.Ingersoll@Sun.COM return file;
447*12720SWyllys.Ingersoll@Sun.COM
448*12720SWyllys.Ingersoll@Sun.COM }
449*12720SWyllys.Ingersoll@Sun.COM
450*12720SWyllys.Ingersoll@Sun.COM /**
451*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fclose()
452*12720SWyllys.Ingersoll@Sun.COM * my filesystem fileclose
453*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fclose(myFILE * f)454*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fclose(myFILE *f)
455*12720SWyllys.Ingersoll@Sun.COM {
456*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
457*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fclose ) ;
458*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg( trace, "entered");
459*12720SWyllys.Ingersoll@Sun.COM
460*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(f);
461*12720SWyllys.Ingersoll@Sun.COM
462*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
463*12720SWyllys.Ingersoll@Sun.COM log_printf("KMSAgent_direct::fclose FN=%s, "
464*12720SWyllys.Ingersoll@Sun.COM "FILE %d "
465*12720SWyllys.Ingersoll@Sun.COM "file size is %d \n",
466*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[f->file_number].fname,
467*12720SWyllys.Ingersoll@Sun.COM f->file_number,
468*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[f->file_number].fsize);
469*12720SWyllys.Ingersoll@Sun.COM #endif
470*12720SWyllys.Ingersoll@Sun.COM
471*12720SWyllys.Ingersoll@Sun.COM if (fstate[f->file_number] == MYFILE_CLOSED)
472*12720SWyllys.Ingersoll@Sun.COM {
473*12720SWyllys.Ingersoll@Sun.COM log_error_printf("KMSAgent_direct::fclose FN=%s, "
474*12720SWyllys.Ingersoll@Sun.COM "FILE %d WAS ALREADY CLOSED "
475*12720SWyllys.Ingersoll@Sun.COM "file size is %d \n",
476*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[f->file_number].fname,
477*12720SWyllys.Ingersoll@Sun.COM f->file_number,
478*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[f->file_number].fsize);
479*12720SWyllys.Ingersoll@Sun.COM }
480*12720SWyllys.Ingersoll@Sun.COM
481*12720SWyllys.Ingersoll@Sun.COM /* remember the file is closed */
482*12720SWyllys.Ingersoll@Sun.COM fstate[f->file_number]= MYFILE_CLOSED;
483*12720SWyllys.Ingersoll@Sun.COM
484*12720SWyllys.Ingersoll@Sun.COM /* don't rewrite eeprom unless file was opened for writing */
485*12720SWyllys.Ingersoll@Sun.COM if (f->mode == MODE_WRITE)
486*12720SWyllys.Ingersoll@Sun.COM {
487*12720SWyllys.Ingersoll@Sun.COM /* Erase the sector we are rewriting */
488*12720SWyllys.Ingersoll@Sun.COM EEPROM_Sector_Erase( (unsigned char*)FILESYSTEM_SECTOR ) ;
489*12720SWyllys.Ingersoll@Sun.COM
490*12720SWyllys.Ingersoll@Sun.COM /* remember the version of toolkit that wrote this filesystem
491*12720SWyllys.Ingersoll@Sun.COM (for any future compatibility problems). */
492*12720SWyllys.Ingersoll@Sun.COM strncpy(ramFileSystem.writingversion,
493*12720SWyllys.Ingersoll@Sun.COM KMSAgent_Version,
494*12720SWyllys.Ingersoll@Sun.COM sizeof(KMSAgent_Version));
495*12720SWyllys.Ingersoll@Sun.COM
496*12720SWyllys.Ingersoll@Sun.COM /* flush the memory indicated by myFILE * out to EEPROM */
497*12720SWyllys.Ingersoll@Sun.COM /* see boot_eeprom.c for details on Flash_Write */
498*12720SWyllys.Ingersoll@Sun.COM Flash_Write ((unsigned char*)FILESYSTEM_SECTOR,
499*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)&ramFileSystem,
500*12720SWyllys.Ingersoll@Sun.COM FILESYSTEM_SECTOR_SIZE);
501*12720SWyllys.Ingersoll@Sun.COM }
502*12720SWyllys.Ingersoll@Sun.COM
503*12720SWyllys.Ingersoll@Sun.COM /* delete the placeholder file */
504*12720SWyllys.Ingersoll@Sun.COM free(f);
505*12720SWyllys.Ingersoll@Sun.COM
506*12720SWyllys.Ingersoll@Sun.COM return 0;
507*12720SWyllys.Ingersoll@Sun.COM }
508*12720SWyllys.Ingersoll@Sun.COM
509*12720SWyllys.Ingersoll@Sun.COM /**
510*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fputs()
511*12720SWyllys.Ingersoll@Sun.COM * my filesystem put string
512*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fputs(const char * s,myFILE * f)513*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fputs(const char *s, myFILE *f)
514*12720SWyllys.Ingersoll@Sun.COM {
515*12720SWyllys.Ingersoll@Sun.COM /* put the string to the memory indicated by myFILE */
516*12720SWyllys.Ingersoll@Sun.COM int i;
517*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
518*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fputs ) ;
519*12720SWyllys.Ingersoll@Sun.COM
520*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg (trace, "\nmy_eeprom_fputs : Entered");
521*12720SWyllys.Ingersoll@Sun.COM
522*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
523*12720SWyllys.Ingersoll@Sun.COM log_printf(
524*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::my_eeprom_fputs "
525*12720SWyllys.Ingersoll@Sun.COM "f->writeptr =%x "
526*12720SWyllys.Ingersoll@Sun.COM "f->readptr=%x "
527*12720SWyllys.Ingersoll@Sun.COM "f->readsize=%x "
528*12720SWyllys.Ingersoll@Sun.COM "f->memptr=%x"
529*12720SWyllys.Ingersoll@Sun.COM "f->memptr->fsize=%x\n",
530*12720SWyllys.Ingersoll@Sun.COM f->writeptr,
531*12720SWyllys.Ingersoll@Sun.COM f->readptr,
532*12720SWyllys.Ingersoll@Sun.COM f->readsize,
533*12720SWyllys.Ingersoll@Sun.COM f->memptr,
534*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize);
535*12720SWyllys.Ingersoll@Sun.COM
536*12720SWyllys.Ingersoll@Sun.COM #endif
537*12720SWyllys.Ingersoll@Sun.COM
538*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(s);
539*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(f);
540*12720SWyllys.Ingersoll@Sun.COM
541*12720SWyllys.Ingersoll@Sun.COM for (i=0;;i++)
542*12720SWyllys.Ingersoll@Sun.COM {
543*12720SWyllys.Ingersoll@Sun.COM /* end of input string? quit */
544*12720SWyllys.Ingersoll@Sun.COM if (*s == '\0')
545*12720SWyllys.Ingersoll@Sun.COM break;
546*12720SWyllys.Ingersoll@Sun.COM
547*12720SWyllys.Ingersoll@Sun.COM /* end of max file memory, quit */
548*12720SWyllys.Ingersoll@Sun.COM if ((unsigned char*)s >=
549*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)(f->memptr + sizeof(struct eepromBlockStruct)))
550*12720SWyllys.Ingersoll@Sun.COM break;
551*12720SWyllys.Ingersoll@Sun.COM
552*12720SWyllys.Ingersoll@Sun.COM /* copy */
553*12720SWyllys.Ingersoll@Sun.COM *(f->writeptr) = *s++;
554*12720SWyllys.Ingersoll@Sun.COM f->writeptr++;
555*12720SWyllys.Ingersoll@Sun.COM
556*12720SWyllys.Ingersoll@Sun.COM /* increment the filesize */
557*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize += 1;
558*12720SWyllys.Ingersoll@Sun.COM
559*12720SWyllys.Ingersoll@Sun.COM }
560*12720SWyllys.Ingersoll@Sun.COM
561*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
562*12720SWyllys.Ingersoll@Sun.COM log_printf(
563*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::fputs wrote %d chars, "
564*12720SWyllys.Ingersoll@Sun.COM "filesize is %d\n",
565*12720SWyllys.Ingersoll@Sun.COM i,
566*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize );
567*12720SWyllys.Ingersoll@Sun.COM #endif
568*12720SWyllys.Ingersoll@Sun.COM
569*12720SWyllys.Ingersoll@Sun.COM /* return how many chars were written */
570*12720SWyllys.Ingersoll@Sun.COM return i;
571*12720SWyllys.Ingersoll@Sun.COM }
572*12720SWyllys.Ingersoll@Sun.COM
573*12720SWyllys.Ingersoll@Sun.COM
574*12720SWyllys.Ingersoll@Sun.COM /**
575*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fwrite()
576*12720SWyllys.Ingersoll@Sun.COM * my filesystem put string
577*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fwrite(const char * s,int size,int nobj,myFILE * f)578*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fwrite(const char *s,
579*12720SWyllys.Ingersoll@Sun.COM int size,
580*12720SWyllys.Ingersoll@Sun.COM int nobj,
581*12720SWyllys.Ingersoll@Sun.COM myFILE *f)
582*12720SWyllys.Ingersoll@Sun.COM {
583*12720SWyllys.Ingersoll@Sun.COM /* put the string to the memory indicated by myFILE */
584*12720SWyllys.Ingersoll@Sun.COM int i,j;
585*12720SWyllys.Ingersoll@Sun.COM
586*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
587*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fwrite ) ;
588*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg ( trace, "Entered");
589*12720SWyllys.Ingersoll@Sun.COM
590*12720SWyllys.Ingersoll@Sun.COM log_printf(
591*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::my_eeprom_fputs "
592*12720SWyllys.Ingersoll@Sun.COM "f->writeptr =%x "
593*12720SWyllys.Ingersoll@Sun.COM "f->readptr=%x "
594*12720SWyllys.Ingersoll@Sun.COM "f->readsize=%x "
595*12720SWyllys.Ingersoll@Sun.COM "f->memptr=%x"
596*12720SWyllys.Ingersoll@Sun.COM "f->memptr->fsize=%x\n",
597*12720SWyllys.Ingersoll@Sun.COM f->writeptr,
598*12720SWyllys.Ingersoll@Sun.COM f->readptr,
599*12720SWyllys.Ingersoll@Sun.COM f->readsize,
600*12720SWyllys.Ingersoll@Sun.COM f->memptr,
601*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize);
602*12720SWyllys.Ingersoll@Sun.COM
603*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(s);
604*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(f);
605*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT((size*nobj) > 0);
606*12720SWyllys.Ingersoll@Sun.COM
607*12720SWyllys.Ingersoll@Sun.COM for (i=0; i<nobj; i++)
608*12720SWyllys.Ingersoll@Sun.COM {
609*12720SWyllys.Ingersoll@Sun.COM for (j=0; j<size; j++)
610*12720SWyllys.Ingersoll@Sun.COM {
611*12720SWyllys.Ingersoll@Sun.COM /* end of max file memory, quit */
612*12720SWyllys.Ingersoll@Sun.COM if ((unsigned char*)s >=
613*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)(f->memptr + sizeof(struct eepromBlockStruct)))
614*12720SWyllys.Ingersoll@Sun.COM goto DONE;
615*12720SWyllys.Ingersoll@Sun.COM
616*12720SWyllys.Ingersoll@Sun.COM /* copy */
617*12720SWyllys.Ingersoll@Sun.COM *(f->writeptr) = *s++;
618*12720SWyllys.Ingersoll@Sun.COM f->writeptr++;
619*12720SWyllys.Ingersoll@Sun.COM
620*12720SWyllys.Ingersoll@Sun.COM /* increment the filesize */
621*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize += 1;
622*12720SWyllys.Ingersoll@Sun.COM }
623*12720SWyllys.Ingersoll@Sun.COM
624*12720SWyllys.Ingersoll@Sun.COM }
625*12720SWyllys.Ingersoll@Sun.COM
626*12720SWyllys.Ingersoll@Sun.COM DONE:
627*12720SWyllys.Ingersoll@Sun.COM
628*12720SWyllys.Ingersoll@Sun.COM
629*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
630*12720SWyllys.Ingersoll@Sun.COM log_printf(
631*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::fwrite wrote %d chars, "
632*12720SWyllys.Ingersoll@Sun.COM "filesize is %d\n",
633*12720SWyllys.Ingersoll@Sun.COM i,
634*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize );
635*12720SWyllys.Ingersoll@Sun.COM #endif
636*12720SWyllys.Ingersoll@Sun.COM
637*12720SWyllys.Ingersoll@Sun.COM /* return how many objects were written */
638*12720SWyllys.Ingersoll@Sun.COM return i;
639*12720SWyllys.Ingersoll@Sun.COM }
640*12720SWyllys.Ingersoll@Sun.COM
641*12720SWyllys.Ingersoll@Sun.COM
642*12720SWyllys.Ingersoll@Sun.COM
643*12720SWyllys.Ingersoll@Sun.COM /**
644*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fgets()
645*12720SWyllys.Ingersoll@Sun.COM * my filesystem getstring
646*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fgets(char * s,int n,myFILE * f)647*12720SWyllys.Ingersoll@Sun.COM extern "C" char *my_eeprom_fgets(char *s, int n, myFILE *f)
648*12720SWyllys.Ingersoll@Sun.COM {
649*12720SWyllys.Ingersoll@Sun.COM /* put the string to the memory indicated by myFILE */
650*12720SWyllys.Ingersoll@Sun.COM int i;
651*12720SWyllys.Ingersoll@Sun.COM char *tmp = s;
652*12720SWyllys.Ingersoll@Sun.COM
653*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
654*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fgets ) ;
655*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg (trace, "entered");
656*12720SWyllys.Ingersoll@Sun.COM
657*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(s);
658*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(n > 0);
659*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(f);
660*12720SWyllys.Ingersoll@Sun.COM
661*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
662*12720SWyllys.Ingersoll@Sun.COM log_printf(
663*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::my_eeprom_fgets from file %s "
664*12720SWyllys.Ingersoll@Sun.COM "fileptr %x "
665*12720SWyllys.Ingersoll@Sun.COM "readptr = %x "
666*12720SWyllys.Ingersoll@Sun.COM "readsize = %d "
667*12720SWyllys.Ingersoll@Sun.COM "filesize = %d \n",
668*12720SWyllys.Ingersoll@Sun.COM f->memptr->fname,
669*12720SWyllys.Ingersoll@Sun.COM f,
670*12720SWyllys.Ingersoll@Sun.COM f->readptr,
671*12720SWyllys.Ingersoll@Sun.COM f->readsize,
672*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize);
673*12720SWyllys.Ingersoll@Sun.COM #endif
674*12720SWyllys.Ingersoll@Sun.COM
675*12720SWyllys.Ingersoll@Sun.COM /* get up to n-1 (and a \0) chars */
676*12720SWyllys.Ingersoll@Sun.COM for (i=0; i < n; i++)
677*12720SWyllys.Ingersoll@Sun.COM {
678*12720SWyllys.Ingersoll@Sun.COM /* end of read line? quit */
679*12720SWyllys.Ingersoll@Sun.COM if (*f->readptr == '\n')
680*12720SWyllys.Ingersoll@Sun.COM {
681*12720SWyllys.Ingersoll@Sun.COM /* increment the number of bytes read */
682*12720SWyllys.Ingersoll@Sun.COM f->readptr++;
683*12720SWyllys.Ingersoll@Sun.COM f->readsize++;
684*12720SWyllys.Ingersoll@Sun.COM break;
685*12720SWyllys.Ingersoll@Sun.COM }
686*12720SWyllys.Ingersoll@Sun.COM
687*12720SWyllys.Ingersoll@Sun.COM /* trying to read beyond what was written? quit */
688*12720SWyllys.Ingersoll@Sun.COM if (f->readsize >
689*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize)
690*12720SWyllys.Ingersoll@Sun.COM {
691*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
692*12720SWyllys.Ingersoll@Sun.COM log_printf(
693*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::fgets eof after %d chars, "
694*12720SWyllys.Ingersoll@Sun.COM "readsize is %d "
695*12720SWyllys.Ingersoll@Sun.COM "filesize is %d\n",
696*12720SWyllys.Ingersoll@Sun.COM i,
697*12720SWyllys.Ingersoll@Sun.COM f->readsize,
698*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize);
699*12720SWyllys.Ingersoll@Sun.COM #endif
700*12720SWyllys.Ingersoll@Sun.COM return NULL;
701*12720SWyllys.Ingersoll@Sun.COM }
702*12720SWyllys.Ingersoll@Sun.COM
703*12720SWyllys.Ingersoll@Sun.COM /* trying to read beyond max file memory, quit */
704*12720SWyllys.Ingersoll@Sun.COM if ((unsigned char*)f->readptr >=
705*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)(f->memptr + sizeof(struct eepromBlockStruct)))
706*12720SWyllys.Ingersoll@Sun.COM {
707*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
708*12720SWyllys.Ingersoll@Sun.COM log_printf(
709*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::fgets end of max file after %d chars "
710*12720SWyllys.Ingersoll@Sun.COM "readsize is %d "
711*12720SWyllys.Ingersoll@Sun.COM "filesize is %d\n",
712*12720SWyllys.Ingersoll@Sun.COM i,
713*12720SWyllys.Ingersoll@Sun.COM f->readsize,
714*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize);
715*12720SWyllys.Ingersoll@Sun.COM #endif
716*12720SWyllys.Ingersoll@Sun.COM /* EOF or error is signalled by NULL return */
717*12720SWyllys.Ingersoll@Sun.COM return NULL;
718*12720SWyllys.Ingersoll@Sun.COM }
719*12720SWyllys.Ingersoll@Sun.COM
720*12720SWyllys.Ingersoll@Sun.COM /* copy a char */
721*12720SWyllys.Ingersoll@Sun.COM *tmp++ = *f->readptr;
722*12720SWyllys.Ingersoll@Sun.COM
723*12720SWyllys.Ingersoll@Sun.COM /* increment the number of bytes read */
724*12720SWyllys.Ingersoll@Sun.COM f->readptr++;
725*12720SWyllys.Ingersoll@Sun.COM f->readsize++;
726*12720SWyllys.Ingersoll@Sun.COM
727*12720SWyllys.Ingersoll@Sun.COM } /* for */
728*12720SWyllys.Ingersoll@Sun.COM
729*12720SWyllys.Ingersoll@Sun.COM /* terminate the returned string with a 0, but not a \n */
730*12720SWyllys.Ingersoll@Sun.COM *tmp='\0';
731*12720SWyllys.Ingersoll@Sun.COM
732*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
733*12720SWyllys.Ingersoll@Sun.COM /* terminate returned string after a non-absurd number of chars
734*12720SWyllys.Ingersoll@Sun.COM */
735*12720SWyllys.Ingersoll@Sun.COM log_printf(
736*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::fgets string [%s] "
737*12720SWyllys.Ingersoll@Sun.COM "end of line after %d chars "
738*12720SWyllys.Ingersoll@Sun.COM "readsize is %d "
739*12720SWyllys.Ingersoll@Sun.COM "filesize is %d\n",
740*12720SWyllys.Ingersoll@Sun.COM s,
741*12720SWyllys.Ingersoll@Sun.COM i,
742*12720SWyllys.Ingersoll@Sun.COM f->readsize,
743*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize);
744*12720SWyllys.Ingersoll@Sun.COM #endif
745*12720SWyllys.Ingersoll@Sun.COM
746*12720SWyllys.Ingersoll@Sun.COM /* on success, return the original pointer */
747*12720SWyllys.Ingersoll@Sun.COM return s;
748*12720SWyllys.Ingersoll@Sun.COM }
749*12720SWyllys.Ingersoll@Sun.COM
750*12720SWyllys.Ingersoll@Sun.COM
751*12720SWyllys.Ingersoll@Sun.COM
752*12720SWyllys.Ingersoll@Sun.COM
753*12720SWyllys.Ingersoll@Sun.COM /**
754*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fread()
755*12720SWyllys.Ingersoll@Sun.COM * my filesystem read a file
756*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fread(char * s,int size,int nobj,myFILE * f)757*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fread(char *s, int size, int nobj, myFILE *f)
758*12720SWyllys.Ingersoll@Sun.COM {
759*12720SWyllys.Ingersoll@Sun.COM /* put the string to the memory indicated by myFILE */
760*12720SWyllys.Ingersoll@Sun.COM int i,j;
761*12720SWyllys.Ingersoll@Sun.COM
762*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
763*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fread ) ;
764*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg (trace, "entered");
765*12720SWyllys.Ingersoll@Sun.COM
766*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(s);
767*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(f);
768*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT((size*nobj) > 0);
769*12720SWyllys.Ingersoll@Sun.COM
770*12720SWyllys.Ingersoll@Sun.COM for (i=0; i<nobj; i++)
771*12720SWyllys.Ingersoll@Sun.COM {
772*12720SWyllys.Ingersoll@Sun.COM for (j=0; j<size; j++)
773*12720SWyllys.Ingersoll@Sun.COM {
774*12720SWyllys.Ingersoll@Sun.COM /* end of written file memory, quit */
775*12720SWyllys.Ingersoll@Sun.COM if ( (unsigned char*) s >=
776*12720SWyllys.Ingersoll@Sun.COM (unsigned char*) (f->memptr + f->memptr->fsize) )
777*12720SWyllys.Ingersoll@Sun.COM goto DONE;
778*12720SWyllys.Ingersoll@Sun.COM
779*12720SWyllys.Ingersoll@Sun.COM /* copy */
780*12720SWyllys.Ingersoll@Sun.COM *s++ = *(f->readptr);
781*12720SWyllys.Ingersoll@Sun.COM f->readptr++;
782*12720SWyllys.Ingersoll@Sun.COM }
783*12720SWyllys.Ingersoll@Sun.COM
784*12720SWyllys.Ingersoll@Sun.COM }
785*12720SWyllys.Ingersoll@Sun.COM
786*12720SWyllys.Ingersoll@Sun.COM DONE:
787*12720SWyllys.Ingersoll@Sun.COM
788*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
789*12720SWyllys.Ingersoll@Sun.COM log_printf(
790*12720SWyllys.Ingersoll@Sun.COM "\nKMSAgent_direct::fread read %d chars, "
791*12720SWyllys.Ingersoll@Sun.COM "filesize is %d\n",
792*12720SWyllys.Ingersoll@Sun.COM i,
793*12720SWyllys.Ingersoll@Sun.COM f->memptr->fsize );
794*12720SWyllys.Ingersoll@Sun.COM #endif
795*12720SWyllys.Ingersoll@Sun.COM
796*12720SWyllys.Ingersoll@Sun.COM /* return how many objects were written */
797*12720SWyllys.Ingersoll@Sun.COM return i;
798*12720SWyllys.Ingersoll@Sun.COM
799*12720SWyllys.Ingersoll@Sun.COM }
800*12720SWyllys.Ingersoll@Sun.COM
801*12720SWyllys.Ingersoll@Sun.COM
802*12720SWyllys.Ingersoll@Sun.COM
803*12720SWyllys.Ingersoll@Sun.COM
804*12720SWyllys.Ingersoll@Sun.COM
805*12720SWyllys.Ingersoll@Sun.COM
806*12720SWyllys.Ingersoll@Sun.COM /**
807*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_unlink() - delete the file named
808*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_unlink(const char * filename)809*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_unlink(const char *filename)
810*12720SWyllys.Ingersoll@Sun.COM {
811*12720SWyllys.Ingersoll@Sun.COM int i;
812*12720SWyllys.Ingersoll@Sun.COM
813*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
814*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fgets ) ;
815*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg (trace, "Entered fn=%s", (char*)filename);
816*12720SWyllys.Ingersoll@Sun.COM
817*12720SWyllys.Ingersoll@Sun.COM /* assume the file is closed */
818*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(filename);
819*12720SWyllys.Ingersoll@Sun.COM
820*12720SWyllys.Ingersoll@Sun.COM /* read the file table */
821*12720SWyllys.Ingersoll@Sun.COM for (i=0; i < FTABLE_SIZE; i++)
822*12720SWyllys.Ingersoll@Sun.COM {
823*12720SWyllys.Ingersoll@Sun.COM
824*12720SWyllys.Ingersoll@Sun.COM if (fstate[i] != MYFILE_CLOSED)
825*12720SWyllys.Ingersoll@Sun.COM {
826*12720SWyllys.Ingersoll@Sun.COM log_error_printf("KMSAgent_direct::unlink FN=%s file matches, "
827*12720SWyllys.Ingersoll@Sun.COM "FILE %d WAS STILL OPEN for %s"
828*12720SWyllys.Ingersoll@Sun.COM "file size is %d \n",
829*12720SWyllys.Ingersoll@Sun.COM filename,
830*12720SWyllys.Ingersoll@Sun.COM i,
831*12720SWyllys.Ingersoll@Sun.COM (fstate[i] == MYFILE_OPEN_WRITE ? "WRITE": "READ"),
832*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize);
833*12720SWyllys.Ingersoll@Sun.COM }
834*12720SWyllys.Ingersoll@Sun.COM
835*12720SWyllys.Ingersoll@Sun.COM /* compare input filename to ram copy filename */
836*12720SWyllys.Ingersoll@Sun.COM if (strcmp(filename, (const char*)ramFileSystem.ftable[i].fname) == 0)
837*12720SWyllys.Ingersoll@Sun.COM {
838*12720SWyllys.Ingersoll@Sun.COM /* if filename matches, zero it out to delete the file */
839*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fname[0] = '\0';
840*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize = 0;
841*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fdata[0] = 1;
842*12720SWyllys.Ingersoll@Sun.COM
843*12720SWyllys.Ingersoll@Sun.COM /* remember the file is closed */
844*12720SWyllys.Ingersoll@Sun.COM fstate[i]= MYFILE_CLOSED;
845*12720SWyllys.Ingersoll@Sun.COM
846*12720SWyllys.Ingersoll@Sun.COM EEPROM_Sector_Erase( FILESYSTEM_SECTOR ) ;
847*12720SWyllys.Ingersoll@Sun.COM
848*12720SWyllys.Ingersoll@Sun.COM /* remember the version of toolkit that wrote this filesystem
849*12720SWyllys.Ingersoll@Sun.COM (for any future compatibility problems). */
850*12720SWyllys.Ingersoll@Sun.COM strncpy(ramFileSystem.writingversion,
851*12720SWyllys.Ingersoll@Sun.COM KMSAgent_Version,
852*12720SWyllys.Ingersoll@Sun.COM sizeof(KMSAgent_Version));
853*12720SWyllys.Ingersoll@Sun.COM
854*12720SWyllys.Ingersoll@Sun.COM /* flush the memory indicated by myFILE * out to EEPROM */
855*12720SWyllys.Ingersoll@Sun.COM Flash_Write ((unsigned char*)FILESYSTEM_SECTOR,
856*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)&ramFileSystem,
857*12720SWyllys.Ingersoll@Sun.COM FILESYSTEM_SECTOR_SIZE);
858*12720SWyllys.Ingersoll@Sun.COM
859*12720SWyllys.Ingersoll@Sun.COM break;
860*12720SWyllys.Ingersoll@Sun.COM }
861*12720SWyllys.Ingersoll@Sun.COM
862*12720SWyllys.Ingersoll@Sun.COM }
863*12720SWyllys.Ingersoll@Sun.COM
864*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
865*12720SWyllys.Ingersoll@Sun.COM log_printf ("my_eeprom_unlink : returning");
866*12720SWyllys.Ingersoll@Sun.COM #endif
867*12720SWyllys.Ingersoll@Sun.COM
868*12720SWyllys.Ingersoll@Sun.COM if (i == FTABLE_SIZE)
869*12720SWyllys.Ingersoll@Sun.COM return -1;
870*12720SWyllys.Ingersoll@Sun.COM
871*12720SWyllys.Ingersoll@Sun.COM /* success */
872*12720SWyllys.Ingersoll@Sun.COM return 0;
873*12720SWyllys.Ingersoll@Sun.COM }
874*12720SWyllys.Ingersoll@Sun.COM
875*12720SWyllys.Ingersoll@Sun.COM
876*12720SWyllys.Ingersoll@Sun.COM /**
877*12720SWyllys.Ingersoll@Sun.COM * my_eeprom_fsys_erase() - delete all files
878*12720SWyllys.Ingersoll@Sun.COM */
my_eeprom_fsys_erase(void)879*12720SWyllys.Ingersoll@Sun.COM extern "C" int my_eeprom_fsys_erase(void)
880*12720SWyllys.Ingersoll@Sun.COM {
881*12720SWyllys.Ingersoll@Sun.COM int i;
882*12720SWyllys.Ingersoll@Sun.COM
883*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE_ENTRY *trace = NULL;
884*12720SWyllys.Ingersoll@Sun.COM ECPT_TRACE( trace, my_eeprom_fread ) ;
885*12720SWyllys.Ingersoll@Sun.COM ecpt_trace_msg (trace, "my_eeprom_fsys_erase : entering ");
886*12720SWyllys.Ingersoll@Sun.COM
887*12720SWyllys.Ingersoll@Sun.COM /* read the file table */
888*12720SWyllys.Ingersoll@Sun.COM for (i=0; i < FTABLE_SIZE; i++)
889*12720SWyllys.Ingersoll@Sun.COM {
890*12720SWyllys.Ingersoll@Sun.COM if (fstate[i] != MYFILE_CLOSED)
891*12720SWyllys.Ingersoll@Sun.COM {
892*12720SWyllys.Ingersoll@Sun.COM log_error_printf("KMSAgent_direct::fsys_erase FN=%s file "
893*12720SWyllys.Ingersoll@Sun.COM "FILE %d WAS STILL OPEN for %s "
894*12720SWyllys.Ingersoll@Sun.COM "file size is %d \n",
895*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fname,
896*12720SWyllys.Ingersoll@Sun.COM i,
897*12720SWyllys.Ingersoll@Sun.COM (fstate[i] == MYFILE_OPEN_WRITE ? "WRITE": "READ"),
898*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize);
899*12720SWyllys.Ingersoll@Sun.COM }
900*12720SWyllys.Ingersoll@Sun.COM
901*12720SWyllys.Ingersoll@Sun.COM /* zero filename out to delete the file */
902*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fname[0] = '\0';
903*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fsize = 0;
904*12720SWyllys.Ingersoll@Sun.COM ramFileSystem.ftable[i].fdata[0] = 2;
905*12720SWyllys.Ingersoll@Sun.COM
906*12720SWyllys.Ingersoll@Sun.COM /* remember the file is closed */
907*12720SWyllys.Ingersoll@Sun.COM fstate[i]= MYFILE_CLOSED;
908*12720SWyllys.Ingersoll@Sun.COM
909*12720SWyllys.Ingersoll@Sun.COM EEPROM_Sector_Erase( FILESYSTEM_SECTOR ) ;
910*12720SWyllys.Ingersoll@Sun.COM
911*12720SWyllys.Ingersoll@Sun.COM /* remember the version of toolkit that wrote this filesystem
912*12720SWyllys.Ingersoll@Sun.COM (for any future compatibility problems). */
913*12720SWyllys.Ingersoll@Sun.COM strncpy(ramFileSystem.writingversion,
914*12720SWyllys.Ingersoll@Sun.COM KMSAgent_Version,
915*12720SWyllys.Ingersoll@Sun.COM sizeof(KMSAgent_Version));
916*12720SWyllys.Ingersoll@Sun.COM
917*12720SWyllys.Ingersoll@Sun.COM /* flush the memory indicated by myFILE * out to EEPROM */
918*12720SWyllys.Ingersoll@Sun.COM Flash_Write ((unsigned char*)FILESYSTEM_SECTOR,
919*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)&ramFileSystem,
920*12720SWyllys.Ingersoll@Sun.COM FILESYSTEM_SECTOR_SIZE);
921*12720SWyllys.Ingersoll@Sun.COM
922*12720SWyllys.Ingersoll@Sun.COM
923*12720SWyllys.Ingersoll@Sun.COM }
924*12720SWyllys.Ingersoll@Sun.COM
925*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG
926*12720SWyllys.Ingersoll@Sun.COM log_printf ("\nmy_eeprom_fsys_erase : returning");
927*12720SWyllys.Ingersoll@Sun.COM #endif
928*12720SWyllys.Ingersoll@Sun.COM
929*12720SWyllys.Ingersoll@Sun.COM if (i == FTABLE_SIZE)
930*12720SWyllys.Ingersoll@Sun.COM return -1;
931*12720SWyllys.Ingersoll@Sun.COM
932*12720SWyllys.Ingersoll@Sun.COM /* success */
933*12720SWyllys.Ingersoll@Sun.COM return 0;
934*12720SWyllys.Ingersoll@Sun.COM }
935*12720SWyllys.Ingersoll@Sun.COM
936*12720SWyllys.Ingersoll@Sun.COM
937*12720SWyllys.Ingersoll@Sun.COM
938*12720SWyllys.Ingersoll@Sun.COM
939*12720SWyllys.Ingersoll@Sun.COM #endif // DEFINE_STORAGE
940*12720SWyllys.Ingersoll@Sun.COM #endif // METAWARE
941*12720SWyllys.Ingersoll@Sun.COM #endif
942*12720SWyllys.Ingersoll@Sun.COM
943