xref: /freebsd/usr.bin/find/find.h (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
19b50d902SRodney W. Grimes /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
49b50d902SRodney W. Grimes  * Copyright (c) 1990, 1993
59b50d902SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
69b50d902SRodney W. Grimes  *
79b50d902SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
89b50d902SRodney W. Grimes  * Cimarron D. Taylor of the University of California, Berkeley.
99b50d902SRodney W. Grimes  *
109b50d902SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
119b50d902SRodney W. Grimes  * modification, are permitted provided that the following conditions
129b50d902SRodney W. Grimes  * are met:
139b50d902SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
149b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
159b50d902SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
169b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
179b50d902SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
199b50d902SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
209b50d902SRodney W. Grimes  *    without specific prior written permission.
219b50d902SRodney W. Grimes  *
229b50d902SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
239b50d902SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
249b50d902SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
259b50d902SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
269b50d902SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
279b50d902SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
289b50d902SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
299b50d902SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
309b50d902SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
319b50d902SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
329b50d902SRodney W. Grimes  * SUCH DAMAGE.
339b50d902SRodney W. Grimes  */
349b50d902SRodney W. Grimes 
357c1d4b3aSAkinori MUSHA #include <regex.h>
36*c3a6ea5bSAlex Richardson #include <sys/mount.h>
37*c3a6ea5bSAlex Richardson #include <sys/stat.h>
38*c3a6ea5bSAlex Richardson 
39*c3a6ea5bSAlex Richardson /*
40*c3a6ea5bSAlex Richardson  * We need to build find during the bootstrap stage when building on a
41*c3a6ea5bSAlex Richardson  * non-FreeBSD system. Linux does not have the st_flags and st_birthtime
42*c3a6ea5bSAlex Richardson  * members in struct stat so we need to omit support for tests that depend
43*c3a6ea5bSAlex Richardson  * on these members. This works fine since none of these flags are used
44*c3a6ea5bSAlex Richardson  * during the build of world and kernel.
45*c3a6ea5bSAlex Richardson  */
46*c3a6ea5bSAlex Richardson #ifdef UF_SETTABLE
47*c3a6ea5bSAlex Richardson #define HAVE_STRUCT_STAT_ST_FLAGS 1
48*c3a6ea5bSAlex Richardson #else
49*c3a6ea5bSAlex Richardson #define HAVE_STRUCT_STAT_ST_FLAGS 0
50*c3a6ea5bSAlex Richardson #endif
51*c3a6ea5bSAlex Richardson #if defined(st_birthtime) || defined(st_birthtimespec)
52*c3a6ea5bSAlex Richardson #define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
53*c3a6ea5bSAlex Richardson #else
54*c3a6ea5bSAlex Richardson #define HAVE_STRUCT_STAT_ST_BIRTHTIME 0
55*c3a6ea5bSAlex Richardson #endif
56*c3a6ea5bSAlex Richardson #if defined(MFSNAMELEN) || defined(MFSTYPENAMELEN)
57*c3a6ea5bSAlex Richardson #define HAVE_STRUCT_STATFS_F_FSTYPENAME 1
58*c3a6ea5bSAlex Richardson #else
59*c3a6ea5bSAlex Richardson #define HAVE_STRUCT_STATFS_F_FSTYPENAME 0
60*c3a6ea5bSAlex Richardson #endif
617c1d4b3aSAkinori MUSHA 
62ea92232aSPoul-Henning Kamp /* forward declarations */
63ea92232aSPoul-Henning Kamp struct _plandata;
64ea92232aSPoul-Henning Kamp struct _option;
65ea92232aSPoul-Henning Kamp 
66ea92232aSPoul-Henning Kamp /* execute function */
67ecca1f1cSMark Murray typedef int exec_f(struct _plandata *, FTSENT *);
68ea92232aSPoul-Henning Kamp /* create function */
69ea92232aSPoul-Henning Kamp typedef	struct _plandata *creat_f(struct _option *, char ***);
70ea92232aSPoul-Henning Kamp 
71ea92232aSPoul-Henning Kamp /* function modifiers */
72ea92232aSPoul-Henning Kamp #define	F_NEEDOK	0x00000001	/* -ok vs. -exec */
73ea92232aSPoul-Henning Kamp #define	F_EXECDIR	0x00000002	/* -execdir vs. -exec */
74ea92232aSPoul-Henning Kamp #define F_TIME_A	0x00000004	/* one of -atime, -anewer, -newera* */
75ea92232aSPoul-Henning Kamp #define F_TIME_C	0x00000008	/* one of -ctime, -cnewer, -newerc* */
76ea92232aSPoul-Henning Kamp #define	F_TIME2_A	0x00000010	/* one of -newer?a */
77ea92232aSPoul-Henning Kamp #define	F_TIME2_C	0x00000020	/* one of -newer?c */
78ea92232aSPoul-Henning Kamp #define	F_TIME2_T	0x00000040	/* one of -newer?t */
79ea92232aSPoul-Henning Kamp #define F_MAXDEPTH	F_TIME_A	/* maxdepth vs. mindepth */
801c832963SOliver Eikemeier #define F_DEPTH		F_TIME_A	/* -depth n vs. -d */
81ea92232aSPoul-Henning Kamp /* command line function modifiers */
82ea92232aSPoul-Henning Kamp #define	F_EQUAL		0x00000000	/* [acm]min [acm]time inum links size */
83ea92232aSPoul-Henning Kamp #define	F_LESSTHAN	0x00000100
84ea92232aSPoul-Henning Kamp #define	F_GREATER	0x00000200
85ea92232aSPoul-Henning Kamp #define F_ELG_MASK	0x00000300
86ea92232aSPoul-Henning Kamp #define	F_ATLEAST	0x00000400	/* flags perm */
87ea92232aSPoul-Henning Kamp #define F_ANY		0x00000800	/* perm */
88ea92232aSPoul-Henning Kamp #define	F_MTMASK	0x00003000
89ea92232aSPoul-Henning Kamp #define	F_MTFLAG	0x00000000	/* fstype */
90ea92232aSPoul-Henning Kamp #define	F_MTTYPE	0x00001000
91ea92232aSPoul-Henning Kamp #define	F_MTUNKNOWN	0x00002000
92ea92232aSPoul-Henning Kamp #define	F_IGNCASE	0x00010000	/* iname ipath iregex */
93adff4fcaSRuslan Ermilov #define	F_EXACTTIME	F_IGNCASE	/* -[acm]time units syntax */
945e25d888STim J. Robbins #define F_EXECPLUS	0x00020000	/* -exec ... {} + */
95*c3a6ea5bSAlex Richardson #if HAVE_STRUCT_STAT_ST_BIRTHTIME
9631d53425SCeri Davies #define	F_TIME_B	0x00040000	/* one of -Btime, -Bnewer, -newerB* */
9731d53425SCeri Davies #define	F_TIME2_B	0x00080000	/* one of -newer?B */
98*c3a6ea5bSAlex Richardson #endif
9946b993ffSWarner Losh #define F_LINK		0x00100000	/* lname or ilname */
1009b50d902SRodney W. Grimes 
1019b50d902SRodney W. Grimes /* node definition */
1029b50d902SRodney W. Grimes typedef struct _plandata {
1039b50d902SRodney W. Grimes 	struct _plandata *next;		/* next node */
104ea92232aSPoul-Henning Kamp 	exec_f	*execute;		/* node evaluation function */
1059b50d902SRodney W. Grimes 	int flags;			/* private flags */
1069b50d902SRodney W. Grimes 	union {
1079b50d902SRodney W. Grimes 		gid_t _g_data;		/* gid */
1089b50d902SRodney W. Grimes 		ino_t _i_data;		/* inode */
1099b50d902SRodney W. Grimes 		mode_t _m_data;		/* mode mask */
110567664c4SOllivier Robert 		struct {
111567664c4SOllivier Robert 			u_long _f_flags;
1127fd5ee41SRuslan Ermilov 			u_long _f_notflags;
113567664c4SOllivier Robert 		} fl;
1149b50d902SRodney W. Grimes 		nlink_t _l_data;		/* link count */
1151c832963SOliver Eikemeier 		short _d_data;			/* level depth (-1 to N) */
1169b50d902SRodney W. Grimes 		off_t _o_data;			/* file size */
117ddd956b0SJilles Tjoelker 		struct timespec _t_data;	/* time value */
1189b50d902SRodney W. Grimes 		uid_t _u_data;			/* uid */
1199b50d902SRodney W. Grimes 		short _mt_data;			/* mount flags */
1209b50d902SRodney W. Grimes 		struct _plandata *_p_data[2];	/* PLAN trees */
1219b50d902SRodney W. Grimes 		struct _ex {
1229b50d902SRodney W. Grimes 			char **_e_argv;		/* argv array */
1239b50d902SRodney W. Grimes 			char **_e_orig;		/* original strings */
1249b50d902SRodney W. Grimes 			int *_e_len;		/* allocated length */
1255e25d888STim J. Robbins 			int _e_pbnum;		/* base num. of args. used */
1265e25d888STim J. Robbins 			int _e_ppos;		/* number of arguments used */
1275e25d888STim J. Robbins 			int _e_pnummax;		/* max. number of arguments */
1285e25d888STim J. Robbins 			int _e_psize;		/* number of bytes of args. */
1295e25d888STim J. Robbins 			int _e_pbsize;		/* base num. of bytes of args */
1305e25d888STim J. Robbins 			int _e_psizemax;	/* max num. of bytes of args */
13122170420SKirill Ponomarev 			struct _plandata *_e_next;/* next F_EXECPLUS in tree */
1329b50d902SRodney W. Grimes 		} ex;
1339b50d902SRodney W. Grimes 		char *_a_data[2];		/* array of char pointers */
1349b50d902SRodney W. Grimes 		char *_c_data;			/* char pointer */
1357c1d4b3aSAkinori MUSHA 		regex_t *_re_data;		/* regex */
1369b50d902SRodney W. Grimes 	} p_un;
1379b50d902SRodney W. Grimes } PLAN;
1389b50d902SRodney W. Grimes #define	a_data	p_un._a_data
1399b50d902SRodney W. Grimes #define	c_data	p_un._c_data
1401c832963SOliver Eikemeier #define	d_data	p_un._d_data
141567664c4SOllivier Robert #define fl_flags	p_un.fl._f_flags
1427fd5ee41SRuslan Ermilov #define fl_notflags	p_un.fl._f_notflags
1439b50d902SRodney W. Grimes #define	g_data	p_un._g_data
144567664c4SOllivier Robert #define	i_data	p_un._i_data
1459b50d902SRodney W. Grimes #define	l_data	p_un._l_data
1469b50d902SRodney W. Grimes #define	m_data	p_un._m_data
1479b50d902SRodney W. Grimes #define	mt_data	p_un._mt_data
1489b50d902SRodney W. Grimes #define	o_data	p_un._o_data
1499b50d902SRodney W. Grimes #define	p_data	p_un._p_data
1509b50d902SRodney W. Grimes #define	t_data	p_un._t_data
1519b50d902SRodney W. Grimes #define	u_data	p_un._u_data
1527c1d4b3aSAkinori MUSHA #define	re_data	p_un._re_data
1539b50d902SRodney W. Grimes #define	e_argv	p_un.ex._e_argv
1549b50d902SRodney W. Grimes #define	e_orig	p_un.ex._e_orig
1559b50d902SRodney W. Grimes #define	e_len	p_un.ex._e_len
1565e25d888STim J. Robbins #define e_pbnum	p_un.ex._e_pbnum
1575e25d888STim J. Robbins #define e_ppos	p_un.ex._e_ppos
1585e25d888STim J. Robbins #define e_pnummax p_un.ex._e_pnummax
1595e25d888STim J. Robbins #define e_psize p_un.ex._e_psize
1605e25d888STim J. Robbins #define e_pbsize p_un.ex._e_pbsize
1615e25d888STim J. Robbins #define e_psizemax p_un.ex._e_psizemax
16222170420SKirill Ponomarev #define e_next p_un.ex._e_next
1639b50d902SRodney W. Grimes 
1649b50d902SRodney W. Grimes typedef struct _option {
165e98080b1SDavid Malone 	const char *name;		/* option name */
166ea92232aSPoul-Henning Kamp 	creat_f *create;		/* create function */
167ea92232aSPoul-Henning Kamp 	exec_f *execute;		/* execute function */
1689b50d902SRodney W. Grimes 	int flags;
1699b50d902SRodney W. Grimes } OPTION;
1709b50d902SRodney W. Grimes 
1719b50d902SRodney W. Grimes #include "extern.h"
172