【发布时间】:2017-08-22 07:58:07
【问题描述】:
我想在 Linux 上的设备文件(scsi 文件 sdb、sdc...)上写我自己的标签。
我在 /dev/sdb 文件上使用 linux C open()、read()、write() 函数,将我的密钥写入此文件。但是当U盘设备从电脑上拔下来再插上时,在/dev/sdb的key中,有时会消失,或者不稳定。
我不知道为什么。
char readBuf[512] = { 0 };
char key[12] = "h%27dcd*()jd";
int fd = open("/dev/sdb",O_RDWR);
lseek(fd,1024,SEEK_SET);
read(fd,readBuf,512);
for(int i=0; i<sizeof key; ++i)
{
readBuf[i] = ~key[i];
}
lseek(fd,1024,SEEK_SET);
write(fd,readBuf,512);
//In order to mark the Usb disk bear fruit...
【问题讨论】:
-
您应该准确地向我们展示您所做的事情以及发生的事情。公式:1)你做了什么? 2) 你预期会发生什么? 3) 究竟发生了什么?
-
对不起..........我可能是这样... char readBuf[512] = { 0 };字符键[12] = "h%27dcd*()jd"; int fd = open("/dev/sdb",O_RDWR); lseek(fd,1024,SEEK_SET);读取(fd,readBuf,512); for(int i=0; i
-
你应该把它放在问题中,这样更容易阅读。还要说明你是如何检查钥匙是否还在的。
-
在拔下 USB 驱动器之前,您是否尝试过运行
sync?