4 * Takes an nbd transaction log file on stdin and translates it into something
12 #include <sys/types.h>
19 static inline void doread(int f, void *buf, size_t len) {
23 if((res=read(f, buf, len)) <=0) {
26 perror ("Error reading transactions");
34 int main(int argc, char**argv) {
35 struct nbd_request req;
44 int readfd = 0; /* stdin */
47 /* Read a request or reply from the transaction file */
48 doread(readfd, &magic, sizeof(magic));
51 case NBD_REQUEST_MAGIC:
52 doread(readfd, sizeof(magic)+(char *)(&req), sizeof(struct nbd_request)-sizeof(magic));
53 handle = ntohll(*((long long int *)(req.handle)));
54 offset = ntohll(req.from);
56 command = ntohl(req.type);
58 switch (command & NBD_CMD_MASK_COMMAND) {
63 ctext="NBD_CMD_WRITE";
69 ctext="NBD_CMD_FLUSH";
75 printf("> H=%016llx C=0x%08x (%13s+%4s) O=%016llx L=%08x\n",
76 (long long unsigned int) handle,
79 (command & NBD_CMD_FLAG_FUA)?"FUA":"NONE",
80 (long long unsigned int) offset,
85 doread(readfd, sizeof(magic)+(char *)(&rep), sizeof(struct nbd_reply)-sizeof(magic));
86 handle = ntohll(*((long long int *)(rep.handle)));
87 error = ntohl(rep.error);
89 printf("< H=%016llx E=0x%08x\n",
90 (long long unsigned int) handle,
95 printf("? Unknown transaction type %08x\n",magic);