From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 26 02:17:03 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 8945F439 for ; Fri, 26 Apr 2013 02:17:03 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by mx1.freebsd.org (Postfix) with ESMTP id 675801646 for ; Fri, 26 Apr 2013 02:17:03 +0000 (UTC) Received: by mail-pd0-f178.google.com with SMTP id w11so159618pde.37 for ; Thu, 25 Apr 2013 19:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=SVY9/FCttx9VqFqIA5szO2PVeVmi93JQUwj5QiB6Da8=; b=KkyfuRw2XVKJvuYt+uGzn5U4hikFerpGNUY6pi1deeoisb9va3nrECXCGQj97BvR1+ cjAhZ2STQI7nJibeZbFZXMVGWA6dPeNxKezdyQ2mUhjL3X2HAz6/MuSWgsrZ8/Enlnhn nHAlRqVS/M2Q8nrlHL1DCuFf+jBvmRgelyim8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=SVY9/FCttx9VqFqIA5szO2PVeVmi93JQUwj5QiB6Da8=; b=i4zuCD/1cIZUyV1WdnqI3B0ZxPH3odppjmYQojDCFAZGr19/IXTIbyfIqWij+T5hiW npJWOCtGiO00N1tgupVcBVB5gCUPhuIgIDAR0Jx1YQCWXrNXrbHQBg85oI5Hdpr1mNy3 ofWNSUMmXZ6BC0364s/b6jaBh4++Ja/i2Vqb4+W7dmolz3lsDIT1wpDA4Z+batUOPv5K 0iblITVkPl+6mz2WfGfWgDP1XEhyXf725gfoEBtrLA2Fth0uMHhy9bIfygdcWUHUi6ik KtBQivA/kSFhW5lkC5K1X1jYwLKKIvbrg2fMFULvdfkEWgHFVwLUeer9INL/wqoVlnTz B5mA== X-Received: by 10.66.102.65 with SMTP id fm1mr43650073pab.164.1366942622630; Thu, 25 Apr 2013 19:17:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.159.97 with HTTP; Thu, 25 Apr 2013 19:16:32 -0700 (PDT) From: Eitan Adler Date: Thu, 25 Apr 2013 22:16:32 -0400 Message-ID: Subject: Some improvements to rm(1) To: FreeBSD Hackers Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQkyNWNlhenQK+VrGYJ81V73/yyA410Cdx5LdbXJoP8RBXaTC8VdKz6vTM7DMTzbstUpN/kE X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2013 02:17:03 -0000 Anyone have thoughts on the following? commit 82c78ba923d8ce4a1bfbb309658c49021c8bb384 Author: Eitan Adler Date: Thu Apr 25 22:14:49 2013 -0400 Take some improvements from DragonFlyBSD: - add const where appropriate - add static where appropriate - fix a whitespace issues Obtained from: DragonFlyBSD diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 1014921..660042b 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -63,15 +63,15 @@ static int rflag, Iflag, xflag; static uid_t uid; static volatile sig_atomic_t info; -int check(char *, char *, struct stat *); -int check2(char **); -void checkdot(char **); -void checkslash(char **); -void rm_file(char **); -int rm_overwrite(char *, struct stat *); -void rm_tree(char **); +static int check(const char *, const char *, struct stat *); +static int check2(char **); +static void checkdot(char **); +static void checkslash(char **); +static void rm_file(char **); +static int rm_overwrite(const char *, struct stat *); +static void rm_tree(char **); static void siginfo(int __unused); -void usage(void); +static void usage(void); /* * rm -- @@ -173,7 +173,7 @@ main(int argc, char *argv[]) exit (eval); } -void +static void rm_tree(char **argv) { FTS *fts; @@ -418,7 +418,7 @@ rm_file(char **argv) * have kernel support. */ int -rm_overwrite(char *file, struct stat *sbp) +rm_overwrite(const char *file, struct stat *sbp) { struct stat sb, sb2; struct statfs fsb; @@ -484,8 +484,8 @@ err: eval = 1; } -int -check(char *path, char *name, struct stat *sp) +static int +check(const char *path, const char *name, struct stat *sp) { int ch, first; char modep[15], *flagsp; @@ -496,7 +496,7 @@ check(char *path, char *name, struct stat *sp) else { /* * If it's not a symbolic link and it's unwritable and we're - * talking to a terminal, ask. Symbolic links are excluded + * talking to a terminal, ask. Symbolic links are excluded * because their permissions are meaningless. Check stdin_ok * first because we may not have stat'ed the file. */ @@ -529,7 +529,7 @@ check(char *path, char *name, struct stat *sp) } #define ISSLASH(a) ((a)[0] == '/' && (a)[1] == '\0') -void +static void checkslash(char **argv) { char **t, **u; @@ -549,7 +549,7 @@ checkslash(char **argv) } } -int +static int check2(char **argv) { struct stat st; @@ -600,7 +600,7 @@ check2(char **argv) } #define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2]))) -void +static void checkdot(char **argv) { char *p, **save, **t; @@ -624,7 +624,7 @@ checkdot(char **argv) } } -void +static void usage(void) { commit 4799c480694b379f73483998e11341bffd3ffa3e Author: Eitan Adler Date: Thu Apr 25 22:03:28 2013 -0400 Add -x option to avoid crossing mount points when removing a hierarchy. Inspired by: DragonflyBSD diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index 3588f38..824b627 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 March 15, 2013 +.Dd April 25, 2013 .Dt RM 1 .Os .Sh NAME @@ -42,7 +42,7 @@ .Sh SYNOPSIS .Nm .Op Fl f | i -.Op Fl dIPRrvW +.Op Fl dIPRrvWx .Ar .Nm unlink .Ar file @@ -132,6 +132,8 @@ Attempt to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts in a union file system (see .Xr undelete 2 ) . +.It Fl x +When removing a hierarchy, do not cross mount points. .El .Pp The diff --git a/bin/rm/rm.c b/bin/rm/rm.c index a450057..1014921 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$"); #include static int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok; -static int rflag, Iflag; +static int rflag, Iflag, xflag; static uid_t uid; static volatile sig_atomic_t info; @@ -106,8 +106,8 @@ main(int argc, char *argv[]) exit(eval); } - Pflag = rflag = 0; - while ((ch = getopt(argc, argv, "dfiIPRrvW")) != -1) + Pflag = rflag = xflag = 0; + while ((ch = getopt(argc, argv, "dfiIPRrvWx")) != -1) switch(ch) { case 'd': dflag = 1; @@ -136,6 +136,9 @@ main(int argc, char *argv[]) case 'W': Wflag = 1; break; + case 'x': + xflag = 1; + break; default: usage(); } @@ -196,6 +199,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))) { if (fflag && errno == ENOENT) return; @@ -624,7 +629,7 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: rm [-f | -i] [-dIPRrvW] file ...", + "usage: rm [-f | -i] [-dIPRrvWx] file ...", " unlink file"); exit(EX_USAGE); } -- Eitan Adler