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 /* xf_profile.c - XFILE routines for read/write profiling */
31 #include <sys/types.h>
41 #define O_MODE_MASK (O_RDONLY | O_WRONLY | O_RDWR)
49 /* do_read for profiled xfiles */
51 xf_PROFILE_do_read(XFILE * X, void *buf, afs_uint32 count)
53 PFILE *PF = X->refcon;
56 err = xfread(&PF->content, buf, count);
57 xfprintf(&PF->profile, "R %ld =%ld\n", (long)count, (long)err);
62 /* do_write for profiled xfiles */
64 xf_PROFILE_do_write(XFILE * X, void *buf, afs_uint32 count)
66 PFILE *PF = X->refcon;
69 err = xfwrite(&PF->content, buf, count);
70 xfprintf(&PF->profile, "W %ld =%ld\n", (long)count, (long)err);
75 /* do_tell for profiled xfiles */
77 xf_PROFILE_do_tell(XFILE * X, u_int64 * offset)
79 PFILE *PF = X->refcon;
82 err = xftell(&PF->content, offset);
84 xfprintf(&PF->profile, "TELL ERR =%ld\n", (long)err);
86 xfprintf(&PF->profile, "TELL %s =0\n", hexify_int64(offset, 0));
91 /* do_seek for profiled xfiles */
93 xf_PROFILE_do_seek(XFILE * X, u_int64 * offset)
95 PFILE *PF = X->refcon;
98 err = xfseek(&PF->content, offset);
99 xfprintf(&PF->profile, "SEEK %s =%ld\n", hexify_int64(offset, 0),
105 /* do_skip for profiled xfiles */
107 xf_PROFILE_do_skip(XFILE * X, afs_uint32 count)
109 PFILE *PF = X->refcon;
112 err = xfskip(&PF->content, count);
113 xfprintf(&PF->profile, "SKIP %ld =%ld\n", (long)count, (long)err);
118 /* do_close for profiled xfiles */
120 xf_PROFILE_do_close(XFILE * X)
122 PFILE *PF = X->refcon;
123 afs_uint32 err, err2;
125 err = xfclose(&PF->content);
126 err2 = xfclose(&PF->profile);
128 return err ? err : err2;
132 /* Open a profiled XFILE */
134 xfopen_profile(XFILE * X, int flag, char *xname, char *profile)
139 PF = malloc(sizeof(*PF));
142 memset(PF, 0, sizeof(*PF));
144 err = xfopen(&PF->profile, O_RDWR | O_CREAT | O_TRUNC, profile);
150 err = xfopen(&PF->content, flag, xname);
152 xfclose(&PF->profile);
157 memset(X, 0, sizeof(*X));
159 X->do_read = xf_PROFILE_do_read;
160 X->do_write = xf_PROFILE_do_write;
161 X->do_tell = xf_PROFILE_do_tell;
162 X->do_close = xf_PROFILE_do_close;
163 X->is_writable = PF->content.is_writable;
164 if (PF->content.is_seekable) {
166 X->do_seek = xf_PROFILE_do_seek;
167 X->do_skip = xf_PROFILE_do_skip;
169 xfprintf(&PF->profile, "OPEN %s\n", xname);
175 xfon_profile(XFILE * X, int flag, char *name)
177 char *x, *profile, *xname;
180 if (!(name = strdup(name)))
185 for (x = name; *x; x++) {
186 if (x[0] == ':' && x[1] == ':') {
195 err = xfopen_profile(X, flag, xname, profile);