2 * Copyright (c) 1995 - 2002 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
,
50 int open_flags
, int fbuf_flags
)
54 ret
= fcache_get_data (centry
, ce
, 0);
58 ret
= fcache_get_fbuf (*centry
, fd
, fbuf
, open_flags
, 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
)
84 ret
= fcache_get_fbuf (centry
, &fd
, &the_fbuf
, O_RDONLY
,
85 FBUF_READ
|FBUF_PRIVATE
);
89 ret
= fdir_lookup (&the_fbuf
, ¢ry
->fid
, name
, file
);
96 * Lookup `name' in the AFS directory identified by `dir' and change the
101 adir_changefid (FCacheEntry
**centry
,
110 ret
= get_fbuf_from_centry (ce
, &fd
, &the_fbuf
, centry
, O_RDWR
,
111 FBUF_READ
|FBUF_WRITE
|FBUF_SHARED
);
115 ret
= fdir_changefid (&the_fbuf
, name
, file
);
116 fbuf_end (&the_fbuf
);
122 * Return TRUE if dir is empty.
126 adir_emptyp (FCacheEntry
**centry
,
133 ret
= get_fbuf_from_centry (ce
, &fd
, &the_fbuf
, centry
,
134 O_RDONLY
, FBUF_READ
|FBUF_PRIVATE
);
138 ret
= fdir_emptyp (&the_fbuf
);
139 fbuf_end (&the_fbuf
);
145 * Read all entries in the AFS directory identified by `dir' and call
146 * `func' on each entry with the fid, the name, and `arg'.
150 adir_readdir (FCacheEntry
**centry
,
151 fdir_readdir_func func
,
159 ret
= get_fbuf_from_centry (ce
, &fd
, &the_fbuf
, centry
,
160 O_RDONLY
, FBUF_READ
|FBUF_PRIVATE
);
164 ret
= fdir_readdir (&the_fbuf
, func
, arg
, (*centry
)->fid
, NULL
);
165 fbuf_end (&the_fbuf
);
171 * Create a new directory with only . and ..
175 adir_mkdir (FCacheEntry
*dir
,
183 AssertExclLocked(&dir
->lock
);
185 ret
= fcache_get_fbuf (dir
, &fd
, &the_fbuf
, O_RDWR
,
186 FBUF_READ
|FBUF_WRITE
|FBUF_SHARED
);
190 ret
= fdir_mkdir (&the_fbuf
, dot
, dot_dot
, 0);
191 fcache_update_length (dir
, fbuf_len(&the_fbuf
), fbuf_len(&the_fbuf
));
192 fbuf_end (&the_fbuf
);
198 * Create a new entry with name `filename' and contents `fid' in `dir'.
202 adir_creat (FCacheEntry
*dir
,
210 ret
= fcache_get_fbuf (dir
, &fd
, &the_fbuf
, O_RDWR
,
211 FBUF_READ
|FBUF_WRITE
|FBUF_SHARED
);
215 ret
= fdir_creat (&the_fbuf
, name
, NULL
, fid
);
216 fcache_update_length (dir
, fbuf_len(&the_fbuf
), fbuf_len(&the_fbuf
));
217 fbuf_end (&the_fbuf
);
223 * Remove the entry named `name' in dir.
227 adir_remove (FCacheEntry
*dir
,
234 ret
= fcache_get_fbuf (dir
, &fd
, &the_fbuf
, O_RDWR
,
235 FBUF_READ
|FBUF_WRITE
|FBUF_SHARED
);
239 ret
= fdir_remove(&the_fbuf
, name
, NULL
);
240 fcache_update_length (dir
, fbuf_len(&the_fbuf
), fbuf_len(&the_fbuf
));
241 fbuf_end (&the_fbuf
);