summaryrefslogtreecommitdiffstats
path: root/bin/rm
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>1999-05-28 12:47:31 +0000
committerkris <kris@FreeBSD.org>1999-05-28 12:47:31 +0000
commit74171e7d70a316b34e4fe4b7fc72111a1819ea70 (patch)
treedff660f848d47da33cf88bc06f4226aba6e9429f /bin/rm
parentf2330285f270d887515ce96289baa43dffc72e5a (diff)
downloadFreeBSD-src-74171e7d70a316b34e4fe4b7fc72111a1819ea70.zip
FreeBSD-src-74171e7d70a316b34e4fe4b7fc72111a1819ea70.tar.gz
Use .Dq instead of ``'' in manpage
Use optimal blocksize for rm -P, instead of always using 8192-byte blocks to overwrite the file. Obtained from: OpenBSD
Diffstat (limited to 'bin/rm')
-rw-r--r--bin/rm/rm.17
-rw-r--r--bin/rm/rm.c24
2 files changed, 23 insertions, 8 deletions
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1
index 7ef2995..ac76673 100644
--- a/bin/rm/rm.1
+++ b/bin/rm/rm.1
@@ -33,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)rm.1 8.5 (Berkeley) 12/5/94
-.\" $Id: rm.1,v 1.12 1998/05/18 06:37:35 charnier Exp $
+.\" $Id: rm.1,v 1.13 1999/01/28 17:41:02 wollman Exp $
.\"
.Dd January 28, 1999
.Dt RM 1
@@ -109,7 +109,10 @@ The
.Nm
utility removes symbolic links, not the files referenced by the links.
.Pp
-It is an error to attempt to remove the files ``.'' and ``..''.
+It is an error to attempt to remove the files
+.Dq \&.
+or
+.Dq .. .
.Pp
The
.Nm
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index e12bbdea..4599c9e 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -42,12 +42,14 @@ static const char copyright[] =
static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94";
#else
static const char rcsid[] =
- "$Id: rm.c,v 1.18 1997/08/07 21:37:39 steve Exp $";
+ "$Id: rm.c,v 1.19 1999/02/25 22:18:08 jkh Exp $";
#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/mount.h>
#include <err.h>
#include <errno.h>
@@ -330,9 +332,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 = NULL;
fd = -1;
if (sbp == NULL) {
@@ -344,11 +347,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; \
} \
@@ -360,10 +368,14 @@ 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;
+ if (buf)
+ free(buf);
warn("%s", file);
}
OpenPOWER on IntegriCloud