#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
int main() {
int fd;
char *dev_path = "/dev/mmcblk1p1";
char buf[128];
int ret;
fd = open(dev_path, O_RDONLY);
if (fd < 0) {
printf("bot get SD\n");
perror("open");
return -1;
}
ret = read(fd, buf, sizeof(buf));
if (ret < 0) {
perror("read");
printf("SD status error\n");
close(fd);
return -1;
}
ret = write(fd, buf, sizeof(buf));
if (ret < 0) {
perror("write");
close(fd);
printf("SD only read status\n");
return -1;
}
printf("SD read write success\n");
close(fd);
return 0;
}
使用代码方式实现快速监测sd卡状态
于 2024-02-01 19:50:15 首次发布