34 #define MAX_NAME_LENGTH 8 36 #define NVM_STORE_FILENAME "NVMFILELIST.dat" 55 static U32BIT total_filesize = 0;
56 static U32BIT nvm_store_size = 0;
62 static void CreateFileList(
U8BIT *encoded_list,
U32BIT list_len);
83 nvm_store_size = nvmSize;
92 CreateFileList(buffer, size);
116 if (buf == 0 || len == 0)
118 DEBUG_PRINT((
"ERROR: MHEG5nvmRead - Bad data variable pointer passed.\n"));
120 #ifdef INVALIDATE_LONG_NAME 123 TRACE(TERROR, (
"filename [%.*s] is too long %d ", fn.
len, fn.
data, fn.
len))
128 #ifndef INVALIDATE_LONG_NAME 152 INFO_PRINT((
"SUCCESS: MHEG5nvmRead - Found file [%.*s] in list.\n", fn.
len, fn.
data));
159 INFO_PRINT((
"WARNING: MHEG5nvmRead - Unable to find file [%.*s] in list.\n", fn.
len, fn.
data));
179 if (size > nvm_store_size)
181 TRACE(TERROR, (
"File [%.*s] too big [0x%x]", fn.
len, fn.
data, size));
184 #ifdef INVALIDATE_LONG_NAME 187 TRACE(TERROR, (
"filename [%.*s] is too long %d ", fn.
len, fn.
data, fn.
len))
193 #ifndef INVALIDATE_LONG_NAME 201 INFO_PRINT((
"BEGIN: MHEG5nvmWrite - File [%.*s], Length [0x%x].\n", fn.
len, fn.
data, size));
212 INFO_PRINT((
"WARNING: MHEG5nvmWrite - Found duplicate file name [%.*s] in list.\n", fn.
len, fn.
data));
214 DeleteNvmFile(to_delete);
223 while ((total_filesize + size > nvm_store_size)
224 && file_list_oldest != NULL
225 && total_filesize > 0)
227 INFO_PRINT((
"WARNING: MHEG5nvmWrite - Not enough space in list, deleting files.\n"));
228 DeleteNvmFile(file_list_oldest);
231 if (new_file == NULL)
241 new_file->
next = NULL;
249 new_file->
previous = file_list_newest;
250 if (file_list_newest)
252 file_list_newest->
next = new_file;
254 file_list_newest = new_file;
255 if (!file_list_oldest)
257 file_list_oldest = new_file;
259 total_filesize += size;
272 INFO_PRINT((
"SUCCESS: MHEG5nvmWrite - File [%.*s] added to list.\n", fn.
len, fn.
data));
285 file_list_oldest = file->
next;
301 static void CreateFileList(
U8BIT *encoded_list,
U32BIT list_len)
307 while (offset < list_len)
309 name_len = encoded_list[offset];
312 file_size = encoded_list[offset];
314 file_size += encoded_list[offset] << 8;
316 file_size += encoded_list[offset] << 16;
318 file_size += encoded_list[offset] << 24;
329 memcpy(new_file->
name, encoded_list + offset, name_len);
330 new_file->
name[name_len] =
'\0';
333 new_file->
next = NULL;
334 new_file->
previous = file_list_newest;
335 if (file_list_newest)
337 file_list_newest->
next = new_file;
339 if (!file_list_oldest)
341 file_list_oldest = new_file;
343 file_list_newest = new_file;
361 buffer[1] = current_file->
file_size & 0xFF;
362 buffer[2] = (current_file->
file_size >> 8) & 0xFF;
363 buffer[3] = (current_file->
file_size >> 16) & 0xFF;
364 buffer[4] = (current_file->
file_size >> 24) & 0xFF;
368 current_file = current_file->
next;
386 next_file = current_file->
next;
388 current_file = next_file;
390 file_list_oldest = NULL;
391 file_list_newest = NULL;
void * STB_NVMOpenFile(U8BIT *name, E_STB_DSK_FILE_MODE mode)
Opens an existing file or creates a new one.
#define NVM_STORE_FILENAME
void MHEG5nvmInitialise(U32BIT nvmSize)
Initialise NVM Storage.
void STB_MemFree(void *ptr)
Releases previously allocated memory.
void STB_NVMCloseFile(void *file)
Flushes and closes an open file.
BOOLEAN STB_NVMFileSize(U8BIT *filename, U32BIT *filesize)
Returns the size in KB of the given file.
struct sNvmFile MHEG5NvmFile
struct sNvmFile * previous
Persistent storage module. The engine provides a persistent storage for 1024 bytes of data...
void * STB_MemAlloc(U32BIT memSize)
Allocates the specified number of bytes.
This file defines the profile for the MHEG engine.
void MHEG5nvmReset(void)
Clear all NVM data from the persistent store.
MHEG5Bool MHEG5nvmRead(MHEG5String fn, void **buf, MHEG5Int *len)
Read a file from the nvm store.
U32BIT STB_NVMReadFile(void *file, U8BIT *data, U32BIT size)
Reads data from an open file.
Mheg5 logging and debug printing.
U32BIT STB_NVMWriteFile(void *file, U8BIT *data, U32BIT size)
Writes data to an open file.
Non-Volatile Memory functions and file access for caching files during power cycles. All file/path names are relative to some implementation dependent root path for MHEG's NVM storage area. So a path of "" (i.e. zero length name), is the root directory of storage area.
MHEG5Bool MHEG5nvmWrite(MHEG5String fn, void *buf, MHEG5Int len)
Write a file to the nvm store.
U8BIT name[MAX_NAME_LENGTH+1]
BOOLEAN STB_NVMDeleteFile(U8BIT *filename)
Deletes the file.