2 * Copyright (c) 1995 - 2002, 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Routines for reading an AFS directory
38 #include "arla_local.h"
47 get_fbuf_from_centry (CredCacheEntry
**ce
,
54 ret
= fcache_get_data (centry
, ce
, 0, 0);
58 ret
= fcache_get_fbuf (*centry
, fbuf
, fbuf_flags
);
66 * Lookup `name' in the AFS directory identified by `centry' and return
67 * the Fid in `file'. All operations are done as `cred' and return
68 * value is 0 or error code.
73 * centry: Locked Locked Locked
78 adir_lookup (FCacheEntry
*centry
, const char *name
, VenusFid
*file
)
83 ret
= fcache_get_fbuf (centry
, &the_fbuf
, FBUF_READ
);
87 ret
= fdir_lookup (&the_fbuf
, ¢ry
->fid
, name
, file
);
93 * Lookup `name' in the AFS directory identified by `dir' and change the
98 adir_changefid (FCacheEntry
**centry
,
106 ret
= get_fbuf_from_centry(ce
, &the_fbuf
, centry
,
107 FBUF_READ
|FBUF_WRITE
);
111 ret
= fdir_changefid (&the_fbuf
, name
, file
);
112 abuf_end (&the_fbuf
);
117 * Return TRUE if dir is empty.
121 adir_emptyp (FCacheEntry
**centry
,
127 ret
= get_fbuf_from_centry(ce
, &the_fbuf
, centry
, FBUF_READ
);
131 ret
= fdir_emptyp (&the_fbuf
);
132 abuf_end (&the_fbuf
);
137 * Read all entries in the AFS directory identified by `dir' and call
138 * `func' on each entry with the fid, the name, and `arg'.
142 adir_readdir (FCacheEntry
**centry
,
143 fdir_readdir_func func
,
150 ret
= get_fbuf_from_centry(ce
, &the_fbuf
, centry
, FBUF_READ
);
154 ret
= fdir_readdir (&the_fbuf
, func
, arg
, (*centry
)->fid
, NULL
);
155 abuf_end (&the_fbuf
);
160 * Create a new directory with only . and ..
164 adir_mkdir (FCacheEntry
*dir
,
171 AssertExclLocked(&dir
->lock
);
173 ret
= abuf_create(&the_fbuf
, dir
, 0, FBUF_READ
|FBUF_WRITE
);
177 /* fcache_set_have_all(dir, fbuf_len(&the_fbuf)); */
178 ret
= fdir_mkdir (&the_fbuf
, dot
, dot_dot
, 0);
179 fcache_set_have_all(dir
, fbuf_len(&the_fbuf
));
185 * Create a new entry with name `filename' and contents `fid' in `dir'.
189 adir_creat (FCacheEntry
*dir
,
196 ret
= fcache_get_fbuf(dir
, &the_fbuf
, FBUF_READ
|FBUF_WRITE
);
200 ret
= fdir_creat (&the_fbuf
, name
, NULL
, fid
);
201 fcache_set_have_all(dir
, fbuf_len(&the_fbuf
));
207 * Remove the entry named `name' in dir.
211 adir_remove (FCacheEntry
*dir
,
217 ret
= fcache_get_fbuf (dir
, &the_fbuf
, FBUF_READ
|FBUF_WRITE
);
221 ret
= fdir_remove(&the_fbuf
, name
, NULL
);
222 fcache_set_have_all(dir
, fbuf_len(&the_fbuf
));
223 abuf_end (&the_fbuf
);