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