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.
and called a write call with
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.
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?
Last edited by Franklin52; 02-21-2010 at 01:57 PM..
Reason: Please use code tags!
You're not doing low-level I/O here, your write is probably going straight into cache. Try opening with O_DIRECT.
Please edit your post to put code in code tags like the thread posting page suggests. [ code ] stuff [ /code ] without the spaces in the tags. Preferably before a mod needs to do so for you.
Surely you could write custom patterns with either dd or dd_rescue though! dd_rescue in particular shows lots of progress info. Just feed them custom patterns on stdin and you'll have your custom patterns.
I know O_DIRECT might work, and I tried with O_DIRECT, but it fails for some reason. I have tried with aligned the write buffer after getting the block size from the HDD. But it fails miserably and I don't know how to debug it. I stopped digging into it because it might branch my work.
gdb is not of much help here. I've tried jumping directly to a known bad sector location in the code for testing., but I could not get it to fail the write call. (btw, dmesg starts spewing errors after a certain write attempts on the bad sector). So, the libata is catching those errors and kernel is aware of it. But the program does not receive the error.
I have tried mapping raw devices for the hdds and executed the same operations without success.
Quote:
Has any body has any example code of writing to a hdd using O_DIRECT? Like atleast for a single sector or a file?
I wrote a small program which is working currently. Doing the testing.
I have been trying to get this to work for a long time with multiple failed options! Having sleepless nights too.
Last edited by sponnusa; 02-21-2010 at 03:06 PM..
Reason: updated the code for O_DIRECT
I know O_DIRECT might work, and I tried with O_DIRECT, but it fails for some reason.
Try printing the error message with perror() to find out what "some reason" is. As a stubborn programmer would say, don't give up until you know why it's not working.
I wanted the write to fail only for the bad sectors, but it was failing for all the sectors in the O_DIRECT mode, but I got a working program. (Well, working means, I was able to write to the sectors, but still could not get it to fail for the bad sectors).
As i had updated in my previous post, i had created a small program which writes to the sectors with O_DIRECT. I guess i might have made some mistake in my original O_DIRECT try. (lets leave it apart! )
But, even with the O_DIRECT and O_SYNC flags in place, the write passes for all the bad sectors.
How to use X11 without Xlib not XCB? How draw window directly on low level?
I must use anyway window manager like Motif?
I have ridden that X11 has server-client architecture, client send via TCP/IP to port 6000 request for primitives and get replies.
Where is detailed description of it? In X11... (0 Replies)
Hi friends,
I hope everyone is doing well and fine. I have always been hearing that C/C++ are relatively low-level as compared to Java/C# etc. Could you please tell me some low-level qualities of C/C++? And I think disk deframenters are written in C/C++, please correct me if I am wrong. And please... (5 Replies)
Hi friends,
I hope everyone is fine and doing well. I queried in my previous thread about the low-level qualities of C/C++ languages.I really thank you people for explaining, it was really helpful. One more ambiquity that I have in my mind is regarding the unix system calls like open, creat,... (1 Reply)
Hello All
I have a system running AIX 61 shared uncapped partition (with 11 physical processors, 24 Virtual 72GB of Memory) .
The output from NMON, vmstat show a high run queue (60+) for continous periods of time intervals, but NO paging, relatively low I/o (6000) , CPU % is 40, Low network.... (9 Replies)
Hi,
What is the best reference that gives in detail on nic cards configuration , assigning multiple ip addresses to a single interface, netlink library etc and all basic stuff at this level..?
Thanks (2 Replies)
I want to do a low level format like in windows (C:\format c:) but I don't know how it works in unix or linux.. Can somebody help me ? thnx :) (3 Replies)