xref: /netbsd-src/sbin/mount_qemufwcfg/virtdir.h (revision fb5eed702691094bd687fbf1ded189c87457cd35)
1 /* $NetBSD: virtdir.h,v 1.3 2017/11/26 03:51:45 christos 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 /* this struct keeps a note of all the info related to a virtual directory entry */
38 typedef struct virt_dirent_t {
39 	char		*name;		/* entry name - used as key */
40 	size_t		 namelen;	/* length of name */
41 	char		*d_name;	/* component in this directory */
42 	char		*tgt;		/* any symlink target */
43 	size_t		 tgtlen;	/* length of symlink target */
44 	uint8_t		 type;		/* entry type - file, dir, lnk */
45 	ino_t		 ino;		/* inode number */
46 	uint16_t	 select;	/* selector */
47 } virt_dirent_t;
48 
49 /* this defines the list of virtual directory entries,
50    sorted in name alpha order */
51 typedef struct virtdir_t {
52 	uint32_t	 c;		/* count of entries */
53 	uint32_t	 size;		/* size of allocated list */
54 	virt_dirent_t	*v;		/* list */
55 	char		*rootdir;	/* root directory of virtual fs */
56 	struct stat	 file;		/* stat struct for file entries */
57 	struct stat	 dir;		/* stat struct for dir entries */
58 	struct stat	 lnk;		/* stat struct for symlinks */
59 } virtdir_t;
60 
61 /* this struct is used to walk through directories */
62 typedef struct VIRTDIR {
63 	char		*dirname;	/* directory name */
64 	size_t		 dirnamelen;	/* length of directory name */
65 	virtdir_t	*tp;		/* the directory tree */
66 	size_t		 i;		/* current offset in dir tree */
67 } VIRTDIR;
68 
69 int virtdir_init(virtdir_t *, const char *, const struct stat *,
70     const struct stat *, const struct stat *);
71 int virtdir_add(virtdir_t *, const char *, size_t, uint8_t, const char *,
72     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 off_t virtdir_offset(const virtdir_t *, const virt_dirent_t *);
80 
81 #endif
82