搜尋此網誌

2011年5月24日 星期二

CHS <=> LBA

/*
目前Windows XP與一些DOS下的分割程式仍然使用Cylinder aligned,在Windows 7下就改換成LBA aligned.


CHS (cylinder/head/sector) 的組合可以對應到LBA address使用下列公式:

 LBA = ((C * HPC) + H ) * SPT + S - 1

* C, H and S are the cylinder number, the head number, and the sector number
* LBA is the logical block address
* HPC(255) is the maximum number of heads per cylinder (reported by disk drive, typically 16 for 28-bit LBA)
* SPT(63) is the maximum number of sectors per track (reported by disk drive, typically 63 for 28-bit LBA)

LBA addresses can be mapped to CHS tuples with the following formula:

 C = LBA / (SPT X HPC)
 H = (LBA / SPT) % HPC
 S = (LBA % SPT) + 1
*/

#define MAX_HEADS   255
#define MAX_SECTORS 63
#define MAX_CYLINDER 1023


#define CHS_HEAD(LBA) (((LBA) / MAX_SECTORS) % MAX_HEADS)
#define CHS_SECTOR(LBA) (((LBA) % MAX_SECTORS) + 1)
#define CHS_CYLINDER(LBA) ((LBA) / (MAX_SECTORS * MAX_HEADS))


#define CYLINDER_TO_LBA(cylinder) ((cylinder) * MAX_SECTORS * MAX_HEADS)

沒有留言:

張貼留言