Starting in 1996, Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to the Wayback Machine after an embargo period.
e-Kit:
Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.
Download:
IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.
e-Kit:
Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
Download these IBM resources today! e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.
Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast. Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life. eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
Media Type(According to Microsoft 0xf8 for fixed disk and 0xf0 for removable disk.
22 - 23
Sectors allocated for each File allocation table.
24 - 25
Sectors per track.
26 - 27
Number of head in storage device.
28 - 31
Number of sectors before start of partition(Not applicable for floppy).
32 - 35
Number of sectors in file system(32-bit value, not applicable for floppy).
36
BIOS INT13h drive number.
37
Not Used.
38
Extended boot signature.
39 - 42
Volume Serial Number.
43 - 53
Volume label in ASCII.
54 - 61
File System Type.
62 - 509
Boot Code, otherwise contains information to replace disk.
510 - 511
Signature for File System.
Data Structure for C++
From the above mentioned table, you got the boot sector information for a floppy disk formatted with FAT. Your next step will be to create a equivalent data structure in C++ to hold data read from the boot structure. So, I have created one structure as shown below:
typedefstruct _BIOS_PARAM_BLOCK
{
BYTE jumpCode[3];
BYTE oemName[8];
WORD bytes_Sector;
BYTE sec_Cluster;
WORD size_Sector_Reserved;
BYTE fatCount;
WORD Max_Root_Entry;
WORD Total_Sector_FS;
BYTE Media_Type;
WORD sectors_per_fat;
WORD sectors_per_track;
WORD total_Head_Count;
DWORD no_Sectors_Before_Part;
DWORD no_Sector_FS32;
BYTE BIOS_13h_Drive_No;
BYTE reserved;
BYTE ext_Boot_Part_Signature;
DWORD vol_Serial_Number;
BYTE vol_Lebel_Name[11];
BYTE FS_Type[8];
BYTE boot_Code[448];
WORD signature;
} BPB;
Now, the structure is ready to hold data from the boot sector. The next step is to open the device and read sector zero. (This is the boot sector for a floppy formatted with FAT.) This step can be achieved with two WIN32 APIs, "CreateFile()" and "ReadFile()". For details of these two API, please refer to the MSDN documentation.
How to use the CreateFile() API
Please look at the following code:
HANDLE hFloppy = NULL;
hFloppy = CreateFile(
"\\\\.\\A:", // Floppy drive to open
GENERIC_READ, // Access mode
FILE_SHARE_READ, // Share ModeNULL, // Security Descriptor
OPEN_EXISTING, // How to create
0, // File attributesNULL); // Handle to template
This code snippet opens a floppy disk and returns a handle. This handle will be used to read the floppy boot sector.
Integrate CreateFile() API with the ReadFile() API
The following code snippet is used to read the boot sector for a floppy and store it into a buffer of size 512. Then, I used memcpy() to copy the boot information from the buffer to the structured data.
#pragma pack(1)
typedefstruct _BIOS_PARAM_BLOCK
{
BYTE jumpCode[3];
BYTE oemName[8];
WORD bytes_Sector;
BYTE sec_Cluster;
WORD size_Sector_Reserved;
BYTE fatCount;
WORD Max_Root_Entry;
WORD Total_Sector_FS;
BYTE Media_Type;
WORD sectors_per_fat;
WORD sectors_per_track;
WORD total_Head_Count;
DWORD no_Sectors_Before_Part;
DWORD no_Sector_FS32;
BYTE BIOS_13h_Drive_No;
BYTE reserved;
BYTE ext_Boot_Part_Signature;
DWORD vol_Serial_Number;
BYTE vol_Lebel_Name[11];
BYTE FS_Type[8];
BYTE boot_Code[448];
WORD signature;
} BPB;
#pragma pack()
void PrintFloppyInformation(BPB _bpb);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print an error on failureif (!AfxWinInit(::GetModuleHandle(NULL), NULL,
::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
BYTE bBootSector[512];
memset(bBootSector, 0, 512);
DWORD dwBytesRead(0);
BPB _bpb;
HANDLE hFloppy = NULL;
hFloppy = CreateFile("\\\\.\\A:", // Floppy drive to open
GENERIC_READ, // Access mode
FILE_SHARE_READ, // Share ModeNULL, // Security Descriptor
OPEN_EXISTING, // How to create
0, // File attributesNULL); // Handle to templateif(hFloppy != NULL)
{
// Read the boot sectorif (!ReadFile(hFloppy, bBootSector, 512, &dwBytesRead, NULL))
{
printf("Error in reading floppy disk\n");
}
else
{
memcpy(&_bpb, bBootSector, 512);
// Print floppy information on Console.
PrintFloppyInformation(_bpb);
}
CloseHandle(hFloppy);
// Close the handle
}
}
return nRetCode;
}
Now, I have printed values on the console using the following code snippet.
void PrintFloppyInformation(BPB _bpb)
{
printf("Floppy Disk Information: \n");
printf("===========================\n");
printf("Assembly Instruction to jump to Boot code: 0x%x\n",
_bpb.jumpCode);
printf("OEM Name: %s\n", _bpb.oemName);
printf("Bytes per sector: %d\n", _bpb.bytes_Sector);
printf("Sector per cluster: %d\n", _bpb.sec_Cluster);
printf("Size in sector for reserved area(Boot Sector): %d\n",
_bpb.size_Sector_Reserved);
printf("Number of FATs(File Allocation Table): %d\n",
_bpb.fatCount);
printf("Number of files for root directory: %d\n",
_bpb.Max_Root_Entry);
printf("Number of Sectors in File System: %d\n",
_bpb.Total_Sector_FS);
printf("Media Type\n(According to Microsoft,
0xF8 == fixed disk and 0xF0 == Removable disk):
0x%x\n", _bpb.Media_Type);
printf("Number of Sectors for each FAT: %d\n",
_bpb.sectors_per_fat);
printf("Sectors per track: %d\n", _bpb.sectors_per_track);
printf("Number of head in storage device: %d\n",
_bpb.total_Head_Count);
printf("BIOS INT13h Drive number: 0x%x\n", _bpb.BIOS_13h_Drive_No);
printf("Volume Serial Number: %d\n", _bpb.vol_Serial_Number);
printf("Volume label Name: %s\n", _bpb.vol_Lebel_Name);
printf("Boot Sector Signature: 0x%x\n", _bpb.signature);
}
That's all. Now, run the program and you will have all the information about a floppy disk. Please look at following picture and assemble all the required information and floppy disk geometry is in front of you.
The next 18 sectors are allocated for FAT (you have two copies of the FAT with nine sectors each).
It means that the First 19 sectors for Boot Sector + FATs.
The next few sectors are for file name entry with cluster address (called as root directory).
Now, from the picture above, it is clear that the FAT for a floppy will have 224 max entries.
Each entry is 32 bytes in size. Then total bytes are allocated for root entries are (32*224) bytes, which is 7168 bytes.
7168 bytes is equal to 14 sectors because each sector is 512 bytes in size.
You have 2880 total sectors for the floppy. Please refer to the picture above.
Out of the 2880 sectors for the floppy, the boot sector + FATs sectors + Root Directory sectors are fixed. This comes to 33 sectors altogether.
The rest of the sectors are used for data storage. In other words, 2847 sectors are used for data storage.
So, in summary, the floppy geometry looks like the following figure:
About the Author
Senior Software Engineer in Ness Technologies (India) Ltd.
Tools:
Add www.codeguru.com to your favorites Add www.codeguru.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed