⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsys_affs.c

📁 open source bios with linux platform, very good and can be reused.
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef FSYS_AFFS#include "shared.h"#include "filesys.h"/******************************** RDB definitions */#define RDB_LOCATION_LIMIT 16#define IDNAME_RIGIDDISK   0x5244534B  /* 'RDSK' */struct RigidDiskBlock{    unsigned long   rdb_ID;    unsigned long   rdb_SummedLongs;    long            rdb_ChkSum;    unsigned long   rdb_HostID;    unsigned long   rdb_BlockBytes;    unsigned long   rdb_Flags;    unsigned long   rdb_BadBlockList;    unsigned long   rdb_PartitionList;    unsigned long   rdb_FileSysHeaderList;    unsigned long   rdb_DriveInit;    unsigned long   rdb_Reserved1[6];    unsigned long   rdb_Cylinders;    unsigned long   rdb_Sectors;    unsigned long   rdb_Heads;    unsigned long   rdb_Interleave;    unsigned long   rdb_Park;    unsigned long   rdb_Reserved2[3];    unsigned long   rdb_WritePreComp;    unsigned long   rdb_ReducedWrite;    unsigned long   rdb_StepRate;    unsigned long   rdb_Reserved3[5];    unsigned long   rdb_RDBBlocksLo;    unsigned long   rdb_RDBBlocksHi;    unsigned long   rdb_LoCylinder;    unsigned long   rdb_HiCylinder;    unsigned long   rdb_CylBlocks;    unsigned long   rdb_AutoParkSeconds;    unsigned long   rdb_HighRDSKBlock;    unsigned long   rdb_Reserved4;    char    rdb_DiskVendor[8];    char    rdb_DiskProduct[16];    char    rdb_DiskRevision[4];    char    rdb_ControllerVendor[8];    char    rdb_ControllerProduct[16];    char    rdb_ControllerRevision[4];    char    rdb_DriveInitName[40];};struct PartitionBlock{    unsigned long   pb_ID;    unsigned long   pb_SummedLongs;    long            pb_ChkSum;    unsigned long   pb_HostID;    unsigned long   pb_Next;    unsigned long   pb_Flags;    unsigned long   pb_Reserved1[2];    unsigned long   pb_DevFlags;    unsigned char   pb_DriveName[32];    unsigned long   pb_Reserved2[15];    unsigned long   pb_Environment[20];    unsigned long   pb_EReserved[12];};#define DE_TABLESIZE    0#define DE_SIZEBLOCK    1#define DE_BLOCKSIZE    2#define DE_NUMHEADS     3#define DE_SECSPERBLOCK 4#define DE_BLKSPERTRACK 5#define DE_RESERVEDBLKS 6#define DE_PREFAC       7#define DE_INTERLEAVE   8#define DE_LOWCYL       9#define DE_HIGHCYL      10#define DE_UPPERCYL     DE_HIGHCYL#define DE_NUMBUFFERS   11#define DE_BUFMEMTYPE   12#define DE_MEMBUFTYPE   DE_BUFMEMTYPE#define DE_MAXTRANSFER  13#define DE_MASK         14#define DE_BOOTPRI      15#define DE_DOSTYPE      16#define DE_BAUD         17#define DE_CONTROL      18#define DE_BOOTBLOCKS   19/******************************** AFFS definitions */#define T_SHORT		2#define T_LIST			16#define ST_FILE		-3#define ST_ROOT		1#define ST_USERDIR	2	struct BootBlock{	int id;	int chksum;	int rootblock;	int data[127];};struct RootBlock{	int p_type;					//0	int n1[2];					//1-2	int hashtable_size;		//3	int n2;						//4	int checksum;				//5	int hashtable[72];		//6-77	int bitmap_valid_flag;	//78	int bitmap_ptrs[25];		//79-103	int bitmap_extension;	//104	int root_days;				//105	int root_mins;				//106	int root_ticks;			//107;	char diskname[32];		//108-115	int n3[2];					//116-117	int volume_days;			//118	int volume_mins;			//119	int volume_ticks;			//120	int creation_days;		//121	int creation_mins;		//122	int creation_ticks;		//123	int n4[3];					//124-126	int s_type;					//127};struct DirHeader {	int p_type;					//0	int own_key;				//1	int n1[3];					//2-4	int checksum;				//5	int hashtable[72];		//6-77	int n2;						//78	int owner;					//79	int protection;			//80	int n3;						//81	char comment[92];			//82-104	int days;					//105	int mins;					//106	int ticks;					//107	char name[32];				//108-115	int n4[2];					//116-117	int linkchain;				//118	int n5[5];					//119-123	int hashchain;				//124	int parent;					//125	int n6;						//126	int s_type;					//127};struct FileHeader {	int p_type;					//0	int own_key;				//1	int n1[3];					//2-4	int checksum;				//5	int filekey_table[72];	//6-77	int n2;						//78	int owner;					//79	int protection;			//80	int bytesize;				//81	char comment[92];			//82-104	int days;					//105	int mins;					//106	int ticks;					//107	char name[32];				//108-115	int n3[2];					//116-117	int linkchain;				//118	int n4[5];					//119-123	int hashchain;				//124	int parent;					//125	int extension;				//126	int s_type;					//127};struct FileKeyExtension{	int p_type;					//0	int own_key;				//1	int table_size;			//2	int n1[2];					//3-4	int checksum;				//5	int filekey_table[72];	//6-77	int info[46];				//78-123	int n2;						//124	int parent;					//125	int extension;				//126	int s_type;					//127};struct Position {	unsigned int block;	short filekey;	unsigned short byte;	unsigned int offset;};struct ReadData {	unsigned int header_block;	struct Position current;	unsigned int filesize;};#warning "Big vs. little endian for configure needed"#define AROS_BE2LONG(l)	\	(                                  \	    ((((unsigned long)(l)) >> 24) & 0x000000FFUL) | \	    ((((unsigned long)(l)) >>  8) & 0x0000FF00UL) | \	    ((((unsigned long)(l)) <<  8) & 0x00FF0000UL) | \	    ((((unsigned long)(l)) << 24) & 0xFF000000UL)   \	)struct CacheBlock {	int blocknum;	unsigned short flags;	unsigned short access_count;	unsigned int blockbuffer[128];};#define LockBuffer(x) (((struct CacheBlock *)(x))->flags |= 0x0001)#define UnLockBuffer(x) (((struct CacheBlock *)(x))->flags &= ~0x0001)#define MAX_CACHE_BLOCKS 10struct FSysBuffer {	struct ReadData file;	struct CacheBlock blocks[MAX_CACHE_BLOCKS];};#define bootBlock(x) ((struct BootBlock *)(x)->blockbuffer)#define rootBlock(x) ((struct RootBlock *)(x)->blockbuffer)#define dirHeader(x) ((struct DirHeader *)(x)->blockbuffer)#define fileHeader(x) ((struct FileHeader *)(x)->blockbuffer)#define extensionBlock(x) ((struct FileKeyExtension *)(x)->blockbuffer)#define rdsk(x) ((struct RigidDiskBlock *)(x)->blockbuffer)#define part(x) ((struct PartitionBlock *)(x)->blockbuffer)struct FSysBuffer *fsysb;int blockoffset; /* offset if there is an embedded RDB partition */int rootb;       /* block number of root block */int rdbb;        /* block number of rdb block */void initCache() {int i;	for (i=0;i<MAX_CACHE_BLOCKS;i++)	{		fsysb->blocks[i].blocknum = -1;		fsysb->blocks[i].flags = 0;		fsysb->blocks[i].access_count = 0;	}}struct CacheBlock *getBlock(unsigned int block) {struct CacheBlock *freeblock;int i;	/* get first unlocked block */	i = 0;	do	{		freeblock = &fsysb->blocks[i++];	} while (freeblock->flags & 0x0001);	/* search through list if block is already loaded in */	for (i=0;i<MAX_CACHE_BLOCKS;i++)	{		if (fsysb->blocks[i].blocknum == block)		{			fsysb->blocks[i].access_count++;			return &fsysb->blocks[i];		}		if (!(fsysb->blocks[i].flags & 0x0001))			if (freeblock->access_count>fsysb->blocks[i].access_count)				freeblock = &fsysb->blocks[i];	}	freeblock->blocknum = block;	devread(block+blockoffset, 0, 512, (char *)freeblock->blockbuffer);	return freeblock;}unsigned int calcChkSum(unsigned short SizeBlock, unsigned int *buffer) {unsigned int sum=0,count=0;	for (count=0;count<SizeBlock;count++)		sum += AROS_BE2LONG(buffer[count]);	return sum;}int affs_mount(void) {struct CacheBlock *cblock;int i;	if (			(current_drive & 0x80) &&			(current_partition != 0xFFFFFF) &&			(current_slice != 0x30)		)		return 0;	fsysb = (struct FSysBuffer *)FSYS_BUF;	blockoffset = 0;	initCache();	/* check for rdb partitiontable */	for (i=0;i<RDB_LOCATION_LIMIT;i++)	{		cblock = getBlock(i);		if (				(					((AROS_BE2LONG(bootBlock(cblock)->id) & 0xFFFFFF00)==0x444F5300) &&					((AROS_BE2LONG(bootBlock(cblock)->id) & 0xFF)>0)				) ||				(AROS_BE2LONG(cblock->blockbuffer[0]) == IDNAME_RIGIDDISK)			)			break;	}	if (i == RDB_LOCATION_LIMIT)		return 0;	if (AROS_BE2LONG(cblock->blockbuffer[0]) == IDNAME_RIGIDDISK)	{		/* we have an RDB partition table within a MBR-Partition */		rdbb = i;	}	else if (i<2)	{		/* partition type is 0x30 = AROS and AFFS formatted */		rdbb = RDB_LOCATION_LIMIT;		rootb = (part_length-1+2)/2;		cblock = getBlock(rootb);		if (				(AROS_BE2LONG(rootBlock(cblock)->p_type) != T_SHORT) ||				(AROS_BE2LONG(rootBlock(cblock)->s_type) != ST_ROOT) ||				calcChkSum(128, cblock->blockbuffer)			)			return 0;	}	else		return 0;	return 1;}int seek(unsigned long offset) {struct CacheBlock *cblock;unsigned long block;unsigned long togo;	block = fsysb->file.header_block;	togo = offset / 512;	fsysb->file.current.filekey = 71-(togo % 72);	togo /= 72;	fsysb->file.current.byte = offset % 512;	fsysb->file.current.offset = offset;	while ((togo) && (block))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -