Chapter 33. Using the FAT Filesystem
The FAT filesystem is accessed through the FILEIO package and responds
to all the standard filesystem functions such as
write(). To use
these operations the filesystem must first be mounted.
A FAT filesystem may be mounted using the
function. The following is an example of how to mount a FAT filesystem:
err = mount( "/dev/hd0/1", "/disk0", "fatfs:sync=write" );
This function call will mount the first partition of hard disk 0 (see
the documentation on the DISKIO package for a full description of the
device name format). The root of this disk can then be accessed
with the name "/disk0". The
mount() function will
return zero if the mount succeeded, or -1 if it failed for any reason,
for example if the partition does not exist, or the filesystem is not
in FAT format.
The options after the colon in the filesystem name are passed to the filesystem to control various aspects of the filesystem. The options currently supported are:
This option controls the synchronization behaviour of the block cache. If omitted then the cache is run on an entirely write-back basis and blocks are only written back to disk when they need to be replaced with new data, when
sync()is called, or the filesystem is unmounted. This is generally the most efficient mode, but is prone to losing data or corrupting the filesystem if power is lost while the filesystem is mounted.
If this option is set to "write" then the cache is operated on a write-back basis and every block update is written immediately back to disk. This is the least efficient mode since any extension to a file may result in several blocks being written back to disk. It does, however, keep the filesystem up to date on disk.
If this option is set to "close" then the cache is only written back to disk whenever a file is closed. Note that this causes the entire cache to be written, not just those blocks associated with the file being closed. In terms of efficiency, this is a good compromise between performance and safety.
- This is a stand-alone option which causes the filesystem to be mounted read-only. The effect of this is to prevent the filesystem writing anything back to the disk. Under normal circumstances this cannot be guaranteed for a normal mount, even when files are only read, since the filesystem may need to update the access time for files that have been read.
When finished with, a filesystem may be unmounted using the
umount() function. The following would unmount
the filesystem mounted above:
err = umount( "/disk0" );
It is important to unmount any removable devices before removing them, otherwise there is no guarantee that all cached data blocks will have been written to disk. The same is true of resetting the system before unmounting non-removable devices.
|2018-07-27||eCosPro Non-Commercial Public License|