Final Year Project:
Using Linux Filesystems Under Windows
Chris Bryden
BEng. Electronics and Software Engineering
School of Computer Science
University of Birmingham
36
The first sector of a hard disk contains three things, the boot loader, used
by the BIOS to boot the operating system from
the first hard disk, the partition table for that
disk and the first sector magic number. The
firstsec structure is designed to represent this.
By reading the first sector from disk straight
into the memory location of the firstsec
structure, the values for the partition table and
the magic number are loaded into the correct
places. A hard disk has space for four entries
in its partition table, and so an array of four
partition structures is used to hold the partition table. The partition structure is
organised in such a way that the values all fall into the right places when the
sector is read, this structure is shown below:
The values are as indicated by the comments. Notice that the start sector
and number of sectors values are stored in the typical lo byte - hi byte form, as
they are on disk. This structure is then used by the GetPartTable function to
return a more convenient form for the partition table.
The 1st sector magic number, stored in the variable Magic, is used to
check the validity of the first sector, its value is 0xAA55. See section 2 for more
information on the structure of hard disks.
This function is called only once, when the library is first loaded.
Boot Loader
Partition Table
1st
Sector
Magic
Number
struct partition {
unsigned char boot_ind;
/* 0x80 - active */
unsigned char head;
/* starting head */
unsigned char sector;
/* starting sector */
unsigned char cyl;
/* starting cylinder */
unsigned char sys_ind;
/* What partition type */
unsigned char end_head;
/* end head */
unsigned char end_sector;
/* end sector */
unsigned char end_cyl;
/* end cylinder */
unsigned short start_sectlo; /* starting sector counting from 0 */
unsigned short start_secthi; /* starting sector counting from 0 */
unsigned short nr_sectslo;
/* nr of sectors in partition */
unsigned short nr_sectshi;
/* nr of sectors in partition */