NetBurner 3.5.0
PDF Version
 
EFFS-FAT File System Operation

EFFS-FAT File System Operation

Typical file system operation will involve mounting a drive, opening and closing files, and reading and writing files. The following is a list of the most common function calls used to perform these operations. For a complete list of functions refer to the EFFS Programming Guide.

Common EFFS FAT Function Calls

Create/delete working directory for current task priority:

int f_enterFS(void)
void f_releaseFS(void)
void f_releaseFS(void)
Removes a task priority from the task list used by the file system.
int f_enterFS(void)
Adds a new task priority to the task list used by the file system.



Mount/dismount a flash card:

int f_mountfat(MMC_DRV_NUM, mmc_initfunc, F_MMC_DRIVE0)
int f_delvolume(int drivenum)
#define f_delvolume(drvnumber)
Un-mounts a flash card.
Definition api_f.h:387



Open/Close a file

F_FILE *f_open(const char *filename, const char *mode)
int f_close(F_FILE *filehandle)
#define f_close(filehandle)
Closes an opened file.
Definition api_f.h:493
#define f_open(filename, mode)
Opens a file in the file system.
Definition api_f.h:518



Read, write, and related functions:

int f_getfreespace(int drivenum, F_SPACE *pspace)
long f_write(const void *buf, long size,long size_st, F_FILE *filehandle)
long f_read( void *buf, long size,long size_st, F_FILE *filehandle)
long f_seek(F_FILE *filehandle,long offset, long whence)
int f_eof(F_FILE *filehandle)
int f_rewind(F_FILE *filehandle)
int f_delete(const char *filename)
#define f_eof(filehandle)
Check whether the current position in the open target file is the end of the file.
Definition api_f.h:581
#define f_read(buf, size, size_st, filehandle)
Read data from the current position in a file.
Definition api_f.h:532
#define f_seek(filehandle, offset, whence)
Move the stream position of an open file.
Definition api_f.h:556
#define f_delete(filename)
Deletes a file.
Definition api_f.h:619
#define f_getfreespace(drivenum, pspace)
Provides information about the drive space usage.
Definition api_f.h:406
#define f_write(buf, size, size_st, filehandle)
Write data to the file at the current position.
Definition api_f.h:544
#define f_rewind(filehandle)
Sets the file position in the open target file to the start of the file.
Definition api_f.h:571



Directory functions:

int f_findfirst(const char *filename, F_FIND *find)
int f_findnext(F_FIND *find)
int f_chdir(const char *dirname)
int f_mkdir(const char *dirname)
#define f_findfirst(filename, find)
Find the first file or subdirectory in a specified directory.
Definition api_f.h:464
#define f_findnext(find)
Finds the next file or subdirectory in a specified directory after a previous call to f_findfirst() o...
Definition api_f.h:480
#define f_chdir(dirname)
Change the directory.
Definition api_f.h:419
#define f_mkdir(dirname)
Makes a new directory.
Definition api_f.h:432



File time functions

int f_settimedate(const char *filename, unsigned short ctime, unsigned short cdate)
int f_gettimedate(const char *filename, unsigned short *pctime, unsigned short *pcdate)
#define f_settimedate(filename, ctime, cdate)
Set the time and date of a file or directory.
Definition api_f.h:607
#define f_gettimedate(filename, pctime, pcdate)
Get the time and date of a file or directory.
Definition api_f.h:595



File Time and Date Stamps

The EFFS supports file time and date stamps. There are a number of ways to obtain the current world time for an embedded system, including a Network Time Server (NTP), Real-time clock (RTC), and setting it manually. For simplicity the first two examples concentrate on file system calls. The third example includes methods to set the time and date through all the aforementioned methods. If no time or date is set, the file time stamp will be January 1, 1980.

File System Utils

All of the NetBurner EFFS examples include a helpful utility file called FileSystemUtils.cpp. This file provides an easy use interface for initializing, getting status, testing, reading and writing to a CF or SD/MMC card. To select between the types of cards, edit the header file cardtype.h. This file also demonstrates many of the commonly used EFFS function calls. These utility files are located in <nburn_install>\examples\_common\EFFS\FAT or <nburn_install>\examples\_common\EFFS\STD, depending on if you want to use an SD card (FAT), or the on chip file system (STD). The examples for EFFS that take advantage of these utility files can be found in <nburn_install>\examples\EFFS\FAT or <nburn_install>\examples\EFFS\STD, again, depending on which file system you wish to use.

EFFS FAT Example Programs

EFFS FAT

Example applications for using the file system as simple storage, with FTP, HTTP, HTTP with Variable tags, multiple tasks, RAM drive, and application updates are located at: \nburn\examples\EFFS\Fat

EFFS FAT Used In Security Applications

Example applications using the file system in security applications are:

  • HttpsDualCert to demonstrate how to have both a permanent compiled-in certificate and key, as well as one that can be loaded from an SD/MMD flash card using the EFFS FAT file system for a web server.
  • SSL_pop3 to demonstrate how to implement retrieving email from a server that requires SSL, and then saves it to an SD/MMD flash card using the EFFS FAT file system.
  • SendMailAttach demonstrates how to attach files from the EFFS FAT file system to an email and send it securely using SSL/TLS encryption.

Project Settings

To create a project that uses the EFFS-FAT file system, you will need to complete a few extra steps in addition to your normal project setup.
For NBEclipse users:

  • Add the EFFS-FAT library, libFatFile.a, to the linker path. This is done by right clicking the NBEclipse project in the "Project Explorer" -> C/C++ Build -> Settings -> GNU C/C++ Linker -> Libraries -> Add "FatFile" to the list of "Libraries (-l)".
  • Import the source files found here into your project: <nburn_install>examples\_common\EFFS\FAT

For projects that use the command line tools, add the following lines to your makefile:

XTRALIB = $(NNDK_ROOT)/platform/$(PLATFORM)/original/lib/libFatFFile.a
include $(NNDK_ROOT)/examples/_common/EFFS/FAT/common.mak