473,761 Members | 5,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read and Write Sector

Hi All,
We developed our project on VC++.Net console application to
create image of disk and to write the image
We are having problem with reading and writing the sector
beyond 6GB Disk or Partition
we are using ReadFile , WriteFile and setFilePointerE x to read
and write the sectors and we are reading/writing 102400 sectors together,
even we have reduced the sectors still it is not able to
read or write,
our program is working fine with disk or partition below 6GB
with no data loss.
We are not able track out what the problem is, can anyone
tell what problem is.?

Feb 1 '06 #1
5 5116
Could you give us some more information / source code?
what method are you using to read and write sectors using the file IO
routines?

without more information, my best guess is that you are using
FILE_FLAG_NO_BU FFERING, and the buffer length or offset is not a multiple of
the volume sector size, or that your buffer is not sector aligned.

tht would be consistent with your observation that it doesn't work with
volumes > 6G, since they are likely to have other sector sizes than small
volumes.

kind regards,
Bruno.
"Sumana" wrote:
Hi All,
We developed our project on VC++.Net console application to
create image of disk and to write the image
We are having problem with reading and writing the sector
beyond 6GB Disk or Partition
we are using ReadFile , WriteFile and setFilePointerE x to read
and write the sectors and we are reading/writing 102400 sectors together,
even we have reduced the sectors still it is not able to
read or write,
our program is working fine with disk or partition below 6GB
with no data loss.
We are not able track out what the problem is, can anyone
tell what problem is.?


Feb 1 '06 #2
Hi

we are using this code to create the handle
//device name can be physical disk or drive

hDevice = CreateFile(_dev icename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRIT E,

NULL, OPEN_EXISTING, 0, NULL);

//we set the pointer usinf this code which point to the specfied sector

// we had used SetFilePointer but it was not able to perform operation
beyond 5 GB so we used SetFilePointerE x

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)== INVALID_SET_FIL E_POINTER)

return NULL;

// To read the sector information we are using ReadFile

// buffer size is 512 * 102400 bytes

// number of sectors = 102400 sectors

ReadFile (hDevice, buffer, 512*numberofsec tors, &bytesread, NULL);

if(bytesread == 0)

return NULL;

this function is reading 52428800 bytes and writes into the file as image
file

///// for writing into the sectors

// we are opening the image file read the 5242880 bytes and writes into the
sectors

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)== INVALID_SET_FIL E_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsec tors,&byteswrit e, NULL))

return false;

Thanks



"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
Could you give us some more information / source code?
what method are you using to read and write sectors using the file IO
routines?

without more information, my best guess is that you are using
FILE_FLAG_NO_BU FFERING, and the buffer length or offset is not a multiple
of
the volume sector size, or that your buffer is not sector aligned.

tht would be consistent with your observation that it doesn't work with
volumes > 6G, since they are likely to have other sector sizes than small
volumes.

kind regards,
Bruno.
"Sumana" wrote:
Hi All,
We developed our project on VC++.Net console application to
create image of disk and to write the image
We are having problem with reading and writing the sector
beyond 6GB Disk or Partition
we are using ReadFile , WriteFile and setFilePointerE x to
read
and write the sectors and we are reading/writing 102400 sectors together,
even we have reduced the sectors still it is not able to
read or write,
our program is working fine with disk or partition below
6GB
with no data loss.
We are not able track out what the problem is, can anyone
tell what problem is.?


Feb 2 '06 #3
and how do you know that sector size is 512? doesn't that depend on the
volume size? in that case it could be 1024, and that could make your offsets
or sizes invalid, since they have to be a multiple of the real sector size.

kind regards,
Bruno.
"Sumana" <sa***@hotmail. com> wrote in message
news:OE******** ********@tk2msf tngp13.phx.gbl. ..
Hi

we are using this code to create the handle
//device name can be physical disk or drive

hDevice = CreateFile(_dev icename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRIT E,

NULL, OPEN_EXISTING, 0, NULL);

//we set the pointer usinf this code which point to the specfied sector

// we had used SetFilePointer but it was not able to perform operation
beyond 5 GB so we used SetFilePointerE x

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FIL E_POINTER)

return NULL;

// To read the sector information we are using ReadFile

// buffer size is 512 * 102400 bytes

// number of sectors = 102400 sectors

ReadFile (hDevice, buffer, 512*numberofsec tors, &bytesread, NULL);

if(bytesread == 0)

return NULL;

this function is reading 52428800 bytes and writes into the file as image
file

///// for writing into the sectors

// we are opening the image file read the 5242880 bytes and writes into
the sectors

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FIL E_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsec tors,&byteswrit e, NULL))

return false;

Thanks



"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
Could you give us some more information / source code?
what method are you using to read and write sectors using the file IO
routines?

without more information, my best guess is that you are using
FILE_FLAG_NO_BU FFERING, and the buffer length or offset is not a multiple
of
the volume sector size, or that your buffer is not sector aligned.

tht would be consistent with your observation that it doesn't work with
volumes > 6G, since they are likely to have other sector sizes than small
volumes.

kind regards,
Bruno.
"Sumana" wrote:
Hi All,
We developed our project on VC++.Net console application
to
create image of disk and to write the image
We are having problem with reading and writing the sector
beyond 6GB Disk or Partition
we are using ReadFile , WriteFile and setFilePointerE x to
read
and write the sectors and we are reading/writing 102400 sectors
together,
even we have reduced the sectors still it is not able
to
read or write,
our program is working fine with disk or partition below
6GB
with no data loss.
We are not able track out what the problem is, can
anyone
tell what problem is.?



Feb 2 '06 #4
Hi

it is working fine till 6 GB disk or drive and we have got sample program to
check the information in each sector of the drive in HEX form or in
character form.
we have got lot of document which specifies that basic allocation unit of
each drive or disk is 512 bytes, even while formatting the disk we are
allocationing the unit with the multiply of 512 like 1024, 2048, 4096 , we
don't think it may create any problem

most of the problem occurs when we restarts the system , after performing
write operation in the sector

Windows XP displays the below information before it loads the OS

//////////////////////////////////////////////////////////////////////////////////
One of your disks needs to be checked for consistency. You
may cancel the disk check, but it is strongly recommended
that you continue.
Windows will now check the disk.
The file name index present bit in file 0x5 should not be set.
Correcting a minor error in file 5.
The file name index present bit in file 0xb should not be set.
Correcting a minor error in file 11.
Index entry _restore{15280B 1B-8B59-4C06-8331-AC6937D07FFC} of index $I30 in
file 0x21 points to unused file 0x19.
Deleting index entry _restore{15280B 1B-8B59-4C06-8331-AC6937D07FFC} in index
$I30 of file 33.
Index entry _RESTO~1 of index $I30 in file 0x21 points to unused file 0x19.
Deleting index entry _RESTO~1 in index $I30 of file 33.
Cleaning up minor inconsistencies on the drive.......... ........etc

Windows has made corrections to the file system.

9213277 KB total disk space.
84 KB in 4 files.
8 KB in 10 indexes.
0 KB in bad sectors.
49149 KB in use by the system. //////// By this it is clear
that system is using this much number of Sector
48128 KB occupied by the log file./////// this sectors are locked by
the OsS
9164036 KB available on disk.

4096 bytes in each allocation unit.
2303319 total allocation units on disk.
2291009 allocation units available on disk.

//////////////////////////////////////////////////////////////////////////////////////////////

may be the OS have some control over some sectors?

"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:OM******** ******@TK2MSFTN GP10.phx.gbl...
and how do you know that sector size is 512? doesn't that depend on the
volume size? in that case it could be 1024, and that could make your
offsets or sizes invalid, since they have to be a multiple of the real
sector size.

kind regards,
Bruno.
"Sumana" <sa***@hotmail. com> wrote in message
news:OE******** ********@tk2msf tngp13.phx.gbl. ..
Hi

we are using this code to create the handle
//device name can be physical disk or drive

hDevice = CreateFile(_dev icename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRIT E,

NULL, OPEN_EXISTING, 0, NULL);

//we set the pointer usinf this code which point to the specfied sector

// we had used SetFilePointer but it was not able to perform operation
beyond 5 GB so we used SetFilePointerE x

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FIL E_POINTER)

return NULL;

// To read the sector information we are using ReadFile

// buffer size is 512 * 102400 bytes

// number of sectors = 102400 sectors

ReadFile (hDevice, buffer, 512*numberofsec tors, &bytesread, NULL);

if(bytesread == 0)

return NULL;

this function is reading 52428800 bytes and writes into the file as
image file

///// for writing into the sectors

// we are opening the image file read the 5242880 bytes and writes into
the sectors

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FIL E_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsec tors,&byteswrit e, NULL))

return false;

Thanks



"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in
message news:A8******** *************** ***********@mic rosoft.com...
Could you give us some more information / source code?
what method are you using to read and write sectors using the file IO
routines?

without more information, my best guess is that you are using
FILE_FLAG_NO_BU FFERING, and the buffer length or offset is not a
multiple of
the volume sector size, or that your buffer is not sector aligned.

tht would be consistent with your observation that it doesn't work with
volumes > 6G, since they are likely to have other sector sizes than
small
volumes.

kind regards,
Bruno.
"Sumana" wrote:

Hi All,
We developed our project on VC++.Net console application
to
create image of disk and to write the image
We are having problem with reading and writing the sector
beyond 6GB Disk or Partition
we are using ReadFile , WriteFile and setFilePointerE x to
read
and write the sectors and we are reading/writing 102400 sectors
together,
even we have reduced the sectors still it is not able
to
read or write,
our program is working fine with disk or partition
below 6GB
with no data loss.
We are not able track out what the problem is, can
anyone
tell what problem is.?




Feb 2 '06 #5
if the sector size is really 1024, and you try to read an un-even times 512
bytes, the resulting size is not a multiple of 1024.
the same is true for the offset. if your starting offset is not a multiple
of 1024, the file operation may fail.

if you cannot get the real sector size from the HDD parameters, the best
solution would be to use a multiple of 4096 bytes. that way your sizes and
offsets will always be a multiple of 512, 1024, 2048 and 4096.
whatever size you use, you should always make it a constant. using numbers
like 512 directly in your code can lead to errors if you ever need to change
them.

I think you should at least try this to make sure that that is not the
problem. this is not a difficult test to do.

If that does not solve your problem, you might want to post this question to
development.dev ice.drivers
another good place would be the NTDEV and NTFSD list on www.osronline.com. i
know that there are a lot of file system experts active on those forums.

kind regards,
Bruno.

"Sumana" wrote:
Hi

it is working fine till 6 GB disk or drive and we have got sample program to
check the information in each sector of the drive in HEX form or in
character form.
we have got lot of document which specifies that basic allocation unit of
each drive or disk is 512 bytes, even while formatting the disk we are
allocationing the unit with the multiply of 512 like 1024, 2048, 4096 , we
don't think it may create any problem

most of the problem occurs when we restarts the system , after performing
write operation in the sector

Windows XP displays the below information before it loads the OS

//////////////////////////////////////////////////////////////////////////////////
One of your disks needs to be checked for consistency. You
may cancel the disk check, but it is strongly recommended
that you continue.
Windows will now check the disk.
The file name index present bit in file 0x5 should not be set.
Correcting a minor error in file 5.
The file name index present bit in file 0xb should not be set.
Correcting a minor error in file 11.
Index entry _restore{15280B 1B-8B59-4C06-8331-AC6937D07FFC} of index $I30 in
file 0x21 points to unused file 0x19.
Deleting index entry _restore{15280B 1B-8B59-4C06-8331-AC6937D07FFC} in index
$I30 of file 33.
Index entry _RESTO~1 of index $I30 in file 0x21 points to unused file 0x19.
Deleting index entry _RESTO~1 in index $I30 of file 33.
Cleaning up minor inconsistencies on the drive.......... ........etc

Windows has made corrections to the file system.

9213277 KB total disk space.
84 KB in 4 files.
8 KB in 10 indexes.
0 KB in bad sectors.
49149 KB in use by the system. //////// By this it is clear
that system is using this much number of Sector
48128 KB occupied by the log file./////// this sectors are locked by
the OsS
9164036 KB available on disk.

4096 bytes in each allocation unit.
2303319 total allocation units on disk.
2291009 allocation units available on disk.

//////////////////////////////////////////////////////////////////////////////////////////////

may be the OS have some control over some sectors?

"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:OM******** ******@TK2MSFTN GP10.phx.gbl...
and how do you know that sector size is 512? doesn't that depend on the
volume size? in that case it could be 1024, and that could make your
offsets or sizes invalid, since they have to be a multiple of the real
sector size.

kind regards,
Bruno.
"Sumana" <sa***@hotmail. com> wrote in message
news:OE******** ********@tk2msf tngp13.phx.gbl. ..
Hi

we are using this code to create the handle
//device name can be physical disk or drive

hDevice = CreateFile(_dev icename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRIT E,

NULL, OPEN_EXISTING, 0, NULL);

//we set the pointer usinf this code which point to the specfied sector

// we had used SetFilePointer but it was not able to perform operation
beyond 5 GB so we used SetFilePointerE x

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FIL E_POINTER)

return NULL;

// To read the sector information we are using ReadFile

// buffer size is 512 * 102400 bytes

// number of sectors = 102400 sectors

ReadFile (hDevice, buffer, 512*numberofsec tors, &bytesread, NULL);

if(bytesread == 0)

return NULL;

this function is reading 52428800 bytes and writes into the file as
image file

///// for writing into the sectors

// we are opening the image file read the 5242880 bytes and writes into
the sectors

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogic alsector*512);

if(SetFilePoint erEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FIL E_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsec tors,&byteswrit e, NULL))

return false;

Thanks



"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in
message news:A8******** *************** ***********@mic rosoft.com...
Could you give us some more information / source code?
what method are you using to read and write sectors using the file IO
routines?

without more information, my best guess is that you are using
FILE_FLAG_NO_BU FFERING, and the buffer length or offset is not a
multiple of
the volume sector size, or that your buffer is not sector aligned.

tht would be consistent with your observation that it doesn't work with
volumes > 6G, since they are likely to have other sector sizes than
small
volumes.

kind regards,
Bruno.
"Sumana" wrote:

> Hi All,
> We developed our project on VC++.Net console application
> to
> create image of disk and to write the image
> We are having problem with reading and writing the sector
> beyond 6GB Disk or Partition
> we are using ReadFile , WriteFile and setFilePointerE x to
> read
> and write the sectors and we are reading/writing 102400 sectors
> together,
> even we have reduced the sectors still it is not able
> to
> read or write,
> our program is working fine with disk or partition
> below 6GB
> with no data loss.
> We are not able track out what the problem is, can
> anyone
> tell what problem is.?
>
>
>
>
>
>



Feb 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
43068
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table. Much appreciated if you can help! Thanks
0
1879
by: munif | last post by:
i wnat write a C++ program that would read from a CD and display information about files and folders in the given CD In simple words you would be performing a simple (ls -l) or (DIR /S) on the CD. LOOk at this code /*
4
7710
by: Jerry | last post by:
I am trying to read a physical sector off of the disk (the boot sector for drive C:) from C#. I have no problems doing it from a C/C++ application using the Win32 API CreateFile and ReadFile. However, when I attempt to use PInvoke to do the very same thing in C# the data read in is somehow being altered from what is on disk. Several of the bytes are being changed from their original value to 0x3f!?!?! Anyone have any ideas as to what I...
1
6289
by: Shrirang Ballal | last post by:
I am doing a project which requires to read the raw bytes from hard disk. It rrequires to access the partition table and then the individual partitions. I want some material related to these issues. If someone can suggest of a book then that is also good. All the books I have seen are related to the GUI design. Waiting for reply, Thank you
2
3534
by: Adelino | last post by:
Is it possible to read/write sectores in any hard drive? I have some examples from the net in vc++ but is there a simple way in c#? Thanks The ideia is to do a disk search of a pattern that identifies pictures for examples and by it's size, save all those sectores/clusters to another disc drive. Very usefull if a virus like some that are in the wild make my files to size 0!!! I have done some sector editing with some programas like...
3
363
by: Rajeesh | last post by:
Hi All i have written a program which can write the sector upto 6 GB if it goes beyond, the program is un able to write this program create the image file after the read the sector information i have used CreateFile()
2
2482
by: Noel Mosa | last post by:
Hi, i have a file in memory in a char* string(which i read using buffered ifstreams from c++) and want to write a fake read() function for a C program that usually reads from files. What id like to know is the following: how can i best copy the array to the buffer? can i for example just say:
5
2946
by: Jordi Maycas | last post by:
Could I do something like this with .net 2005? PROGRAM WriteBootSector; VAR DiskSectorsPerTrack, DiskTracksPerHead, DiskHeads : WORD; FUNCTION WriteSector(Sector : WORD; Buffer : POINTER) : BYTE; ASSEMBLER; ASM
3
3745
by: aditigupta | last post by:
hi actually i m using absread to read a particular sector but when i write it i m getting some special characters instead of actual data....... i m writing the data by this command for (i=0; i<512; i++) { ch_out = buf; fprintf(fnew1,"%c",ch_out);
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.