Sistema de maniobra y gobierno
5.5. Sistema de achique y lastre
5.5.1. Sistema de achique
All Verix V-based terminals include support for a separate user file system stored in flash memory. Any file with F: preceding the filename is assigned to flash. In many respects, it behaves similar to the default RAM file system previously discussed. the following is an overview of features unique to the flash file system.
The most significant difference between flash and RAM is that the space used by a flash file is not automatically recovered when the file is deleted. That space is not immediately available for use by other files. Many applications use flash files to hold only codefiles and parameter files downloaded from a host PC. For this kind of application, all flash files are read-only, and are handled exactly like files in the RAM file system.
Restrictions on Flash Files
There are several restrictions on flash files:
• Only one flash file can be open with write access at any time. If a second flash file is open with write access, the open returns EACCES. Multiple flash files with read-only access can be open at the same time.
• If a file that exists is open with write access, the existing file is deleted and a new file created. That is, the file is truncated; it is important to include the O_TRUNC access option in the open() statement.
• When a flash file is removed, the space used by the file is not immediately recovered, so it is not available for use by other flash files. To recover this space and make it available, the flash file system must be coalesced to bring all valid flash files together at the beginning of the flash file system, with all the remaining space erased and available for new flash files. This process is invoked using dir_flash_coalesce().
• Any file function that only requires a read access to a file returns EBUSY if the file requested is not closed by its creator (that is, the write-access handle is not closed). These functions include open() with O_RDONLY access, read(), all status() functions, and some directory functions (dir_xxx()).
• If a flash file is opened as read-only and a new open() with write access to that file is issued, that file is tagged as deleted by the write handle, and a new file is created. The handle with read-only access is still accessing the deleted file until a close() is done on that handle. Any open() after the open() with write access gets the new file.
File Manager Function Calls Supported in the Flash File System
• open()— multiple read handles, one write handle
• close()
• read()
• write()
• lseek()
• status() functions (on open file):
FILE MANAGEMENT
Flash File System
• get_file_size()
• get_file_date()
• get_file_attributes()
• get_file_max()
• Control functions (on open file):
• lock()/unlock()
• set_file_attributes()
• reset_file_attributes()
• put_file_date(int handle, char *yyyymmddhhmmss) — same
as dir_put_file_date(), except file is specified by handle instead of filename
• dir_get_first() *drive parameter
• dir_get_next()—returns drive as part of filename
• _remove()
• dir_get_file_sz()
• dir_get_sizes() *drive parameter, count includes deleted files
• SVC_CHECKFILE()
• dir_get_file_date()
• dir_get_attributes()
• get_dir_file_hdr()
• get_dir_file_size()
File Manager Function Calls Not Supported in the Flash File System
The following functions return EINVAL if a file handle for a flash file is passed as a parameter:
• Control functions (on open file):
NOTE *drive parameter—the above functions require the char *drive parameter to distinguish between the RAM and flash file systems.
Flash File System
Open and Close When a new flash file is opened, only the filename is written to the flash. There is only support for one open flash file with write access at any time.
To open a flash file with write access, the file must have the O_APPEND bit set, and either O_RDWR or O_WRONLY set. If the file to open already exists, O_TRUNC is also required; if it is a new file, O_CREAT is required. An attempt to open a second file with write access at the same time returns errno set to EACCES.
When opening an existing closed flash file for write access, the existing file is deleted. A new version of the file is created at the next available address in flash with a size of zero. The contents of the previous file are lost. The file is not actually removed from the file system until a dir_flash_coalesce call is performed;
the filename is changed to tag the file as deleted.
Multiple flash files can be opened with read-only access (with the O_RDONLY attribute bit set). To open a file with read-only access, the file must exist and must be closed after creation. If it was not closed, the open with read-only access returns EBUSY.
Flash Rebuild If a flash file was written to and was not closed on a memory clear, the file is tagged deleted. This means that if the terminal loses power or SVC_RESTART() or dir_flash_coalesce() is called before a flash file with write access was closed, that file is tagged as deleted at restart.
Flash Erase The only way to erase flash is to call dir_flash_coalesce(). During a file operation to a flash file if there is not enough room to write the header on open() or to write the data on write(), the function fails with ENOSPC. When this occurs, one of the two following operations must be performed to allow further writes to the flash file system. Also,
• The coalesce process deletes any file with write access not closed prior to the coalesce. The dir_flash_coalesce_size() function returns EBUSY if there is an open file, so call this function prior to performing the coalesce.
• This is a time-consuming process; use accordingly.
NOTE The file count in the flash file system header includes all the deleted but not erased files. This is because to get to the current files, the files tagged deleted must be skipped. All space must be accounted for.
FILE MANAGEMENT