virtdir.h revision 1.1 1 /* $NetBSD: virtdir.h,v 1.1 2017/11/25 23:23:39 jmcneill Exp $ */
2
3 /*
4 * Copyright 2007 Alistair Crooks. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef VIRTDIR_H_
32 #define VIRTDIR_H_ 20070405
33
34 #include <sys/types.h>
35 #include <sys/stat.h>
36
37 #include "defs.h"
38
39 /* this struct keeps a note of all the info related to a virtual directory entry */
40 typedef struct virt_dirent_t {
41 char *name; /* entry name - used as key */
42 size_t namelen; /* length of name */
43 char *d_name; /* component in this directory */
44 char *tgt; /* any symlink target */
45 size_t tgtlen; /* length of symlink target */
46 uint8_t type; /* entry type - file, dir, lnk */
47 ino_t ino; /* inode number */
48 uint16_t select; /* selector */
49 } virt_dirent_t;
50
51 /* this defines the list of virtual directory entries,
52 sorted in name alpha order */
53 typedef struct virtdir_t {
54 uint32_t c; /* count of entries */
55 uint32_t size; /* size of allocated list */
56 virt_dirent_t *v; /* list */
57 char *rootdir; /* root directory of virtual fs */
58 struct stat file; /* stat struct for file entries */
59 struct stat dir; /* stat struct for dir entries */
60 struct stat lnk; /* stat struct for symlinks */
61 } virtdir_t;
62
63 /* this struct is used to walk through directories */
64 typedef struct VIRTDIR {
65 char *dirname; /* directory name */
66 int dirnamelen; /* length of directory name */
67 virtdir_t *tp; /* the directory tree */
68 int i; /* current offset in dir tree */
69 } VIRTDIR;
70
71 int virtdir_init(virtdir_t *, const char *, struct stat *, struct stat *, struct stat *);
72 int virtdir_add(virtdir_t *, const char *, size_t, uint8_t, const char *, size_t, uint16_t);
73 virt_dirent_t *virtdir_find(virtdir_t *, const char *, size_t);
74
75 VIRTDIR *openvirtdir(virtdir_t *, const char *);
76 virt_dirent_t *readvirtdir(VIRTDIR *);
77 void closevirtdir(VIRTDIR *);
78
79 int virtdir_offset(virtdir_t *, virt_dirent_t *);
80
81 #endif
82