summaryrefslogtreecommitdiff
path: root/src/diskinfo.c
blob: 815f7df808bbea7a2981ddaa314fef849c7f3382 (plain)
    1 #include "diskinfo.h"
    2 
    3 int disk_io_kb(char* disk,
    4     unsigned long long* read,
    5     unsigned long long* write) {
    6   char syspath[512] = {'\0'};
    7   unsigned long long stats[8] = {-1};
    8   FILE* fd = NULL;
    9 
   10   sprintf(syspath, "/sys/block/%s/stat", disk);
   11 
   12   fd = fopen(syspath, "r");
   13   if(!fd)
   14     return -1;
   15 
   16   // read io   read merge   read sectors   read ticks
   17   // write io  write merge  write sectors  write ticks
   18   fscanf(fd, "%lld %lld %lld %lld %lld %lld %lld %lld ",
   19     &stats[0], &stats[1], &stats[2], &stats[3],
   20     &stats[4], &stats[5], &stats[6], &stats[7]);
   21 
   22   fclose(fd);
   23 
   24   *read = stats[2] / 2;
   25   *write = stats[6] / 2;
   26 
   27   return 1;
   28 }

Generated by cgit