6.3.2 Procedure
The procedure for calculating free/occupied space is as follows:
- Initialize the free space to the size of the flash (as formatted by Uniflash) and the occupied space to 0. Units are blocks (of 4KB)
- Account for FAT and the reserved blocks:
- Decrease free space by 5 blocks
- Increase occupied space by 5 blocks
- Calculate the allocated size for every user file created. For more information, see Section 4.
- Loop over all user files and for every file apply:
- Decrease free space by the allocated size in blocks
- Increase occupied space by the allocated size in blocks
- Loop over all system/configuration files, invoke fsGetInfo() API and conclude:
- If return value is SL_FS_ERR_FILE_NOT_EXISTS, file does not exist and thus counters should remain, else, if no error is returned, followings should be updated:
- Decrease free space by the allocated size in blocks
- Increase occupied space by the allocated size in blocks
- If return value is SL_FS_ERR_TOKEN_IS_NOT_VALID, it means the file is secured but exists. This return value applies to the following three files:
- /tmp/fcon.frm
- /sys/pref.net
- /sys/smartconfigkeys.cfg
In this case, the file exists and followings should be updated:
- Decrease free space by the allocated size in blocks
- Increase occupied space by the allocated size in blocks
Figure 3 illustrates the procedure.