Back to the WFC main page

CPhysicalDiskFile : CFile

$Revision: 8 $

Description

This class makes it easy to read physical sectors on a disk.

Data Members

None.

Methods

void Close( void )
Closes the disk.
DWORD GetLength( void ) const
Returns the total number of bytes in the disk. If (and this is quite likely) your disk contains more that 4GB, GetLength() will return 4GB. 4GB is the maximum value of a DWORD.
DWORD GetMediaType( void ) const
Returns the type of media that has been opened.
BOOL GetSectorSize( DWORD& number_of_bytes_per_sector ) const
Return TRUE if the disk has been Open()'d or FALSE if Open() has not yet been called. It will fill number_of_bytes_per_sector with the number of bytes per sector on the disk on success.
BOOL Open( LPCTSTR drive_letter, UINT open_flags, CFileException * error = NULL )
BOOL Open( int physical_disk_number, UINT open_flags, CFileException * error = NULL )
Opens the disk. The open_flags and error parameters are ignored.
UINT Read( void * buffer, UINT number_of_bytes_to_read )
Reads data from the disk. The class takes care of all that memory boundary on a page size stuff.
void SetLength( DWORD length )
This function is intercepted. In other words, it does nothing.
void Write( void * buffer, UINT number_of_bytes_to_write )
Writes data to the disk.

Example

#include <wfc.h>
#pragma hdrstop

BOOL copy_diskette_to_file( CFile& file )
{
   WFCTRACEINIT( TEXT( "copy_diskette_to_file()" ) );

   CPhysicalDiskFile disk;

   if ( disk.Open( "A:", 0 ) == FALSE )
   {
      return( FALSE );
   }

   CByteArray disk_contents;

   DWORD length = disk.GetLength();

   disk_contents.SetSize( length );

   disk.Read( disk_contents.GetBuffer(), disk_contents.GetSize() );

   // disk_contents now contains all sectors on the diskette

   file.Write( disk_contents.GetBuffer(), disk_contents.GetSize() );

   return( TRUE );
}

void get_sector( TCHAR drive_letter, DWORD sector_number, CByteArray& sector_contents )
{
   WFCTRACEINIT( TEXT( "get_sector()" ) );

   sector_contents.Empty();

   TCHAR filename[ 3 ];

   filename[ 0 ] = drive_letter;
   filename[ 1 ] = TEXT( ':' );
   filename[ 2 ] = 0x00;

   CPhysicalDiskFile disk;

   if ( disk.Open( filename, 0 ) == FALSE )
   {
      return;
   }

   DWORD sector_size = 0;

   disk.GetSectorSize( sector_size );

   DWORD location_to_seek_to = sector_size * sector_number;

   if ( ( location_to_seek_to + sector_size ) > disk.GetLength() )
   {
      return;
   }

   disk.Seek( location_to_seek_to, CFile::begin );

   sector_contents.SetSize( sector_size );

   disk.Read( sector_contents.GetData(), sector_size );
}

API's Used

CNetworkUsers uses the following API's:
Copyright, 2000, Samuel R. Blackburn
$Workfile: CPhysicalDiskFile.cpp $
$Modtime: 1/17/00 9:09a $