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>
38 #define SKIP_SIZE 65536
40 extern afs_uint32 xfon_path(XFILE *, int, char *);
41 extern afs_uint32 xfon_fd(XFILE *, int, char *);
42 extern afs_uint32 xfon_voldump(XFILE *, int, char *);
43 extern afs_uint32 xfon_profile(XFILE *, int, char *);
44 extern afs_uint32 xfon_stdio(XFILE *, int);
49 afs_uint32(*do_on) (XFILE *, int, char *);
53 static struct xftype *xftypes = 0;
54 static int did_register_defaults = 0;
58 xfread(XFILE * X, void *buf, afs_uint32 count)
63 code = (X->do_read) (X, buf, count);
67 add64_32(tmp64, X->filepos, count);
68 cp64(X->filepos, tmp64);
70 return xfwrite(X->passthru, buf, count);
76 xfwrite(XFILE * X, void *buf, afs_uint32 count)
82 return ERROR_XFILE_RDONLY;
83 code = (X->do_write) (X, buf, count);
87 add64_32(tmp64, X->filepos, count);
88 cp64(X->filepos, tmp64);
94 xftell(XFILE * X, u_int64 * offset)
97 return (X->do_tell) (X, offset);
98 cp64(*offset, X->filepos);
104 xfseek(XFILE * X, u_int64 * offset)
109 return ERROR_XFILE_NOSEEK;
110 code = (X->do_seek) (X, offset);
113 cp64(X->filepos, *offset);
119 xfskip(XFILE * X, afs_uint32 count)
124 /* Use the skip method, if there is one */
125 if (X->do_skip && !X->passthru) {
126 code = (X->do_skip) (X, count);
129 add64_32(tmp64, X->filepos, count);
130 cp64(X->filepos, tmp64);
134 /* Simulate using absolute seek, if available */
135 if (X->do_seek && !X->passthru) {
136 if ((code = xftell(X, &tmp64)))
138 add64_32(X->filepos, tmp64, count);
139 cp64(tmp64, X->filepos);
140 return xfseek(X, &tmp64);
143 /* Do it the hard/slow way - read all the data to be skipped.
144 * This is done if no other method is available, or if we are
145 * supposed to be copying all the data to another XFILE
152 n = (count > SKIP_SIZE) ? SKIP_SIZE : count;
153 if ((code = xfread(X, buf, n)))
163 xfpass(XFILE * X, XFILE * Y)
166 return ERROR_XFILE_ISPASS;
168 return ERROR_XFILE_RDONLY;
178 return ERROR_XFILE_NOPASS;
190 code = (X->do_close) (X);
191 memset(X, 0, sizeof(*X));
197 xfregister(char *name, afs_uint32(*do_on) (XFILE *, int, char *))
201 if (!(x = (struct xftype *)malloc(sizeof(struct xftype))))
203 memset(x, 0, sizeof(*x));
213 register_default_types(void)
215 xfregister("FILE", xfon_path);
216 xfregister("FD", xfon_fd);
217 xfregister("AFSDUMP", xfon_voldump);
218 xfregister("PROFILE", xfon_profile);
219 did_register_defaults = 1;
224 xfopen(XFILE * X, int flag, char *name)
229 if (!did_register_defaults)
230 register_default_types();
231 if (!strcmp(name, "-"))
232 return xfon_stdio(X, flag);
234 for (type = name; *name && *name != ':'; name++);
244 for (x = xftypes; x; x = x->next)
245 if (!strcmp(type, x->name))
250 return (x->do_on) (X, flag, name);
251 return ERROR_XFILE_TYPE;