3 Tree, alloctree, freetree,
4 File, createfile, closefile, removefile, walkfile,
5 opendirfile, readdirfile, closedirfile, hasperm \- in-memory file hierarchy
40 .ta \w'\fLReaddir* 'u +4n +4n
41 Tree* alloctree(char *uid, char *gid, ulong mode,
42 void (*destroy)(File*))
43 void freetree(Tree *tree)
44 File* createfile(File *dir, char *name, char *uid,
45 ulong mode, void *aux)
46 int removefile(File *file)
47 void closefile(File *file)
48 File* walkfile(File *dir, char *path)
49 Readdir* opendirfile(File *dir)
50 long readdirfile(Readdir *rdir, uchar *buf, long n)
51 void closedirfile(Readdir *rdir)
52 int hasperm(File *file, char *uid, int p)
58 provide an in-memory file hierarchy
59 intended for use in 9P file servers.
62 creates a new tree of files, and
68 element in the structure)
78 structures and is described later.
81 (including directories)
82 other than the root are created using
84 which attempts to create a file named
88 If created, the file will have owner
90 and have a group inherited from
93 and the permissions of
95 are used to calculate the permission bits for
96 the file as described in
100 to be a slash-separated path rather than a single element.
103 removes a file from the file tree.
104 The file will not be freed until the last
105 reference to it has been removed.
106 Directories may only be removed when empty.
108 returns zero on success, \-1 on error.
109 It is correct to consider
113 with the side effect of removing the file
119 relative to the directory
121 returning the resulting file,
122 or zero if the named file or any intermediate element
129 pointer may be used by the client
134 are reference-counted: if not zero,
136 (specified in the call to
138 will be called for each file when its
139 last reference is removed or when the tree is freed.
141 should take care of any necessary cleanup related to
143 When creating new file references by copying pointers,
148 to update the reference count.
149 To note the removal of a reference to a file, call
154 return new references.
161 consume the passed reference.
163 Directories may be read, yielding a directory entry structure
166 for each file in the directory.
167 In order to allow concurrent reading of directories,
168 clients must obtain a
175 will each yield an integral number of machine-independent
176 stat buffers, until end of directory.
183 does simplistic permission checking; it assumes only
184 one-user groups named by uid and returns non-zero if
195 9P servers written using
197 trees will do standard permission checks automatically;
199 may be called explicitly to do additional checks.
200 A 9P server may link against a different
202 implementation to provide more complex groups.
204 The following code correctly handles references
205 when elementwise walking a path and creating a file.
210 for(i=0; i<n && f!=nil; i++)
211 f = walkfile(f, elem[i]);
214 nf = createfile(f, "foo", "nls", 0666, nil);
219 .B /sys/src/lib9p/file.c
223 The reference counting is cumbersome.