*** empty log message ***
[arla.git] / arlad / subr.c
blobbc91da6b288fcffd92ce6d2f375948ad55e14da0
1 /*
2 * Copyright (c) 1995-2002, 2005-2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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
31 * SUCH DAMAGE.
34 #include "arla_local.h"
35 RCSID("$Id$");
38 * come up with a good inode number for `name', `fid' in `parent'
41 ino_t
42 dentry2ino (const char *name, const VenusFid *fid, const FCacheEntry *parent)
44 if (strcmp (name, ".") == 0
45 && (parent->flags.vol_root
46 || (fid->fid.Vnode == 1 && fid->fid.Unique == 1))
47 && parent->volume != NULL) {
49 long voltype = getvoltype(fid->fid.Volume, parent->volume);
50 return afsfid2inode (&parent->volume->parent[voltype].mp_fid);
52 } else if (strcmp (name, "..") == 0
53 && (parent->flags.vol_root
54 || (parent->fid.fid.Vnode == 1
55 && parent->fid.fid.Unique == 1))
56 && parent->volume != NULL) {
58 long voltype = getvoltype(fid->fid.Volume, parent->volume);
59 return afsfid2inode (&parent->volume->parent[voltype].fid);
61 } else if (strcmp (name, "..") == 0
62 && fid->fid.Vnode == 1 && fid->fid.Unique == 1
63 && parent->volume != NULL) {
65 long voltype = getvoltype(fid->fid.Volume, parent->volume);
66 return afsfid2inode (&parent->volume->parent[voltype].mp_fid);
68 } else {
69 return afsfid2inode (fid);
74 * Assume `e' has valid data.
77 int
78 conv_dir_sub(FCacheEntry *e, CredCacheEntry *ce, u_int tokens,
79 fdir_readdir_func func,
80 void (*flush_func)(void *),
81 size_t blocksize)
83 int flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
84 struct write_dirent_args args;
85 int ret;
86 fbuf the_fbuf;
88 e->flags.extradirp = TRUE;
89 args.fd = fcache_open_extra_dir(e, flags, 0666);
90 if (args.fd == -1) {
91 ret = errno;
92 arla_warn (ADEBWARN, ret, "open index %u", e->index);
93 return ret;
96 /* ret = fcache_fhget (cache_name, cache_handle); */
98 args.off = 0;
99 args.buf = (char *)malloc (blocksize);
100 if (args.buf == NULL) {
101 ret = errno;
102 arla_warn (ADEBWARN, ret, "malloc %u", (unsigned)blocksize);
103 close (args.fd);
104 return ret;
106 memset(args.buf, 0, blocksize);
108 ret = fcache_get_fbuf(e, &the_fbuf, FBUF_READ);
109 if (ret) {
110 close (args.fd);
111 free (args.buf);
112 return ret;
115 args.ptr = args.buf;
116 args.last = NULL;
117 args.e = e;
118 args.ce = ce;
120 /* translate to local dir format, write in args.fd */
121 fdir_readdir (&the_fbuf, func, (void *)&args, e->fid, NULL);
123 abuf_end (&the_fbuf);
125 if (args.last)
126 (*flush_func) (&args);
127 free (args.buf);
128 ret = close (args.fd);
129 if (ret)
130 ret = errno;
131 return ret;