
blockdev --getsize64
/dev/block/sdb
を使用せずにサイズを計算するC ++に同じ関数がありますかsystem()
?
回答者: Vojtech Trefny
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
// ...
const char* pathname="/dev/sda";
int fd = open(pathname, O_RDONLY);
if (fd == -1) {
die("%s", strerror(errno));
}
uint64_t size;
if (ioctl(fd, BLKGETSIZE64, &size) == -1) {
die("%s", strerror(errno));
}
close(fd);
答え1
あなたはそれを使用することができますBLKGETSIZE64
I/W制御または読みます/sys/class/block/sdb/size
(ここではサイズは512セクタです)。