fdisk in minix 源代码分析

fdisk -h16 -s63 /dev/hd5

c

1

0

60

结果是 0 0 2 -> 60 15 62



sec_to_hst(logsec, hd, sec, cyl)
long logsec;
unsigned char *hd, *sec, *cyl;
{
/* Convert a logical sector number to  head / sector / cylinder */

  int bigcyl;

  bigcyl = logsec / (nhead * nsec);
  *sec = (logsec % nsec) + 1 + ((bigcyl >> CYL_SHIFT) & CYL_MASK);
  *cyl = bigcyl;
  *hd = (logsec % (nhead * nsec)) / nsec;
}


#define CYL_MASK    0xc0    /* mask to extract cyl bits from sec field */
#define CYL_SHIFT    2    /* shift to extract cyl bits from sec field */
#define SEC_MASK    0x3f    /* mask to extract sec bits from sec field */


bigcyl=1/(16*63)=0;

  *sec = 1 + 1 + ((bigcyl >> CYL_SHIFT) & CYL_MASK)=2;

  *cyl = 0;

  *hd = (logsec % (nhead * nsec)) / nsec = 1 % (16 * 63) = 0;

c h s    c h s

0 0 2    20 15 62


你可能感兴趣的:(fdisk,minix)