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