473,396 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 setFilePointerEx 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 5062
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_BUFFERING, 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 setFilePointerEx 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(_devicename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

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 SetFilePointerEx

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)== INVALID_SET_FILE_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*numberofsectors, &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 =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)== INVALID_SET_FILE_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsectors,&byteswrite, NULL))

return false;

Thanks



"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:A8**********************************@microsof t.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_BUFFERING, 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 setFilePointerEx 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****************@tk2msftngp13.phx.gbl...
Hi

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

hDevice = CreateFile(_devicename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

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 SetFilePointerEx

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FILE_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*numberofsectors, &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 =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FILE_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsectors,&byteswrite, NULL))

return false;

Thanks



"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:A8**********************************@microsof t.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_BUFFERING, 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 setFilePointerEx 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{15280B1B-8B59-4C06-8331-AC6937D07FFC} of index $I30 in
file 0x21 points to unused file 0x19.
Deleting index entry _restore{15280B1B-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**********************@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP10.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****************@tk2msftngp13.phx.gbl...
Hi

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

hDevice = CreateFile(_devicename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

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 SetFilePointerEx

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FILE_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*numberofsectors, &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 =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FILE_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsectors,&byteswrite, NULL))

return false;

Thanks



"Bruno van Dooren" <br**********************@hotmail.com> wrote in
message news:A8**********************************@microsof t.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_BUFFERING, 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 setFilePointerEx 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.device.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{15280B1B-8B59-4C06-8331-AC6937D07FFC} of index $I30 in
file 0x21 points to unused file 0x19.
Deleting index entry _restore{15280B1B-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**********************@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP10.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****************@tk2msftngp13.phx.gbl...
Hi

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

hDevice = CreateFile(_devicename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

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 SetFilePointerEx

LARGE_INTEGER L,L1;

L.QuadPart =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FILE_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*numberofsectors, &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 =(startinglogicalsector*512);

if(SetFilePointerEx (hDevice, L,&L1, FILE_BEGIN)==
INVALID_SET_FILE_POINTER)

return NULL;

if (!WriteFile (hDevice, buffer, 512*numberofsectors,&byteswrite, NULL))

return false;

Thanks



"Bruno van Dooren" <br**********************@hotmail.com> wrote in
message news:A8**********************************@microsof t.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_BUFFERING, 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 setFilePointerEx 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
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...
0
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...
4
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....
1
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...
2
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...
3
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...
2
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...
5
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) :...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.