From: Will Sowerbutts Date: Tue, 3 Feb 2015 00:35:01 +0000 (+0000) Subject: prtroot: Bug fix, new -i flag to initialise /etc/mtab X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c4dc0c0487d73db2c411f127e35de9a82c78a2e5;p=FUZIX.git prtroot: Bug fix, new -i flag to initialise /etc/mtab Bug fix: prtroot would write a 0 byte at the end of its output. The new "-i" flag causes output to go into /etc/mtab instead of to stdout. --- diff --git a/Applications/util/prtroot.c b/Applications/util/prtroot.c index 19dce5a5..effccb3e 100644 --- a/Applications/util/prtroot.c +++ b/Applications/util/prtroot.c @@ -15,9 +15,11 @@ * 5 Oct 1992 - Use readdir (kjb) * 26 Nov 1994 - Flag -r: print just the root device (kjb) * 19 May 2001 - Ported to UZI180 + * 3 Feb 015 - Flag -i: initialise the /etc/mtab file (WRS) */ #include +#include #include #include #include @@ -28,16 +30,28 @@ #define UNKNOWN_DEV "/dev/unknown" #define ROOT "/" -int rflag; +int rflag = 0; +int iflag = 0; void done(const char *name, int status) { - write(1, name, strlen(name)); - if (rflag) { - write(1, "\n", 1); - exit(status); + int fd; + + if(iflag){ + fd = open("/etc/mtab", O_CREAT | O_TRUNC | O_WRONLY, 0644); + if(fd < 0){ + perror("prtroot: cannot open /etc/mtab: "); + exit(1); + } + }else{ /* !iflag */ + fd = 1; } - write(1, MESSAGE, sizeof(MESSAGE)); + + write(fd, name, strlen(name)); + if (rflag) + write(fd, "\n", 1); + else + write(fd, MESSAGE, sizeof(MESSAGE)-1); /* do not write the terminating NUL */ exit(status); } @@ -45,11 +59,17 @@ void done(const char *name, int status) int main(int argc, const char *argv[]) { DIR *dp; + int i; struct dirent *entry; struct stat filestat, rootstat; static char namebuf[sizeof(DEV_PATH) + MAXNAMLEN + 1]; - rflag = (argc > 1 && strcmp(argv[1], "-r") == 0); + for(i=1; i