#include "diskinfo.h" int disk_io_kb(char* disk, unsigned long long* read, unsigned long long* write) { char syspath[512] = {'\0'}; unsigned long long stats[8] = {-1}; FILE* fd = NULL; sprintf(syspath, "/sys/block/%s/stat", disk); fd = fopen(syspath, "r"); if(!fd) return -1; // read io read merge read sectors read ticks // write io write merge write sectors write ticks fscanf(fd, "%lld %lld %lld %lld %lld %lld %lld %lld ", &stats[0], &stats[1], &stats[2], &stats[3], &stats[4], &stats[5], &stats[6], &stats[7]); fclose(fd); *read = stats[2] / 2; *write = stats[6] / 2; return 1; }