|
Author: Peter S. Housel
Date: 23-07-03 19:04
I dual-boot my laptop between FreeBSD 5.1-CURRENT and Windows XP Professional. I've found through bitter experience that a sure
recipe for lost files is to:
1. Boot into XP, then hibernate it.
2. When starting the machine again, boot into FreeBSD.
3. Mount XP's FAT partition read-write, and write some files.
4. Reboot and resume XP.
XP's in-memory cache now no longer matches what's on the disk,
resulting in cross-linked files and other filesystem corruption.
To avoid this, I now mount my FAT filesystem read-only by default:
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1 /dos/c msdos ro 0 0
To re-mount it as read-write when it is safe, I placed the
following msdosfs.sh file in /usr/local/etc/rc.d:
#!/bin/sh
#
case "$1" in
start)
if /usr/local/sbin/hiberfil; then
/sbin/mount -u -o rw /dev/ad0s1
fi
;;
stop|restart)
;;
esac
I found through experimentation that when XP is not hibernating,
the first 4K of C:\hiberfil.sys is all zeroes. The
/usr/local/sbin/hiberfil script performs this check:
#!/usr/local/bin/perl
open(HIBERFIL, "</dos/c/hiberfil.sys") || exit 0;
my $sector = '';
if(sysread(HIBERFIL, $sector, 4096) != 4096) {
exit 0;
}
if ($sector eq ("\0" x 4096)) {
exit 0;
} else {
exit 1;
}
|
|
Reply To This Message
|
|
Author: Peter S. Housel
Date: 26-07-03 23:54
Oops... unescaped angle brackets messed up the perl script. The open(HIBERFIL, ...) line should read:
open(HIBERFIL, "</dos/c/hiberfil.sys") || exit 0;
|
|
Reply To This Message
|
|