/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1989, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#ifndef _FTS_H_32#define _FTS_H_3334#include <sys/_types.h>3536typedef struct _ftsent FTSENT;3738typedef struct {39FTSENT *fts_cur; /* current node */40FTSENT *fts_child; /* linked list of children */41FTSENT **fts_array; /* sort array */42__dev_t fts_dev; /* starting device # */43char *fts_path; /* path for this descent */44int fts_rfd; /* fd for root */45__size_t fts_pathlen; /* sizeof(path) */46__size_t fts_nitems; /* elements in the sort array */47union {48int (*fts_compar) /* compare function */49(const FTSENT * const *, const FTSENT * const *);50#ifdef __BLOCKS__51int (^fts_compar_b)52(const FTSENT * const *, const FTSENT * const *);53#else54void *fts_compar_b;55#endif /* __BLOCKS__ */56};5758/* valid for fts_open() */59#define FTS_COMFOLLOW 0x000001 /* follow command line symlinks */60#define FTS_LOGICAL 0x000002 /* logical walk */61#define FTS_NOCHDIR 0x000004 /* don't change directories */62#define FTS_NOSTAT 0x000008 /* don't get stat info */63#define FTS_PHYSICAL 0x000010 /* physical walk */64#define FTS_SEEDOT 0x000020 /* return dot and dot-dot */65#define FTS_XDEV 0x000040 /* don't cross devices */66#define FTS_WHITEOUT 0x000080 /* return whiteout information */67/* 0x0100 is FTS_NAMEONLY below */68/* 0x0200 was previously FTS_STOP */69#define FTS_COMFOLLOWDIR 0x00400 /* like COMFOLLOW but directories only */70#define FTS_NOSTAT_TYPE 0x000800 /* like NOSTAT but use d_type */71#define FTS_OPTIONMASK 0x000cff /* valid user option mask */7273/* valid only for fts_children() */74#define FTS_NAMEONLY 0x000100 /* child names only */7576/* internal use only */77#define FTS_STOP 0x010000 /* unrecoverable error */78#define FTS_COMPAR_B 0x020000 /* compare function is a block */79int fts_options; /* fts_open options, global flags */80void *fts_clientptr; /* thunk for sort function */81} FTS;8283struct _ftsent {84struct _ftsent *fts_cycle; /* cycle node */85struct _ftsent *fts_parent; /* parent directory */86struct _ftsent *fts_link; /* next file in directory */87long long fts_number; /* local numeric value */88#define fts_bignum fts_number /* XXX non-std, should go away */89void *fts_pointer; /* local address value */90char *fts_accpath; /* access path */91char *fts_path; /* root path */92int fts_errno; /* errno for this node */93int fts_symfd; /* fd for symlink */94__size_t fts_pathlen; /* strlen(fts_path) */95__size_t fts_namelen; /* strlen(fts_name) */9697__ino_t fts_ino; /* inode */98__dev_t fts_dev; /* device */99__nlink_t fts_nlink; /* link count */100101#define FTS_ROOTPARENTLEVEL -1102#define FTS_ROOTLEVEL 0103long fts_level; /* depth (-1 to N) */104105#define FTS_D 1 /* preorder directory */106#define FTS_DC 2 /* directory that causes cycles */107#define FTS_DEFAULT 3 /* none of the above */108#define FTS_DNR 4 /* unreadable directory */109#define FTS_DOT 5 /* dot or dot-dot */110#define FTS_DP 6 /* postorder directory */111#define FTS_ERR 7 /* error; errno is set */112#define FTS_F 8 /* regular file */113#define FTS_INIT 9 /* initialized only */114#define FTS_NS 10 /* stat(2) failed */115#define FTS_NSOK 11 /* no stat(2) requested */116#define FTS_SL 12 /* symbolic link */117#define FTS_SLNONE 13 /* symbolic link without target */118#define FTS_W 14 /* whiteout object */119int fts_info; /* user status for FTSENT structure */120121#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */122#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */123#define FTS_ISW 0x04 /* this is a whiteout object */124unsigned fts_flags; /* private flags for FTSENT structure */125126#define FTS_AGAIN 1 /* read node again */127#define FTS_FOLLOW 2 /* follow symbolic link */128#define FTS_NOINSTR 3 /* no instructions */129#define FTS_SKIP 4 /* discard node */130int fts_instr; /* fts_set() instructions */131132struct stat *fts_statp; /* stat(2) information */133char *fts_name; /* file name */134FTS *fts_fts; /* back pointer to main FTS */135};136137#include <sys/cdefs.h>138139__BEGIN_DECLS140FTSENT *fts_children(FTS *, int);141int fts_close(FTS *);142void *fts_get_clientptr(FTS *);143#define fts_get_clientptr(fts) ((fts)->fts_clientptr)144FTS *fts_get_stream(FTSENT *);145#define fts_get_stream(ftsent) ((ftsent)->fts_fts)146FTS *fts_open(char * const *, int,147int (*)(const FTSENT * const *, const FTSENT * const *));148#ifdef __BLOCKS__149FTS *fts_open_b(char * const *, int,150int (^)(const FTSENT * const *, const FTSENT * const *));151#endif /* __BLOCKS__ */152FTSENT *fts_read(FTS *);153int fts_set(FTS *, FTSENT *, int);154void fts_set_clientptr(FTS *, void *);155__END_DECLS156157#endif /* !_FTS_H_ */158159160