Code:
//version 0.1.0
/* Using Structure to hold data+Floppy disk stats
Original code :A Piece of COde that extracts floppy disk geometry information,
its been writen in pure C and has been tested and ran seccessfully under TC 3 ...
Added session:Floppy Disk Stat reader!, it is intended to show the floppy
-disk information rather than its FAT info or floppy geometry!
Cod3r :Seyyed HOssein hasn pour in NOvember 12th 2007
www.PersianOs.org*/
//##################Define Session######################
typedef unsigned char BYTE;
typedef short int WORD;
typedef int DWORD;
//###################Main Session#######################
void profile_1(void);
//void FLOPPY_STATS(void);
#include <stdio.h>
#include <process.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
/* Functions should start with no leading spaces or tabs */
int main(void)
{
//###################Structure To hold data#############
/* Structures are not meant to be declared inside functions.
It should be OUTSIDE all functions, preferably at the beginning of your source file or in a header */
struct Floppy_DISK_INFORMATION
{
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_Label_Name[11];
BYTE FS_Type[8];
BYTE boot_Code[448];
WORD signature;
} fdi;
//###################Declaring variables#################
/* Usually, it's best to keep things consistent. Don't use 3 spaces for indentation some
place and 4 spaces other places. Use one of those and stick with it. Myself, I prefer tabs. */
int j,i,start,sector,bad_counter=0,sector_counter=0;
char buf[512];
profile_1();
sector =0;
//#################Reading From Floppy Disk #############
/* All { and } should be on the same line. This tells us where a new block begins and
ends, so we can easily see what code belongs where.
Further, all code inside a block should be indented another level, to tell us that this
code belongs to this block. */
if (absread (0, 1, sector,&fdi)!=0)
{
printf ("An Error Has Occurred!");
exit(1);
}
/* Keep indentation consistent! */
printf("Read Seccessfully !\n");
//################Printing The Infos on Consol##############
printf("Floppy Disk Information: \n");
printf("===========================\n");
printf("Assembly Instruction to jump to Boot code: 0x%x\n",
fdi.jumpCode); /* Keep indentation consistent! */
printf("OEM Name: %s\n",&fdi.oemName);
printf("Bytes per sector: %d\n",fdi.bytes_Sector);
printf("Sector per cluster: %d\n", fdi.sec_Cluster);
printf("Size in sector for reserved area(Boot Sector): %d\n",
fdi.size_Sector_Reserved); /* Keep indentation consistent! */
printf("Number of FATs(File Allocation Table): %d\n",
fdi.fatCount);
printf("Number of files for root directory: %d\n",
fdi.Max_Root_Entry);
printf("Number of Sectors in File System: %d\n",
fdi.Total_Sector_FS);
printf("Media Type\n(According to Microsoft,0xF8 == fixed disk and 0xF0 == Removable disk):0x%x\n", fdi.Media_Type);
printf("Number of Sectors for each FAT: %d\n",
fdi.sectors_per_fat);
printf("Sectors per track: %d\n", fdi.sectors_per_track);
printf("Number of head in storage device: %d\n",
fdi.total_Head_Count);
printf("BIOS INT13h Drive number: 0x%x\n", fdi.BIOS_13h_Drive_No);
printf("Volume Serial Number: %d\n", fdi.vol_Serial_Number);
printf("Volume label Name: %s\n", fdi.vol_Label_Name);
printf("Boot Sector Signature: 0x%x\n", fdi.signature);
//#######################FLP STATS#################
/* Keep indentation consistent and every block must be indented one level and don't put
those { and } just about anywhere - place them where they SHOULD be. At the same
level, at the same level as the block element (eg the for of the if, etc). */
for(i=0;i<=fdi.Total_Sector_FS;i++){
if (absread (0, 1,i,&fdi)!=0) //&fdi is a memory buffer that we will use to hold data
{ bad_counter++;}//number of bad sectors
{
sector_counter++;//number of used sectors
}
}
//############declaring x and temp ###############
unsigned long int x=fdi.bytes_Sector*fdi.Total_Sector_FS,y=fdi.bytes_Sector;
unsigned long temp = (unsigned long)fdi.bytes_Sector * (unsigned long)fdi.Total_Sector_FS;
//################################################
printf("\n ################## FLOPPY_STATS###############");
printf("\n\nYour Floppy Disk Stats are as follows\n");
printf("You have currently %ld Bytes on your Disk\n",x);
printf("You have currently %d Sectors of your disk space occupied\n",sector_counter);
printf("You have currently %d bad sectors in YOur Floppy Disk\n",bad_counter);
printf("Total used space on YOur Floppy disk is %d %% \n",(y*sector_counter)/100);
printf("Total Free space on Your Floppy disk is %d %% \n",(x)-(y*sector_counter)/100);
printf("\n\nX= %d %ul %i %li\n\n",x,x,x,x);
printf("YOu have currently %ld Bytes on your disk",temp);
//###################End of Cods#############################
printf("\n\n Programed By Seyyed Hossein Hasan Pour\n");
printf(" December 12th 2007 ");
printf("\n http://www.codeguru.com/forum ");
getch();
return 0;
} /* Should be at the same level as the function! */
//############This will pirnt the coder info ################
void profile_1(void)
{
/* It's preferred not to place lines at the same line as the { since it makes it more
readable */
int k;
clrscr();
gotoxy(27,5);
printf("In the name of God\n");
gotoxy(22,7);
printf("A S.Hossein hasan pour Project\n\n");
printf ("This program will show you the information stored on sector 0 of the Floppy Disk\n\n
(FAT TABLE INFORMATION).\n\n\n if you are ready press any key to continue ");
for (k=0;k<=3;k++){
//delay(50);
printf(".");
}
getch();
}