From aab67d52106d23a3891cf5c1c3f3ca02d8ac4f6f Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 26 Apr 2013 18:43:22 +0000 Subject: [PATCH] PR/47770: Eitan Adler: add x flag to rm to avoid cross mount points --- bin/rm/rm.1 | 12 ++++++++---- bin/rm/rm.c | 16 +++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index a1bfb270dccc..3f89c46daf05 100644 --- a/bin/rm/rm.1 +++ b/bin/rm/rm.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: rm.1,v 1.25 2012/10/13 14:18:16 njoly Exp $ +.\" $NetBSD: rm.1,v 1.26 2013/04/26 18:43:22 christos Exp $ .\" .\" Copyright (c) 1990, 1993, 1994, 2003 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)rm.1 8.5 (Berkeley) 12/5/94 .\" -.Dd August 25, 2006 +.Dd April 26, 2013 .Dt RM 1 .Os .Sh NAME @@ -41,7 +41,7 @@ .Sh SYNOPSIS .Nm .Op Fl f | Fl i -.Op Fl dPRrvW +.Op Fl dPRrvWx .Ar .Sh DESCRIPTION The @@ -110,6 +110,8 @@ to be verbose, showing files as they are processed. Attempts to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts. +.It Fl x +When removing a hierarchy, do not cross mount points. .El .Pp The @@ -189,7 +191,9 @@ utility is expected to be compatible. The .Fl v -option is an extension. +and +.Fl x +options are extensions. .Pp The .Fl P diff --git a/bin/rm/rm.c b/bin/rm/rm.c index df1990ac6956..c1d2e8dd50e8 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -1,4 +1,4 @@ -/* $NetBSD: rm.c,v 1.52 2012/06/13 07:35:37 dholland Exp $ */ +/* $NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994, 2003 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\ #if 0 static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: rm.c,v 1.52 2012/06/13 07:35:37 dholland Exp $"); +__RCSID("$NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $"); #endif #endif /* not lint */ @@ -61,6 +61,7 @@ __RCSID("$NetBSD: rm.c,v 1.52 2012/06/13 07:35:37 dholland Exp $"); #include static int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag; +static int xflag; static sig_atomic_t pinfo; static int check(char *, char *, struct stat *); @@ -94,8 +95,8 @@ main(int argc, char *argv[]) setprogname(argv[0]); (void)setlocale(LC_ALL, ""); - Pflag = rflag = 0; - while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1) + Pflag = rflag = xflag = 0; + while ((ch = getopt(argc, argv, "dfiPRrvWx")) != -1) switch (ch) { case 'd': dflag = 1; @@ -118,6 +119,9 @@ main(int argc, char *argv[]) case 'v': vflag = 1; break; + case 'x': + xflag = 1; + break; case 'W': Wflag = 1; break; @@ -175,6 +179,8 @@ rm_tree(char **argv) flags |= FTS_NOSTAT; if (Wflag) flags |= FTS_WHITEOUT; + if (xflag) + flags |= FTS_XDEV; if ((fts = fts_open(argv, flags, NULL)) == NULL) err(1, "fts_open failed"); while ((p = fts_read(fts)) != NULL) { @@ -591,7 +597,7 @@ static void usage(void) { - (void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrvW] file ...\n", + (void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrvWx] file ...\n", getprogname()); exit(1); /* NOTREACHED */