Virtual Files


Modules

 I/O routines
 Virtual file sources

Data Structures

struct  VIRTUAL_FILE
struct  VIRTUAL_FILE_SOURCE
struct  UL_VIRTUALFILENAME

Enumerations

enum  VF_OPEN_MODES { VF_O_READ, VF_O_READWRITE, VF_O_WRITE }

Functions

void VirtualFileInit ()
VIRTUAL_FILEVirtualFileOpen (void *param1, int param2, int type, int mode)
int VirtualFileClose (VIRTUAL_FILE *f)
int VirtualFileRegisterSource (VIRTUAL_FILE_SOURCE *vfs)
void ulSetVirtualFilenameList (UL_VIRTUALFILENAME *vfl, int numberOfEntries)
UL_VIRTUALFILENAMEulFindFileInVirtualFilenameList (const char *fname, int type)
void * ulReadEntireFileToMemory (VIRTUAL_FILE *f, int *size)

Detailed Description

Virtual File support for µLibrary. This API is meant to be an universal mean to manipulate every file source possible as you can define your own.

Enumeration Type Documentation

enum VF_OPEN_MODES

Enumeration describing the available file open modes. Please note that some sources do not support some modes like READWRITE or WRITE, in this case they'll fail when an attempt to open a file in one of these modes is made. The resulting file returned by VirtualFileOpen will be NULL.

Enumerator:
VF_O_READ  Read only.
VF_O_READWRITE  Read & Write.
VF_O_WRITE  Write only.


Function Documentation

void VirtualFileInit (  ) 

Initializes the virtual filesystem. Done by default by µLibrary, so there is no need to call it by yourself.

VIRTUAL_FILE* VirtualFileOpen ( void *  param1,
int  param2,
int  type,
int  mode 
)

Open a new file.

Parameters:
param1 Depends on the file source. By default:
  • VF_MEMORY: pointer to your data
  • VF_GBFS, VF_FILE: pointer to a string containing the file name
param2 Depends on the file source. By default:
  • VF_MEMORY: total size of the memory block
  • VF_GBFS, VF_FILE: 0
type File type. By default, can be:
  • VF_MEMORY: read/write from a memory block
  • VF_FILE: read from standard stdio routines (libfat). Requires a prior call to ulInitLibFat.
  • VF_GBFS: read from GBFS. Requires a prior call to ulInitGBFS.
mode One of VF_OPEN_MODES.

int VirtualFileClose ( VIRTUAL_FILE f  ) 

Closes an open file.

int VirtualFileRegisterSource ( VIRTUAL_FILE_SOURCE vfs  ) 

Adds a new file source to the virtual file system.

Parameters:
vfs Must be a pointer to a valid VIRTUAL_FILE_SOURCE interface containing all your functions for handling the file source.
Returns:
Returns the identifier of your source or -1 if it has failed. You can then use this ID as a file type (parameter for VirtualFileOpen).

void ulSetVirtualFilenameList ( UL_VIRTUALFILENAME vfl,
int  numberOfEntries 
)

Registers a file list for RAM based devices (such as VF_MEMORY). This way you can make a virtual file driver for files in RAM and then easily switch from a libFat, GBFS or RAM system, only by speficying file names when loading.

Parameters:
vfl List of files (each file is a UL_VIRTUALFILENAME item)

UL_VIRTUALFILENAME* ulFindFileInVirtualFilenameList ( const char *  fname,
int  type 
)

Call this function in your virtual file source OPEN handler, if it's a RAM based device and param2 == 0 (means null size, impossible). It will return a UL_VIRTUALFILENAME where you can get a pointer to the data and their size. Note that the return value can be NULL if the file has not been found or an error occured (e.g. fname is NULL).

void* ulReadEntireFileToMemory ( VIRTUAL_FILE f,
int *  size 
)

Reads an entire file to memory and returns a pointer to the memory block. The block memory usage is stepped by 4 kB, so even a 1 kB file will take 16 kB, so this function is not recommended for opening a lot of small files. The bloc must be freed (using free) once you've finished with it!

Parameters:
f Pointer to an open virtual file.
size Pointer to an integer that will contain the number of bytes read from the file.


Generated on Sat Jul 14 23:39:33 2007 by  doxygen 1.5.2