我有一个小程序,我用它来尝试在我的嵌入式 Linux 平台上读取 MTD 的详细信息。我遇到了大多数块无法读取的问题,而且我不是 100% 确定为什么会发生这种情况。
检查/dev
目录显示 8 mtd
s 都具有相同的权限:
# ls -al | grep "mtd*"
crwxrwxrwx 1 root root 90, 0 Jan 1 1970 mtd0
crwxrwxrwx 1 root root 90, 2 Jan 1 1970 mtd1
crwxrwxrwx 1 root root 90, 4 Jan 1 1970 mtd2
...
crwxrwxrwx 1 root root 90, 14 Jan 1 1970 mtd7
我的应用程序也以 root 身份运行:
# ls -al mtd_test
-rwxrwxrwx 1 root root 19688 Nov 30 01:18 mtd_test
检查/proc
我可以看到 8 个 mtd 中有 7 个已安装(所以我预计mtd7
无法读取)
# cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00020000 "u-boot (128 kB)"
mtd1: 00020000 00020000 "u-boot Environment (128 kB)"
mtd2: 00040000 00020000 "Reserved (256 kB)"
mtd3: 00200000 00020000 "Kernel (2048 kB)"
mtd4: 00000064 00020000 "rootFS header"
mtd5: 003fff9c 00020000 "rootFS (4096 kB)"
mtd6: 00180000 00020000 "Permanent Storage (1536 KB)"
奇怪的是,只有mtd1
并且mtd6
能够被读取,所有其他人都因错误“权限被拒绝”而失败,有人知道为什么会这样吗?
我怀疑这是我的代码,但这里是:
int main()
{
mtd_info_t mtd_info;
int count, fd;
char devs[][15] = { {"/dev/mtd0"},{"/dev/mtdblock0"},
{"/dev/mtd1"},{"/dev/mtdblock1"},
{"/dev/mtd2"},{"/dev/mtdblock2"},
{"/dev/mtd3"},{"/dev/mtdblock3"},
{"/dev/mtd4"},{"/dev/mtdblock4"},
{"/dev/mtd5"},{"/dev/mtdblock5"},
{"/dev/mtd6"},{"/dev/mtdblock6"},
{"/dev/mtd7"},{"/dev/mtdblock7"}, };
for(count = 0; count < 16; count++) {
fd = open(devs[count], O_RDWR);
if(fd > 0) {
ioctl(fd, MEMGETINFO, &mtd_info);
printf("For dev: %s\nMTD Type: %u\nMTD total size: %u bytes\nMTD erase size: %u bytes\n",
devs[count], mtd_info.type, mtd_info.size, mtd_info.erasesize);
close(fd);
}
else
printf("Failed for %s: error - %s\n", devs[count], strerror(errno));
}
return 0;
}