SetFilePointer() + WriteFile() Problems?
-
Hii In my program I'm reading the clusters in the volume using the appropriate physical offsets to the disk.
drive_handle=Createfile(L"\\\\.\\PhysicalDrive0",......);
for( i=0;total_noof_clusters;i++)//assign 0 as logical startling offset.
{
// convert cluster logical offset to physical offset
// (source& dest same size,same file system)phys_offset_source= conversion(i); // this value I get correctly
phys_offset_dest= conversion(i); // this value I get correctlyDWORD dwPtr1=SetFilePointer(drive_handle,phys_offset_source,NULL,0);
if (dwPtr1 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\nSetFilePointer Failed to read from source,:%d\n",GetLastError());
return 0;
}if(!ReadFile(drive_handle,
bBuffer1,
cluster_size,
&dwRetBytes1,
0))
{
printf("\nUnable to Read the Disk Error: %d\n",GetLastError());
return o;
}DWORD dwPtr2=SetFilePointer(drive_handle,phys_offset_dest,NULL,0);
if (dwPtr2 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\nSetFilePointer Failed to write position%d\n",GetLastError());
return 0;
}if(!WriteFile(drive_handle,
bBuffer1,
cluster_size,
&dwRetBytes1,
0))
{
printf("\nUnable to write he Drive Error: %d\n",GetLastError());
return o;
}} // next cluster
The above code not giving no (compilation and link)error messages, But does not give the result. How do we know the program reading correctly? It returns the correct no of bytes read after one read operation . When I wrote theses data into destination , nothing wrote. What may be the problem?? Where is the mistake in the code ? Any idea? ----------- Thanking you Krish krishnampkkm is online now Report Post Edit/Delete Message
-
Hii In my program I'm reading the clusters in the volume using the appropriate physical offsets to the disk.
drive_handle=Createfile(L"\\\\.\\PhysicalDrive0",......);
for( i=0;total_noof_clusters;i++)//assign 0 as logical startling offset.
{
// convert cluster logical offset to physical offset
// (source& dest same size,same file system)phys_offset_source= conversion(i); // this value I get correctly
phys_offset_dest= conversion(i); // this value I get correctlyDWORD dwPtr1=SetFilePointer(drive_handle,phys_offset_source,NULL,0);
if (dwPtr1 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\nSetFilePointer Failed to read from source,:%d\n",GetLastError());
return 0;
}if(!ReadFile(drive_handle,
bBuffer1,
cluster_size,
&dwRetBytes1,
0))
{
printf("\nUnable to Read the Disk Error: %d\n",GetLastError());
return o;
}DWORD dwPtr2=SetFilePointer(drive_handle,phys_offset_dest,NULL,0);
if (dwPtr2 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\nSetFilePointer Failed to write position%d\n",GetLastError());
return 0;
}if(!WriteFile(drive_handle,
bBuffer1,
cluster_size,
&dwRetBytes1,
0))
{
printf("\nUnable to write he Drive Error: %d\n",GetLastError());
return o;
}} // next cluster
The above code not giving no (compilation and link)error messages, But does not give the result. How do we know the program reading correctly? It returns the correct no of bytes read after one read operation . When I wrote theses data into destination , nothing wrote. What may be the problem?? Where is the mistake in the code ? Any idea? ----------- Thanking you Krish krishnampkkm is online now Report Post Edit/Delete Message
krish_kumar wrote:
In my program I'm reading the clusters in the volume using the appropriate physical offsets to the disk.
I could not understand how could achieve this using
SetFilePointer
, that uses an offset relative to the start of the file. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hii In my program I'm reading the clusters in the volume using the appropriate physical offsets to the disk.
drive_handle=Createfile(L"\\\\.\\PhysicalDrive0",......);
for( i=0;total_noof_clusters;i++)//assign 0 as logical startling offset.
{
// convert cluster logical offset to physical offset
// (source& dest same size,same file system)phys_offset_source= conversion(i); // this value I get correctly
phys_offset_dest= conversion(i); // this value I get correctlyDWORD dwPtr1=SetFilePointer(drive_handle,phys_offset_source,NULL,0);
if (dwPtr1 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\nSetFilePointer Failed to read from source,:%d\n",GetLastError());
return 0;
}if(!ReadFile(drive_handle,
bBuffer1,
cluster_size,
&dwRetBytes1,
0))
{
printf("\nUnable to Read the Disk Error: %d\n",GetLastError());
return o;
}DWORD dwPtr2=SetFilePointer(drive_handle,phys_offset_dest,NULL,0);
if (dwPtr2 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\nSetFilePointer Failed to write position%d\n",GetLastError());
return 0;
}if(!WriteFile(drive_handle,
bBuffer1,
cluster_size,
&dwRetBytes1,
0))
{
printf("\nUnable to write he Drive Error: %d\n",GetLastError());
return o;
}} // next cluster
The above code not giving no (compilation and link)error messages, But does not give the result. How do we know the program reading correctly? It returns the correct no of bytes read after one read operation . When I wrote theses data into destination , nothing wrote. What may be the problem?? Where is the mistake in the code ? Any idea? ----------- Thanking you Krish krishnampkkm is online now Report Post Edit/Delete Message
-
krish_kumar wrote:
In my program I'm reading the clusters in the volume using the appropriate physical offsets to the disk.
I could not understand how could achieve this using
SetFilePointer
, that uses an offset relative to the start of the file. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Hiiii As per MSDN the condition is "file handle must be created with the GENERIC_READ or GENERIC_WRITE". Here I opened a Hard disk handle using NTFs in windows xp. ------------ thanking you ------------
-
And it always shows ..... the error Error 131 - Error Code 0x83 Windows Error Message 131: 'ERROR_NEGATIVE_SEEK' An attempt was made to move the file pointer before the beginning of the file. I am changing the setfilepointer() code ...but result is same...same error displaying How to solve this...? ------------ thanking you ------------
-
Hiiii As per MSDN the condition is "file handle must be created with the GENERIC_READ or GENERIC_WRITE". Here I opened a Hard disk handle using NTFs in windows xp. ------------ thanking you ------------
Well, such a sentence, without context, does not provide any evidence of. Could you please post the link? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
And it always shows ..... the error Error 131 - Error Code 0x83 Windows Error Message 131: 'ERROR_NEGATIVE_SEEK' An attempt was made to move the file pointer before the beginning of the file. I am changing the setfilepointer() code ...but result is same...same error displaying How to solve this...? ------------ thanking you ------------
You do realise that by only using the low-order DWORD in SetFilePointer, you're limited to the first 2GB of the disk, I presume? What offset are you feeding to SetFilePointer?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
You do realise that by only using the low-order DWORD in SetFilePointer, you're limited to the first 2GB of the disk, I presume? What offset are you feeding to SetFilePointer?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
I have tried offset as LARGE_INTEGER alsooo.....but same error...
-
I have tried offset as LARGE_INTEGER alsooo.....but same error...
Passing the low and high words separately as specified by the documentation? You can't just pass a LARGE_INTEGER or LARGE_INTEGER pointer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Passing the low and high words separately as specified by the documentation? You can't just pass a LARGE_INTEGER or LARGE_INTEGER pointer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
DWORD dwPtr1=SetFilePointer(hDevice1,
li_offset2.LowPart,
&li_offset2.HighPart,
FILE_BEGIN);if (dwPtr1 == INVALID_SET_FILE_POINTER) // Test for failure
{
printf("\n\nSetFilePointer Failed to write,Err No:%d\n",GetLastError());
return 0;
} -
Passing the low and high words separately as specified by the documentation? You can't just pass a LARGE_INTEGER or LARGE_INTEGER pointer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Have you actually checked what the value is that you're passing to it? It's entirely possible that SetFilePointer isn't lying and that you are passing a negative number to it?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Have you actually checked what the value is that you're passing to it? It's entirely possible that SetFilePointer isn't lying and that you are passing a negative number to it?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thank uu.. thank uu thank uu I was passing -ve value......... Mr.Stuart Dootson U are really great...... :laugh: :laugh: :laugh: -------------- Thanking you --------------