检测挂载的存储块是否写保护,可使用如下方法:
- 1.Opening the device file in write mode and see if it fails with
errno
valueEROFS
(Read-only file system). - 2.Opening the device file in read mode, then issue
ioctl()
namedBLKROGET
, and check if the result value is nonzero; this is the wayhdparm
work.
方法2例子:
int fd1 = 0, status1 = 0;
if ((fd1 = open(TF1_PATH_BLOCK, O_RDONLY|O_NONBLOCK)) == -1)
logd("#### TF1_PATH Can not open!");
if (ioctl(fd1, BLKROGET, &state1) == -1)
logd("#### TF1_PATH Read-only!\n");