SMFS Reference

SMFS is a Secure Memory File System (as exported to FMs).

It allows FMs to store keys into tamper-protected battery-backed Static RAM (SRAM)

It has the following general specifications:

>Arbitrary depth directory structure supported.

>File names are any character other than '\' or '/'.

>Path separator is '/' (the Windows '\' is not allowed)

>Files are of fixed size and initialized with zeros when created.

>Directories will expand in size as needed to fit more files.

This chapter contains the following sections:

>Important Constants

>Error Codes

>File Attributes Structure (SmFsAttr)

>Function Descriptions

Important Constants

>Max file name length is 15

>Max path length is 100

>Max number of open files is 32

>Max number of file search handles is 16

Error Codes

SMFS_ERR_ERROR 1 A general error has occurred
SMFS_ERR_NOT_INITED 2 The SMFS has not been initialized
SMFS_ERR_MEMORY 3 The SMFS has run out of memory
SMFS_ERR_NAME_TOO_LONG 4 The name given for a file is too long
SMFS_ERR_RESOURCES 5 The SMFS has run out of resources
SMFS_ERR_PARAMETER 6 An invalid parameter was passed to SMFS
SMFS_ERR_ACCESS 7 User does not have request access to file
SMFS_ERR_NOT_FOUND 8 Requested file was not found
SMFS_ERR_BUSY 9 Operation is being attempted on an open file
SMFS_ERR_EXIST 10 A file being created already exists
SMFS_ERR_FILE_TYPE 11 Operation being performed on wrong file type

File Attributes Structure (SmFsAttr)

This structure holds the file or directory attributes

Synopsis

SmFsAttr {
unsigned int Size; 
unsigned int isDir;
   };

Members

Size: Current file size in bytes or directory size in entries

isDir: Flag specifying if file is a directory

Function Descriptions

This section contains descriptions of the following functions:

>SmFsCreateDir

>SmFsCloseFile

>SmFsCalcFree

>SmFsCreateFile

>SmFsDeleteFile

>SmFsFindFile

>SmFsFindFileClose

>SmFsFindFileInit

>SmFsGetFileAttr

>SmFsGetOpenFileAttr

>SmFsOpenFile

>SmFsReadFile

>SmFsRenameFile

>SmFsWriteFile

SmFsCreateDir

Allocates SRAM memory and a directory entry for a directory.

Synopsis

int SmFsCreateDir(const char * name,

unsigned int entries);
Parameter Description
name Pointer to the absolute path of the directory to create
entries Maximum number of entries that may exist in this directory

Return Value

Returns 0 for success or an error condition.

SmFsCloseFile

Close the file by removing it from the file descriptor table.

Synopsis

int SmFsCloseFile( SMFS_HANDLE fh);
Parameter Description
fh File handle of file to close.

Return Value

Returns 0 or an error condition.

SmFsCalcFree

Synopsis

unsigned int SmFsCalcFree( void );

Return Value

Returns amount of free memory (in bytes) in the file system.

SmFsCreateFile

Allocates SRAM memory and a directory entry for a file. Once a file has been created, its size can not be changed.

Synopsis

int SmFsCreateFile(const char * name,
unsigned int len);
Parameter Description
name Pointer to the absolute path of the file to create
len Size of file to create (in bytes)

Return Value

Returns 0 for success or an error condition.

SmFsDeleteFile

Deletes a file from secure memory by removing the directory entry and zeroing out its data area.

Synopsis

int SmFsDeleteFile(const char * name);
Parameter Description
name Pointer to the absolute path of the file to delete

Return Value

Returns 0 or an error condition.

SmFsFindFile

Fetch name of next directory entry from file search context

Synopsis

int SmFsFindFile( int sh,
    char * name,
    unsigned int size
);
Parameter Description
sh Search handle to continue
name Pointer to location to hold found file name matching pattern
pattern Length of name buffer

Return Value

Returns 0 or an error condition.

SmFsFindFileClose

Close a file search context.

Synopsis

int SmFsFindFileClose( int sh);
Parameter Description
sh Search handle to close

Return Value

Returns 0 or an error condition.

SmFsFindFileInit

Creates a file iteration context. 

Wild cards are:

>? - match any character

>* -  match many characters

Synopsis

int SmFsFindFileInit(
    int *sh,
    const char * path,
    const char * pattern
);
Parameter Description
sh Pointer to location to hold search handle
path Pointer to the absolute path where to search for file
pattern Pointer to pattern of file name (including wild cards) to search for

Return Value

Returns 0 or an error condition.

SmFsGetFileAttr

Get attributes of an open file. Returns an attributes structure for the unopen file ‘name’.

Synopsis

int SmFsGetFileAttr( const char * name,
SmFsAttr * a);
Parameter Description
name Pointer to absolute path
a Pointer to the returned attributes structure

Return Value

Returns 0 or an error condition.

SmFsGetOpenFileAttr

Returns an attribute structure for the open file ‘name’.

Synopsis

int SmFsGetOpenFileAttr( SMFS_HANDLE fh,
SmFSAttr * a);
Parameter Description
fh File handle
a Pointer to the returned attributes structure

Return Value

Returns 0 or an error condition.

SmFsOpenFile

Finds the file and creates an entry for it in the file descriptor table. The table index returned in ‘fh’ and is used by other file functions.

Synopsis

int SmFsOpenFile( SMFS_HANDLE * fh,,
const char * name,);
Parameter Description
fh Pointer to the file handle
name Pointer to the absolute path

Return Value

Returns 0 or an error condition.

SmFsReadFile

Reads data from file.

Synopsis

int SmFsReadFile( SMFS_HANDLE fh,
unsigned int offset,
char *buf,
unsigned int bc);
Parameter Description
fh Open file handle
offset Zero-based starting point
buf Pointer to the returned result
bc The number of bytes to read from file

Return Value

Returns 0 or an error condition.

SmFsRenameFile

Renames a file.

Synopsis

int SmFsRenameFile( const char * oldName,
       const char * newName
      );
Parameter Description
oldName Pointer to the absolute path of file to rename
newName Pointer of new file name only (no path)

Return Value

Returns 0 or an error condition.

SmFsWriteFile

Write data to file.

Synopsis

int SmFsWriteFile( SMFS_HANDLE fh,
unsigned int offset,
char *buf,unsigned int bc);
Parameter Description
fh Open file handle
offset Zero-based starting point
buf Data to be written
bc The number of bytes to write

Return Value

Returns 0 or an error condition.