ajtgarber wrote:How does that tell when the partition tables begin? (how does it know where to look for partition information? is it set? or is it variable?)
For HDs:
Every hard disk starts with the MBR(MasterBootRecord) which is contained in the
first sector of the disk as a BOOT sector.
boot records starts at offset +3 from postion 0
(like:
char buf[512];
boot_record *br=(boot_record)(&buf+3);)
some important constants:
boot_record_start = 3;
#define part_01_start 0x1be
#define part_02_start 0x1Ce
#define part_03_start 0x1de
#define part_04_start 0x1ee
#define FAT12 0x01
#define FAT16_small32m 0x04
#define EXTENDED_PART 0x05
#define FAT16_LBA 0x0E
#define FAT16_CHS 0x06
#define FAT32_LBA 0x0c
#define FAT32_CHS 0x0b
#define FAT32_LBA_EXTENDED 0x0F
#define LINUX_NATIVE 0x83
#define LINUX_SWAP 0x82
#define LINUX_EXTENDED 0x85
#define NTFS_extended1 0x86
#define NTFS_extended2 0x87
#define SPF_BOOT_MANAGER 0x20
#define XENIX_root 2
#define XENIX_usr 3
#define NTFS_ID 7
#define LBA_HD 0x60
#define CHS_HD 0x00
here's how the simple boot_record look like :
typedef struct boot_record {
char OEM_Identifier[8];
word BytesPerSector ;
char SectorsPerCluster ;
word ReservedSectors ;
char NumberOfFATs ;
word RootEntries ;
word NumberOfSectors ;
word MediaDescriptor ;
word SectorsPerFAT ;
word SectorsPerHead ;
word HeadsPerCylinder ;
dword HiddenSectors ;
dword BigNumberOfSectors ;
dword BigSectorsPerFAT ;
word ExtFlags ;
word FSVersion ;
dword RootDirectoryStart ;
word FSInfoSector ;
word BackupBootSector ;
} boot_record;
Another important thing is that each MBR contains 4 entries for 4 partitions definitions ! (they start at the following indexes inside the boot sector : 0x1be,
0x1Ce, 0x1de, 0x1ee as defined above)
Here's how the PARTITION TABLE looks like:
typedef struct partition_table {
char Boot_indicator;
char Beginning_head_number ;
char Beginning_sector_and_high_cylinder_number ;
char Beginning_low_cylinder_number ;
char System_indicator ;
char Ending_head_number ;
char Ending_sector_and_high_cylinder_number ;
char Ending_low_cylinder_number;
dword Number_of_sectors_preceding_the_partition; // or LBA start
dword Number_of_sectors_in_the_partition; //or LBA length
} partition_table;
A partition table define both CHS location and LBA location.
CHS = CylinderHeadSector (in terms of cylinders, heads, and sectors , old, old,old)
LBA = LargeBlockAddressing (in terms of secotors [good])
Another important thing :
- in the MBR we can have the following :
partition 1 : Number_of_sectors_preceding_the_partition=63
Number_of_sectors_in_the_partition=10000000 (~5GB)
System_indicator=FAT32_LBA
partition 2 : Number_of_sectors_preceding_the_partition=63+1000000+some few additional sectors
Number_of_sectors_in_the_partition=200000000 (~100GB)
System_indicator= EXTENDED_PART
partition 3 : 0 and 0
partition 4 : 0 and 0
Now partition 2 is of type EXTENDED_PART (extended partition) : it means that at sector [63+1000000+some few additional sectors] we will find another MBR like sector with another 4partition defs, with a maximum usage of Number_of_sectors_in_the_partition=200000000 (~100GB)
Traditionaly the space between the MBR and the Number_of_sectors_preceding_the_partition is left for BOOT_EXTENDERS like SPFDISK, GRUB, etc... there you can put your staff ...
FOR CDs/DVDs :
each CD/DVD which is ISO9660 complient and starts with session 1 at
sector position 16.
At sector 16 you will find the ISO_PRIMARY_DESCRIPTOR....
The 16 sectors left behind can be used to emulate a HARD DISK boot record ...
(now I hope you get it ...) as define by "EL_TORITO"
//ISO9660 Date and Time record
typedef struct date_iso9660 {
char year_[4]; //ascii
char month_[2] //ascii
char day_[2];
char hour_[2];
char min_[2];
char sec_[2];
char houndres_[2];
char greenwich15; // SIGNED ! in units of 15 minutes ! (west is negative, east is positive
} date_iso9660;
typedef struct iso_primary_descriptor{
char VDtype;
char VDid[5];
char version; //=1
char unused1; //=0
char system_id[32]; //(1 To 32)
char volume_id[32]; //(1 To 32)
char unused2[8];
dword total_number_of_sectors[2];
char unused3[32]
word volume_set_size[2];
word volume_sequence_number[2];
word sector_size[2];
dword path_table_size[2]
dword path_table_LE1
dword path_table_LE2
dword path_table_BE1
dword path_table_BE2
char root_dir_rec[34] // directory_record root_dir_rec + filename + 1|0
char volume_set_id[128];
char publisher_id[128];
char preparer_id[128];
char application_id[128];
char copyright_file_id[37];
char abstract_file_id[37];
char bibliographic_file_id[37];
date_iso9660 creation_date;
date_iso9660 modification_date;
date_iso9660 expiration_date;
date_iso9660 effective_date;
char file_structure_version; //=1
char unused4; //=0
char application_data[512]; //don't care
char unused5[653]; //=0
} iso_primary_descriptor;
Now I'm sure you want to learn (if don't know already) about FAT32/16,
ISO9660 and at least EXT2 ...
You will find all the docs with google/yahoo/alta_vista/bing/ or what ever ...
Maybe you are also interested in low level ASM read hd sector and ATAPI CD/DVD read sector ... (it's hard to find atapi read sector example ... unless you visit my web site ....
http://mbarboi.home.ro/project_fat.html ... or you can look inside my
project's open-sources
http://filesystemd.sourceforge.net)
I hope this will solve some of your problems ...
You can search for this people and their docs if you need more docs :
"Thanks to following people for their good docs ( &tutorial sources)!"
" - Tilmann Reh - (IDE HD tutorial)"
" - IDE ATA HardDisk Specification"
" - Philip J. Erdelsky - ISO9660 Simplified"
" - ISO 9660 - Wikipedia, the free encyclopedia"
" - Joilet Spec - Microsoft"
" - An Introduction To Programming With ATA And ATAPI"
" - Ben Cadieux - WDE asm sources"
" - Jack R. Ellis - XCDROM.SYS sources"
" - Information Technology - AT Attachment Packet Interface (ATAPI)"
" - Hale Landis - How it Works -- Partition Tables"
" - Hsu-Ping Feng - SpfDisk : Values for operating system indicator"
" - Robert Vandervelde - How Windows 95 Stores Long Filenames"
" - Inbar Raz - FAT DIRs' document"
" - Galen C. Hunt(&Gordon Chaffee) -NOTES ON THE STRUCTURE OF THE VFAT FILESYSTEM"
" - Jozsef Hidasi - How does Windows 95 stores LONG FILENAMES"
" - Thomas Kjoernes - File Allocation Table : How It Seems To Work, etc..."
" - Alex Verstak - FAT/PARTITION documents"
" - EXT2 Specification"
" - Wikipedia - EXT2"
" - EXT2 Overview"
" - John's spec of the second extended filesystem (EXPLORE2FS)"
" - Intel IA32/64 CPU Manuals"
" - Christopher Giese - protected-mode demo code"
" - Alexei A. Frounze - protected-mode tutorial"
" - Wim Osterholt - PORTLIST.TXT"
" - Ralph Brown - Interrupts Bible ..."
" - FreeDOS development team - Big thanks to all programmers, of all kind !"
" - FreeBASIC compiler team and forum member - Nothing of this would be possible without you !"
" - NASM - NASMDOC.TXT"
" - FASM - FASMDOC.TXT"
" - Glaciar P. Moreno I - Set's Editor (setedit)"
" - FbEdit"
" - NC, SCANDISK, Win9xDEFRAG for inspiration about GUI"
" - HOME.RO for free web page hosting"
" - google for being such a good 'searcher'
)"
" - AlphaX team members (for moral suport)"
" - wikipedia - most needed enciclopedia (as good as MS Encarta)"
" - all HOBIEST programmers all over the world - Thanks !"
" - A. Einstein , ICHB & MIT - good teachers"