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