Final Year Project: Using Linux Filesystems Under Windows   Chris Bryden BEng. Electronics and Software Engineering    School of Computer Science   University of Birmingham 38 5.10  Layer 0: The ReadLogicalSector Function The  ReadLogicalSector  function  provides  the  interface  between  layer  0 and layer 1. It reads a logical sector from a specified drive number and partition number. It accepts five arguments: · =bDrive - The Drive number, 0x80 for 1 st HDD, 0x81 for 2nd, etc. · =bPart - The partition number, 0 for 1 st partition, 1 for the 2nd, etc. · =chSecNum - The sector number of the sector to be read. · =lpBuff - The buffer into which to read the sector data. · =chBuffSize - The size of the buffer This  function  must  calculate  the  CHS  reference  that  corresponds  to  the logical sector to be read, then calls ReadPhysicalSector to perform the disk read. First  the  absolute  sector  number  (sectors  numbered  from  0  from  the  1st sector  on  the  disk)  is  calculated.  This  is  simply  done  by  adding  the  ulStartSec value  for  the  specified  partition  to  the  logical  sector  number,  ulSecNum.  This absolute sector number must then be converted to a CHS reference for use by the ReadLogicalSector function. This is done using the calculation shown below: For  more  information  on  how  the  absolute  sector  number  translates  to  a  CHS reference,  please  see  section  2.  For  more  information  on  the  DiskInfo  array, please see section 5.7 Once  the  CHS  reference  has  been  calculated,  the  ReadPhysicalSector function is called to perform the disk read. 5.11  Layer 1: The ReadBlock Function This  function  reads  a  logical  block  from  the  mounted  filesystem.  It  must take  into  account  the  block  size,  which  can  vary  from  filesystem  to  filesystem. Typical  values  for  the  block  size  are  1024,  2048  or  4096  bytes.  This  function provides the interface between layer 0 and layer 1 and is used by any operation in layer 2 that needs to access the filesystem on disk. It calls the layer 0 function ReadLogicalSector  to  perform  the  disk  reads,  one  or  more  of  which  may  be necessary to read a complete block. To read the correct sectors from disk, two values  need  to  be  calculated.  The  start  sector  (ulSector)  and  the  number  of sectors to read (uNumSec). These are calculated as shown below: //perform sector # to CHS translation ulPhSec = chSecNum % DiskInfo[iDrive].rgDskParams[3] + 1; chSecNum /= DiskInfo[iDrive].rgDskParams[3]; ulPhHead = chSecNum % (DiskInfo[iDrive].rgDskParams[2] + 1); ulPhCyl = chSecNum / (DiskInfo[iDrive].rgDskParams[2] + 1); ulSector = ulBlkSize * ulBlock / SECTOR_SIZE; uNumSec = ulBlkSize / SECTOR_SIZE;