From owner-freebsd-hackers@FreeBSD.ORG Sun Oct 29 22:26:38 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5FA3916A416 for ; Sun, 29 Oct 2006 22:26:38 +0000 (UTC) (envelope-from smortex@free.fr) Received: from smtp2-g19.free.fr (smtp2-g19.free.fr [212.27.42.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id C415243D5E for ; Sun, 29 Oct 2006 22:26:35 +0000 (GMT) (envelope-from smortex@free.fr) Received: from marvin.astase.com (unknown [81.56.211.189]) by smtp2-g19.free.fr (Postfix) with ESMTP id BDD4475D55 for ; Sun, 29 Oct 2006 23:26:34 +0100 (CET) Received: by marvin.astase.com (Postfix, from userid 1001) id E2B4756426; Sun, 29 Oct 2006 23:28:47 +0100 (CET) Date: Sun, 29 Oct 2006 23:28:47 +0100 From: Romain Tartiere To: freebsd-hackers@freebsd.org Message-ID: <20061029222847.GA68272@marvin.astase.com> Mail-Followup-To: freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="SkvwRMAIpAhPCcCJ" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Subject: [patch] rm can have undesired side-effects X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Oct 2006 22:26:38 -0000 --SkvwRMAIpAhPCcCJ Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello The rm utility provides a "-P" option for overwriting files before removing them. I was wondering about the behaviour of it on regular files with more than one hard link. I just wrote a few lines in a file, created an hard link to it and "rm -P" the first one. The content of the second one was just lost too. I wonder if this is a desired feature, in accordance to some standard, or just something so improbable that nobody got in trouble with it (yet) ? I guess that in some circumstances this may be an issue. As an example, for associating UIDs with user names in an anonymous FTP server, you may have to provide a copy of the /etc/passwd file... or maybe you will just think about creating a hard link to it. I guess that it can be fixed (in case it is not desired) by: - Ignoring the -P option when the link count is greater then one, or - Asking the user whether he is ready to lose data, assuming "no" if the -f option is set, or - Asking the user whether he is ready to lose data, assuming "yes" if the -f option is set. I have attached a patch that implements the first behaviour. I think here is the best place to speak about this, maybe before thinking about filling-in a problem-report? Regards, Romain --=20 Romain Tartiere http://romain.astase.com/ pgp: 8DAB A124 0DA4 7024 F82A E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43) (plain text =3Dnon-HTML=3D PGP/GPG encrypted/signed e-mail much appreciated) --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="rm.patch" diff -ru /usr/src/bin/rm/rm.1 rm/rm.1 --- /usr/src/bin/rm/rm.1 Fri Mar 31 01:58:14 2006 +++ rm/rm.1 Sun Oct 29 22:44:17 2006 @@ -92,6 +92,8 @@ .Nm to generate an error message and exit. The file will not be removed or overwritten. +This option is silently ignored if the file link count is greater than +one and overwriting it would cause data loss. .It Fl R Attempt to remove the file hierarchy rooted in each file argument. The diff -ru /usr/src/bin/rm/rm.c rm/rm.c --- /usr/src/bin/rm/rm.c Tue May 16 18:14:51 2006 +++ rm/rm.c Sun Oct 15 22:55:05 2006 @@ -289,7 +289,7 @@ continue; /* FALLTHROUGH */ default: - if (Pflag) + if (Pflag && (1 == p->fts_statp->st_nlink)) if (!rm_overwrite(p->fts_accpath, NULL)) continue; rval = unlink(p->fts_accpath); @@ -357,7 +357,7 @@ else if (S_ISDIR(sb.st_mode)) rval = rmdir(f); else { - if (Pflag) + if (Pflag && (1 == sb.st_nlink)) if (!rm_overwrite(f, &sb)) continue; rval = unlink(f); --9jxsPFA5p3P2qPhR-- --SkvwRMAIpAhPCcCJ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFFRSsf2OmjP/9W/0MRAql8AJ9oIM4AIkRcGUFBYaj5C78DlHcwvQCdEWVV HpmrfzFPLYIPac6sV8VzgCw= =IuNE -----END PGP SIGNATURE----- --SkvwRMAIpAhPCcCJ--