blockdev --getsize64はC ++で同じですか?

blockdev --getsize64はC ++で同じですか?

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セクタです)。

おすすめ記事