xref: /illumos-gate/usr/src/head/fts.h (revision db132910a923e71326bd3fde5c15548dabd000b9)
14585130bSYuri Pankov /*
24585130bSYuri Pankov  * Copyright (c) 1989, 1993
34585130bSYuri Pankov  *	The Regents of the University of California.  All rights reserved.
44585130bSYuri Pankov  *
54585130bSYuri Pankov  * Redistribution and use in source and binary forms, with or without
64585130bSYuri Pankov  * modification, are permitted provided that the following conditions
74585130bSYuri Pankov  * are met:
84585130bSYuri Pankov  * 1. Redistributions of source code must retain the above copyright
94585130bSYuri Pankov  *    notice, this list of conditions and the following disclaimer.
104585130bSYuri Pankov  * 2. Redistributions in binary form must reproduce the above copyright
114585130bSYuri Pankov  *    notice, this list of conditions and the following disclaimer in the
124585130bSYuri Pankov  *    documentation and/or other materials provided with the distribution.
134585130bSYuri Pankov  * 3. Neither the name of the University nor the names of its contributors
144585130bSYuri Pankov  *    may be used to endorse or promote products derived from this software
154585130bSYuri Pankov  *    without specific prior written permission.
164585130bSYuri Pankov  *
174585130bSYuri Pankov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
184585130bSYuri Pankov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
194585130bSYuri Pankov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204585130bSYuri Pankov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
214585130bSYuri Pankov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
224585130bSYuri Pankov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234585130bSYuri Pankov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244585130bSYuri Pankov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
254585130bSYuri Pankov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264585130bSYuri Pankov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
274585130bSYuri Pankov  * SUCH DAMAGE.
284585130bSYuri Pankov  */
294585130bSYuri Pankov 
304585130bSYuri Pankov #ifndef	_FTS_H
314585130bSYuri Pankov #define	_FTS_H
324585130bSYuri Pankov 
334585130bSYuri Pankov #ifdef	__cplusplus
344585130bSYuri Pankov extern "C" {
354585130bSYuri Pankov #endif
364585130bSYuri Pankov 
374585130bSYuri Pankov typedef struct {
384585130bSYuri Pankov 	struct _ftsent *fts_cur;	/* current node */
394585130bSYuri Pankov 	struct _ftsent *fts_child;	/* linked list of children */
404585130bSYuri Pankov 	struct _ftsent **fts_array;	/* sort array */
414585130bSYuri Pankov 	dev_t fts_dev;			/* starting device # */
424585130bSYuri Pankov 	char *fts_path;			/* path for this descent */
434585130bSYuri Pankov 	int fts_rfd;			/* fd for root */
444585130bSYuri Pankov 	size_t fts_pathlen;		/* sizeof(path) */
454585130bSYuri Pankov 	int fts_nitems;			/* elements in the sort array */
464585130bSYuri Pankov 	int (*fts_compar)();		/* compare function */
474585130bSYuri Pankov 
484585130bSYuri Pankov #define	FTS_COMFOLLOW	0x0001		/* follow command line symlinks */
494585130bSYuri Pankov #define	FTS_LOGICAL	0x0002		/* logical walk */
504585130bSYuri Pankov #define	FTS_NOCHDIR	0x0004		/* don't change directories */
514585130bSYuri Pankov #define	FTS_NOSTAT	0x0008		/* don't get stat info */
524585130bSYuri Pankov #define	FTS_PHYSICAL	0x0010		/* physical walk */
534585130bSYuri Pankov #define	FTS_SEEDOT	0x0020		/* return dot and dot-dot */
544585130bSYuri Pankov #define	FTS_XDEV	0x0040		/* don't cross devices */
554585130bSYuri Pankov #define	FTS_OPTIONMASK	0x00ff		/* valid user option mask */
564585130bSYuri Pankov 
574585130bSYuri Pankov #define	FTS_NAMEONLY	0x1000		/* (private) child names only */
584585130bSYuri Pankov #define	FTS_STOP	0x2000		/* (private) unrecoverable error */
594585130bSYuri Pankov 	int fts_options;		/* fts_open options, global flags */
604585130bSYuri Pankov } FTS;
614585130bSYuri Pankov 
624585130bSYuri Pankov typedef struct _ftsent {
634585130bSYuri Pankov 	struct _ftsent *fts_cycle;	/* cycle node */
644585130bSYuri Pankov 	struct _ftsent *fts_parent;	/* parent directory */
654585130bSYuri Pankov 	struct _ftsent *fts_link;	/* next file in directory */
664585130bSYuri Pankov 	long fts_number;		/* local numeric value */
674585130bSYuri Pankov 	void *fts_pointer;		/* local address value */
684585130bSYuri Pankov 	char *fts_accpath;		/* access path */
694585130bSYuri Pankov 	char *fts_path;			/* root path */
704585130bSYuri Pankov 	int fts_errno;			/* errno for this node */
714585130bSYuri Pankov 	int fts_symfd;			/* fd for symlink */
724585130bSYuri Pankov 	size_t fts_pathlen;		/* strlen(fts_path) */
734585130bSYuri Pankov 	size_t fts_namelen;		/* strlen(fts_name) */
744585130bSYuri Pankov 
754585130bSYuri Pankov 	ino_t fts_ino;			/* inode */
764585130bSYuri Pankov 	dev_t fts_dev;			/* device */
774585130bSYuri Pankov 	nlink_t fts_nlink;		/* link count */
784585130bSYuri Pankov 
794585130bSYuri Pankov #define	FTS_ROOTPARENTLEVEL	-1
804585130bSYuri Pankov #define	FTS_ROOTLEVEL		 0
814585130bSYuri Pankov #define	FTS_MAXLEVEL		 0x7fffffff
824585130bSYuri Pankov 	int fts_level;		/* depth (-1 to N) */
834585130bSYuri Pankov 
844585130bSYuri Pankov #define	FTS_D		 1		/* preorder directory */
854585130bSYuri Pankov #define	FTS_DC		 2		/* directory that causes cycles */
864585130bSYuri Pankov #define	FTS_DEFAULT	 3		/* none of the above */
874585130bSYuri Pankov #define	FTS_DNR		 4		/* unreadable directory */
884585130bSYuri Pankov #define	FTS_DOT		 5		/* dot or dot-dot */
894585130bSYuri Pankov #define	FTS_DP		 6		/* postorder directory */
904585130bSYuri Pankov #define	FTS_ERR		 7		/* error; errno is set */
914585130bSYuri Pankov #define	FTS_F		 8		/* regular file */
924585130bSYuri Pankov #define	FTS_INIT	 9		/* initialized only */
934585130bSYuri Pankov #define	FTS_NS		10		/* stat(2) failed */
944585130bSYuri Pankov #define	FTS_NSOK	11		/* no stat(2) requested */
954585130bSYuri Pankov #define	FTS_SL		12		/* symbolic link */
964585130bSYuri Pankov #define	FTS_SLNONE	13		/* symbolic link without target */
974585130bSYuri Pankov 	unsigned short fts_info;	/* user flags for FTSENT structure */
984585130bSYuri Pankov 
994585130bSYuri Pankov #define	FTS_DONTCHDIR	 0x01		/* don't chdir .. to the parent */
1004585130bSYuri Pankov #define	FTS_SYMFOLLOW	 0x02		/* followed a symlink to get here */
1014585130bSYuri Pankov 	unsigned short fts_flags;	/* private flags for FTSENT structure */
1024585130bSYuri Pankov 
1034585130bSYuri Pankov #define	FTS_AGAIN	 1		/* read node again */
1044585130bSYuri Pankov #define	FTS_FOLLOW	 2		/* follow symbolic link */
1054585130bSYuri Pankov #define	FTS_NOINSTR	 3		/* no instructions */
1064585130bSYuri Pankov #define	FTS_SKIP	 4		/* discard node */
1074585130bSYuri Pankov 	unsigned short fts_instr;	/* fts_set() instructions */
1084585130bSYuri Pankov 
1094585130bSYuri Pankov 	unsigned short fts_spare;	/* unused */
1104585130bSYuri Pankov 
1114585130bSYuri Pankov 	struct stat *fts_statp;		/* stat(2) information */
1124585130bSYuri Pankov 	char fts_name[1];		/* file name */
1134585130bSYuri Pankov } FTSENT;
1144585130bSYuri Pankov 
115*db132910SJonathan Perkin #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
116*db132910SJonathan Perkin #ifdef __PRAGMA_REDEFINE_EXTNAME
117*db132910SJonathan Perkin #pragma	redefine_extname	fts_children	fts_children64
118*db132910SJonathan Perkin #pragma	redefine_extname	fts_close	fts_close64
119*db132910SJonathan Perkin #pragma	redefine_extname	fts_open	fts_open64
120*db132910SJonathan Perkin #pragma	redefine_extname	fts_read	fts_read64
121*db132910SJonathan Perkin #pragma	redefine_extname	fts_set		fts_set64
122*db132910SJonathan Perkin #else
123*db132910SJonathan Perkin #define	fts_children	fts_children64
124*db132910SJonathan Perkin #define	fts_close	fts_close64
125*db132910SJonathan Perkin #define	fts_open	fts_open64
126*db132910SJonathan Perkin #define	fts_read	fts_read64
127*db132910SJonathan Perkin #define	fts_set		fts_set64
128*db132910SJonathan Perkin #endif /* __PRAGMA_REDEFINE_EXTNAME */
129*db132910SJonathan Perkin #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
130*db132910SJonathan Perkin 
1314585130bSYuri Pankov FTSENT	*fts_children(FTS *, int);
1324585130bSYuri Pankov int	 fts_close(FTS *);
1334585130bSYuri Pankov FTS	*fts_open(char * const *, int,
1344585130bSYuri Pankov 	    int (*)(const FTSENT **, const FTSENT **));
1354585130bSYuri Pankov FTSENT	*fts_read(FTS *);
1364585130bSYuri Pankov int	 fts_set(FTS *, FTSENT *, int);
1374585130bSYuri Pankov 
1384585130bSYuri Pankov #ifdef	__cplusplus
1394585130bSYuri Pankov }
1404585130bSYuri Pankov #endif
1414585130bSYuri Pankov 
1424585130bSYuri Pankov #endif /* !_FTS_H */
143