From 567664c4a7534c7e998249b59cba10d5395c9086 Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Sun, 19 Dec 1999 15:43:19 +0000 Subject: [PATCH] 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 --- usr.bin/find/Makefile | 4 ++- usr.bin/find/extern.h | 2 ++ usr.bin/find/find.1 | 14 ++++++++++ usr.bin/find/find.h | 11 ++++++-- usr.bin/find/function.c | 59 ++++++++++++++++++++++++++++++++++++++++- usr.bin/find/option.c | 1 + 6 files changed, 87 insertions(+), 4 deletions(-) diff --git a/usr.bin/find/Makefile b/usr.bin/find/Makefile index c305d6a7e39..1770ffa350c 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 diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index cf2d959d5bd..8119e322f79 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 @@ -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 59e76ef2803..e16a6e2e2dd 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 33b00ad570d..b6e2eab86b6 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 1c813d97a79..de7f8b1b7c0 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 @@ -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,13 +948,67 @@ 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); return (new); } +/* + * -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, ¬flags) == 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 -- * diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index c6cb12ef129..b1ebd4583cd 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 }, /* -- 2.45.2