diff options
author | Xin LI <delphij@FreeBSD.org> | 2006-10-30 03:32:09 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2006-10-30 03:32:09 +0000 |
commit | 0b6f55b77ca245e9010905fa8d8973d125d1f85c (patch) | |
tree | 5b962860bd6b7ab3494f4613fa7f381c04343f7f /bin/rm | |
parent | 4e33ba36b8e5b4d070f3abaeb6cca9cffc022f65 (diff) | |
download | src-0b6f55b77ca245e9010905fa8d8973d125d1f85c.tar.gz src-0b6f55b77ca245e9010905fa8d8973d125d1f85c.zip |
Be more reasonable when overwrite mode is specified while there
is hard links. Overwritting when links > 1 would cause data
loss, which is usually undesired.
Inspired by: discussion on -hackers@
Suggested by: elessar at bsdforen de
Obtained from: OpenBSD
Notes
Notes:
svn path=/head/; revision=163777
Diffstat (limited to 'bin/rm')
-rw-r--r-- | bin/rm/rm.1 | 4 | ||||
-rw-r--r-- | bin/rm/rm.c | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index 0ffb00e3f030..2235b3bc202e 100644 --- a/bin/rm/rm.1 +++ b/bin/rm/rm.1 @@ -32,7 +32,7 @@ .\" @(#)rm.1 8.5 (Berkeley) 12/5/94 .\" $FreeBSD$ .\" -.Dd September 29, 2005 +.Dd October 30, 2006 .Dt RM 1 .Os .Sh NAME @@ -88,6 +88,8 @@ yet provides almost the same level of protection against mistakes. Overwrite regular files before deleting them. Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted. +Files with multiple links will not be overwritten. +.Pp Specifying this flag for a read only file will cause .Nm to generate an error message and exit. diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 614479d89320..c311b6e4386d 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -400,6 +400,11 @@ rm_overwrite(char *file, struct stat *sbp) } if (!S_ISREG(sbp->st_mode)) return (1); + if (sbp->st_nlink > 1) { + warnx("%s (inode %u): not overwritten due to multiple links", + file, sbp->st_ino); + return (1); + } if ((fd = open(file, O_WRONLY, 0)) == -1) goto err; if (fstatfs(fd, &fsb) == -1) |