source: trunk/src/lib/nt/fts-nt.h@ 2997

Last change on this file since 2997 was 2997, checked in by bird, 9 years ago

rm.c: Use fts_dirfd on windows.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1/* $Id: fts-nt.h 2997 2016-11-01 23:28:02Z bird $ */
2/** @file
3 * Header for the NT port of BSD fts.h.
4 *
5 * @copyright Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved.
6 * @copyright NT modifications Copyright (C) 2016 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
7 * @licenses BSD3
8 */
9
10/*
11 * Copyright (c) 1989, 1993
12 * The Regents of the University of California. All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)fts.h 8.3 (Berkeley) 8/14/94
39 * $FreeBSD$
40 *
41 */
42
43#ifndef INCLUDED_FTS_NT_H
44#define INCLUDED_FTS_NT_H
45
46#include <sys/types.h>
47#include <stdint.h>
48#include "ntstat.h" /* ensure correct stat structure */
49
50typedef uint64_t fts_dev_t;
51typedef uint64_t fts_ino_t;
52typedef uint32_t fts_nlink_t;
53#ifdef _WINNT_
54typedef HANDLE fts_fd_t;
55# define NT_FTS_INVALID_HANDLE_VALUE INVALID_HANDLE_VALUE
56#else
57typedef void * fts_fd_t;
58# define NT_FTS_INVALID_HANDLE_VALUE ((void *)~(uintptr_t)0)
59#endif
60#define FTSCALL __cdecl
61
62typedef struct {
63 struct _ftsent *fts_cur; /* current node */
64 struct _ftsent *fts_child; /* linked list of children */
65 struct _ftsent **fts_array; /* sort array */
66 fts_dev_t fts_dev; /* starting device # */
67 char *fts_path; /* path for this descent */
68 size_t fts_pathlen; /* sizeof(path) */
69 size_t fts_nitems; /* elements in the sort array */
70 int (FTSCALL *fts_compar) /* compare function */
71 (const struct _ftsent * const *, const struct _ftsent * const *);
72
73#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
74#define FTS_LOGICAL 0x002 /* logical walk */
75#define FTS_NOCHDIR 0x004 /* don't change directories */
76#define FTS_NOSTAT 0x008 /* don't get stat info */
77#define FTS_PHYSICAL 0x010 /* physical walk */
78#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
79#define FTS_XDEV 0x040 /* don't cross devices */
80#if 0 /* No whiteout on NT. */
81#define FTS_WHITEOUT 0x080 /* return whiteout information */
82#endif
83#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
84
85#define FTS_NAMEONLY 0x100 /* (private) child names only */
86#define FTS_STOP 0x200 /* (private) unrecoverable error */
87 int fts_options; /* fts_open options, global flags */
88 void *fts_clientptr; /* thunk for sort function */
89} FTS;
90
91typedef struct _ftsent {
92 struct _ftsent *fts_cycle; /* cycle node */
93 struct _ftsent *fts_parent; /* parent directory */
94 struct _ftsent *fts_link; /* next file in directory */
95 int64_t fts_number; /* local numeric value */
96#define fts_bignum fts_number /* XXX non-std, should go away */
97 void *fts_pointer; /* local address value */
98 char *fts_accpath; /* access path */
99 char *fts_path; /* root path */
100 int fts_errno; /* errno for this node */
101 fts_fd_t fts_symfd; /* NT: Normally -1; -2 we followed this symlinked dir */
102 fts_fd_t fts_dirfd; /* NT: Handle to the directory (NT_FTS_)INVALID_HANDLE_VALUE if not valid */
103 size_t fts_pathlen; /* strlen(fts_path) */
104 size_t fts_namelen; /* strlen(fts_name) */
105
106 fts_ino_t fts_ino; /* inode */
107 fts_dev_t fts_dev; /* device */
108 fts_nlink_t fts_nlink; /* link count */
109
110#define FTS_ROOTPARENTLEVEL -1
111#define FTS_ROOTLEVEL 0
112 long fts_level; /* depth (-1 to N) */
113
114#define FTS_D 1 /* preorder directory */
115#define FTS_DC 2 /* directory that causes cycles */
116#define FTS_DEFAULT 3 /* none of the above */
117#define FTS_DNR 4 /* unreadable directory */
118#define FTS_DOT 5 /* dot or dot-dot */
119#define FTS_DP 6 /* postorder directory */
120#define FTS_ERR 7 /* error; errno is set */
121#define FTS_F 8 /* regular file */
122#define FTS_INIT 9 /* initialized only */
123#define FTS_NS 10 /* stat(2) failed */
124#define FTS_NSOK 11 /* no stat(2) requested */
125#define FTS_SL 12 /* symbolic link */
126#define FTS_SLNONE 13 /* symbolic link without target */
127//#define FTS_W 14 /* whiteout object */
128 int fts_info; /* user status for FTSENT structure */
129
130#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
131#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
132#define FTS_ISW 0x04 /* this is a whiteout object */
133 unsigned fts_flags; /* private flags for FTSENT structure */
134
135#define FTS_AGAIN 1 /* read node again */
136#define FTS_FOLLOW 2 /* follow symbolic link */
137#define FTS_NOINSTR 3 /* no instructions */
138#define FTS_SKIP 4 /* discard node */
139 int fts_instr; /* fts_set() instructions */
140
141 struct stat *fts_statp; /* stat(2) information */
142 char *fts_name; /* file name */
143 FTS *fts_fts; /* back pointer to main FTS */
144 BirdStat_T fts_stat; /* NT: We always got stat info. */
145} FTSENT;
146
147
148#ifdef __cplusplus
149extern "C" {
150#endif
151
152FTSENT *FTSCALL nt_fts_children(FTS *, int);
153int FTSCALL nt_fts_close(FTS *);
154void *FTSCALL nt_fts_get_clientptr(FTS *);
155#define fts_get_clientptr(fts) ((fts)->fts_clientptr)
156FTS *FTSCALL nt_fts_get_stream(FTSENT *);
157#define fts_get_stream(ftsent) ((ftsent)->fts_fts)
158FTS *FTSCALL nt_fts_open(char * const *, int,
159 int (FTSCALL*)(const FTSENT * const *, const FTSENT * const *));
160FTSENT *FTSCALL nt_fts_read(FTS *);
161int FTSCALL nt_fts_set(FTS *, FTSENT *, int);
162void FTSCALL nt_fts_set_clientptr(FTS *, void *);
163
164/* API mappings. */
165#define fts_children(a_pFts, a_iInstr) nt_fts_children(a_pFts, a_iInstr)
166#define fts_close(a_pFts) nt_fts_close(a_pFts)
167#define fts_open(a_papszArgs, a_fOptions, a_pfnCompare) nt_fts_open(a_papszArgs, a_fOptions, a_pfnCompare)
168#define fts_read(a_pFts) nt_fts_read(a_pFts)
169#define fts_set(a_pFts, a_pFtsEntry, a_iInstr) nt_fts_set(a_pFts, a_pFtsEntry, a_iInstr)
170#define fts_set_clientptr(a_pFts, a_pvUser) nt_fts_set_clientptr(a_pFts, a_pvUser)
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* !INCLUDED_FTS_NT_H */
177
Note: See TracBrowser for help on using the repository browser.