summaryrefslogtreecommitdiff
path: root/sbin/dump/main.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-07 17:29:26 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-07 17:29:26 +0000
commite35ef9b65068f5196a0b33c34106f6f49db38780 (patch)
tree036fadc5a8a77dc4f68952e055bcd824e6a1469e /sbin/dump/main.c
parent53796aa2246dd1e12da7ecff86653af747b67da4 (diff)
Use strlcpy() instead of strncpy().
Change the order of name -> raw device conversions 1) statfs the name and use that info iff the name is the mount point 2) look up name in fstab 3) treat as a device The reason for this is that the mounted filesystems may not agree with what fstab says. Anyone who has ever moved disks around and accidentally dumped and empty filesystem will know what I mean.
Diffstat (limited to 'sbin/dump/main.c')
-rw-r--r--sbin/dump/main.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/sbin/dump/main.c b/sbin/dump/main.c
index f57f5404241..270727983dc 100644
--- a/sbin/dump/main.c
+++ b/sbin/dump/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.20 1998/07/28 23:27:58 millert Exp $ */
+/* $OpenBSD: main.c,v 1.21 1998/08/07 17:29:25 millert Exp $ */
/* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */
/*-
@@ -347,36 +347,36 @@ main(argc, argv)
* the special name missing the leading '/',
* the file system name with or without the leading '/'.
*/
- dt = fstabsearch(disk);
- if (dt != NULL) {
+ if (!statfs(disk, &fsbuf) && !strcmp(fsbuf.f_mntonname, disk)) {
+ /* mounted disk? */
+ disk = rawname(fsbuf.f_mntfromname);
+ (void)strlcpy(spcl.c_dev, fsbuf.f_mntfromname,
+ sizeof(spcl.c_dev));
+ if (dirlist != 0) {
+ (void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys),
+ "a subset of %s", fsbuf.f_mntonname);
+ } else {
+ (void)strlcpy(spcl.c_filesys, fsbuf.f_mntonname,
+ sizeof(spcl.c_filesys));
+ }
+ } else if ((dt = fstabsearch(disk)) != NULL) {
+ /* in fstab? */
disk = rawname(dt->fs_spec);
- (void)strncpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev) - 1);
- spcl.c_dev[sizeof(spcl.c_dev) - 1] = '\0';
+ (void)strlcpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev));
if (dirlist != 0) {
(void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys),
"a subset of %s", dt->fs_file);
} else {
- (void)strncpy(spcl.c_filesys, dt->fs_file,
- sizeof(spcl.c_filesys) - 1);
- spcl.c_filesys[sizeof(spcl.c_filesys) - 1] = '\0';
+ (void)strlcpy(spcl.c_filesys, dt->fs_file,
+ sizeof(spcl.c_filesys));
}
- } else if (!statfs(disk, &fsbuf) && !strcmp(fsbuf.f_mntonname, disk)) {
- disk = rawname(fsbuf.f_mntfromname);
- (void)strncpy(spcl.c_dev, fsbuf.f_mntfromname,
- sizeof(spcl.c_dev) - 1);
- spcl.c_dev[sizeof(spcl.c_dev) - 1] = '\0';
- (void)strncpy(spcl.c_filesys, fsbuf.f_mntonname,
- sizeof(spcl.c_filesys) - 1);
- spcl.c_filesys[sizeof(spcl.c_filesys) - 1] = '\0';
} else {
- (void)strncpy(spcl.c_dev, disk, sizeof(spcl.c_dev) - 1);
- spcl.c_dev[sizeof(spcl.c_dev) - 1] = '\0';
- (void)strncpy(spcl.c_filesys, "an unlisted file system",
- sizeof(spcl.c_filesys) - 1);
- spcl.c_filesys[sizeof(spcl.c_filesys) - 1] = '\0';
+ /* must be a device */
+ (void)strlcpy(spcl.c_dev, disk, sizeof(spcl.c_dev));
+ (void)strlcpy(spcl.c_filesys, "an unlisted file system",
+ sizeof(spcl.c_filesys));
}
- (void)strncpy(spcl.c_label, "none", sizeof(spcl.c_label) - 1);
- spcl.c_label[sizeof(spcl.c_label) - 1] = '\0';
+ (void)strlcpy(spcl.c_label, "none", sizeof(spcl.c_label));
(void)gethostname(spcl.c_host, sizeof(spcl.c_host));
spcl.c_level = level - '0';
spcl.c_type = TS_TAPE;