(clean): clean universal binary intermediate steps, too
[arla.git] / arlad / aix-subr.c
blob25a890334eb7eaf19cd89ddde7ad2c628a9f10e2
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 #define _KERNEL
36 #include "arla_local.h"
37 RCSID("$Id$");
39 static long blocksize = 1024;
41 static void
42 flushbuf (void *vargs)
44 struct write_dirent_args *args = (struct write_dirent_args *)vargs;
45 struct dirent *last = (struct dirent *)args->last;
46 unsigned inc = blocksize - (args->ptr - args->buf);
48 last->d_reclen += inc;
49 last->d_offset += inc;
50 if (write (args->fd, args->buf, blocksize) != blocksize)
51 arla_warn (ADEBWARN, errno, "write");
52 args->ptr = args->buf;
53 args->last = NULL;
54 memset(args->buf, 0, blocksize);
57 #undef DIRSIZ
58 #define DIRSIZ(name) \
59 (((sizeof(struct dirent)+ (strlen(name)+1)) + \
60 3) & ~3)
62 static int
63 write_dirent(VenusFid *fid, const char *name, void *arg)
65 struct dirent *real;
66 struct write_dirent_args *args = (struct write_dirent_args *)arg;
67 u_short reclen;
69 reclen = DIRSIZ(name);
71 if (args->ptr + reclen > args->buf + blocksize)
72 flushbuf (args);
73 real = (struct dirent *)args->ptr;
75 real->d_reclen = reclen;
76 real->d_ino = dentry2ino (name, fid, args->e);
77 strcpy (real->d_name, name);
78 args->ptr += real->d_reclen;
79 args->off += real->d_reclen;
80 real->d_offset = args->off;
81 args->last = real;
82 return 0;
85 int
86 conv_dir (FCacheEntry *e, CredCacheEntry *ce, u_int tokens,
87 fcache_cache_handle *cache_handle,
88 char *cache_name, size_t cache_name_sz)
90 return conv_dir_sub (e, ce, tokens, cache_handle, cache_name,
91 cache_name_sz, write_dirent, flushbuf, blocksize);
95 * remove `filename` from the converted directory for `e'
98 int
99 dir_remove_name (FCacheEntry *e, const char *filename,
100 fcache_cache_handle *cache_handle,
101 char *cache_name, size_t cache_name_sz)
103 int ret;
104 int fd;
105 fbuf fb;
106 struct stat sb;
107 char *buf;
108 char *p;
109 size_t len;
110 struct dirent *dp;
111 struct dirent *last_dp;
113 fcache_extra_file_name (e, cache_name, cache_name_sz);
114 fd = open (cache_name, O_RDWR, 0);
115 if (fd < 0)
116 return errno;
117 fcache_fhget (cache_name, cache_handle);
118 if (fstat (fd, &sb) < 0) {
119 ret = errno;
120 close (fd);
121 return ret;
123 len = sb.st_size;
125 ret = fbuf_create (&fb, fd, len, FBUF_READ|FBUF_WRITE|FBUF_SHARED);
126 if (ret) {
127 close (fd);
128 return ret;
130 last_dp = NULL;
131 ret = ENOENT;
132 for (p = buf = fbuf_buf (&fb); p < buf + len; p += dp->d_reclen) {
133 dp = (struct dirent *)p;
135 if (strcmp (filename, dp->d_name) == 0) {
136 if (last_dp != NULL) {
137 struct dirent new_last;
139 new_last.d_reclen = last_dp->d_reclen + dp->d_reclen;
140 if (new_last.d_reclen >= last_dp->d_reclen)
141 last_dp->d_reclen = new_last.d_reclen;
143 dp->d_ino = 0;
144 ret = 0;
145 break;
147 last_dp = dp;
149 fbuf_end (&fb);
150 close (fd);
151 return ret;