What happens when we switch the power off, and files are still open
for write access?
Do we get invalid files / bad blocks?
If the power is physically switched off without taking the proper
precautions the following could happen:
- If files are open for write access but nothing is being written
to the drive, you'll lose the unsaved changes (what's in the cache for
instance) if the power loss occurs before that cache is automatically
synced to the drive
(umount
or
sync
will force that to happen).
This shouldn't corrupt the file.
However note that if the file was being
grown, the inode is marked as BUSY on-disk until you close the file.
If there's a power failure, you can get EBADFSYS errors
for that file.
In that case, you can use the qnx4 unbusy option to instead
just truncate it back to the old size (see the
fs-qnx4.so documentation for more details).
- You could also reduce the write delay to flush a dirty block
out of the cache sooner if this is a concern (see
io-blk's
delwri option for more details).
- If files are open for reading/writing and you're currently reading
files, corruption can't occur as long as the access time for that file
isn't updated in the directory entry (use io-blk's
noatime option).
- If files are open for reading/writing, and you're currently writing
to the drive (physically as opposed to the write cache), then in the
best case you can corrupt the file; in the worse case, you can corrupt
the directory entry where that file is.
If that directory entry is the root directory, then you could corrupt
the root block too.
That is the absolute worse case because you may not be able to boot
from the disk any more.
The
chkfsys,
utility should be able to recover from the file or directory corruption.
For more information, see the
Backing Up and Recovering Data
chapter of the QNX Neutrino User's Guide.