diff options
author | Aaron Campbell <aaron@cvs.openbsd.org> | 1998-11-04 21:52:42 +0000 |
---|---|---|
committer | Aaron Campbell <aaron@cvs.openbsd.org> | 1998-11-04 21:52:42 +0000 |
commit | d6f1d6dc661df1dc7b33ef68c2ee6705236dec85 (patch) | |
tree | dd62656b2d465252ab064019507a4ae36cc933b6 | |
parent | c99fa1193f3be035853c686ea9dca148002061ef (diff) |
use optimal xfer block size in rm_overwrite() instead of assuming 8192
-rw-r--r-- | bin/rm/rm.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 63406f2eb27..7b9730647d4 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rm.c,v 1.6 1997/09/01 18:30:26 deraadt Exp $ */ +/* $OpenBSD: rm.c,v 1.7 1998/11/04 21:52:41 aaron Exp $ */ /* $NetBSD: rm.c,v 1.19 1995/09/07 06:48:50 jtc Exp $ */ /*- @@ -44,12 +44,14 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: rm.c,v 1.6 1997/09/01 18:30:26 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: rm.c,v 1.7 1998/11/04 21:52:41 aaron Exp $"; #endif #endif /* not lint */ #include <sys/types.h> #include <sys/stat.h> +#include <sys/param.h> +#include <sys/mount.h> #include <locale.h> #include <err.h> @@ -309,9 +311,10 @@ rm_overwrite(file, sbp) struct stat *sbp; { struct stat sb; + struct statfs fsb; off_t len; - int fd, wlen; - char buf[8 * 1024]; + int bsize, fd, wlen; + char *buf; fd = -1; if (sbp == NULL) { @@ -323,11 +326,16 @@ rm_overwrite(file, sbp) return; if ((fd = open(file, O_WRONLY, 0)) == -1) goto err; + if (fstatfs(fd, &fsb) == -1) + goto err; + bsize = MAX(fsb.f_iosize, 1024); + if ((buf = malloc(bsize)) == NULL) + err(1, "malloc"); #define PASS(byte) { \ - memset(buf, byte, sizeof(buf)); \ + memset(buf, byte, bsize); \ for (len = sbp->st_size; len > 0; len -= wlen) { \ - wlen = len < sizeof(buf) ? len : sizeof(buf); \ + wlen = len < bsize ? len : bsize; \ if (write(fd, buf, wlen) != wlen) \ goto err; \ } \ @@ -339,10 +347,13 @@ rm_overwrite(file, sbp) if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) goto err; PASS(0xff); - if (!fsync(fd) && !close(fd)) + if (!fsync(fd) && !close(fd)) { + free(buf); return; + } err: eval = 1; + free(buf); warn("%s", file); } |