summaryrefslogtreecommitdiffstats
path: root/usr.bin/find
diff options
context:
space:
mode:
authorroberto <roberto@FreeBSD.org>1999-12-19 15:43:19 +0000
committerroberto <roberto@FreeBSD.org>1999-12-19 15:43:19 +0000
commit58b687c462e608fbb9d0baebacd235cdcfb54f4c (patch)
tree10a71d4fcec8683830742e4bc329fe467bfbfca5 /usr.bin/find
parentb7335626ede0054c55ccf2e76514a4710b1f1ee7 (diff)
downloadFreeBSD-src-58b687c462e608fbb9d0baebacd235cdcfb54f4c.zip
FreeBSD-src-58b687c462e608fbb9d0baebacd235cdcfb54f4c.tar.gz
Second part of bin/3648: add -flags to search for specific flags.
I added $FreeBSD$ whicle I was here. The patch wasn't usable anymore due to its age so I adapted it. PR: bin/3648 Submitted by: Martin Birgmeier <mbirg@austria.ds.philips.com>
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/Makefile4
-rw-r--r--usr.bin/find/extern.h2
-rw-r--r--usr.bin/find/find.114
-rw-r--r--usr.bin/find/find.h11
-rw-r--r--usr.bin/find/function.c59
-rw-r--r--usr.bin/find/option.c1
6 files changed, 87 insertions, 4 deletions
diff --git a/usr.bin/find/Makefile b/usr.bin/find/Makefile
index c305d6a..1770ffa 100644
--- a/usr.bin/find/Makefile
+++ b/usr.bin/find/Makefile
@@ -1,6 +1,8 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
+# $FreeBSD$
PROG= find
-SRCS= find.c function.c ls.c main.c misc.c operator.c option.c
+SRCS= find.c function.c ls.c main.c misc.c operator.c option.c stat_flags.c
+.PATH: ${.CURDIR}/../../bin/ls
.include <bsd.prog.mk>
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index cf2d959..8119e32 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.3 (Berkeley) 4/16/94
+ * $FreeBSD$
*/
#include <sys/cdefs.h>
@@ -54,6 +55,7 @@ PLAN *c_ctime __P((char *));
PLAN *c_delete __P((void));
PLAN *c_depth __P((void));
PLAN *c_exec __P((char ***, int));
+PLAN *c_flags __P((char *));
PLAN *c_execdir __P((char ***));
PLAN *c_follow __P((void));
#if !defined(__NetBSD__)
diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1
index 59e76ef..e16a6e2 100644
--- a/usr.bin/find/find.1
+++ b/usr.bin/find/find.1
@@ -327,6 +327,19 @@ if at least all of the bits in the mode are set in the file's mode bits.
If the mode is not preceded by a dash, this primary evaluates to true if
the bits in the mode exactly match the file's mode bits.
Note, the first character of a symbolic mode may not be a dash (``\-'').
+.It Ic -flags Op Fl Ns Ar flags
+This primary evaluates to true if exactly those flags of the file are
+set which are also set using the specified
+.Ar flags
+(if these are not preceded by a dash (``\-''),
+or if they match the specified flags (if these are preceded by a dash).
+The
+.Ar flags
+are specified using symbolic names (see
+.Xr chflags 1 ).
+Note that this is different from
+.Ic -perm ,
+which only allows you to specify flags which are set.
.It Ic -print
This primary always evaluates to true.
It prints the pathname of the current file to standard output.
@@ -458,6 +471,7 @@ Print out a list of all the files that are either owned by ``wnj'' or
that are newer than ``ttt''.
.El
.Sh SEE ALSO
+.Xr chflags 1 ,
.Xr chmod 1 ,
.Xr locate 1 ,
.Xr whereis 1 ,
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index 33b00ad..b6e2eab 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -34,13 +34,14 @@
* SUCH DAMAGE.
*
* @(#)find.h 8.1 (Berkeley) 6/6/93
+ * $FreeBSD$
*/
/* node type */
enum ntype {
N_AND = 1, /* must start > 0 */
N_AMIN, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CTIME, N_DEPTH,
- N_EXEC, N_EXECDIR, N_EXPR,
+ N_EXEC, N_EXECDIR, N_EXPR, N_FLAGS,
N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MMIN,
N_MTIME, N_NAME,
N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH,
@@ -66,6 +67,10 @@ typedef struct _plandata {
gid_t _g_data; /* gid */
ino_t _i_data; /* inode */
mode_t _m_data; /* mode mask */
+ struct {
+ u_long _f_flags;
+ u_long _f_mask;
+ } fl;
nlink_t _l_data; /* link count */
off_t _o_data; /* file size */
time_t _t_data; /* time value */
@@ -83,8 +88,10 @@ typedef struct _plandata {
} PLAN;
#define a_data p_un._a_data
#define c_data p_un._c_data
-#define i_data p_un._i_data
+#define fl_flags p_un.fl._f_flags
+#define fl_mask p_un.fl._f_mask
#define g_data p_un._g_data
+#define i_data p_un._i_data
#define l_data p_un._l_data
#define m_data p_un._m_data
#define mt_data p_un._mt_data
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 1c813d9..de7f8b1 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -36,6 +36,7 @@
#ifndef lint
static char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
+static char rcsid[] = "$FreeBSD$";
#endif /* not lint */
#include <sys/param.h>
@@ -57,6 +58,8 @@ static char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
#include "find.h"
+int string_to_flags __P((char **, u_long *, u_long *));
+
#define COMPARE(a, b) { \
switch (plan->flags) { \
case F_EQUAL: \
@@ -945,7 +948,7 @@ c_perm(perm)
}
if ((set = setmode(perm)) == NULL)
- err(1, "-perm: %s: illegal mode string", perm);
+ errx(1, "-perm: %s: illegal mode string", perm);
new->m_data = getmode(set, 0);
free(set);
@@ -953,6 +956,60 @@ c_perm(perm)
}
/*
+ * -flags functions --
+ *
+ * The flags argument is used to represent file flags bits.
+ */
+int
+f_flags(plan, entry)
+ PLAN *plan;
+ FTSENT *entry;
+{
+ u_long flags;
+
+ flags = entry->fts_statp->st_flags &
+ (UF_NODUMP | UF_IMMUTABLE | UF_APPEND | UF_OPAQUE |
+ SF_ARCHIVED | SF_IMMUTABLE | SF_APPEND);
+ if (plan->flags == F_ATLEAST)
+ /* note that plan->fl_flags always is a subset of
+ plan->fl_mask */
+ return (flags & plan->fl_mask) == plan->fl_flags;
+ else
+ return flags == plan->fl_flags;
+ /* NOTREACHED */
+}
+
+PLAN *
+c_flags(flags_str)
+ char *flags_str;
+{
+ PLAN *new;
+ u_long flags, notflags;
+
+ ftsoptions &= ~FTS_NOSTAT;
+
+ new = palloc(N_FLAGS, f_flags);
+
+ if (*flags_str == '-') {
+ new->flags = F_ATLEAST;
+ flags_str++;
+ }
+ if (string_to_flags(&flags_str, &flags, &notflags) == 1)
+ errx(1, "-flags: %s: illegal flags string", flags_str);
+
+ new->fl_flags = flags;
+ new->fl_mask = flags | notflags;
+#if 0
+ printf("flags = %08x, mask = %08x (%08x, %08x)\n",
+ new->fl_flags, new->fl_mask, flags, notflags);
+#endif
+ return new;
+}
+
+ /*
+
+
+/*
* -print functions --
*
* Always true, causes the current pathame to be written to
diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c
index c6cb12e..b1ebd45 100644
--- a/usr.bin/find/option.c
+++ b/usr.bin/find/option.c
@@ -70,6 +70,7 @@ static OPTION const options[] = {
{ "-depth", N_DEPTH, c_depth, O_ZERO },
{ "-exec", N_EXEC, c_exec, O_ARGVP },
{ "-execdir", N_EXECDIR, c_execdir, O_ARGVP },
+ { "-flags", N_FLAGS, c_flags, O_ARGV },
{ "-follow", N_FOLLOW, c_follow, O_ZERO },
/*
OpenPOWER on IntegriCloud