Sync with FreeBSD. This adds read-only support for zip and ISO9660.
[dragonfly.git] / contrib / bsdtar / tree.h
blob325c6c67676ef3600429b7ddffb5c78c06918a29
1 /*-
2 * Copyright (c) 2003-2004 Tim Kientzle
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/usr.bin/tar/tree.h,v 1.1 2005/04/24 05:53:37 kientzle Exp $
29 /*-
30 * A set of routines for traversing directory trees.
31 * Similar in concept to the fts library, but with a few
32 * important differences:
33 * * Uses less memory. In particular, fts stores an entire directory
34 * in memory at a time. This package only keeps enough subdirectory
35 * information in memory to track the traversal. Information
36 * about non-directories is discarded as soon as possible.
37 * * Supports very deep logical traversals. The fts package
38 * uses "non-chdir" approach for logical traversals. This
39 * package does use a chdir approach for logical traversals
40 * and can therefore handle pathnames much longer than
41 * PATH_MAX.
42 * * Supports deep physical traversals "out of the box."
43 * Due to the memory optimizations above, there's no need to
44 * limit dir names to 32k.
47 #include <sys/stat.h>
48 #include <stdio.h>
50 struct tree;
52 /* Initiate/terminate a tree traversal. */
53 struct tree *tree_open(const char * /* pathname */);
54 void tree_close(struct tree *);
57 * tree_next() returns Zero if there is no next entry, non-zero if there is.
58 * Note that directories are potentially visited three times. The first
59 * time as "regular" file. If tree_descend() is invoked at that time,
60 * the directory is added to a work list and will be visited two more
61 * times: once just after descending into the directory and again
62 * just after ascending back to the parent.
64 * TREE_ERROR is returned if the descent failed (because the
65 * directory couldn't be opened, for instance). This is returned
66 * instead of TREE_PREVISIT/TREE_POSTVISIT.
68 #define TREE_REGULAR 1
69 #define TREE_POSTDESCENT 2
70 #define TREE_POSTASCENT 3
71 #define TREE_ERROR -1
72 int tree_next(struct tree *);
74 int tree_errno(struct tree *);
77 * Request that current entry be visited. If you invoke it on every
78 * directory, you'll get a physical traversal. This is ignored if the
79 * current entry isn't a directory or a link to a directory. So, if
80 * you invoke this on every returned path, you'll get a full logical
81 * traversal.
83 void tree_descend(struct tree *);
86 * Return information about the current entry.
89 int tree_current_depth(struct tree *);
91 * The current full pathname, length of the full pathname,
92 * and a name that can be used to access the file.
93 * Because tree does use chdir extensively, the access path is
94 * almost never the same as the full current path.
96 const char *tree_current_path(struct tree *);
97 size_t tree_current_pathlen(struct tree *);
98 const char *tree_current_access_path(struct tree *);
100 * Request the lstat() or stat() data for the current path. Since the
101 * tree package needs to do some of this anyway, and caches the
102 * results, you should take advantage of it here if you need it rather
103 * than make a redundant stat() or lstat() call of your own.
105 const struct stat *tree_current_stat(struct tree *);
106 const struct stat *tree_current_lstat(struct tree *);
107 /* The following tests may use mechanisms much faster than stat()/lstat(). */
108 /* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */
109 int tree_current_is_physical_dir(struct tree *);
110 /* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */
111 int tree_current_is_physical_link(struct tree *);
112 /* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */
113 int tree_current_is_dir(struct tree *);
115 /* For testing/debugging: Dump the internal status to the given filehandle. */
116 void tree_dump(struct tree *, FILE *);