3 * dumpscan - routines for scanning and manipulating AFS volume dumps
5 * Copyright (c) 1998 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software_Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
29 /* xfiles.c - General support routines for xfiles */
30 #include <sys/types.h>
37 #define SKIP_SIZE 65536
39 extern afs_uint32 xfon_path(XFILE *, int, char *);
40 extern afs_uint32 xfon_fd(XFILE *, int, char *);
41 extern afs_uint32 xfon_voldump(XFILE *, int, char *);
42 extern afs_uint32 xfon_profile(XFILE *, int, char *);
43 extern afs_uint32 xfon_stdio(XFILE *, int);
48 afs_uint32(*do_on) (XFILE *, int, char *);
52 static struct xftype *xftypes = 0;
53 static int did_register_defaults = 0;
57 xfread(XFILE * X, void *buf, afs_uint32 count)
62 code = (X->do_read) (X, buf, count);
66 add64_32(tmp64, X->filepos, count);
67 cp64(X->filepos, tmp64);
69 return xfwrite(X->passthru, buf, count);
75 xfwrite(XFILE * X, void *buf, afs_uint32 count)
81 return ERROR_XFILE_RDONLY;
82 code = (X->do_write) (X, buf, count);
86 add64_32(tmp64, X->filepos, count);
87 cp64(X->filepos, tmp64);
93 xftell(XFILE * X, u_int64 * offset)
96 return (X->do_tell) (X, offset);
97 cp64(*offset, X->filepos);
103 xfseek(XFILE * X, u_int64 * offset)
108 return ERROR_XFILE_NOSEEK;
109 code = (X->do_seek) (X, offset);
112 cp64(X->filepos, *offset);
118 xfskip(XFILE * X, afs_uint32 count)
123 /* Use the skip method, if there is one */
124 if (X->do_skip && !X->passthru) {
125 code = (X->do_skip) (X, count);
128 add64_32(tmp64, X->filepos, count);
129 cp64(X->filepos, tmp64);
133 /* Simulate using absolute seek, if available */
134 if (X->do_seek && !X->passthru) {
135 if (code = xftell(X, &tmp64))
137 add64_32(X->filepos, tmp64, count);
138 cp64(tmp64, X->filepos);
139 return xfseek(X, &tmp64);
142 /* Do it the hard/slow way - read all the data to be skipped.
143 * This is done if no other method is available, or if we are
144 * supposed to be copying all the data to another XFILE
151 n = (count > SKIP_SIZE) ? SKIP_SIZE : count;
152 if (code = xfread(X, buf, n))
162 xfpass(XFILE * X, XFILE * Y)
165 return ERROR_XFILE_ISPASS;
167 return ERROR_XFILE_RDONLY;
177 return ERROR_XFILE_NOPASS;
189 code = (X->do_close) (X);
190 memset(X, 0, sizeof(*X));
196 xfregister(char *name, afs_uint32(*do_on) (XFILE *, int, char *))
200 if (!(x = (struct xftype *)malloc(sizeof(struct xftype))))
202 memset(x, 0, sizeof(*x));
211 register_default_types(void)
213 xfregister("FILE", xfon_path);
214 xfregister("FD", xfon_fd);
215 xfregister("AFSDUMP", xfon_voldump);
216 xfregister("PROFILE", xfon_profile);
217 did_register_defaults = 1;
222 xfopen(XFILE * X, int flag, char *name)
227 if (!did_register_defaults)
228 register_default_types();
229 if (!strcmp(name, "-"))
230 return xfon_stdio(X, flag);
232 for (type = name; *name && *name != ':'; name++);
242 for (x = xftypes; x; x = x->next)
243 if (!strcmp(type, x->name))
248 return (x->do_on) (X, flag, name);
249 return ERROR_XFILE_TYPE;