通过C++获取微型SD卡的大小
Getting the size of a micro SD card via C++
我正在寻找一些函数,该函数将返回挂载到/dev/sdb的micro SD卡的总容量。我不太关心可用空间,我关心驱动器的总容量。我需要一个可靠和准确的功能。如果不存在,我将如何创建一个?
谢谢!
blockdev
的strace告诉我你可以使用:
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
int main()
{
unsigned long long size;
int fd = open("/dev/sdx", O_RDONLY);
ioctl(fd, BLKGETSIZE64, &size);
std::cout << size << std::endl;
std::cout << (size>>20) << std::endl; // MiBytes
}
(将 SDX 替换为设备节点名称(
注意 如果您的编译器已经支持uint64_t
,则更喜欢使用它(包括<cstdint>
(
您可以在/sys/
目录中读取一个特殊文件:
/sys/block/sdb/sdb1/size
它返回以字节为单位的大小。
相关文章:
- phytec phyBOARD iMX-6在从闪存而不是SD卡运行qt5 opengles应用程序时表现不佳(FPS减半
- 在不使用系统的情况下从C++应用程序格式化 Linux 中的 SD 卡
- 从Arduino SD卡模块到Array的文件名
- 如何使用 sd-bus 获取服务的状态?
- 在Windows上读取/写入未格式化的SD卡
- 我应该如何在 Mbed 中有效地写入 SD 卡?
- C++ SD 总线源文件编译问题
- 读取SD卡时FR_Not_Enabled Fat_fs错误
- Arduino不写入SD卡?
- 在SD卡上读取和存储二进制GPS数据方面的问题
- Libuv中SD-BUS的事件循环处理
- 如何在Arduino上为SD卡创建动态文件名
- f_close错误(写入SD卡是我的最终项目)
- SD.remove() 不会删除 Arduino C++ 上的文件
- 递归扫描SD卡Android NDK
- 使用Arduino中的SD.Remove()和SD库
- 在安卓5.0.1_r1中从音频系统(C++代码)在SD卡上写入文件
- Arduino内存泄漏(SD卡+字符串)
- 如何在Arduino中从SD卡创建变量
- 将存储在SD卡上的电话号码插入短信发送AT命令Arduino