1*0afb8a1bSAugustin Cavalier /* 2*0afb8a1bSAugustin Cavalier * Copyright (c) 1989, 1993 3*0afb8a1bSAugustin Cavalier * The Regents of the University of California. All rights reserved. 4*0afb8a1bSAugustin Cavalier * 5*0afb8a1bSAugustin Cavalier * Redistribution and use in source and binary forms, with or without 6*0afb8a1bSAugustin Cavalier * modification, are permitted provided that the following conditions 7*0afb8a1bSAugustin Cavalier * are met: 8*0afb8a1bSAugustin Cavalier * 1. Redistributions of source code must retain the above copyright 9*0afb8a1bSAugustin Cavalier * notice, this list of conditions and the following disclaimer. 10*0afb8a1bSAugustin Cavalier * 2. Redistributions in binary form must reproduce the above copyright 11*0afb8a1bSAugustin Cavalier * notice, this list of conditions and the following disclaimer in the 12*0afb8a1bSAugustin Cavalier * documentation and/or other materials provided with the distribution. 13*0afb8a1bSAugustin Cavalier * 3. Neither the name of the University nor the names of its contributors 14*0afb8a1bSAugustin Cavalier * may be used to endorse or promote products derived from this software 15*0afb8a1bSAugustin Cavalier * without specific prior written permission. 16*0afb8a1bSAugustin Cavalier * 17*0afb8a1bSAugustin Cavalier * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18*0afb8a1bSAugustin Cavalier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*0afb8a1bSAugustin Cavalier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*0afb8a1bSAugustin Cavalier * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21*0afb8a1bSAugustin Cavalier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*0afb8a1bSAugustin Cavalier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*0afb8a1bSAugustin Cavalier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*0afb8a1bSAugustin Cavalier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*0afb8a1bSAugustin Cavalier * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*0afb8a1bSAugustin Cavalier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*0afb8a1bSAugustin Cavalier * SUCH DAMAGE. 28*0afb8a1bSAugustin Cavalier * 29*0afb8a1bSAugustin Cavalier * @(#)fts.h 8.3 (Berkeley) 8/14/94 30*0afb8a1bSAugustin Cavalier * $FreeBSD$ 31*0afb8a1bSAugustin Cavalier */ 32*0afb8a1bSAugustin Cavalier 33*0afb8a1bSAugustin Cavalier #ifndef _FTS_H_ 34*0afb8a1bSAugustin Cavalier #define _FTS_H_ 35*0afb8a1bSAugustin Cavalier 36*0afb8a1bSAugustin Cavalier #include <features.h> 37*0afb8a1bSAugustin Cavalier 38*0afb8a1bSAugustin Cavalier #ifdef _DEFAULT_SOURCE 39*0afb8a1bSAugustin Cavalier 40*0afb8a1bSAugustin Cavalier #include <sys/cdefs.h> 41*0afb8a1bSAugustin Cavalier 42*0afb8a1bSAugustin Cavalier typedef struct { 43*0afb8a1bSAugustin Cavalier struct _ftsent *fts_cur; /* current node */ 44*0afb8a1bSAugustin Cavalier struct _ftsent *fts_child; /* linked list of children */ 45*0afb8a1bSAugustin Cavalier struct _ftsent **fts_array; /* sort array */ 46*0afb8a1bSAugustin Cavalier dev_t fts_dev; /* starting device # */ 47*0afb8a1bSAugustin Cavalier char *fts_path; /* path for this descent */ 48*0afb8a1bSAugustin Cavalier int fts_rfd; /* fd for root */ 49*0afb8a1bSAugustin Cavalier size_t fts_pathlen; /* sizeof(path) */ 50*0afb8a1bSAugustin Cavalier size_t fts_nitems; /* elements in the sort array */ 51*0afb8a1bSAugustin Cavalier int (*fts_compar) /* compare function */ 52*0afb8a1bSAugustin Cavalier (const struct _ftsent * const *, const struct _ftsent * const *); 53*0afb8a1bSAugustin Cavalier 54*0afb8a1bSAugustin Cavalier #define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ 55*0afb8a1bSAugustin Cavalier #define FTS_LOGICAL 0x002 /* logical walk */ 56*0afb8a1bSAugustin Cavalier #define FTS_NOCHDIR 0x004 /* don't change directories */ 57*0afb8a1bSAugustin Cavalier #define FTS_NOSTAT 0x008 /* don't get stat info */ 58*0afb8a1bSAugustin Cavalier #define FTS_PHYSICAL 0x010 /* physical walk */ 59*0afb8a1bSAugustin Cavalier #define FTS_SEEDOT 0x020 /* return dot and dot-dot */ 60*0afb8a1bSAugustin Cavalier #define FTS_XDEV 0x040 /* don't cross devices */ 61*0afb8a1bSAugustin Cavalier #if !defined(__HAIKU__) 62*0afb8a1bSAugustin Cavalier #define FTS_WHITEOUT 0x080 /* return whiteout information */ 63*0afb8a1bSAugustin Cavalier #endif 64*0afb8a1bSAugustin Cavalier #define FTS_OPTIONMASK 0x0ff /* valid user option mask */ 65*0afb8a1bSAugustin Cavalier 66*0afb8a1bSAugustin Cavalier #define FTS_NAMEONLY 0x100 /* (private) child names only */ 67*0afb8a1bSAugustin Cavalier #define FTS_STOP 0x200 /* (private) unrecoverable error */ 68*0afb8a1bSAugustin Cavalier int fts_options; /* fts_open options, global flags */ 69*0afb8a1bSAugustin Cavalier void *fts_clientptr; /* thunk for sort function */ 70*0afb8a1bSAugustin Cavalier } FTS; 71*0afb8a1bSAugustin Cavalier 72*0afb8a1bSAugustin Cavalier typedef struct _ftsent { 73*0afb8a1bSAugustin Cavalier struct _ftsent *fts_cycle; /* cycle node */ 74*0afb8a1bSAugustin Cavalier struct _ftsent *fts_parent; /* parent directory */ 75*0afb8a1bSAugustin Cavalier struct _ftsent *fts_link; /* next file in directory */ 76*0afb8a1bSAugustin Cavalier long long fts_number; /* local numeric value */ 77*0afb8a1bSAugustin Cavalier #define fts_bignum fts_number /* XXX non-std, should go away */ 78*0afb8a1bSAugustin Cavalier void *fts_pointer; /* local address value */ 79*0afb8a1bSAugustin Cavalier char *fts_accpath; /* access path */ 80*0afb8a1bSAugustin Cavalier char *fts_path; /* root path */ 81*0afb8a1bSAugustin Cavalier int fts_errno; /* errno for this node */ 82*0afb8a1bSAugustin Cavalier int fts_symfd; /* fd for symlink */ 83*0afb8a1bSAugustin Cavalier size_t fts_pathlen; /* strlen(fts_path) */ 84*0afb8a1bSAugustin Cavalier size_t fts_namelen; /* strlen(fts_name) */ 85*0afb8a1bSAugustin Cavalier 86*0afb8a1bSAugustin Cavalier ino_t fts_ino; /* inode */ 87*0afb8a1bSAugustin Cavalier dev_t fts_dev; /* device */ 88*0afb8a1bSAugustin Cavalier nlink_t fts_nlink; /* link count */ 89*0afb8a1bSAugustin Cavalier 90*0afb8a1bSAugustin Cavalier #define FTS_ROOTPARENTLEVEL -1 91*0afb8a1bSAugustin Cavalier #define FTS_ROOTLEVEL 0 92*0afb8a1bSAugustin Cavalier long fts_level; /* depth (-1 to N) */ 93*0afb8a1bSAugustin Cavalier 94*0afb8a1bSAugustin Cavalier #define FTS_D 1 /* preorder directory */ 95*0afb8a1bSAugustin Cavalier #define FTS_DC 2 /* directory that causes cycles */ 96*0afb8a1bSAugustin Cavalier #define FTS_DEFAULT 3 /* none of the above */ 97*0afb8a1bSAugustin Cavalier #define FTS_DNR 4 /* unreadable directory */ 98*0afb8a1bSAugustin Cavalier #define FTS_DOT 5 /* dot or dot-dot */ 99*0afb8a1bSAugustin Cavalier #define FTS_DP 6 /* postorder directory */ 100*0afb8a1bSAugustin Cavalier #define FTS_ERR 7 /* error; errno is set */ 101*0afb8a1bSAugustin Cavalier #define FTS_F 8 /* regular file */ 102*0afb8a1bSAugustin Cavalier #define FTS_INIT 9 /* initialized only */ 103*0afb8a1bSAugustin Cavalier #define FTS_NS 10 /* stat(2) failed */ 104*0afb8a1bSAugustin Cavalier #define FTS_NSOK 11 /* no stat(2) requested */ 105*0afb8a1bSAugustin Cavalier #define FTS_SL 12 /* symbolic link */ 106*0afb8a1bSAugustin Cavalier #define FTS_SLNONE 13 /* symbolic link without target */ 107*0afb8a1bSAugustin Cavalier #define FTS_W 14 /* whiteout object */ 108*0afb8a1bSAugustin Cavalier int fts_info; /* user status for FTSENT structure */ 109*0afb8a1bSAugustin Cavalier 110*0afb8a1bSAugustin Cavalier #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ 111*0afb8a1bSAugustin Cavalier #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ 112*0afb8a1bSAugustin Cavalier #define FTS_ISW 0x04 /* this is a whiteout object */ 113*0afb8a1bSAugustin Cavalier unsigned fts_flags; /* private flags for FTSENT structure */ 114*0afb8a1bSAugustin Cavalier 115*0afb8a1bSAugustin Cavalier #define FTS_AGAIN 1 /* read node again */ 116*0afb8a1bSAugustin Cavalier #define FTS_FOLLOW 2 /* follow symbolic link */ 117*0afb8a1bSAugustin Cavalier #define FTS_NOINSTR 3 /* no instructions */ 118*0afb8a1bSAugustin Cavalier #define FTS_SKIP 4 /* discard node */ 119*0afb8a1bSAugustin Cavalier int fts_instr; /* fts_set() instructions */ 120*0afb8a1bSAugustin Cavalier 121*0afb8a1bSAugustin Cavalier struct stat *fts_statp; /* stat(2) information */ 122*0afb8a1bSAugustin Cavalier char *fts_name; /* file name */ 123*0afb8a1bSAugustin Cavalier FTS *fts_fts; /* back pointer to main FTS */ 124*0afb8a1bSAugustin Cavalier } FTSENT; 125*0afb8a1bSAugustin Cavalier 126*0afb8a1bSAugustin Cavalier #include <sys/cdefs.h> 127*0afb8a1bSAugustin Cavalier 128*0afb8a1bSAugustin Cavalier __BEGIN_DECLS 129*0afb8a1bSAugustin Cavalier FTSENT *fts_children(FTS *, int); 130*0afb8a1bSAugustin Cavalier int fts_close(FTS *); 131*0afb8a1bSAugustin Cavalier void *fts_get_clientptr(FTS *); 132*0afb8a1bSAugustin Cavalier #define fts_get_clientptr(fts) ((fts)->fts_clientptr) 133*0afb8a1bSAugustin Cavalier FTS *fts_get_stream(FTSENT *); 134*0afb8a1bSAugustin Cavalier #define fts_get_stream(ftsent) ((ftsent)->fts_fts) 135*0afb8a1bSAugustin Cavalier FTS *fts_open(char * const *, int, 136*0afb8a1bSAugustin Cavalier int (*)(const FTSENT * const *, const FTSENT * const *)); 137*0afb8a1bSAugustin Cavalier FTSENT *fts_read(FTS *); 138*0afb8a1bSAugustin Cavalier int fts_set(FTS *, FTSENT *, int); 139*0afb8a1bSAugustin Cavalier void fts_set_clientptr(FTS *, void *); 140*0afb8a1bSAugustin Cavalier __END_DECLS 141*0afb8a1bSAugustin Cavalier 142*0afb8a1bSAugustin Cavalier #endif /* _DEFAULT_SOURCE */ 143*0afb8a1bSAugustin Cavalier 144*0afb8a1bSAugustin Cavalier #endif /* !_FTS_H_ */ 145