diff --git a/utils/Makefile b/utils/Makefile index ed8c319c..3a5477bd 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -84,6 +84,7 @@ chroot \ unmount \ MANPAGES8=\ +unmount.8 \ all: $(BINARIES) $(SBINS) @@ -97,8 +98,8 @@ install: all install $(SBINS) $(DESTDIR)$(SBINDIR) mkdir -p $(DESTDIR)$(MANDIR)/man1 cp $(MANPAGES1) $(DESTDIR)$(MANDIR)/man1 - #mkdir -p $(DESTDIR)$(MANDIR)/man8 - #cp $(MANPAGES8) $(DESTDIR)$(MANDIR)/man8 + mkdir -p $(DESTDIR)$(MANDIR)/man8 + cp $(MANPAGES8) $(DESTDIR)$(MANDIR)/man8 %: %.c $(CC) -std=gnu11 $(CFLAGS) $(CPPFLAGS) $< -o $@ diff --git a/utils/unmount.8 b/utils/unmount.8 new file mode 100644 index 00000000..5a566f1f --- /dev/null +++ b/utils/unmount.8 @@ -0,0 +1,35 @@ +.Dd October 11, 2016 +.Dt UNMOUNT 8 +.Os +.Sh NAME +.Nm unmount +.Nd unmount filesystems +.Sh SYNOPSIS +.Nm +.Op Fl fl +.Ar directory ... +.Sh DESCRIPTION +.Nm +unmounts the specified paths. The mountpoint is removed so that it cannot be +opened further, and +.Nm +waits until no files on the filesystem are open, after which the filesystem is +shut off cleanly. +.Pp +The options are as follows: +.Bl -tag -width "12345678" +.It Fl f, Fl \-force +Shut off the filesystem immediately, further operations to any open files will +fail. The filesystem will be consistent, but processes may be stopped in the +middle of file operations. +.It Fl l, Fl \-lazy +Do not wait for the filesystem to be unused, and shut off the filesystem in +the background. It is not safe to shut down the computer directly after using +this option. +.El +.Sh EXIT STATUS +.Nm +will exit 0 on success and non-zero otherwise. +.Sh SEE ALSO +.Xr unmount 2 , +.Xr extfs 8 diff --git a/utils/unmount.c b/utils/unmount.c index 793b1af6..295d088a 100644 --- a/utils/unmount.c +++ b/utils/unmount.c @@ -19,8 +19,7 @@ #include -#include -#include +#include #include #include #include @@ -40,22 +39,6 @@ static void compact_arguments(int* argc, char*** argv) } } -static void help(FILE* fp, const char* argv0) -{ - fprintf(fp, "Usage: %s [OPTION]... DIRECTORY...\n", argv0); - fprintf(fp, "Unmounts filesystems mounted at directories..\n"); - fprintf(fp, "\n"); - fprintf(fp, "Mandatory arguments to long options are mandatory for short options too.\n"); - fprintf(fp, " -f, --force unmount even though still in use\n"); - fprintf(fp, " -l, --lazy remove mountpoint but delay unmounting until no longer used"); - -} - -static void version(FILE* fp, const char* argv0) -{ - fprintf(fp, "%s (Sortix) %s\n", argv0, VERSIONSTR); -} - int main(int argc, char* argv[]) { setlocale(LC_ALL, ""); @@ -63,7 +46,6 @@ int main(int argc, char* argv[]) bool force = false; bool lazy = false; - const char* argv0 = argv[0]; for ( int i = 1; i < argc; i++ ) { const char* arg = argv[i]; @@ -80,25 +62,15 @@ int main(int argc, char* argv[]) case 'f': force = true; break; case 'l': lazy = true; break; default: - fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); - help(stderr, argv0); - exit(1); + errx(1, "unknown option -- '%c'", c); } } - else if ( !strcmp(arg, "--help") ) - help(stdout, argv0), exit(0); - else if ( !strcmp(arg, "--version") ) - version(stdout, argv0), exit(0); else if ( !strcmp(arg, "--force") ) force = true; else if ( !strcmp(arg, "--lazy") ) lazy = true; else - { - fprintf(stderr, "%s: unknown option: %s\n", argv0, arg); - help(stderr, argv0); - exit(1); - } + errx(1, "unknown option: %s", arg); } compact_arguments(&argc, &argv); @@ -113,7 +85,7 @@ int main(int argc, char* argv[]) { const char* path = argv[i]; if ( unmount(path, flags) < 0 ) - error(1, errno, "`%s'", path); + err(1, "%s", path); } return 0;