Date: Thu, 25 Apr 2013 21:50:49 -0500 From: Brooks Davis <brooks@freebsd.org> To: Eitan Adler <lists@eitanadler.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: Some improvements to rm(1) Message-ID: <20130426025049.GC50623@lor.one-eyed-alien.net> In-Reply-To: <CAF6rxg=5aAyk88KcbuGhG1Nwn5HdYqMiaT7umX2EOLApDwOk4Q@mail.gmail.com> References: <CAF6rxg=5aAyk88KcbuGhG1Nwn5HdYqMiaT7umX2EOLApDwOk4Q@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--UHN/qo2QbUvPLonB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Thu, Apr 25, 2013 at 10:16:32PM -0400, Eitan Adler wrote:
> Anyone have thoughts on the following?
>=20
> commit 82c78ba923d8ce4a1bfbb309658c49021c8bb384
> Author: Eitan Adler <lists@eitanadler.com>
> Date: Thu Apr 25 22:14:49 2013 -0400
>=20
> Take some improvements from DragonFlyBSD:
> - add const where appropriate
> - add static where appropriate
> - fix a whitespace issues
The no-op changes look more correct to me.
I think the -x option seems a bit odd. What is the use case? At a
first thought, it seems to raise more questions than it resolves.
-- Brooks
> Obtained from: DragonFlyBSD
>=20
> 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;
>=20
> -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);
>=20
> /*
> * rm --
> @@ -173,7 +173,7 @@ main(int argc, char *argv[])
> exit (eval);
> }
>=20
> -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 =3D 1;
> }
>=20
>=20
> -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)
> }
>=20
> #define ISSLASH(a) ((a)[0] =3D=3D '/' && (a)[1] =3D=3D '\0')
> -void
> +static void
> checkslash(char **argv)
> {
> char **t, **u;
> @@ -549,7 +549,7 @@ checkslash(char **argv)
> }
> }
>=20
> -int
> +static int
> check2(char **argv)
> {
> struct stat st;
> @@ -600,7 +600,7 @@ check2(char **argv)
> }
>=20
> #define ISDOT(a) ((a)[0] =3D=3D '.' && (!(a)[1] || ((a)[1] =3D=3D '.' &&=
!(a)[2])))
> -void
> +static void
> checkdot(char **argv)
> {
> char *p, **save, **t;
> @@ -624,7 +624,7 @@ checkdot(char **argv)
> }
> }
>=20
> -void
> +static void
> usage(void)
> {
>=20
>=20
> commit 4799c480694b379f73483998e11341bffd3ffa3e
> Author: Eitan Adler <lists@eitanadler.com>
> Date: Thu Apr 25 22:03:28 2013 -0400
>=20
> Add -x option to avoid crossing mount points when removing a hierarch=
y.
>=20
> Inspired by: DragonflyBSD
>=20
> 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 <unistd.h>
>=20
> 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;
>=20
> @@ -106,8 +106,8 @@ main(int argc, char *argv[])
> exit(eval);
> }
>=20
> - Pflag =3D rflag =3D 0;
> - while ((ch =3D getopt(argc, argv, "dfiIPRrvW")) !=3D -1)
> + Pflag =3D rflag =3D xflag =3D 0;
> + while ((ch =3D getopt(argc, argv, "dfiIPRrvWx")) !=3D -1)
> switch(ch) {
> case 'd':
> dflag =3D 1;
> @@ -136,6 +136,9 @@ main(int argc, char *argv[])
> case 'W':
> Wflag =3D 1;
> break;
> + case 'x':
> + xflag =3D 1;
> + break;
> default:
> usage();
> }
> @@ -196,6 +199,8 @@ rm_tree(char **argv)
> flags |=3D FTS_NOSTAT;
> if (Wflag)
> flags |=3D FTS_WHITEOUT;
> + if (xflag)
> + flags |=3D FTS_XDEV;
> if (!(fts =3D fts_open(argv, flags, NULL))) {
> if (fflag && errno =3D=3D ENOENT)
> return;
> @@ -624,7 +629,7 @@ usage(void)
> {
>=20
> (void)fprintf(stderr, "%s\n%s\n",
> - "usage: rm [-f | -i] [-dIPRrvW] file ...",
> + "usage: rm [-f | -i] [-dIPRrvWx] file ...",
> " unlink file");
> exit(EX_USAGE);
> }
>=20
>=20
> --=20
> Eitan Adler
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
>=20
--UHN/qo2QbUvPLonB
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)
iD8DBQFReeuJXY6L6fI4GtQRApQZAJ4hmN3sT7xF22MhOK+JBnyevk3zlACgm0Ir
il9I1z9sY2t9q818gPKNvf0=
=N366
-----END PGP SIGNATURE-----
--UHN/qo2QbUvPLonB--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130426025049.GC50623>
