📄 ramdsk.c
字号:
/****************************************************************************
* *
* RAM GDIC (for FS33G<-->RAMDSK GDIC) *
* *
* Copyright (C) SEIKO EPSON CORP. 2003 *
* *
****************************************************************************/
#include <string.h>
#include "ramdsk.h"
/****************************************************************************
* internal definition *
****************************************************************************/
#define PAT_SLEEP (0x00)
#define PAT_ACTIVE (0x80)
#define PAT_TYPE_NONE (0x00)
#define PAT_TYPE_FAT12 (0x01)
#define PAT_TYPE_FAT16_S (0x04)
#define PAT_TYPE_EXDOS (0x05)
#define PAT_TYPE_FAT16_L (0x06)
#define PAT_TYPE_FAT32 (0x0b)
#define PAT_TYPE_FAT32_LBA (0x0c)
#define PAT_TYPE_FAT16_LBA (0x0e)
#define PAT_TYPE_EXDOS_LBA (0x0f)
#define MBR_BOOT_CODE (0)
#define MBR_PATITION0 (446)
#define MBR_PAT0_BOOT_FLAG (446)
#define MBR_PAT0_CHS_STR (447)
#define MBR_PAT0_TYPE (450)
#define MBR_PAT0_CHS_END (451)
#define MBR_PAT0_LBA_ADR_L (454)
#define MBR_PAT0_LBA_ADR_H (456)
#define MBR_PAT0_LBA_SIZE_L (458)
#define MBR_PAT0_LBA_SIZE_H (460)
#define MBR_PATITION1 (462)
#define MBR_PAT1_BOOT_FLAG (462)
#define MBR_PAT1_CHS_STR (463)
#define MBR_PAT1_TYPE (466)
#define MBR_PAT1_CHS_END (467)
#define MBR_PAT1_LBA_ADR_L (470)
#define MBR_PAT1_LBA_ADR_H (472)
#define MBR_PAT1_LBA_SIZE_L (474)
#define MBR_PAT1_LBA_SIZE_H (476)
#define MBR_PATITION2 (478)
#define MBR_PAT2_BOOT_FLAG (478)
#define MBR_PAT2_CHS_STR (479)
#define MBR_PAT2_TYPE (482)
#define MBR_PAT2_CHS_END (483)
#define MBR_PAT2_LBA_ADR_L (486)
#define MBR_PAT2_LBA_ADR_H (488)
#define MBR_PAT2_LBA_SIZE_L (490)
#define MBR_PAT2_LBA_SIZE_H (492)
#define MBR_PATITION3 (494)
#define MBR_PAT3_BOOT_FLAG (494)
#define MBR_PAT3_CHS_STR (495)
#define MBR_PAT3_TYPE (498)
#define MBR_PAT3_CHS_END (499)
#define MBR_PAT3_LBA_ADR_L (502)
#define MBR_PAT3_LBA_ADR_H (504)
#define MBR_PAT3_LBA_SIZE_L (506)
#define MBR_PAT3_LBA_SIZE_H (508)
#define MBR_SIGNATURE (510)
/* */
#define PBR5_JUMP_CODE (0)
#define PBR5_OEM_NAME (3)
#define PBR5_BYTE_PAR_SEC_L (11)
#define PBR5_BYTE_PAR_SEC_H (12)
#define PBR5_SEC_PAR_CLUS (13)
#define PBR5_RSV_SEC_CNT (14)
#define PBR5_FAT_CNT (16)
#define PBR5_ROOT_ENT_CNT_L (17)
#define PBR5_ROOT_ENT_CNT_H (18)
#define PBR5_TOTAL_SEC_L (19)
#define PBR5_TOTAL_SEC_H (20)
#define PBR5_MEDIA (21)
#define PBR5_FAT_SIZE (22)
#define PBR5_SEC_PAR_TRK (24)
#define PBR5_HEAD_CNT (26)
#define PBR5_HIDDEN_SEC_CNT (28)
#define PBR5_TOTAL_SEC32 (32)
#define PBR5_DRV_NUM (36)
#define PBR5_RSV (37)
#define PBR5_BOOT_SIG (38)
#define PBR5_VOL_ID_L (39)
#define PBR5_VOL_ID_M (40)
#define PBR5_VOL_ID_H (42)
#define PBR5_VOL_LABEL (43)
#define PBR5_FS_TYPE (54)
#define PBR5_BOOT_CODE (62)
#define PBR5_SIGNATURE (510)
/****************************************************************************
* internal variable definition *
****************************************************************************/
static const char OemName[] = "EPSON1.0";
static const char Copyright[] = "Copyright (C) SEIKO EPSON Corp. 2003";
static unsigned char *RAMDSK_Area; /* RAM Disk area address */
static unsigned long RAMDSK_MaxSec; /* RAM Disk max sector [sector] */
static unsigned long RAMDSK_SecSize; /* RAM Disk sector size [byte] */
/****************************************************************************
* macro function definition *
****************************************************************************/
#define Revalue(x, y) (((unsigned long)(x) - 1) / (unsigned long)(y))
/****************************************************************************
ramdskOpenLib()
----------------------------------------------------------------------------
description:
RAMDSK GDIC Library RAMDSK Function
argument: (none)
return:
int iRetVal <out> RAMDSK_E_SUCCESS:
RAMDSK_E_FAILURE:
input:
FatInitParams_t* pstParams <in> FAT
void* StrAdr <in> RAM
unsigned long Size <in> RAM [byte]
output: (none)
flag: (none)
global: (none)
comment:
RAMDSK GDIC
****************************************************************************/
int ramdskOpenLib(FatInitParams_t *pstParams)
{
return ramdskInitDev(pstParams);
}
/**** End of function *******************************************************/
/****************************************************************************
ramdskCloseLib()
----------------------------------------------------------------------------
description:
RAMDSK GDIC Library ()
argument: (none)
return:
int iRetVal <out> RAMDSK_E_SUCCESS:
input: (none)
output: (none)
flag: (none)
global: (none)
comment:
RAMDSK GDIC
****************************************************************************/
int ramdskCloseLib()
{
return RAMDSK_E_SUCCESS;
}
/**** End of function *******************************************************/
/****************************************************************************
ramdskTotalSec()
----------------------------------------------------------------------------
description:
RAM Disk
argument: (none)
return:
unsigned long ulRetVal <out> RAM Disk
input: (none)
output: (none)
flag: (none)
global: (none)
comment: (none)
****************************************************************************/
unsigned long ramdskTotalSec()
{
return RAMDSK_MaxSec;
}
/**** End of function *******************************************************/
/****************************************************************************
ramdskInitDev()
----------------------------------------------------------------------------
description:
RAMDSK Device
argument: (none)
return:
int iRetVal <out> RAMDSK_E_SUCCESS:
RAMDSK_E_FAILURE:
input:
FatInitParams_t* pstParams <in> FAT
void* StrAdr <in> RAM
unsigned long Size <in> RAM [byte]
output: (none)
flag: (none)
global: (none)
comment: (none)
****************************************************************************/
int ramdskInitDev(FatInitParams_t *pstParams)
{
int iRetVal; // Return value
// Return value is initialized.
iRetVal = RAMDSK_E_SUCCESS;
////////////////////////////////////////
/// ENTRY SECTOR READ/WRITE FUNCTION ///
////////////////////////////////////////
fatReadEntry(ramdskRdSect);
fatWriteEntry(ramdskWtSect);
///////////////////
/// RAMDSK RESET //
///////////////////
iRetVal = ramdskMediaReset();
if (iRetVal != RAMDSK_E_SUCCESS)
{
// A smart media is reset.
return iRetVal;
}
/////////////////////////////////
/// FORMAT CHECK & MAKE TABLE ///
/////////////////////////////////
// The check of the format and a block table
iRetVal = ramdskPhyFmtChk();
if (iRetVal != RAMDSK_E_SUCCESS)
// - are made.
return iRetVal;
iRetVal = ramdskLogFmtChk();
if (iRetVal != RAMDSK_E_SUCCESS)
return iRetVal;
fatFatInit(pstParams);
return iRetVal;
}
/**** End of function *******************************************************/
/****************************************************************************
ramdskPhyFormat()
----------------------------------------------------------------------------
description:
RAMDSK
argument: (none)
unsigned long ulSelNum <in>
unsigned char **pbVolLbl <in>
FatInitParams_t *pstParams <in> FAT
unsigned char *pStrAdr <in> RAM Disk
unsigned long ulSize <in> RAM Disk [byte]
return:
int iRetVal <out> RAMDSK_E_SUCCESS:
RAMDSK_E_FAILURE:
input: (none)
output: (none)
flag: (none)
global: (none)
comment: (none)
RAMDSK GDIC
RAM Disk
****************************************************************************/
int ramdskPhyFormat(unsigned long ulSelNum, unsigned char **pbVolLbl,
FatInitParams_t *pstParams)
{
int iRetVal; // Return Value
/////////////////////////////
/// SMART MEDIA INITIALIZE //
/////////////////////////////
ramdskInitDev(pstParams);
///////////////////////
/// PHYSICAL FORMAT ///
///////////////////////
iRetVal = ramdskPhyFmtChk(); // Physical format check
if (iRetVal != RAMDSK_E_SUCCESS)
return iRetVal;
//////////////////////
/// LOGICAL FORMAT ///
//////////////////////
fatCacheRAMEntry(0);
iRetVal = ramdskLogFormat(ulSelNum, pbVolLbl, pstParams);
if (iRetVal != RAMDSK_E_SUCCESS)
return iRetVal;
return RAMDSK_E_SUCCESS;
}
/**** End of function *******************************************************/
/****************************************************************************
int ramdskLogFormat()
----------------------------------------------------------------------------
description:
RAMDSK
argument: (none)
return:
int iRetVal <out> RAMDSK_E_SUCCESS:
RAMDSK_E_FAILURE:
input: (none)
output: (none)
flag: (none)
global: (none)
comment:
****************************************************************************/
int ramdskLogFormat(unsigned long ulSelNum, unsigned char **pbVolLbl,
FatInitParams_t *pstParams)
{
int iRetVal; // Retuen Value
/////////////////////////////
/// SMART MEDIA INITIALIZE //
/////////////////////////////
ramdskInitDev(pstParams);
/////////////////////////////
/// PHYSICAL FORMAT CHECK ///
/////////////////////////////
iRetVal = ramdskPhyFmtChk(); // Physical format check
if(iRetVal != RAMDSK_E_SUCCESS)
return RAMDSK_E_FAILURE;
////////////////////////
/// MAKE DRIVE IMAGE ///
////////////////////////
ramdskMakeDriveImage();
////////////////////////////
/// LOGICAL FORMAT CHECK ///
////////////////////////////
if (ramdskLogFmtChk() != RAMDSK_E_SUCCESS)
// Check logical format
return RAMDSK_E_FAILURE;
////////////////////////////////////
/// SERIAL NUMBER & VOLUME LABEL ///
////////////////////////////////////
fatFatInit(pstParams);
fatCacheRAMEntry(0);
if (fatSetVolume(0, ulSelNum, pbVolLbl) != RAMDSK_E_SUCCESS)
return RAMDSK_E_FAILURE;
return RAMDSK_E_SUCCESS;
}
/**** End of function *******************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -