xref: /freebsd/lib/libc/gen/fts-compat.h (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
1*8a16b7a1SPedro F. Giffuni /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
459deaec5SRodney W. Grimes  * Copyright (c) 1989, 1993
559deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
659deaec5SRodney W. Grimes  *
759deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
859deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
959deaec5SRodney W. Grimes  * are met:
1059deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1159deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1259deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1359deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1459deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15e2e9c35fSEd Maste  * 3. Neither the name of the University nor the names of its contributors
1659deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
1759deaec5SRodney W. Grimes  *    without specific prior written permission.
1859deaec5SRodney W. Grimes  *
1959deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2059deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2159deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2259deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2359deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2459deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2559deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2659deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2759deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2859deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2959deaec5SRodney W. Grimes  * SUCH DAMAGE.
3059deaec5SRodney W. Grimes  */
3159deaec5SRodney W. Grimes 
3259deaec5SRodney W. Grimes #ifndef	_FTS_H_
3359deaec5SRodney W. Grimes #define	_FTS_H_
3459deaec5SRodney W. Grimes 
3559deaec5SRodney W. Grimes typedef struct {
3659deaec5SRodney W. Grimes 	struct _ftsent *fts_cur;	/* current node */
3759deaec5SRodney W. Grimes 	struct _ftsent *fts_child;	/* linked list of children */
3859deaec5SRodney W. Grimes 	struct _ftsent **fts_array;	/* sort array */
3969921123SKonstantin Belousov 	uint32_t fts_dev;		/* starting device # */
4059deaec5SRodney W. Grimes 	char *fts_path;			/* path for this descent */
4159deaec5SRodney W. Grimes 	int fts_rfd;			/* fd for root */
4259deaec5SRodney W. Grimes 	int fts_pathlen;		/* sizeof(path) */
4359deaec5SRodney W. Grimes 	int fts_nitems;			/* elements in the sort array */
44589ee357SRuslan Ermilov 	int (*fts_compar)		/* compare function */
450d3bcc2eSGarrett Wollman 	    (const struct _ftsent * const *, const struct _ftsent * const *);
4659deaec5SRodney W. Grimes 
4759deaec5SRodney W. Grimes #define	FTS_COMFOLLOW	0x001		/* follow command line symlinks */
4859deaec5SRodney W. Grimes #define	FTS_LOGICAL	0x002		/* logical walk */
4959deaec5SRodney W. Grimes #define	FTS_NOCHDIR	0x004		/* don't change directories */
5059deaec5SRodney W. Grimes #define	FTS_NOSTAT	0x008		/* don't get stat info */
5159deaec5SRodney W. Grimes #define	FTS_PHYSICAL	0x010		/* physical walk */
5259deaec5SRodney W. Grimes #define	FTS_SEEDOT	0x020		/* return dot and dot-dot */
5359deaec5SRodney W. Grimes #define	FTS_XDEV	0x040		/* don't cross devices */
540b7ae03cSPeter Wemm #define	FTS_WHITEOUT	0x080		/* return whiteout information */
550b7ae03cSPeter Wemm #define	FTS_OPTIONMASK	0x0ff		/* valid user option mask */
5659deaec5SRodney W. Grimes 
570b7ae03cSPeter Wemm #define	FTS_NAMEONLY	0x100		/* (private) child names only */
580b7ae03cSPeter Wemm #define	FTS_STOP	0x200		/* (private) unrecoverable error */
5959deaec5SRodney W. Grimes 	int fts_options;		/* fts_open options, global flags */
600d3bcc2eSGarrett Wollman 	void *fts_clientptr;		/* thunk for sort function */
6159deaec5SRodney W. Grimes } FTS;
6259deaec5SRodney W. Grimes 
6359deaec5SRodney W. Grimes typedef struct _ftsent {
6459deaec5SRodney W. Grimes 	struct _ftsent *fts_cycle;	/* cycle node */
6559deaec5SRodney W. Grimes 	struct _ftsent *fts_parent;	/* parent directory */
6659deaec5SRodney W. Grimes 	struct _ftsent *fts_link;	/* next file in directory */
6728644c1bSPawel Jakub Dawidek 	union {
6828644c1bSPawel Jakub Dawidek 		struct {
6928644c1bSPawel Jakub Dawidek 			long __fts_number;	/* local numeric value */
7028644c1bSPawel Jakub Dawidek 			void *__fts_pointer;	/* local address value */
7128644c1bSPawel Jakub Dawidek 		} __struct_ftsent;
7228644c1bSPawel Jakub Dawidek 		int64_t __fts_bignum;
7328644c1bSPawel Jakub Dawidek 	} __union_ftsent;
7428644c1bSPawel Jakub Dawidek #define	fts_number	__union_ftsent.__struct_ftsent.__fts_number
7528644c1bSPawel Jakub Dawidek #define	fts_pointer	__union_ftsent.__struct_ftsent.__fts_pointer
7628644c1bSPawel Jakub Dawidek #define	fts_bignum	__union_ftsent.__fts_bignum
7759deaec5SRodney W. Grimes 	char *fts_accpath;		/* access path */
7859deaec5SRodney W. Grimes 	char *fts_path;			/* root path */
7959deaec5SRodney W. Grimes 	int fts_errno;			/* errno for this node */
8059deaec5SRodney W. Grimes 	int fts_symfd;			/* fd for symlink */
8159deaec5SRodney W. Grimes 	u_short fts_pathlen;		/* strlen(fts_path) */
8259deaec5SRodney W. Grimes 	u_short fts_namelen;		/* strlen(fts_name) */
8359deaec5SRodney W. Grimes 
8469921123SKonstantin Belousov 	uint32_t fts_ino;		/* inode */
8569921123SKonstantin Belousov 	uint32_t fts_dev;		/* device */
8669921123SKonstantin Belousov 	uint16_t fts_nlink;		/* link count */
8759deaec5SRodney W. Grimes 
8859deaec5SRodney W. Grimes #define	FTS_ROOTPARENTLEVEL	-1
8959deaec5SRodney W. Grimes #define	FTS_ROOTLEVEL		 0
9059deaec5SRodney W. Grimes 	short fts_level;		/* depth (-1 to N) */
9159deaec5SRodney W. Grimes 
9259deaec5SRodney W. Grimes #define	FTS_D		 1		/* preorder directory */
9359deaec5SRodney W. Grimes #define	FTS_DC		 2		/* directory that causes cycles */
9459deaec5SRodney W. Grimes #define	FTS_DEFAULT	 3		/* none of the above */
9559deaec5SRodney W. Grimes #define	FTS_DNR		 4		/* unreadable directory */
9659deaec5SRodney W. Grimes #define	FTS_DOT		 5		/* dot or dot-dot */
9759deaec5SRodney W. Grimes #define	FTS_DP		 6		/* postorder directory */
9859deaec5SRodney W. Grimes #define	FTS_ERR		 7		/* error; errno is set */
9959deaec5SRodney W. Grimes #define	FTS_F		 8		/* regular file */
10059deaec5SRodney W. Grimes #define	FTS_INIT	 9		/* initialized only */
10159deaec5SRodney W. Grimes #define	FTS_NS		10		/* stat(2) failed */
10259deaec5SRodney W. Grimes #define	FTS_NSOK	11		/* no stat(2) requested */
10359deaec5SRodney W. Grimes #define	FTS_SL		12		/* symbolic link */
10459deaec5SRodney W. Grimes #define	FTS_SLNONE	13		/* symbolic link without target */
1050b7ae03cSPeter Wemm #define	FTS_W		14		/* whiteout object */
10659deaec5SRodney W. Grimes 	u_short fts_info;		/* user flags for FTSENT structure */
10759deaec5SRodney W. Grimes 
10859deaec5SRodney W. Grimes #define	FTS_DONTCHDIR	 0x01		/* don't chdir .. to the parent */
10959deaec5SRodney W. Grimes #define	FTS_SYMFOLLOW	 0x02		/* followed a symlink to get here */
1100b7ae03cSPeter Wemm #define	FTS_ISW		 0x04		/* this is a whiteout object */
11159deaec5SRodney W. Grimes 	u_short fts_flags;		/* private flags for FTSENT structure */
11259deaec5SRodney W. Grimes 
11359deaec5SRodney W. Grimes #define	FTS_AGAIN	 1		/* read node again */
11459deaec5SRodney W. Grimes #define	FTS_FOLLOW	 2		/* follow symbolic link */
11559deaec5SRodney W. Grimes #define	FTS_NOINSTR	 3		/* no instructions */
11659deaec5SRodney W. Grimes #define	FTS_SKIP	 4		/* discard node */
11759deaec5SRodney W. Grimes 	u_short fts_instr;		/* fts_set() instructions */
11859deaec5SRodney W. Grimes 
11969921123SKonstantin Belousov 	struct freebsd11_stat *fts_statp; /* stat(2) information */
1200d3bcc2eSGarrett Wollman 	char *fts_name;			/* file name */
1210d3bcc2eSGarrett Wollman 	FTS *fts_fts;			/* back pointer to main FTS */
12259deaec5SRodney W. Grimes } FTSENT;
12359deaec5SRodney W. Grimes 
1240d3bcc2eSGarrett Wollman #define	 fts_get_clientptr(fts)	((fts)->fts_clientptr)
1250d3bcc2eSGarrett Wollman #define	 fts_get_stream(ftsent)	((ftsent)->fts_fts)
12659deaec5SRodney W. Grimes 
12759deaec5SRodney W. Grimes #endif /* !_FTS_H_ */
128