Logical drive copying using CreateFile

Discussion in 'Microsoft Windows 2000 Advanced Server' started by Guest, Apr 13, 2005.

  1. Guest

    Guest Guest

    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);
    }

    ------------------------------------------------------------------------------
     
    Guest, Apr 13, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Logical drive copying using CreateFile

    Guest, Apr 13, 2005, in forum: Microsoft Windows 2000 Advanced Server
    Replies:
    0
    Views:
    206
    Guest
    Apr 13, 2005
  2. Guest

    Logical drive copying using CreateFile

    Guest, Apr 13, 2005, in forum: Microsoft Windows 2000 Advanced Server
    Replies:
    0
    Views:
    242
    Guest
    Apr 13, 2005
  3. Guest

    Logical drive copying using CreateFile

    Guest, Apr 13, 2005, in forum: Microsoft Windows 2000 Advanced Server
    Replies:
    0
    Views:
    207
    Guest
    Apr 13, 2005
  4. Guest

    Logical drive copying using CreateFile

    Guest, Apr 13, 2005, in forum: Microsoft Windows 2000 Advanced Server
    Replies:
    0
    Views:
    205
    Guest
    Apr 13, 2005
  5. Guest

    Logical drive copying using CreateFile

    Guest, Apr 13, 2005, in forum: Microsoft Windows 2000 Advanced Server
    Replies:
    0
    Views:
    179
    Guest
    Apr 13, 2005
Loading...

Share This Page