mainstream-format fstab format

. detect both formats in /etc/rc
	. generate new format in setup
	. obsoletes /etc/fstab.local: everything can go in /etc/fstab
	. put shutdown/reboot/halt and a copy of /usr/adm/wtmp
	  (/etc/wtmp) on root FS so that we can do shutdown checks before
	  mounting /usr
	. new fstab format makes getfsent() and friends work
This commit is contained in:
Ben Gras 2011-11-09 16:34:47 +01:00
parent 4311136125
commit cedeabb357
21 changed files with 200 additions and 182 deletions

View file

@ -28,7 +28,7 @@ SUBDIR= aal add_route adduser arp ash at autil awk \
sleep slip sort spell split srccrc ackstrip \
stty su sum svclog swifi sync synctree sysenv \
syslogd tail tar tcpd tcpdp tcpstat tee telnet \
telnetd term termcap tget time tinyhalt touch tr \
telnetd term termcap tget time touch tr \
truncate tsort tty udpstat umount uname unexpand \
unstack update uud uue version vol wc \
whereis which who write writeisofs fetch \

View file

@ -1557,6 +1557,7 @@ char **argv;
prog = *argv++;
while ((arg = *argv++) != 0)
if (arg[0] == '-' && arg[1] != 0 && arg[2] == 0) switch (arg[1]) {
case 'y':
case 'p':
case 'a': automatic ^= 1; break;
case 'c':
@ -1571,6 +1572,7 @@ char **argv;
case 'r': repair ^= 1; break;
case 'l': listing ^= 1; break;
case 's': listsuper ^= 1; break;
case 'f': break;
default:
printf("%s: unknown flag '%s'\n", prog, arg);
}
@ -1582,7 +1584,7 @@ char **argv;
devgiven = 1;
}
if (!devgiven) {
printf("Usage: fsck [-pacilrsz] file\n");
printf("Usage: fsck [-yfpacilrsz] file\n");
exit(1);
}
return(0);

View file

@ -3,8 +3,12 @@
PROGS= shutdown halt
SRCS.shutdown= shutdown.c sh_wall.c log.c
SRCS.halt= halt.c log.c
BINDIR=/bin
BINMODE= 4754
LINKS+= ${BINDIR}/halt ${BINDIR}/reboot
SYMLINKS+= ${BINDIR}/halt ${BINDIR}/reboot
SYMLINKS+= ${BINDIR}/halt /usr/bin/halt
SYMLINKS+= ${BINDIR}/shutdown /usr/bin/shutdown
SYMLINKS+= ${BINDIR}/reboot /usr/bin/reboot
MAN.shutdown=
MAN.halt=

View file

@ -22,7 +22,9 @@
#include <sys/stat.h>
#include <sys/wait.h>
void write_log _ARGS(( void ));
#include "wtmp.h"
void write_log _ARGS(( char *fn ));
void usage _ARGS(( void ));
int main _ARGS(( int argc, char *argv[] ));
@ -127,7 +129,8 @@ char **argv;
kill(-1, SIGTERM);
sleep(1);
write_log();
write_log(STR_WTMP);
write_log(STR_ROOT_WTMP);
sync();

View file

@ -19,9 +19,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#undef WTMP
static char WTMP[] = "/usr/adm/wtmp"; /* Record of logins and logouts. */
static char SHUT_LOG[] = "/usr/adm/log";
char who[8];
@ -29,9 +27,7 @@ extern char *prog;
static char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
void write_log _ARGS(( void ));
void write_log()
void write_log(char *wtmpfile)
{
int fd;
static struct utmp wtmp;
@ -52,7 +48,7 @@ void write_log()
strcpy (who,"root");
else
strcpy (who,pwd->pw_name);
fd = open(WTMP,O_APPEND|O_WRONLY,1);
fd = open(wtmpfile,O_APPEND|O_WRONLY|O_CREAT,1);
if (fd) {
if (strcmp(prog,"reboot"))
#ifdef __NBSD_LIBC

View file

@ -36,9 +36,9 @@
#include <unistd.h>
#include <utmp.h>
#include <errno.h>
#undef WTMP
static char WTMP[] = "/usr/adm/wtmp";
#include "wtmp.h"
static char SHUT_PID[] = "/usr/run/shutdown.pid";
static char NOLOGIN[] = "/etc/nologin";
@ -387,11 +387,15 @@ void write_pid()
int crash_check()
{
struct utmp last;
int fd, crashed;
int fd = -1, crashed;
struct stat st;
if (stat(WTMP, &st) < 0 || st.st_size == 0) return 0;
if ((fd = open(WTMP, O_RDONLY)) < 0) return 0;
if (stat(STR_ROOT_WTMP, &st) < 0 || st.st_size == 0) {
if (stat(STR_WTMP, &st) < 0 || st.st_size == 0) {
return 0;
}
if ((fd = open(STR_WTMP, O_RDONLY)) < 0) return 0;
} else if ((fd = open(STR_ROOT_WTMP, O_RDONLY)) < 0) return 0;
crashed = (lseek(fd, - (off_t) sizeof(last), SEEK_END) == -1
|| read(fd, (void *) &last, sizeof(last)) != sizeof(last)

3
commands/reboot/wtmp.h Normal file
View file

@ -0,0 +1,3 @@
static char STR_WTMP[] = "/usr/adm/wtmp";
static char STR_ROOT_WTMP[] = "/etc/wtmp";

View file

@ -469,7 +469,7 @@ mkfs.mfs -B $blocksizebytes /dev/$usr || exit
if [ "$nohome" = 0 ]
then
fshome="home=/dev/$home"
fshome="/dev/$home /home mfs rw 0 2"
else fshome=""
fi
@ -503,11 +503,8 @@ ln -s /usr/log /mnt/var/log
# CD remnants that aren't for the installed system
rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null
echo >/mnt/etc/fstab "\
# Poor man's File System Table.
root=/dev/$root
usr=/dev/$usr
echo >/mnt/etc/fstab "/dev/$root / mfs rw 0 1
/dev/$usr /usr mfs rw 0 2
$fshome"
# National keyboard map.

View file

@ -1,12 +0,0 @@
# Makefile for tinyhalt
.include <bsd.own.mk>
PROG= halt
SRCS= tinyhalt.c
BINDIR= /bin
BINMODE= 744
LINKS+= ${BINDIR}/halt ${BINDIR}/reboot
MAN=
.include <bsd.prog.mk>

View file

@ -1 +0,0 @@
See commands/reboot/README for more info.

View file

@ -1,42 +0,0 @@
/* tinyhalt 1.0 - small forerunner Author: Kees J. Bot
*
* Disk space on the root file system is a scarce resource. This little
* program sits in /sbin. It normally calls the real halt/reboot, but if
* that isn't available then it simply calls reboot(). Can't do any logging
* of the event anyhow.
*/
#define nil 0
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
int main(int argc, char **argv)
{
char *prog;
char *reboot_code = "delay; boot";
/* Try to run the real McCoy. */
#if __minix_vmd
execv("/usr/sbin/halt", argv);
#else
execv("/usr/bin/halt", argv);
#endif
if ((prog = strrchr(*argv,'/')) == nil) prog= argv[0]; else prog++;
sleep(1); /* Not too fast. */
signal(SIGHUP, SIG_IGN);
signal(SIGTERM, SIG_IGN);
kill(1, SIGTERM);
kill(-1, SIGTERM);
sleep(1);
reboot(strcmp(prog, "reboot") == 0 ? RBT_MONITOR : RBT_HALT,
reboot_code, strlen(reboot_code));
write(2, "reboot call failed\n", 19);
return 1;
}

View file

@ -1,3 +1,13 @@
20111109:
fstab format change. /etc/rc reads both formats for a while.
Please convert your /etc/fstab to the new format though as
the system will assume the new format in the future.
A helper script is in etc/. Example:
# sh etc/newfstab.sh /etc/fstab >newfstab
(Don't redirect to /etc/fstab directly as the shell will
truncate it before it can be read.)
20110928:
Update your /usr/etc/daily and /etc/man.conf if you
want to fully enjoy the manpage fixes.

View file

@ -1,11 +1,11 @@
ETC=/etc/
USR=/usr/
USRETC=/usr/etc/
FILES1=fstab group hostname.file inet.conf motd.install mtab passwd profile \
FILES1=group hostname.file inet.conf motd.install mtab passwd profile \
protocols rc services termcap ttytab utmp rc.cd binary_sizes \
binary_sizes.big binary_sizes.xxl syslog.conf rc.daemons.dist \
rs.inet rs.single make.conf system.conf ttys resolv.conf rc.conf \
rc.subr man.conf fstab.local
rc.subr rc.subr.minix man.conf
FILES2=shadow
FILES3=daily dhcptags.conf rc

View file

@ -1,4 +0,0 @@
# Poor man's File System Table.
root=/dev/ROOT
usr=/dev/USR

View file

@ -1,3 +0,0 @@
# Device Mountpoint FStype
# Example:
# /dev/ram /mnt mfs

22
etc/newfstab.sh Normal file
View file

@ -0,0 +1,22 @@
#!/bin/sh
set -e
if [ $# -ne 1 ]
then echo "Usage: $0 <minix-style-fstab> >newfstab"
exit 1
fi
fstab="$1"
. $fstab
if [ -z "$usr" -o -z "$root" ]
then echo "\$root and \$usr not set in $fstab"
exit 1
fi
echo "$root / mfs rw 0 2"
echo "$usr /usr mfs rw 0 1"
if [ -n "$home" ]
then echo "$home /home mfs rw 0 1"
fi

116
etc/rc
View file

@ -1,10 +1,13 @@
# /etc/rc - System startup script run by init before going multiuser.
. /etc/rc.subr.minix
exec >/dev/log
exec 2>/dev/log
exec </dev/null
umask 022
FSTAB=/etc/fstab
TERM="${TERM-minix}"
PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/sbin
RC_TZ=/etc/rc.timezone
@ -49,12 +52,47 @@ edit()
service $opt edit /usr/sbin/$service -label $service "$@"
}
# This function parses the deprecated minix shellscript-style
# /etc/fstab, and fscks and mounts its filesystems.
mountfstab_poorman()
{
# /etc/fstab lists the root, tmp and usr devices.
. $FSTAB
# Check if the system crashed.
if shutdown -C
then
echo
echo "The system was not properly shut down. Checking file systems."
fflag=-f
fi
if [ -n "$fflag" ]
then
echo "fsck.mfs / - $root"
intr fsck.mfs $fsckopts $root
echo "fsck.mfs /usr - $usr"
intr fsck.mfs $fsckopts $usr
if [ ! -z "$home" ]
then echo "fsck.mfs /home - $home"
intr fsck.mfs $fsckopts $home
fi
fi
# mount /usr
mount $bin_img $usr /usr
if [ ! -z "$home" ]
then mount $bin_img $home /home || echo "WARNING: couldn't mount $home on /home"
fi
}
while getopts 'saf' opt
do
case $opt in
s) sflag=t ;; # Single user
a) aflag=t ;; # Ask for /usr
f) fflag=t ;; # Force a full file system check
f) fflag=-f ;; # Force a full file system check
*) usage
esac
done
@ -99,9 +137,6 @@ start)
printroot >/etc/mtab # /etc/mtab keeps track of mounts
>/etc/utmp # /etc/utmp keeps track of logins
# /etc/fstab lists the root, tmp and usr devices.
. /etc/fstab
# Unmount now defunct ramdisk
umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
@ -114,62 +149,19 @@ start)
# Are we booting from CD?
bootcd="`/bin/sysenv bootcd`"
# If booting from CD, /usr has to be mounted readonly.
# Also, $usr won't be specified correctly in the
# fstab (the CD could be anywhere), so we decide
# where it is based on sysenv (set by FS when probing for CD).
# If booting from CD, mounting is a special case.
# We know what to do - only /usr is mounted and it's readonly.
if [ "$bootcd" = 1 ]
then
#imagedev="`/bin/sysenv cdproberoot`"
#usrdev="`expr $imagedev + 1`"
usr_roflag="-r"
usr="$cddev"p2
echo "Setting /usr on cd is $usr"
fi
# Mount the /usr partition unless this is a single floppy Minix.
if [ ! -d /usr/bin ]
then
if [ "$aflag" -o "$usr" = unknown ]
then
# We need to ask what the /usr du jour is.
intr sh -c '
echo -n "Finish the name of device to mount as /usr: /dev/"
read usr
echo "usr=/dev/$usr" >/tmp/usr'
. /tmp/usr
fi
mount $bin_img $usr_roflag $usr /usr || {
echo "\
Please try to mount something else as /usr, then hit CTRL-D to continue startup.
Mount $usr /usr failed -- Single user."
intr sh
}
rm -f /tmp/usr
fi
# Check if the system crashed.
if shutdown -C
then
echo
echo "The system was not properly shut down. Checking file systems."
fflag=t
fi
if [ "$fflag" ]
then
umount $usr
echo "fsck.mfs / - $root"
intr fsck.mfs $fsckopts $root
echo "fsck.mfs /usr - $usr"
intr fsck.mfs $fsckopts $usr
if [ ! -z "$home" ]
then echo "fsck.mfs /home - $home"
intr fsck.mfs $fsckopts $home
fi
mount $bin_img $usr /usr
then usrdev="$cddev"p2
echo "/usr on cd is $usrdev"
mount -r $usrdev /usr
else
# If we're not booting from CD, fsck + mount using /etc/fstab.
read <$FSTAB fstabline
if [ "$fstabline" = "# Poor man's File System Table." ]
then mountfstab_poorman # Old minix /etc/fstab
else mountfstab $fflag -o"$fsckopts" $FSTAB
fi
fi
# Edit settings for boot system services
@ -188,13 +180,9 @@ Mount $usr /usr failed -- Single user."
edit init
fi
if [ ! -z "$home" ]
then mount $bin_img $home /home || echo "WARNING: couldn't mount $home on /home"
fi
# This file is necessary for above 'shutdown -C' check.
# (Silence stderr in case of running from cd.)
touch /usr/adm/wtmp 2>/dev/null
touch /usr/adm/wtmp /etc/wtmp 2>/dev/null
if [ "$sflag" ]
then

68
etc/rc.subr.minix Executable file
View file

@ -0,0 +1,68 @@
mountfstab()
{
fsck_opts=""
fflag=""
while getopts "fo:" opt
do case $opt
in f) fflag="-f"
;;
o) fsck_opts="$OPTARG"
;;
*) echo "mountfstab: odd"
return 1
;;
esac
done
shift `expr $OPTIND - 1`
# Make fsck necessary for unclean shutdown
msg="The system was not properly shut down. Checking file systems."
if shutdown -C
then echo "$msg"
fflag="-f"
fi
fstabfile="$1"
if [ ! -f $fstabfile ]
then echo "mountfstab: $fstabfile not found"
return 1
fi
cat $fstabfile | sed 's/#.*//' | while read fsline
do set "" $fsline
shift
if [ $# -eq 0 ]; then continue; fi
if [ $# -lt 3 ]
then echo "$fstabfile: short line"
continue
fi
# This line's parameters
dev="$1"; mp="$2"; fstype="$3"
# Sanity checks
if [ ! -b $dev ]; then echo "$dev missing"; continue; fi
if [ ! -d $mp ]; then echo "$mp missing"; continue; fi
# Do fsck if necessary or requested
if [ -n "$fflag" ]
then echo "Checking $fstype $dev"
if ! fsck.$fstype $fflag $fsck_opts -p $dev
then echo "$dev fail"
continue
fi
fi
# Skip the actual mount for /, it's already mounted
if [ "$mp" = / ]
then continue
fi
# Do actual mount command
mount -t $fstype $dev $mp
done
}

View file

@ -2,7 +2,6 @@
RANDOM_FILE=/usr/adm/random.dat
LOCAL_FILE=/usr/etc/rc.local
LOCAL_FSTAB=/etc/fstab.local
case "$#:$1" in
1:start|1:stop|1:down)
@ -188,30 +187,6 @@ start)
# Run the daily cleanup on systems that are not on at night.
test -f /usr/etc/daily && sh /usr/etc/daily boot &
# Mount non-standard filesystems
[ -f $LOCAL_FSTAB ] && cat $LOCAL_FSTAB | grep -v '^#' | while read fsline
do set $fsline
if [ $# -lt 3 ]; then echo "$LOCAL_FSTAB: short line"; continue; fi
# This line's parameters
dev="$1"; mp="$2"; fstype="$3"
# Sanity checks
if mount | fgrep "$dev"; then echo "$dev mounted."; continue; fi
if [ ! -b $dev ]; then echo "$dev missing"; continue; fi
if [ ! -d $mp ]; then echo "$mp missing"; continue; fi
# Do fsck if necessary
if shutdown -C
then echo "Checking $fstype $dev"
if ! fsck.$fstype -p $dev; then echo "$dev fail"; continue; fi
fi
# Do actual mount command
echo "$fstype $dev on $mp:"
mount -t $fstype $dev $mp
done
;;
stop|down)
# Save random data, if /usr is mounted rw.

View file

@ -17,13 +17,18 @@ case "$#:$1" in
esac
# Get the device table.
. /etc/fstab
FSTAB=/etc/fstab
touch $FSTAB
if grep -q "Poor man" $FSTAB
then . $FSTAB
else root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
fi
# The real root device may be the RAM disk.
realroot=`printroot -r`
# If it's an initial fstab, pretend root is real root
if [ $root = "/dev/ROOT" ]
if [ "$root" = "/dev/ROOT" -o -z "$root" ]
then root=$realroot
fi

View file

@ -308,19 +308,22 @@ extrakb=`du -s $RELEASEDIR/usr/install | awk '{ print $1 }'`
find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles
find $RELEASEDIR -print -path $RELEASEDIR/usr -prune | wc -l >$RELEASEDIR/.rootfiles
fstab_marker="# Poor man's File System Table."
echo " * Writing fstab"
if [ "$USB" -ne 0 ]
then
echo \
'root=/dev/c0d7p0s0
"$fstab_marker
root=/dev/c0d7p0s0
usr=/dev/c0d7p0s2
' > $RELEASEDIR/etc/fstab
" > $RELEASEDIR/etc/fstab
elif [ "$HDEMU" -ne 0 ]
then
echo \
'root=/dev/c0d7p0s0
"$fstab_marker
root=/dev/c0d7p0s0
usr=/dev/c0d7p0s2
usr_roflag="-r"' > $RELEASEDIR/etc/fstab
usr_roflag=\"-r\"" > $RELEASEDIR/etc/fstab
fi
echo " * Mounting $TMPDISKROOT as $RELEASEMNTDIR"