1 /* defs.h -- data types and declarations.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000, 2004 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 #include <sys/types.h>
27 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
35 #define strrchr rindex
62 # include <inttypes.h>
72 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
73 # define PARAMS(Args) Args
75 # define PARAMS(Args) ()
79 int lstat
PARAMS((const char *__path
, struct stat
*__statbuf
));
80 int stat
PARAMS((const char *__path
, struct stat
*__statbuf
));
82 int optionl_stat
PARAMS((const char *name
, struct stat
*p
));
83 int optionp_stat
PARAMS((const char *name
, struct stat
*p
));
84 int optionh_stat
PARAMS((const char *name
, struct stat
*p
));
87 # define S_ISUID 0004000
90 # define S_ISGID 0002000
93 # define S_ISVTX 0001000
96 # define S_IRUSR 0000400
99 # define S_IWUSR 0000200
102 # define S_IXUSR 0000100
105 # define S_IRGRP 0000040
108 # define S_IWGRP 0000020
111 # define S_IXGRP 0000010
114 # define S_IROTH 0000004
117 # define S_IWOTH 0000002
120 # define S_IXOTH 0000001
123 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
124 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
125 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
126 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
127 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
131 typedef bool boolean
;
133 /* Not char because of type promotion; NeXT gcc can't handle it. */
139 /* Pointer to function returning boolean. */
140 typedef boolean (*PFB
)();
142 /* The number of seconds in a day. */
143 #define DAYSECS 86400
145 /* Argument structures for predicates. */
154 enum permissions_type
171 enum predicate_precedence
183 enum comparison_type kind
;
184 boolean negative
; /* Defined only when representing time_t. */
190 enum permissions_type kind
;
194 /* dir_id is used to support loop detection in find.c and
195 * also to support the -samefile test.
205 enum comparison_type kind
;
212 short offset
; /* Offset in `vec' of this arg. */
213 short count
; /* Number of path replacements in this arg. */
214 char *origarg
; /* Arg with "{}" intact. */
219 struct path_arg
*paths
; /* Array of args with path replacements. */
220 char **vec
; /* Array of args to pass to program. */
223 /* The format string for a -printf or -fprintf is chopped into one or
224 more `struct segment', linked together into a list.
225 Each stretch of plain text is a segment, and
226 each \c and `%' conversion is a segment. */
228 /* Special values for the `kind' field of `struct segment'. */
229 #define KIND_PLAIN 0 /* Segment containing just plain text. */
230 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
234 int kind
; /* Format chars or KIND_{PLAIN,STOP}. */
235 char *text
; /* Plain text or `%' format string. */
236 int text_len
; /* Length of `text'. */
237 struct segment
*next
; /* Next segment for this predicate. */
242 struct segment
*segment
; /* Linked list of segments. */
243 FILE *stream
; /* Output stream to print on. */
248 /* Pointer to the function that implements this predicate. */
251 /* Only used for debugging, but defined unconditionally so individual
252 modules can be compiled with -DDEBUG. */
255 /* The type of this node. There are two kinds. The first is real
256 predicates ("primaries") such as -perm, -print, or -exec. The
257 other kind is operators for combining predicates. */
258 enum predicate_type p_type
;
260 /* The precedence of this node. Only has meaning for operators. */
261 enum predicate_precedence p_prec
;
263 /* True if this predicate node produces side effects.
264 If side_effects are produced
265 then optimization will not be performed */
266 boolean side_effects
;
268 /* True if this predicate node requires default print be turned off. */
269 boolean no_default_print
;
271 /* True if this predicate node requires a stat system call to execute. */
276 /* Information needed by the predicate processor.
277 Next to each member are listed the predicates that use it. */
280 char *str
; /* fstype [i]lname [i]name [i]path */
281 struct re_pattern_buffer
*regex
; /* regex */
282 struct exec_val exec_vec
; /* exec ok */
283 struct long_val info
; /* atime ctime gid inum links mtime
285 struct size_val size
; /* size */
286 uid_t uid
; /* user */
287 gid_t gid
; /* group */
288 time_t time
; /* newer */
289 struct perm_val perm
; /* perm */
290 struct dir_id fileid
; /* samefile */
291 mode_t type
; /* type */
292 FILE *stream
; /* fprint fprint0 */
293 struct format_val printf_vec
; /* printf fprintf */
296 /* The next predicate in the user input sequence,
297 which repesents the order in which the user supplied the
298 predicates on the command line. */
299 struct predicate
*pred_next
;
301 /* The right and left branches from this node in the expression
302 tree, which represents the order in which the nodes should be
304 struct predicate
*pred_left
;
305 struct predicate
*pred_right
;
308 /* find library function declarations. */
311 char *dirname
PARAMS((char *path
));
314 void error
PARAMS((int status
, int errnum
, char *message
, ...));
317 void list_file
PARAMS((char *name
, char *relname
, struct stat
*statp
, time_t current_time
, int output_block_size
, FILE *stream
));
318 char *get_link_name
PARAMS((char *name
, char *relname
));
322 char *stpcpy
PARAMS((char *dest
, const char *src
));
326 char *xgetcwd
PARAMS((void));
335 /* find global function declarations. */
338 /* SymlinkOption represents the choice of
339 * -P, -L or -P (default) on the command line.
343 SYMLINK_NEVER_DEREF
, /* Option -P */
344 SYMLINK_ALWAYS_DEREF
, /* Option -L */
345 SYMLINK_DEREF_ARGSONLY
/* Option -H */
347 extern enum SymlinkOption symlink_handling
; /* defined in find.c. */
349 void set_follow_state
PARAMS((enum SymlinkOption opt
));
352 char *filesystem_type
PARAMS((const struct stat
*statp
));
353 char * get_mounted_filesystems (void);
354 dev_t
* get_mounted_devices
PARAMS((size_t *));
357 PFB find_parser
PARAMS((char *search_name
));
358 boolean parse_close
PARAMS((char *argv
[], int *arg_ptr
));
359 boolean parse_open
PARAMS((char *argv
[], int *arg_ptr
));
360 boolean parse_print
PARAMS((char *argv
[], int *arg_ptr
));
363 boolean pred_amin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
364 boolean pred_and
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
365 boolean pred_anewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
366 boolean pred_atime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
367 boolean pred_close
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
368 boolean pred_cmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
369 boolean pred_cnewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
370 boolean pred_comma
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
371 boolean pred_ctime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
372 boolean pred_delete
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
373 boolean pred_empty
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
374 boolean pred_exec
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
375 boolean pred_false
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
376 boolean pred_fls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
377 boolean pred_fprint
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
378 boolean pred_fprint0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
379 boolean pred_fprintf
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
380 boolean pred_fstype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
381 boolean pred_gid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
382 boolean pred_group
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
383 boolean pred_ilname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
384 boolean pred_iname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
385 boolean pred_inum
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
386 boolean pred_ipath
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
387 boolean pred_links
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
388 boolean pred_lname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
389 boolean pred_ls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
390 boolean pred_mmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
391 boolean pred_mtime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
392 boolean pred_name
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
393 boolean pred_negate
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
394 boolean pred_newer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
395 boolean pred_nogroup
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
396 boolean pred_nouser
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
397 boolean pred_ok
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
398 boolean pred_open
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
399 boolean pred_or
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
400 boolean pred_path
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
401 boolean pred_perm
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
402 boolean pred_print
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
403 boolean pred_print0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
404 boolean pred_prune
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
405 boolean pred_quit
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
406 boolean pred_regex
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
407 boolean pred_samefile
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
408 boolean pred_size
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
409 boolean pred_true
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
410 boolean pred_type
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
411 boolean pred_uid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
412 boolean pred_used
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
413 boolean pred_user
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
414 boolean pred_xtype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
415 char *find_pred_name
PARAMS((PFB pred_func
));
417 void print_tree
PARAMS((FILE*, struct predicate
*node
, int indent
));
418 void print_list
PARAMS((FILE*, struct predicate
*node
));
419 void print_optlist
PARAMS((FILE *fp
, struct predicate
*node
));
424 get_expr
PARAMS((struct predicate
**input
, short int prev_prec
));
425 boolean opt_expr
PARAMS((struct predicate
**eval_treep
));
426 boolean mark_stat
PARAMS((struct predicate
*tree
));
429 struct predicate
*get_new_pred
PARAMS((void));
430 struct predicate
*get_new_pred_chk_op
PARAMS((void));
431 struct predicate
*insert_primary
PARAMS((boolean (*pred_func
)()));
432 void usage
PARAMS((char *msg
));
434 extern char *program_name
;
435 extern struct predicate
*predicates
;
436 extern struct predicate
*last_pred
;
440 /* If true, process directory before contents. True unless -depth given. */
441 boolean do_dir_first
;
443 /* If >=0, don't descend more than this many levels of subdirectories. */
446 /* If >=0, don't process files above this level. */
449 /* If true, do not assume that files in directories with nlink == 2
450 are non-directories. */
451 boolean no_leaf_check
;
453 /* If true, don't cross filesystem boundaries. */
454 boolean stay_on_filesystem
;
456 /* If true, we ignore the problem where we find that a directory entry
457 * no longer exists by the time we get around to processing it.
459 boolean ignore_readdir_race
;
461 /* If true, we issue warning messages
464 time_t start_time
; /* Time at start of execution. */
466 /* Seconds between 00:00 1/1/70 and either one day before now
467 (the default), or the start of today (if -daystart is given). */
468 time_t cur_day_start
;
470 /* If true, cur_day_start has been adjusted to the start of the day. */
473 int output_block_size
; /* Output block size. */
475 enum SymlinkOption symlink_handling
;
478 /* Pointer to the function used to stat files. */
479 int (*xstat
) (const char *name
, struct stat
*statbuf
);
481 extern struct options options
;
486 /* Current depth; 0 means current path is a command line arg. */
489 /* If true, we have called stat on the current path. */
492 /* The file being operated on, relative to the current directory.
493 Used for stat, readlink, remove, and opendir. */
496 /* Length of current path. */
499 /* If true, don't descend past current directory.
500 Can be set by -prune, -maxdepth, and -xdev/-mount. */
501 boolean stop_at_current_level
;
503 /* Status value to return to system. */
506 extern struct state state
;
508 extern char const *starting_dir
;
509 extern int starting_desc
;
510 #if ! defined HAVE_FCHDIR && ! defined fchdir
511 # define fchdir(fd) (-1)