(clean): clean universal binary intermediate steps, too
[arla.git] / arlad / subr.c
blobee66bd5461b7cb23d974822fdf6b057db55c03be
1 /*
2 * Copyright (c) 1995 - 2002 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 fcache_cache_handle *cache_handle,
80 char *cache_name, size_t cache_name_sz,
81 fdir_readdir_func func,
82 void (*flush_func)(void *),
83 size_t blocksize)
85 struct write_dirent_args args;
86 int ret;
87 int fd;
88 fbuf the_fbuf;
90 e->flags.extradirp = TRUE;
91 fcache_extra_file_name (e, cache_name, cache_name_sz);
92 e->tokens |= NNPFS_DATA_R | NNPFS_OPEN_NR;
94 args.fd = open (cache_name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
95 if (args.fd == -1) {
96 ret = errno;
97 arla_warn (ADEBWARN, ret, "open %s", cache_name);
98 return ret;
100 ret = fcache_fhget (cache_name, cache_handle);
102 args.off = 0;
103 args.buf = (char *)malloc (blocksize);
104 if (args.buf == NULL) {
105 ret = errno;
106 arla_warn (ADEBWARN, ret, "malloc %u", (unsigned)blocksize);
107 close (args.fd);
108 return ret;
110 memset(args.buf, 0, blocksize);
112 ret = fcache_get_fbuf (e, &fd, &the_fbuf,
113 O_RDONLY, FBUF_READ|FBUF_PRIVATE);
114 if (ret) {
115 close (args.fd);
116 free (args.buf);
117 return ret;
120 args.ptr = args.buf;
121 args.last = NULL;
122 args.e = e;
123 args.ce = ce;
125 /* translate to local dir format, write in args.fd */
126 fdir_readdir (&the_fbuf, func, (void *)&args, e->fid, NULL);
128 fbuf_end (&the_fbuf);
129 close (fd);
131 if (args.last)
132 (*flush_func) (&args);
133 free (args.buf);
134 ret = close (args.fd);
135 if (ret)
136 ret = errno;
137 return ret;