Skip to content

Instantly share code, notes, and snippets.

@maxux
Created July 7, 2021 09:51
Show Gist options
  • Save maxux/18c4ba0cb3b3d446e4c221c7e89446b9 to your computer and use it in GitHub Desktop.
Save maxux/18c4ba0cb3b3d446e4c221c7e89446b9 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
typedef struct stats_t {
size_t fuse_reqs;
size_t cache_hit;
size_t cache_miss;
size_t cache_full;
size_t cache_linear_flush;
size_t cache_random_flush;
size_t syscall_getattr;
size_t syscall_setattr;
size_t syscall_create;
size_t syscall_readdir;
size_t syscall_open;
size_t syscall_read;
size_t syscall_write;
size_t syscall_mkdir;
size_t syscall_unlink;
size_t syscall_rmdir;
size_t syscall_rename;
size_t syscall_link;
size_t syscall_symlink;
size_t syscall_statsfs;
size_t syscall_ioctl;
size_t read_bytes;
size_t write_bytes;
size_t errors;
} stats_t;
#define ZDBFS_IOCTL_SNAPSHOT _IOR('E', 0, uint64_t)
#define ZDBFS_IOCTL_STATISTICS _IOR('E', 1, stats_t)
int main(int argc, char *argv[]) {
char *path;
int fd;
int ret = 0;
uint64_t snapid;
stats_t stats;
if(argc < 2) {
fprintf(stderr, "[-] missing target path\n");
exit(EXIT_FAILURE);
}
path = argv[1];
if((fd = open(path, O_RDONLY)) < 0) {
perror(path);
exit(EXIT_FAILURE);
}
if((ret = ioctl(fd, ZDBFS_IOCTL_STATISTICS, &stats))) {
perror("ioctl");
exit(EXIT_FAILURE);
}
printf(">> cache_hit : %lu\n", stats.cache_hit);
printf(">> cache_miss : %lu\n", stats.cache_miss);
printf(">> cache_full : %lu\n", stats.cache_full);
printf(">> cache_linear_fl: %lu\n", stats.cache_linear_flush);
printf(">> cache_random_fl: %lu\n", stats.cache_random_flush);
printf(">> syscall_getattr: %lu\n", stats.syscall_getattr);
printf(">> syscall_setattr: %lu\n", stats.syscall_setattr);
printf(">> syscall_create : %lu\n", stats.syscall_create);
printf(">> syscall_readdir: %lu\n", stats.syscall_readdir);
printf(">> syscall_open : %lu\n", stats.syscall_open);
printf(">> syscall_read : %lu\n", stats.syscall_read);
printf(">> syscall_write : %lu\n", stats.syscall_write);
printf(">> syscall_mkdir : %lu\n", stats.syscall_mkdir);
printf(">> syscall_unlink : %lu\n", stats.syscall_unlink);
printf(">> syscall_rmdir : %lu\n", stats.syscall_rmdir);
printf(">> syscall_rename : %lu\n", stats.syscall_rename);
printf(">> syscall_link : %lu\n", stats.syscall_link);
printf(">> syscall_symlink: %lu\n", stats.syscall_symlink);
printf(">> syscall_statsf : %lu\n", stats.syscall_statsfs);
printf(">> syscall_ioctl : %lu\n", stats.syscall_ioctl);
printf(">> read_bytes : %lu\n", stats.read_bytes);
printf(">> write_bytes : %lu\n", stats.write_bytes);
printf(">> errors : %lu\n", stats.errors);
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment