问题描述
系统:rt-smart
问题:程序中挂载sd10设备(TF卡)到/tmp/sdcard_out目录失败
目前尝试使用mount()、system()、popen()去执行命令都失败
在msh命令行使用mount sd10 /tmp/sdcard-out elm 能够正常挂载与使用
在rt-smart中,如何在程序中去执行msh命令行以后的指令,类似Linux中system(命令)
复现步骤
std::string device = "sd10";
std::string mount_point = "/tmp/sdcard_out";
std::string fstype = "elm";
if (Files::Exists(mount_point.c_str())) {
log_info("Mount point %s exists", mount_point.c_str());
} else {
log_warning("Mount point %s not exist, creating...", mount_point.c_str());
if (Files::CreateDirectory(mount_point.c_str()) != 0) {
log_error("Failed to create mount point %s", mount_point.c_str());
}
}
int ret = mount(device.c_str(), mount_point.c_str(), fstype.c_str(), 0, NULL);
if (ret == 0) {
log_success("SD card mounted successfully via mount()");
struct statvfs vfs;
if (statvfs(mount_point.c_str(), &vfs) == 0) {
unsigned long long total = (unsigned long long)vfs.f_blocks * vfs.f_frsize;
unsigned long long free = (unsigned long long)vfs.f_bfree * vfs.f_frsize;
log_info("Total: %.2f GB, Free: %.2f GB",
total / (1024.0*1024*1024),
free / (1024.0*1024*1024));
} else {
log_error("statvfs failed: %s (errno=%d)", strerror(errno), errno);
}
} else {
log_error("mount failed: %s (errno=%d)", strerror(errno), errno);
}
[INFO] 2025-01-01 09:06:14 : Mount point /tmp/sdcard_out exists
[SUCCESS] 2025-01-01 09:06:14 : SD card mounted successfully via mount()
[INFO] 2025-01-01 09:06:14 : Total: 0.00 GB, Free: 0.00 GB
msh /data>mount
filesystem device mountpoint
devfs (NULL) /dev
procfs (NULL) /proc
rom (NULL) /
tmp (NULL) /dev/shm
tmp (NULL) /tmp
tmp (NULL) /etc
elm sd00 /bin
elm sd01 /sdcard
elm sd02 /data
手动挂载可以:
msh /data>mount sd10 /tmp/sdcard_out elm
mount device sd10(elm) onto /tmp/sdcard_out ... succeed!
msh /data>mount
filesystem device mountpoint
devfs (NULL) /dev
procfs (NULL) /proc
rom (NULL) /
tmp (NULL) /dev/shm
tmp (NULL) /tmp
tmp (NULL) /etc
elm sd00 /bin
elm sd01 /sdcard
elm sd02 /data
elm sd10 /tmp/sdcard_out
硬件板卡
DShanPI CanMV V2
软件版本
local_nncase_v2.11.0