PC Review


Reply
Thread Tools Rate Thread

Logical drive copying using CreateFile

 
 
=?Utf-8?B?U29mdHdhcmUgRW5naW5lZXI=?=
Guest
Posts: n/a
 
      13th Apr 2005
Hi,

In the following code i am copying the contents of logical drive F to G
and then after that, from G to H.

After the program execution completes, the contents of the drives g and
h are not updated in windows explorer, even after pressing F5.

If I executed chkdsk on G and H drives the content sync up with that of F.
This problem is reproducable on NTFS but is not there on FAT32 partitions.

Please suggest the reason and a possible solution to fix this problem.

I have tried this program on 400 MB drives but the problem is reproducable
on any sizes.

Thanks in Anticipation.

---------------------------------------------------------------------------
#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<iostream.h>
#include<conio.h>

void main()
{
char buffer[1024];
unsigned long bytesread;

HANDLE
h=INVALID_HANDLE_VALUE,h2=INVALID_HANDLE_VALUE,h3=INVALID_HANDLE_VALUE;
h = CreateFile(
"\\\\.\\f:", // file name
GENERIC_READ, // access mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // SD
OPEN_EXISTING, // how to create
0, // file attributes
NULL // handle to template file
);

if(h==INVALID_HANDLE_VALUE)
{
cout<<"first open failed"<<GetLastError()<<endl;
getch();
exit(1);
}
else
{
cout<<"first open successful"<<endl;
}
h2 = CreateFile(
"\\\\.\\g:", // file name
GENERIC_READ|GENERIC_WRITE, // access mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // SD
OPEN_EXISTING, // how to create
FILE_FLAG_WRITE_THROUGH, // file attributes
FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING
NULL // handle to template file
);

if(h2==INVALID_HANDLE_VALUE)
{
cout<<"second open failed"<<endl;
getch();
exit(1);
}
else
{
cout<<"second open successful"<<endl;
}

while(ReadFile(h,&buffer,sizeof(buffer),&bytesread,NULL) && bytesread)
WriteFile(h2,buffer,bytesread,&bytesread,NULL);

FlushFileBuffers(h2);

CloseHandle(h);
CloseHandle(h2);

h2=INVALID_HANDLE_VALUE;

cout<<"First write done"<<endl;

h2 = CreateFile(
"\\\\.\\g:", // file name
GENERIC_READ, // access mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // SD
OPEN_EXISTING, // how to create
0, // file attributes
FILE_FLAG_WRITE_THROUGH,
NULL // handle to template file
);

if(h2==INVALID_HANDLE_VALUE)
{
cout<<"second open failed"<<endl;
getch();
exit(1);
}
else
{
cout<<"second open successful"<<endl;
}

h3 = CreateFile(
"\\\\.\\h:", // file name
GENERIC_WRITE, // access mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // SD
OPEN_EXISTING, // how to create
FILE_FLAG_WRITE_THROUGH, // file attributes
FILE_FLAG_WRITE_THROUGH ,
NULL // handle to template file
);

if(h3==INVALID_HANDLE_VALUE)
{
cout<<"third open failed"<<endl;
getch();
exit(1);
}
else
{
cout<<"third open successful"<<endl;
}

while(ReadFile(h2,&buffer,sizeof(buffer),&bytesread,NULL) &&
bytesread)
WriteFile(h3,buffer,bytesread,&bytesread,NULL);

FlushFileBuffers(h3);

CloseHandle(h2);
CloseHandle(h3);
}

------------------------------------------------------------------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Logical drive copying using CreateFile =?Utf-8?B?U29mdHdhcmUgRW5naW5lZXI=?= Microsoft Windows 2000 Advanced Server 0 13th Apr 2005 07:14 AM
Logical drive copying using CreateFile =?Utf-8?B?U29mdHdhcmUgRW5naW5lZXI=?= Microsoft Windows 2000 Advanced Server 0 13th Apr 2005 07:14 AM
Logical drive copying using CreateFile =?Utf-8?B?U29mdHdhcmUgRW5naW5lZXI=?= Microsoft Windows 2000 Advanced Server 0 13th Apr 2005 07:13 AM
Logical drive copying using CreateFile =?Utf-8?B?U29mdHdhcmUgRW5naW5lZXI=?= Microsoft Windows 2000 Advanced Server 0 13th Apr 2005 07:13 AM
Logical drive copying using CreateFile =?Utf-8?B?U29mdHdhcmUgRW5naW5lZXI=?= Microsoft Windows 2000 Advanced Server 0 13th Apr 2005 07:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:11 PM.