cbd/libcbd/stats.c

28 lines
595 B
C

#include <libcbd.h>
#include <cbdutil.h>
int
cbd_stats(const char* dev, struct cbd_stats* stats)
{
int fd;
uint8_t buf[PBLK_SIZE];
struct cbd_header header;
fd = open(dev, O_RDONLY);
if (fd < 0) {
error("Cannot open device\n");
}
if (read(fd, buf, sizeof(buf)) != sizeof(buf)) {
error("Cannot read device\n");
}
close(fd);
cbd_header_get(buf, &header);
if (memcmp(header.magic, CBD_MAGIC, sizeof(header.magic)) != 0) {
error("Bad magic\n");
}
memcpy(stats, &header.stats, sizeof(struct cbd_stats));
return 0;
}