Hi,
I am trying to write zeroes to the hdd using a c program. I don't want to use the dd or ddrescue or any such inbuilt program because of reasons like real time progress, writing custom patterns. (my program is more like an erasure application, but does only zero fill).
here are the steps which i have followed. (I am executing under root).
Linux version used is ubuntu with (Intrepid) 8.10, with 2.6.27-7-generic.
opened the device /dev/sda using open call.
fd = open("/dev/sda", O_WRONLY);
and called a write call with
write(fd,buff,512);
The write call never fails for some strange reasons. It always returns 512 even in the case of a bad hdd connected to system. (The dmesg shows either the hdd is bad or not responding the write requests, or has I/O errors, or has sectors errors, or has failed the hard / soft reset operations).
I have tried using errno to get the error value, but nothing returns the error condition. Is that something i am missing?
Following is the code for the write function.
int writesector(const uint64_t offset, const int fd, const uint8_t *mybuff, const uint16_t len)
{
if(!fd)
{
return 4;
}
errno = 0;
if(lseek64(fd, offset, SEEK_SET) != -1)
{
if (errno!=0)
{
return 1;
}
errno = 0;
if( (write(fd, mybuff, len)) != len)
{
return 1;
}
if (errno!=0)
{
return 1;
}
}
else
{
return 2;
}
return 0;
}
Has anyone tried a similar approach in writing to hdd's at low level?
What else I can check for? I am currently out of options to identify the issue. I have tried implementing a write timeout, but it bombs badly!
Any inputs / help on this issue please?