xref: /titanic_44/usr/src/lib/libast/common/include/fts.h (revision 1babaf948dd28d81d79cf3ec089d6edc111ed4a8)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * David Korn
26  * Phong Vo
27  * AT&T Research
28  *
29  * fts interface definitions
30  */
31 
32 #ifndef	_FTS_H
33 #define _FTS_H
34 
35 #include <ast_std.h>
36 #include <ast_fs.h>
37 #include <ast_mode.h>
38 
39 /*
40  * fts_open flags
41  */
42 
43 #define FTS_LOGICAL	0	/* logical traversal, follow symlinks	*/
44 #define FTS_META	(1<<0)	/* follow top dir symlinks even if phys	*/
45 #define FTS_NOCHDIR	(1<<1)	/* don't chdir				*/
46 #define FTS_NOPOSTORDER	(1<<2)	/* no postorder visits			*/
47 #define FTS_NOPREORDER	(1<<3)	/* no preorder visits			*/
48 #define FTS_NOSEEDOTDIR	(1<<11)	/* never retain leading . dir		*/
49 #define FTS_NOSTAT	(1<<4)	/* don't stat children			*/
50 #define FTS_ONEPATH	(1<<5)	/* pathnames arg is one const char*	*/
51 #define FTS_PHYSICAL	(1<<6)	/* physical traversal, don't follow	*/
52 #define FTS_SEEDOT	(1<<7)	/* return . and ..			*/
53 #define FTS_SEEDOTDIR	(1<<10)	/* always retain leading . dir		*/
54 #define FTS_TOP		(1<<8)	/* don't traverse subdirectories	*/
55 #define FTS_XDEV	(1<<9)	/* don't cross mount points		*/
56 
57 #define FTS_USER	(1<<12)	/* first user flag bit			*/
58 
59 #define FTS_COMFOLLOW	FTS_META
60 
61 /*
62  * fts_info flags
63  */
64 
65 #define FTS_DEFAULT	0	/* ok, someone must have wanted this	*/
66 
67 #define FTS_NS		(1<<0)	/* stat failed				*/
68 #define FTS_F		(1<<1)	/* file - not directory or symbolic link*/
69 #define FTS_SL		(1<<2)	/* symbolic link			*/
70 #define FTS_D		(1<<3)	/* directory - pre-order visit		*/
71 
72 #define FTS_C		(1<<4)	/* causes cycle				*/
73 #define FTS_ERR		(1<<5)	/* some other error			*/
74 #define FTS_DD		(1<<6)	/* . or ..				*/
75 #define FTS_NR		(1<<7)	/* cannot read				*/
76 #define FTS_NX		(1<<8)	/* cannot search			*/
77 #define FTS_OK		(1<<9)	/* no info but otherwise ok		*/
78 #define FTS_P		(1<<10)	/* post-order visit			*/
79 
80 #define FTS_DC		(FTS_D|FTS_C)	/* dir - would cause cycle	*/
81 #define FTS_DNR		(FTS_D|FTS_NR)	/* dir - no read permission	*/
82 #define FTS_DNX		(FTS_D|FTS_NX)	/* dir - no search permission	*/
83 #define FTS_DOT		(FTS_D|FTS_DD)	/* . or ..			*/
84 #define FTS_DP		(FTS_D|FTS_P)	/* dir - post-order visit	*/
85 #define FTS_NSOK	(FTS_NS|FTS_OK)	/* no stat (because you asked)	*/
86 #define FTS_SLNONE	(FTS_SL|FTS_NS)	/* symlink - to nowhere		*/
87 
88 /*
89  * fts_set flags
90  */
91 
92 #define FTS_AGAIN	FTS_TOP		/* process entry again		*/
93 #define FTS_FOLLOW	FTS_META	/* follow FTS_SL symlink	*/
94 #define FTS_SKIP	FTS_NOSTAT	/* skip FTS_D directory		*/
95 #define FTS_STAT	FTS_PHYSICAL	/* stat() done by user		*/
96 
97 typedef struct Fts FTS;
98 typedef struct Ftsent FTSENT;
99 
100 struct Ftsent
101 {
102 	char*		fts_accpath;	/* path relative to .		*/
103 	char*		fts_name;	/* file name			*/
104 	char*		fts_path;	/* path relative to top dir	*/
105 	FTSENT*		fts_cycle;	/* offender if cycle		*/
106 	FTSENT*		fts_link;	/* next child			*/
107 	FTSENT*		fts_parent;	/* parent directory		*/
108 	struct stat*	fts_statp;	/* stat info			*/
109 #ifdef _FTSENT_LOCAL_PRIVATE_
110 	_FTSENT_LOCAL_PRIVATE_
111 #else
112 	void*		fts_pointer;	/* local pointer value		*/
113 #endif
114 	long		fts_number;	/* local numeric value		*/
115 	int		fts_errno;	/* errno for this entry		*/
116 	unsigned short	fts_info;	/* info flags			*/
117 
118 	unsigned short	_fts_namelen;	/* old fts_namelen		*/
119 	unsigned short	_fts_pathlen;	/* old fts_pathlen		*/
120 	short		_fts_level;	/* old fts_level		*/
121 
122 	short		_fts_status;	/* <ftwalk.h> compatibility	*/
123 	struct stat	_fts_statb;	/* <ftwalk.h> compatibility	*/
124 
125 	FTS*		fts;		/* fts_open() handle		*/
126 	size_t		fts_namelen;	/* strlen(fts_name)		*/
127 	size_t		fts_pathlen;	/* strlen(fts_path)		*/
128 	ssize_t		fts_level;	/* file tree depth, 0 at top	*/
129 
130 #ifdef _FTSENT_PRIVATE_
131 	_FTSENT_PRIVATE_
132 #endif
133 
134 };
135 
136 struct Fts
137 {
138 	int		fts_errno;	/* last errno			*/
139 	void*		fts_handle;	/* user defined handle		*/
140 
141 #ifdef _FTS_PRIVATE_
142 	_FTS_PRIVATE_
143 #endif
144 
145 };
146 
147 #if _BLD_ast && defined(__EXPORT__)
148 #define extern		__EXPORT__
149 #endif
150 
151 extern FTSENT*	fts_children(FTS*, int);
152 extern int	fts_close(FTS*);
153 extern int	fts_flags(void);
154 extern int	fts_local(FTSENT*);
155 extern int	fts_notify(int(*)(FTS*, FTSENT*, void*), void*);
156 extern FTS*	fts_open(char* const*, int, int(*)(FTSENT* const*, FTSENT* const*));
157 extern FTSENT*	fts_read(FTS*);
158 extern int	fts_set(FTS*, FTSENT*, int);
159 
160 #undef	extern
161 
162 #endif
163