(afsrights2nnpfsrights): export
[arla.git] / arlad / hpux-subr.c
blob6c21aa315556502fc246d4fff073ce219b17c437
1 /*
2 * Copyright (c) 1995 - 2000 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 /* If this isn't defined, we get a constant for DIRSIZ */
36 #define DIRSIZ_MACRO
37 #define _INCLUDE_HPUX_SOURCE
39 #include "arla_local.h"
40 RCSID("$Id$");
42 static long blocksize = 1024; /* XXX */
44 static void
45 flushbuf (void *vargs)
47 struct write_dirent_args *args = (struct write_dirent_args *)vargs;
48 struct dirent *last = (struct dirent *)args->last;
49 unsigned inc = blocksize - (args->ptr - args->buf);
51 last->d_reclen += inc;
52 #if 0
53 last->d_off += inc;
54 #endif
55 if (write (args->fd, args->buf, blocksize) != blocksize)
56 arla_warn (ADEBWARN, errno, "write");
57 args->ptr = args->buf;
58 args->last = NULL;
59 memset(args->buf, 0, blocksize);
62 #if 0 /* this seems wrong? */
63 #define DIRSIZ(dp) \
64 (((sizeof(struct dirent)+ (strlen((dp)->d_name)+1)) +3) & ~3)
65 #endif
67 static int
68 write_dirent(VenusFid *fid, const char *name, void *arg)
70 struct dirent dirent, *real;
71 struct write_dirent_args *args = (struct write_dirent_args *)arg;
73 /* dirent.d_namlen = strlen (name);*/
74 dirent.d_reclen = DIRSIZ(&dirent);
76 if (args->ptr + dirent.d_reclen > args->buf + blocksize)
77 flushbuf (args);
78 real = (struct dirent *)args->ptr;
80 /* real->d_namlen = dirent.d_namlen;*/
81 real->d_reclen = dirent.d_reclen;
82 real->d_ino = dentry2ino (name, fid, args->e);
83 strlcpy (real->d_name, name, sizeof(real->d_name));
84 args->ptr += real->d_reclen;
85 args->off += real->d_reclen;
86 #if 0
87 real->d_off = args->off;
88 #endif
89 args->last = real;
90 return 0;
93 int
94 conv_dir(FCacheEntry *e, CredCacheEntry *ce, u_int tokens)
96 return conv_dir_sub(e, ce, tokens, write_dirent, flushbuf, blocksize);
99 * remove `filename` from the converted directory for `e'
103 dir_remove_name(FCacheEntry *e, const char *filename)
105 int ret;
106 int fd;
107 fbuf fb;
108 struct stat sb;
109 char *buf;
110 char *p;
111 size_t len;
112 struct dirent *dp;
113 struct dirent *last_dp;
115 fcache_extra_file_name (e, cache_name, cache_name_sz);
116 fd = open (cache_name, O_RDWR, 0);
117 if (fd < 0)
118 return errno;
119 fcache_fhget (cache_name, cache_handle);
120 if (fstat (fd, &sb) < 0) {
121 ret = errno;
122 close (fd);
123 return ret;
125 len = sb.st_size;
127 ret = fbuf_create (&fb, fd, len, FBUF_READ|FBUF_WRITE);
128 if (ret) {
129 close (fd);
130 return ret;
132 last_dp = NULL;
133 ret = ENOENT;
134 for (p = buf = fbuf_buf (&fb); p < buf + len; p += dp->d_reclen) {
135 dp = (struct dirent *)p;
137 if (strcmp (filename, dp->d_name) == 0) {
138 if (last_dp != NULL) {
139 struct dirent new_last;
141 new_last.d_reclen = last_dp->d_reclen + dp->d_reclen;
142 if (new_last.d_reclen >= last_dp->d_reclen)
143 last_dp->d_reclen = new_last.d_reclen;
145 dp->d_ino = 0;
146 ret = 0;
147 break;
149 last_dp = dp;
151 fbuf_end (&fb);
152 close (fd);
153 return ret;