I want to write my own tag on the device file (scsi file sdb, sdc...) on Linux.
I use linux C open()
, read()
, write()
functions on /dev/sdb
file, write my key in this file. But when usb disk device Unplug from computer and plug again, in /dev/sdb
's key, sometimes it's gone, or is unstable.
I don't know why.
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...