chflags: Add -x option to not traverse mount points.

MFC after:	2 weeks
This commit is contained in:
Bryan Drewery 2018-03-05 01:56:07 +00:00
parent 15920907ba
commit 25d90d5c97
2 changed files with 13 additions and 6 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)chflags.1 8.4 (Berkeley) 5/2/95 .\" @(#)chflags.1 8.4 (Berkeley) 5/2/95
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd April 20, 2015 .Dd March 4, 2018
.Dt CHFLAGS 1 .Dt CHFLAGS 1
.Os .Os
.Sh NAME .Sh NAME
@ -40,7 +40,7 @@
.Nd change file flags .Nd change file flags
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl fhv .Op Fl fhvx
.Oo .Oo
.Fl R .Fl R
.Op Fl H | Fl L | Fl P .Op Fl H | Fl L | Fl P
@ -98,6 +98,8 @@ If the
.Fl v .Fl v
option is specified more than once, the old and new flags of the file option is specified more than once, the old and new flags of the file
will also be printed, in octal notation. will also be printed, in octal notation.
.It Fl x
Do not cross mount points.
.El .El
.Pp .Pp
The flags are specified as an octal number or a comma separated list The flags are specified as an octal number or a comma separated list

View File

@ -65,12 +65,12 @@ main(int argc, char *argv[])
FTSENT *p; FTSENT *p;
u_long clear, newflags, set; u_long clear, newflags, set;
long val; long val;
int Hflag, Lflag, Rflag, fflag, hflag, vflag; int Hflag, Lflag, Rflag, fflag, hflag, vflag, xflag;
int ch, fts_options, oct, rval; int ch, fts_options, oct, rval;
char *flags, *ep; char *flags, *ep;
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; Hflag = Lflag = Rflag = fflag = hflag = vflag = xflag = 0;
while ((ch = getopt(argc, argv, "HLPRfhv")) != -1) while ((ch = getopt(argc, argv, "HLPRfhvx")) != -1)
switch (ch) { switch (ch) {
case 'H': case 'H':
Hflag = 1; Hflag = 1;
@ -95,6 +95,9 @@ main(int argc, char *argv[])
case 'v': case 'v':
vflag++; vflag++;
break; break;
case 'x':
xflag = 1;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -123,6 +126,8 @@ main(int argc, char *argv[])
} else { } else {
fts_options = FTS_LOGICAL; fts_options = FTS_LOGICAL;
} }
if (xflag)
fts_options |= FTS_XDEV;
flags = *argv; flags = *argv;
if (*flags >= '0' && *flags <= '7') { if (*flags >= '0' && *flags <= '7') {
@ -201,6 +206,6 @@ static void
usage(void) usage(void)
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: chflags [-fhv] [-R [-H | -L | -P]] flags file ...\n"); "usage: chflags [-fhvx] [-R [-H | -L | -P]] flags file ...\n");
exit(1); exit(1);
} }