class::sys::Appfs

class sys::Appfs
  : public api::WorkObject

This class provides an interface for creating data files in flash memory.

The following is a basic example of creating a data file in flash and then reading from it.

#include <sapi/sys.hpp>

int main(int argc, char * argv[]){
   char my_user_data[16];
   //populate my_user_data as you please here
   sprintf(my_user_data, "Hello World!");
   Appfs::create("my_data", my_user_data, 16); //creates /app/flash/my_data as read only data
}

Now the file can be read just like any other file would be. Of course, reading files from /app/flash is very fast compared to filesystems built on external chips.

#include <sapi/sys.hpp>

int main(int argc, char * argv[]){
   char my_user_data[16];
   File f;
   f.open("/app/flash/my_data", File::RDONLY); //only the file read only
   f.read(my_user_data, 16); //read 16 bytes of user data
   f.close();  //free resources
   return 0;
}

Summary

Appfs()

int close()

int create(

const var::ConstString name,
const arg::Size size
)

Appfs & operator<<(

const var::Data & data
)

static int cleanup(

bool data
)

static int create(

const arg::FileName name,
const arg::SourceFile source_data,
const arg::SourceDirectoryPath mount,
const ProgressCallback * progress_callback
)

static var::String get_id(

const arg::SourceFilePath path
)

static AppfsInfo get_info(

const arg::SourceFilePath path
)

static u16 get_version(

const arg::SourceFilePath path
)

static int page_size()

Members

Appfs()

int close()

int create(

const var::ConstString name,
const arg::Size size
)


Appfs & operator<<(

const var::Data & data
)


static int cleanup(

bool data
)


static int create(

const arg::FileName name,
const arg::SourceFile source_data,
const arg::SourceDirectoryPath mount,
const ProgressCallback * progress_callback
)

Creates a file in flash memory consisting of the data specified.

Parameters

  • name The name of the data file (no path info)

  • buf A pointer to the data to be saved

  • nbyte The number of bytes to save

  • mount The mount path (default is /app)

  • update A callback that is executed after each page write

  • context The first argument passed to the update callback

Returns

Zero on success or -1 with errno set accordingly


static var::String get_id(

const arg::SourceFilePath path
)

Gets the application ID value.

Parameters

  • path The path to the file (must be in the /app folder)

  • id A pointer to the destination data for the ID

  • capacity The number of bytes available in id

Returns

Zero on success


static AppfsInfo get_info(

const arg::SourceFilePath path
)

Gets the info associated with an executable file.

Parameters

  • path The path to the file

  • info A reference to the destination info

Returns

Zero on success

This method will work if the file is installed in the application filesystem or on a normal data filesystem.

The method will return less than zero if the file is not a recognized executable file.

The errno will be set to ENOENT or ENOEXEC if the file does not exist or is not a recognized executable, respectively.


static u16 get_version(

const arg::SourceFilePath path
)

Gets the application version.

Parameters

  • path The path to the file (must be in the /app folder)

Returns

The BCD version of the file

For example, the BCD representation of version “1.1” is 0x0101.


static int page_size()

Returns the page size for writing data.


X

Thanks for Coming!

Subscribe to news and updates