diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/find/Makefile | 5 | ||||
-rw-r--r-- | usr.bin/find/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/find/find.1 | 19 | ||||
-rw-r--r-- | usr.bin/find/find.h | 12 | ||||
-rw-r--r-- | usr.bin/find/function.c | 54 | ||||
-rw-r--r-- | usr.bin/find/option.c | 5 |
6 files changed, 86 insertions, 12 deletions
diff --git a/usr.bin/find/Makefile b/usr.bin/find/Makefile index 6bc22ee35c7..db331cd2a13 100644 --- a/usr.bin/find/Makefile +++ b/usr.bin/find/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.2 1996/06/26 05:33:07 deraadt Exp $ +# $OpenBSD: Makefile,v 1.3 2000/07/08 16:09:33 millert Exp $ 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 672563b8d42..fc8839789da 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: extern.h,v 1.10 2000/06/07 15:25:30 deraadt Exp $*/ +/* * $OpenBSD: extern.h,v 1.11 2000/07/08 16:09:33 millert Exp $*/ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -60,6 +60,7 @@ PLAN *c_depth __P((void)); PLAN *c_empty __P((void)); PLAN *c_exec __P((char ***, int)); PLAN *c_execdir __P((char ***)); +PLAN *c_flags __P((char *)); PLAN *c_follow __P((void)); PLAN *c_fstype __P((char *)); PLAN *c_group __P((char *)); diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index 95434a6e68a..30a8f3a18c9 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: find.1,v 1.27 2000/06/07 15:25:30 deraadt Exp $ +.\" $OpenBSD: find.1,v 1.28 2000/07/08 16:09:33 millert Exp $ .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -191,6 +191,23 @@ the current file. The filename substituted for the string .Qq {} is not qualified. +.It Xo +.Ic -flags +.Op Fl +.Ar flags +.Xc +The +.Ar flags +are comma-separated symbolic file flags (see +.Xr chflags 1 +for a list of valid flag names). +If the flags are preceded by a dash +.Pq Sq \- , +this primary evaluates to true if the file in question has at least +one of the file flags specified by +.Ar flags . +If the flags are not preceded by a dash, this primary evaluates to true if the +flags specified exactly match those of the file. .It Ic -follow Follow symbolic links. .It Ic -fstype Ar type diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h index 778db7014b2..10a0c26c5d9 100644 --- a/usr.bin/find/find.h +++ b/usr.bin/find/find.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: find.h,v 1.9 2000/06/07 15:25:30 deraadt Exp $*/ +/* * $OpenBSD: find.h,v 1.10 2000/07/08 16:09:33 millert Exp $*/ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -41,8 +41,8 @@ enum ntype { N_AND = 1, /* must start > 0 */ N_AMIN, N_ANEWER, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, N_CTIME, - N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, - N_EXPR, N_FOLLOW, N_FSTYPE, N_GROUP, N_INAME, N_INUM, N_LINKS, N_LS, + N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXPR, + N_FLAGS, N_FOLLOW, N_FSTYPE, N_GROUP, N_INAME, N_INUM, N_LINKS, N_LS, N_MMIN, N_MAXDEPTH, N_MINDEPTH, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRUNE, @@ -67,6 +67,10 @@ typedef struct _plandata { gid_t _g_data; /* gid */ ino_t _i_data; /* inode */ mode_t _m_data; /* mode mask */ + struct { + u_int _f_flags; + u_int _f_mask; + } fl; nlink_t _l_data; /* link count */ off_t _o_data; /* file size */ struct timespec _t_data; /* time value */ @@ -87,6 +91,8 @@ typedef struct _plandata { #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 l_data p_un._l_data #define m_data p_un._m_data diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 3713de164ee..fb969903b6c 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.18 2000/06/07 15:25:30 deraadt Exp $ */ +/* $OpenBSD: function.c,v 1.19 2000/07/08 16:09:34 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: function.c,v 1.18 2000/06/07 15:25:30 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: function.c,v 1.19 2000/07/08 16:09:34 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -545,6 +545,54 @@ c_execdir(argvp) *argvp = argv + 1; return (new); } + +/* + * -flags functions -- + * + * The flags argument is used to represent file flags bits. + */ +int +f_flags(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + u_int 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_int 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; + return (new); +} /* * -follow functions -- @@ -1151,7 +1199,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); diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index 4569907a4a5..03033cb4d11 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: option.c,v 1.11 2000/06/07 15:25:30 deraadt Exp $ */ +/* $OpenBSD: option.c,v 1.12 2000/07/08 16:09:34 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)option.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: option.c,v 1.11 2000/06/07 15:25:30 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: option.c,v 1.12 2000/07/08 16:09:34 millert Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -69,6 +69,7 @@ static OPTION options[] = { { "-empty", N_EMPTY, c_empty, 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 }, { "-fstype", N_FSTYPE, c_fstype, O_ARGV }, { "-group", N_GROUP, c_group, O_ARGV }, |