emFile Journaling is an additional component which sits on top of the file system and makes the file system layer fail-safe. File systems without journaling support (for example, FAT and EFS) are not fail-safe. Journaling means that a file system logs all changes to a journal before committing them to the main file system and thus ensuring the consistence of the file system.
emFile is typically used with non fail-safe file systems such as FAT and EFS. Loss of data can occur in either the driver layer or the file system layer. The driver layer is typically fail-safe so the only place for typical data loss is the file system layer. The file system can be corrupted through an interrupted write access for example in the event of power failure or system crash. This is by design for FAT and true for all implementations from any vendor. The emFile Journaling add-on adds journaling to the file system layer.
The goal of this additional layer is to guarantee that the file system that is always in a consistent state after an unexpected reset. Operations on the file system layer are mostly not atomic. For example, a single call of FS_FWrite() to write data into a new file causes the execution of the following three storage layer operations:
- Allocate cluster and update the allocation table
- Write user data
- Update directory entry
An unexpected reset (such as a power failure) in this process can corrupt the file system. To prevent such corruptions the Journaling add-on caches every write access to achieve an always consistent state of the file system. All changes to the file system are stored in a journal file. The data stored in the journal file is copied into the file system only if the operation of the file system layer has been finished without interruption.
This procedure guarantees an always consistent state of the file system, because an interruption of the copy process does not lead to data loss. The interrupted copy process will be restarted after the target is restarted again.
|Moment of error||File system state||Data state|
|While writing into journal.||Consistent||Lost|
|While finalizing of the journal.||Consistent||Lost|
|While copying from journal into file system.||Consistent||Obtained|
|After copy process, before invalidating of the journal.||Consistent||Obtained|
|While invalidating of the journal.||Consistent||Obtained|
Using journaling is very simple from a user perspective.
- Enable journaling in the emFile configuration.
- Call FS_JOURNAL_Create() after formatting the volume.
That’s it. Everything else is done by the emFile Journaling extension.
Data can be lost in case of unexpected reset in either the file system layer (FAT or EFS) or in the device driver layer. The entire system is fail-safe only if both layers are fail-safe. The Journaling add-on makes sure that the file system layer is fail-safe. For the fail-safety of the individual device drivers please refer to the specific device driver pages.