Page 1 of 1

copy one sector to the other sector of Same hard disk

Posted: Fri May 16, 2008 3:17 am
by ravi_chobey
Hi All,

I am working on a hard disk duplicator project.

I have some doubts.

1> Is it possible to read sector of hard disk and writing to the 4th sector of same hard disk?

2> If yes then, will there be any delay between read and write operation?

3> I am doing this using C programming.But i have implemented READ sector command and stored the sector 1 data in array of 255 integers.
But i am not able to write to 4th sector.


Regards,
Ravi Chobey

Re: copy one sector to the other sector of Same hard disk

Posted: Fri May 16, 2008 3:21 am
by JamesM
Hi,
ravi_chobey wrote:Hi All,

I am working on a hard disk duplicator project.

I have some doubts.

1> Is it possible to read sector of hard disk and writing to the 4th sector of same hard disk?
Yes.
2> If yes then, will there be any delay between read and write operation?
Yes, only one read or write can be done at any one time.
3> I am doing this using C programming.But i have implemented READ sector command and stored the sector 1 data in array of 255 integers.
But i am not able to write to 4th sector.
Why are you not able to write to the fourth sector of the hard disk?

Cheers,

James

Posted: Fri May 16, 2008 3:32 am
by AJ
Hi,

It would also be useful to know how you are doing this. Are you using the BIOS basic read/write (CHS), the BIOS Extended Read/Write using a packet of information (LBA) or have you implemented (S/P)ATA drivers yourself.

If using the BIOS function, is the carry flag set after the call, or can you simply not read the expected data at the expected location? More info, please!

Cheers,
Adam

Posted: Fri May 16, 2008 4:06 am
by ravi_chobey
Hi JamesM and AJ,

Thanks for sending me reply.
James, i am not able to pass my array of 255 to my data register in my write function and it is due to mu bad programming skills.

AM, if u r interesting in knowing more about my project, please go through my earlier posts.For your knowledge i am not using any BIOS,but i am writing my own bootloader code or i will be using reading available U-boot for this project.

Thanks again for replies.

Regards,
Ravi Chobey

Posted: Fri May 16, 2008 4:27 am
by AJ
ravi_chobey wrote:if u r interesting in knowing more about my project, please go through my earlier posts.
I have done so, although I really think that each topic should be self contained with all the information required to properly answer the question. You should not have to trawl through someone's earlier posts to be able to answer the question.

You have written your own drivers, but the gist of my reply still stands. Does the disk give you a write error, or does the write appear to happen but the data is simply not where you expect it to be (at sector 4)? You may be able to mount the hard drive with a hex editor to establish where the data is (is it present on the disk but in the wrong sector?).
ravi_chobey wrote:i am not able to pass my array of 255 to my data register in my write function and it is due to mu bad programming skills.
If you are unable to pass arrays (or references to arrays) between functions, are you really ready for this project? Sorry to be harsh, but perhaps you should know more about using your chosen programming language before attempting a low-level project of this nature, particularly seeing as an end user wants any disk cloning/backup/editing tool to be extremely reliable.

Cheers,
Adam

Posted: Fri May 16, 2008 7:40 am
by bewing
Well, Ravi -- a write function is nearly identical to a read function (and your array is 256 shorts, you know). You pass your array to the write function exactly the same way that you pass the array to the read function.

The differences between a read and write LBA function are:

1.) you send a different command to the Command port (0x30)
2.) I don't know if you managed to read your sector using 256 shorts or 512 bytes, but you need to output the same way -- and your code should implement a tiny delay between each short or byte that you output. A C call to an empty function is a perfectly acceptable delay.
3.) After your output loops for all the sectors of data, you need to send an additional Flush Cache command (0xE7 to the command port) -- then wait for BSY to clear again.

@AJ -- he doesn't have a choice. This is a task he's been set at work, not a hobby OS. And no, the machine he's using is completely nonstandard hardware. It has no BIOS. It uses indirectly memory mapped IO ports.

Posted: Wed May 21, 2008 2:29 am
by ravi_chobey
Hi All,

Thanks for your comments.I have implemented the read sector and write sector of a C code.

@bewing: Dear Bruce,thanks for your support throughout this project and sharing your experience with me.Actually this is COPY function of my device.
I want to copy one 80 GB hard disk drive data to another hard disk drive.
I was trying for sector by sector and i want to move for big chunks.It is sucessful.

Once again thanks for your support,

Regards,
Ravi