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 */
50 static afs_uint32 xf_PROFILE_do_read(XFILE *X, void *buf, afs_uint32 count)
52 PFILE *PF = X->refcon;
55 err = xfread(&PF->content, buf, count);
56 xfprintf(&PF->profile, "R %ld =%ld\n", (long)count, (long)err);
61 /* do_write for profiled xfiles */
62 static afs_uint32 xf_PROFILE_do_write(XFILE *X, void *buf, afs_uint32 count)
64 PFILE *PF = X->refcon;
67 err = xfwrite(&PF->content, buf, count);
68 xfprintf(&PF->profile, "W %ld =%ld\n", (long)count, (long)err);
73 /* do_tell for profiled xfiles */
74 static afs_uint32 xf_PROFILE_do_tell(XFILE *X, u_int64 *offset)
76 PFILE *PF = X->refcon;
79 err = xftell(&PF->content, offset);
80 if (err) xfprintf(&PF->profile, "TELL ERR =%ld\n", (long)err);
81 else xfprintf(&PF->profile, "TELL %s =0\n", hexify_int64(offset, 0));
86 /* do_seek for profiled xfiles */
87 static afs_uint32 xf_PROFILE_do_seek(XFILE *X, u_int64 *offset)
89 PFILE *PF = X->refcon;
92 err = xfseek(&PF->content, offset);
93 xfprintf(&PF->profile, "SEEK %s =%ld\n", hexify_int64(offset, 0), (long)err);
98 /* do_skip for profiled xfiles */
99 static afs_uint32 xf_PROFILE_do_skip(XFILE *X, afs_uint32 count)
101 PFILE *PF = X->refcon;
104 err = xfskip(&PF->content, count);
105 xfprintf(&PF->profile, "SKIP %ld =%ld\n", (long)count, (long)err);
110 /* do_close for profiled xfiles */
111 static afs_uint32 xf_PROFILE_do_close(XFILE *X)
113 PFILE *PF = X->refcon;
114 afs_uint32 err, err2;
116 err = xfclose(&PF->content);
117 err2 = xfclose(&PF->profile);
119 return err ? err : err2;
123 /* Open a profiled XFILE */
124 afs_uint32 xfopen_profile(XFILE *X, int flag, char *xname, char *profile)
129 PF = malloc(sizeof(*PF));
130 if (!PF) return ENOMEM;
131 memset(PF, 0, sizeof(*PF));
133 err = xfopen(&PF->profile, O_RDWR|O_CREAT|O_TRUNC, profile);
139 err = xfopen(&PF->content, flag, xname);
141 xfclose(&PF->profile);
146 memset(X, 0, sizeof(*X));
148 X->do_read = xf_PROFILE_do_read;
149 X->do_write = xf_PROFILE_do_write;
150 X->do_tell = xf_PROFILE_do_tell;
151 X->do_close = xf_PROFILE_do_close;
152 X->is_writable = PF->content.is_writable;
153 if (PF->content.is_seekable) {
155 X->do_seek = xf_PROFILE_do_seek;
156 X->do_skip = xf_PROFILE_do_skip;
158 xfprintf(&PF->profile, "OPEN %s\n", xname);
163 afs_uint32 xfon_profile(XFILE *X, int flag, char *name)
165 char *x, *profile, *xname;
168 if (!(name = strdup(name))) return ENOMEM;
172 for (x = name; *x; x++) {
173 if (x[0] == ':' && x[1] == ':') {
180 if (!*name) profile = "-";
181 err = xfopen_profile(X, flag, xname, profile);