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