User`s manual

Dynamic C Users Manual digi.com 135
10.1.3.1 FS2 API Error Codes
The library ERRNO.LIB contains a list of all possible error codes returnable by the FS2 API. These error
codes mostly conform to POSIX standards. If the return value indicates an error, then the global variable
errno may be examined to determine a more specific reason for the failure. The possible errno codes
returned from each function are documented with the function.
10.1.4 Setting up and Partitioning the File System
This step merits some thought before plowing ahead. The context within which the file system will be used
should be considered. For example, if the target board contains both battery-backed SRAM and a second
flash chip, then both types of storage may be used for their respective advantages. The SRAM might be
used for a small application configuration file that changes frequently, and the flash used for a large log
file.
FS2 automatically detects the second flash device (if any) and will also use any SRAM set aside for the
file system (if FS2_RAM_RESERVE is set).
10.1.4.1 Initial Formatting
The filesystem must be formatted when it is first used. The only exception is when a flash memory device
is known to be completely erased, which is the normal condition on receipt from the factory. If the device
contains random data, then formatting is required to avoid the possibility of some sectors being perma-
nently locked out of use.
Formatting is also required if any of the logical extent parameters are changed, such as changing the logi-
cal sector size or re-partitioning. This would normally happen only during application development.
The question for application developers is how to code the application so that it formats the filesystem
only the first time it is run. There are several approaches that may be taken:
A special program that is loaded and run once in the factory, before the application is loaded. The spe-
cial program prepares the filesystem and formats it. The application never formats; it expects the file-
system to be in a proper state.
The application can perform some sort of consistency check. If it determines an inconsistency, it calls
format. The consistency check could include testing for a file that should exist, or by checking some
sort of "signature" that would be unlikely to occur by chance.
Have the application prompt the end-user, if some form of interaction is possible.
A combination of one or more of the above.
Rely on a flash device being erased. This would be OK for a production run, but not suitable if battery-
backed SRAM was being used for part of the filesystem.