📄 translat.c
字号:
/*************************************************************
File Name: TRANSLAT.C *
**************************************************************
Programmer: Huang Giun-Haur
Last Modified Date: 1999/2/1
Compiler : Gnu Cross-compiler
Platform : X86 protection mode
Usage :
unsigned long FAT_cluster_to_logical_sector(unsigned short cluster)
void FAT_logical_sector_to_chs(unsigned long sectorNO,
struct FAT_C_H_S *p )
*************************************************************/
#include <sys/constant.h>
// added by chilong 01/30/2002
#include "../../FileSys/include/FileSys.h"
#include "../include/fat1x.h"
#ifdef FAT_USE_PCMCIA
/**** added by chilong ****/
//#include "../pcm/cf_typedef.h"
/**** added by chilong ****/
#include "../include/ata_pcc.h"
#else
#include "../include/ata_pcc.h"
#endif
#ifdef FAT_ID
/* init.c */
extern unsigned short FATSecPerCluster[];
extern unsigned long FATDataBegin[];
extern int FATIsLBA;
extern struct FAT_C_H_S FATDiskInfo;
/*************************************************************
Function: FAT_cluster_to_logical_sector
Descirption:
Transfer the cluster number to the beginning of
its logical sector number; logical sector number
start at 0, which represents the boot sector
ThreadSafe:
**************************************************************/
unsigned long FAT_cluster_to_logical_sector(short drive, unsigned short cluster)
{
return (unsigned long)(FATDataBegin[drive] + ((unsigned long)cluster
- NO_OF_RESERVED_CLUSTER) * FATSecPerCluster[drive]);
}
/*************************************************************
Function : LOGICAL_TO_CHS
Descirption :
Transfer logical sector to CHS.
CHS: Logical sector 0 (boot sector) is CHS(0,0,1), so we
must add it to CHS.
LBA: Logical sector 0 is the MBR of the drive.
A LBA address is stored as follows:
|31--24|23--16|15--08|07--00|
H CH CL S
**************************************************************/
void FAT_logical_sector_to_chs(unsigned long sectorNO, struct FAT_C_H_S *p)
{
#ifdef FAT_USE_PCMCIA
unsigned long h1;
if (FATIsLBA == FALSE) /* CHS */
{
p->Sector = (unsigned char)(sectorNO % FATDiskInfo.Sector) + 1;
// h1 = (sectorNO / FATDiskInfo.Sector) + 1;
h1 = sectorNO / FATDiskInfo.Sector;
p->Head = (unsigned char)((h1) % FATDiskInfo.Head);
p->Cylinder = (unsigned short)(h1 / FATDiskInfo.Head);
p->CylHigh = (unsigned char)(p->Cylinder >> 8);
p->CylLow = (unsigned char)(p->Cylinder & 0x00FF);
}
else /* LBA */
{
p->Sector = (unsigned char)(sectorNO & 0x000000ff);
h1 = sectorNO >> 8;
p->CylLow = (unsigned char)(h1 & 0x000000ff);
h1 = h1 >> 8;
p->CylHigh = (unsigned char)(h1 & 0x000000ff);
h1 = h1 >> 8;
p->Head = (unsigned char)(h1 & 0x000000ff);
}
#endif
}
#endif // #ifdef FAT_ID
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -