Don't ignore --disable-mtab
[fuse.git] / test / stracedecode.c
blob27b883c9c72c72196baf569427bce9606697a7f6
1 #include <stdio.h>
2 #include <string.h>
3 #include "fuse_kernel.h"
5 static struct {
6 const char *name;
7 } fuse_ll_ops[] = {
8 [FUSE_LOOKUP] = { "LOOKUP" },
9 [FUSE_FORGET] = { "FORGET" },
10 [FUSE_GETATTR] = { "GETATTR" },
11 [FUSE_SETATTR] = { "SETATTR" },
12 [FUSE_READLINK] = { "READLINK" },
13 [FUSE_SYMLINK] = { "SYMLINK" },
14 [FUSE_MKNOD] = { "MKNOD" },
15 [FUSE_MKDIR] = { "MKDIR" },
16 [FUSE_UNLINK] = { "UNLINK" },
17 [FUSE_RMDIR] = { "RMDIR" },
18 [FUSE_RENAME] = { "RENAME" },
19 [FUSE_LINK] = { "LINK" },
20 [FUSE_OPEN] = { "OPEN" },
21 [FUSE_READ] = { "READ" },
22 [FUSE_WRITE] = { "WRITE" },
23 [FUSE_STATFS] = { "STATFS" },
24 [FUSE_RELEASE] = { "RELEASE" },
25 [FUSE_FSYNC] = { "FSYNC" },
26 [FUSE_SETXATTR] = { "SETXATTR" },
27 [FUSE_GETXATTR] = { "GETXATTR" },
28 [FUSE_LISTXATTR] = { "LISTXATTR" },
29 [FUSE_REMOVEXATTR] = { "REMOVEXATTR" },
30 [FUSE_FLUSH] = { "FLUSH" },
31 [FUSE_INIT] = { "INIT" },
32 [FUSE_OPENDIR] = { "OPENDIR" },
33 [FUSE_READDIR] = { "READDIR" },
34 [FUSE_RELEASEDIR] = { "RELEASEDIR" },
35 [FUSE_FSYNCDIR] = { "FSYNCDIR" },
36 [FUSE_GETLK] = { "GETLK" },
37 [FUSE_SETLK] = { "SETLK" },
38 [FUSE_SETLKW] = { "SETLKW" },
39 [FUSE_ACCESS] = { "ACCESS" },
40 [FUSE_CREATE] = { "CREATE" },
41 [FUSE_INTERRUPT] = { "INTERRUPT" },
42 [FUSE_BMAP] = { "BMAP" },
43 [FUSE_DESTROY] = { "DESTROY" },
46 #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
48 static const char *opname(enum fuse_opcode opcode)
50 if (opcode >= FUSE_MAXOP || !fuse_ll_ops[opcode].name)
51 return "???";
52 else
53 return fuse_ll_ops[opcode].name;
57 static void process_buf(int dir, char *buf, int len)
59 static unsigned long long prevuniq = -1;
60 static int prevopcode;
62 if (!dir) {
63 struct fuse_in_header *in = (struct fuse_in_header *) buf;
64 buf += sizeof(struct fuse_in_header);
66 printf("unique: %llu, opcode: %s (%i), nodeid: %lu, len: %i, insize: %i\n",
67 (unsigned long long) in->unique,
68 opname((enum fuse_opcode) in->opcode), in->opcode,
69 (unsigned long) in->nodeid, in->len, len);
71 switch (in->opcode) {
72 case FUSE_READ: {
73 struct fuse_read_in *arg = (struct fuse_read_in *) buf;
74 printf("-READ fh:%llu off:%llu siz:%u rfl:%u own:%llu fl:%u\n",
75 arg->fh, arg->offset, arg->size, arg->read_flags,
76 arg->lock_owner, arg->flags);
77 break;
79 case FUSE_WRITE: {
80 struct fuse_write_in *arg = (struct fuse_write_in *) buf;
81 printf("-WRITE fh:%llu off:%llu siz:%u wfl:%u own:%llu fl:%u\n",
82 arg->fh, arg->offset, arg->size, arg->write_flags,
83 arg->lock_owner, arg->flags);
84 break;
87 prevuniq = in->unique;
88 prevopcode = in->opcode;
89 } else {
90 struct fuse_out_header *out = (struct fuse_out_header *) buf;
91 buf += sizeof(struct fuse_out_header);
93 printf(" unique: %llu, error: %i (%s), len: %i, outsize: %i\n",
94 (unsigned long long) out->unique, out->error,
95 strerror(-out->error), out->len, len);
97 if (out->unique == prevuniq) {
98 switch (prevopcode) {
99 case FUSE_GETATTR: {
100 struct fuse_attr_out *arg = (struct fuse_attr_out *) buf;
101 printf("+ATTR v:%llu.%09u i:%llu s:%llu b:%llu\n",
102 arg->attr_valid, arg->attr_valid_nsec,
103 arg->attr.ino, arg->attr.size, arg->attr.blocks);
104 break;
106 case FUSE_LOOKUP: {
107 struct fuse_entry_out *arg = (struct fuse_entry_out *) buf;
108 printf("+ENTRY nodeid:%llu v:%llu.%09u i:%llu s:%llu b:%llu\n",
109 arg->nodeid, arg->attr_valid, arg->attr_valid_nsec,
110 arg->attr.ino, arg->attr.size, arg->attr.blocks);
111 break;
119 int main(void)
121 FILE *in = stdin;
122 while (1) {
123 int dir;
124 int res;
125 char buf[1048576];
126 unsigned len = 0;
128 memset(buf, 0, sizeof(buf));
129 while (1) {
130 char str[32];
132 res = fscanf(in, "%30s", str);
133 if (res != 1 && feof(in))
134 return 0;
136 if (res == 0)
137 continue;
139 if (strncmp(str, "read(", 5) == 0) {
140 dir = 0;
141 break;
142 } else if (strncmp(str, "writev(", 7) == 0) {
143 dir = 1;
144 break;
148 while (1) {
149 int c = getc(in);
150 if (c == '"') {
151 while (1) {
152 int val;
154 c = getc(in);
155 if (c == EOF) {
156 fprintf(stderr, "eof in string\n");
157 break;
159 if (c == '\n') {
160 fprintf(stderr, "eol in string\n");
161 break;
163 if (c == '"')
164 break;
165 if (c != '\\') {
166 val = c;
167 } else {
168 c = getc(in);
169 switch (c) {
170 case 'n': val = '\n'; break;
171 case 'r': val = '\r'; break;
172 case 't': val = '\t'; break;
173 case '"': val = '"'; break;
174 case '\\': val = '\\'; break;
175 case 'x':
176 res = scanf("%x", &val);
177 if (res != 1) {
178 fprintf(stderr, "parse error\n");
179 continue;
181 break;
182 default:
183 fprintf(stderr, "unknown sequence: '\\%c'\n", c);
184 continue;
187 buf[len++] = val;
190 if (c == '\n')
191 break;
193 process_buf(dir, buf, len);
194 memset(buf, 0, len);
195 len = 0;