2019-10-09 18:06:43 +02:00
|
|
|
#include <libcbd.h>
|
|
|
|
|
|
|
|
#include <cbdutil.h>
|
|
|
|
|
|
|
|
int
|
2019-11-04 21:25:54 +01:00
|
|
|
cbd_stats(const char* dev, struct cbd_stats* stats)
|
2019-10-09 18:06:43 +02:00
|
|
|
{
|
2019-11-04 21:25:54 +01:00
|
|
|
int fd;
|
2019-11-12 22:25:46 +01:00
|
|
|
uint8_t buf[SECTOR_SIZE];
|
2019-11-04 21:25:54 +01:00
|
|
|
struct cbd_header header;
|
|
|
|
|
|
|
|
fd = open(dev, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
error("Cannot open device\n");
|
|
|
|
}
|
2019-11-12 22:25:46 +01:00
|
|
|
if (read(fd, buf, sizeof(buf)) != sizeof(buf)) {
|
2019-11-04 21:25:54 +01:00
|
|
|
error("Cannot read device\n");
|
|
|
|
}
|
|
|
|
close(fd);
|
2019-11-12 22:25:46 +01:00
|
|
|
cbd_header_get(buf, &header);
|
2019-11-04 21:25:54 +01:00
|
|
|
if (memcmp(header.magic, CBD_MAGIC, sizeof(header.magic)) != 0) {
|
|
|
|
error("Bad magic\n");
|
|
|
|
}
|
|
|
|
memcpy(stats, &header.stats, sizeof(struct cbd_stats));
|
2019-10-09 18:06:43 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|