目前正在尝试找到一种防弹方法来查找基于闪存的设备的扇区大小(使用 USB 拇指驱动器进行测试),但在其他地方没有得到令人信服的答复
使用 stat 给我大小 = 4096 字节
struct stat info;
const char* device = "/dev/sdc";
if (stat(device, &info))
{
std::cout << "stat() error" << strerror(errno) << "\r\n";
exit(1);
}
std::cout << "Prefered block size for '" << device << "' is " << info.st_blksize << " byte" << std::endl;
Run Code Online (Sandbox Code Playgroud)
但 fdisk 说 512 字节
Disk /dev/sdc: 3.8 GiB, 4047503360 bytes, 7905280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 …Run Code Online (Sandbox Code Playgroud)