From cedeabb357aabd23c1737fcc7b051d385b8bf940 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 9 Nov 2011 16:34:47 +0100 Subject: [PATCH] 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 --- commands/Makefile | 2 +- commands/fsck.mfs/fsck.c | 4 +- commands/reboot/Makefile | 6 +- commands/reboot/halt.c | 7 ++- commands/reboot/log.c | 8 +-- commands/reboot/shutdown.c | 14 +++-- commands/reboot/wtmp.h | 3 + commands/setup/setup.sh | 9 +-- commands/tinyhalt/Makefile | 12 ---- commands/tinyhalt/README | 1 - commands/tinyhalt/tinyhalt.c | 42 ------------- docs/UPDATING | 10 +++ etc/Makefile | 4 +- etc/fstab | 4 -- etc/fstab.local | 3 - etc/newfstab.sh | 22 +++++++ etc/rc | 118 ++++++++++++++++------------------- etc/rc.subr.minix | 68 ++++++++++++++++++++ etc/usr/rc | 25 -------- tools/mkboot | 9 ++- tools/release.sh | 11 ++-- 21 files changed, 200 insertions(+), 182 deletions(-) create mode 100644 commands/reboot/wtmp.h delete mode 100644 commands/tinyhalt/Makefile delete mode 100644 commands/tinyhalt/README delete mode 100644 commands/tinyhalt/tinyhalt.c delete mode 100755 etc/fstab delete mode 100644 etc/fstab.local create mode 100644 etc/newfstab.sh create mode 100755 etc/rc.subr.minix diff --git a/commands/Makefile b/commands/Makefile index 65e1c5999..73f36e48c 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -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 \ diff --git a/commands/fsck.mfs/fsck.c b/commands/fsck.mfs/fsck.c index 45a737b6c..5f26a22bf 100644 --- a/commands/fsck.mfs/fsck.c +++ b/commands/fsck.mfs/fsck.c @@ -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); diff --git a/commands/reboot/Makefile b/commands/reboot/Makefile index 44da118cc..91c6cee4e 100644 --- a/commands/reboot/Makefile +++ b/commands/reboot/Makefile @@ -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= diff --git a/commands/reboot/halt.c b/commands/reboot/halt.c index 5c627a64d..62a122544 100644 --- a/commands/reboot/halt.c +++ b/commands/reboot/halt.c @@ -22,7 +22,9 @@ #include #include -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(); diff --git a/commands/reboot/log.c b/commands/reboot/log.c index bd3e2df8c..74e7bd0f4 100644 --- a/commands/reboot/log.c +++ b/commands/reboot/log.c @@ -19,9 +19,7 @@ #include #include #include -#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 diff --git a/commands/reboot/shutdown.c b/commands/reboot/shutdown.c index 5937701de..8578cbeaa 100644 --- a/commands/reboot/shutdown.c +++ b/commands/reboot/shutdown.c @@ -36,9 +36,9 @@ #include #include #include -#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) diff --git a/commands/reboot/wtmp.h b/commands/reboot/wtmp.h new file mode 100644 index 000000000..69044ddef --- /dev/null +++ b/commands/reboot/wtmp.h @@ -0,0 +1,3 @@ + +static char STR_WTMP[] = "/usr/adm/wtmp"; +static char STR_ROOT_WTMP[] = "/etc/wtmp"; diff --git a/commands/setup/setup.sh b/commands/setup/setup.sh index 61b46e3ab..8b045d423 100644 --- a/commands/setup/setup.sh +++ b/commands/setup/setup.sh @@ -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. diff --git a/commands/tinyhalt/Makefile b/commands/tinyhalt/Makefile deleted file mode 100644 index dc9daffcb..000000000 --- a/commands/tinyhalt/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Makefile for tinyhalt - -.include - -PROG= halt -SRCS= tinyhalt.c -BINDIR= /bin -BINMODE= 744 -LINKS+= ${BINDIR}/halt ${BINDIR}/reboot -MAN= - -.include diff --git a/commands/tinyhalt/README b/commands/tinyhalt/README deleted file mode 100644 index 185fff020..000000000 --- a/commands/tinyhalt/README +++ /dev/null @@ -1 +0,0 @@ -See commands/reboot/README for more info. diff --git a/commands/tinyhalt/tinyhalt.c b/commands/tinyhalt/tinyhalt.c deleted file mode 100644 index bbde83daf..000000000 --- a/commands/tinyhalt/tinyhalt.c +++ /dev/null @@ -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 -#include -#include -#include -#include -#include - -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; -} diff --git a/docs/UPDATING b/docs/UPDATING index a21898b91..45be2aba9 100644 --- a/docs/UPDATING +++ b/docs/UPDATING @@ -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. diff --git a/etc/Makefile b/etc/Makefile index a81ea6343..2624e603f 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -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 diff --git a/etc/fstab b/etc/fstab deleted file mode 100755 index 8df5be80c..000000000 --- a/etc/fstab +++ /dev/null @@ -1,4 +0,0 @@ -# Poor man's File System Table. - -root=/dev/ROOT -usr=/dev/USR diff --git a/etc/fstab.local b/etc/fstab.local deleted file mode 100644 index ec5db9ad2..000000000 --- a/etc/fstab.local +++ /dev/null @@ -1,3 +0,0 @@ -# Device Mountpoint FStype -# Example: -# /dev/ram /mnt mfs diff --git a/etc/newfstab.sh b/etc/newfstab.sh new file mode 100644 index 000000000..c925fdf4e --- /dev/null +++ b/etc/newfstab.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e + +if [ $# -ne 1 ] +then echo "Usage: $0 >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 diff --git a/etc/rc b/etc/rc index 3b6626280..80d22804e 100755 --- a/etc/rc +++ b/etc/rc @@ -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 /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 diff --git a/etc/rc.subr.minix b/etc/rc.subr.minix new file mode 100755 index 000000000..c98c86fd4 --- /dev/null +++ b/etc/rc.subr.minix @@ -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 +} diff --git a/etc/usr/rc b/etc/usr/rc index 66c5b4773..dafd371cb 100644 --- a/etc/usr/rc +++ b/etc/usr/rc @@ -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. diff --git a/tools/mkboot b/tools/mkboot index 95824f2b6..a53289880 100755 --- a/tools/mkboot +++ b/tools/mkboot @@ -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 diff --git a/tools/release.sh b/tools/release.sh index c01b5eed7..3fc599619 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -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"