diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-06-07 03:55:04 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-06-07 03:55:04 +0000 |
commit | 922c06edc2d51873abbb2107aaa44c4077223761 (patch) | |
tree | 72ee9e0b5cb7d2d27ac4dcd283eb10bd0697dbd2 /usr.sbin | |
parent | 42996fb7977cd3e37ef35a267f902066f2da9004 (diff) |
Strip trailing slashes from dir names and give a reasonable error if
what is specified on the command line is not a mount point or device.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/quot/quot.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 14e54e89dc0..bd3c66b235a 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quot.c,v 1.8 2000/06/06 18:29:46 millert Exp $ */ +/* $OpenBSD: quot.c,v 1.9 2000/06/07 03:55:03 millert Exp $ */ /* $NetBSD: quot.c,v 1.7.4.1 1996/05/31 18:06:36 jtc Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: quot.c,v 1.8 2000/06/06 18:29:46 millert Exp $"; +static char rcsid[] = "$Id: quot.c,v 1.9 2000/06/07 03:55:03 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -538,17 +538,16 @@ quot(name, mp) * XXX this is completely broken. Of course you can't read a * directory, well, not anymore. How to fix this, though... */ - if ((fd = open(name, 0)) < 0 - || lseek(fd, SBOFF, 0) != SBOFF - || read(fd, superblock, SBSIZE) != SBSIZE) { + if ((fd = open(name, 0)) < 0) { warn("%s", name); - close(fd); return; } - if (((struct fs *)superblock)->fs_magic != FS_MAGIC + if (lseek(fd, SBOFF, 0) != SBOFF + || read(fd, superblock, SBSIZE) != SBSIZE + || ((struct fs *)superblock)->fs_magic != FS_MAGIC || ((struct fs *)superblock)->fs_bsize > MAXBSIZE || ((struct fs *)superblock)->fs_bsize < sizeof(struct fs)) { - fprintf(stderr, "%s: not a BSD filesystem\n", name); + warnx("%s: not a BSD filesystem", name); close(fd); return; } @@ -567,7 +566,7 @@ main(argc, argv) char **argv; { int cnt, all, i; - char dev[MNAMELEN], *nm, *mountpoint; + char dev[MNAMELEN], *nm, *mountpoint, *cp; struct statfs *mp; all = 0; @@ -623,17 +622,28 @@ main(argc, argv) } } for (; --argc >= 0; argv++) { - nm = *argv; mountpoint = NULL; + nm = *argv; + + /* Remove trailing slashes from name. */ + cp = nm + strlen(nm); + while (*(--cp) == '/' && cp != nm) + *cp = '\0'; /* Look up the name in the mount table. */ for (i = 0; i < cnt; i++) { + /* Remove trailing slashes from name. */ + cp = mp[i].f_mntonname + strlen(mp[i].f_mntonname); + while (*(--cp) == '/' && cp != mp[i].f_mntonname) + *cp = '\0'; + if ((!strcmp(mp->f_fstypename, MOUNT_FFS) || !strcmp(mp->f_fstypename, MOUNT_MFS) || !strcmp(mp->f_fstypename, "ufs")) && - strcmp(*argv, mp[i].f_mntonname) == 0) { + strcmp(nm, mp[i].f_mntonname) == 0) { nm = mp[i].f_mntfromname; mountpoint = mp[i].f_mntonname; + break; } } |