add scard libs

This commit is contained in:
optixx
2009-08-11 11:47:10 +02:00
parent 07086b2a3c
commit b47af2c376
139 changed files with 31430 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
CONFDIR=../../conf
include $(CONFDIR)/config.makefile
# VFAT includes do NOT belong here, remove them when VFS is implemented !
INC_VFAT=../fs/vfat/include
INCLUDEDIRS=-I../include -Iinclude -I$(CONFDIR) -I$(INC_VFAT)
CFLAGS= $(GCFLAGS) $(INCLUDEDIRS)
OBJ=debug.o disc.o efs.o extract.o sextract.o interface.o ioman.o partition.o plibc.o
all: efsl-base
efsl-base: $(OBJ)
$(AR) rcs efsl-base.a $(OBJ)
clean:
rm -f $(OBJ) efsl-base.a

View File

@@ -0,0 +1,333 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : debug.c *
* Release : 0.3 - devel *
* Description : These functions are used for debugging output on different *
* environments *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/* COMMENT REGARDING FUNCTION COMMENTS IN THIS FILE
* Only the linuxfile debug functions are commented since all functions
* perform the same logical task.
*/
/*****************************************************************************/
#include "debug.h"
/*****************************************************************************/
/*****************************************************************************/
#ifdef DEBUG
#ifdef HW_ENDPOINT_LINUX_ALL
/*****************************************************************************/
/* ****************************************************************************
* void debug(const eint8 *format, ...)
* Description: This function prints debug output to the screen (target dependant)
* and if DO_FUNC_DEBUG is defined also to a localfile.
* Return value: void
*/
void debug(const eint8 *format, ...)
{
va_list ap;
#ifdef DO_FUNC_DEBUG
euint8 c;
extern FILE* debugfile;
extern volatile euint8 tw;
#endif
va_start(ap, format);
vprintf(format,ap);
#ifdef DO_FUNC_DEBUG
for(c=0;c<tw+1;c++)
{
fprintf(debugfile," ");
}
vfprintf(debugfile,format,ap);
#endif
va_end(ap);
}
/*****************************************************************************/
/* ****************************************************************************
* void debug_funcin(const eint8 *format, ...)
* Description: This function marks the entrance of a function, which
* increments a tabfieldcounter. A tree like structure can the be found in the
* debugging file.
* Return value: void
*/
void debug_funcin(const eint8 *format, ...)
{
#ifdef DO_FUNC_DEBUG
eint8 c;
va_list ap;
extern FILE* debugfile;
extern volatile unsigned char tw;
if(debugfile==NULL)return;
for(c=0;c<tw;c++){
fprintf(debugfile," ");
}
va_start(ap, format);
vfprintf(debugfile,format,ap);
va_end(ap);
fprintf(debugfile,"\n");
tw++;
#endif
}
/*****************************************************************************/
/* ****************************************************************************
* void debug_funcout(const eint8 *format, ...)
* Description: Decrements the tabfieldcounter. This function is called everywhere
* a function is left.
* Return value: void
*/
void debug_funcout(const eint8 *format, ...)
{
#ifdef DO_FUNC_DEBUG
eint8 c;
va_list ap;
extern FILE* debugfile;
extern volatile euint8 tw;
if(debugfile==NULL)return;
if(tw>0)tw--;
for(c=0;c<tw;c++){
fprintf(debugfile," ");
}
va_start(ap, format);
vfprintf(debugfile,format,ap);
va_end(ap);
fprintf(debugfile,"\n");
#endif
}
/*****************************************************************************/
/* ****************************************************************************
* void debug_init()
* Description: This function optionally opens the debugfile, or does any other
* initialisation to enable debugoutput.
* Return value: void
*/
void debug_init()
{
#ifdef DO_FUNC_DEBUG
extern FILE* debugfile;
extern volatile unsigned char tw;
debugfile=NULL;
tw=0;
debugfile=fopen("DBG.OUT","w");
#endif
}
/*****************************************************************************/
/* ****************************************************************************
* void debug_end()
* Description: This function closes the debugfile.
* Return value: void
*/
void debug_end()
{
#ifdef DO_FUNC_DEBUG
extern FILE* debugfile;
fflush(debugfile);
fclose(debugfile);
#endif
}
/*****************************************************************************/
/*****************************************************************************/
#endif
#endif
/*****************************************************************************/
/*****************************************************************************/
#ifdef DEBUG
#ifdef HW_ENDPOINT_ATMEGA128_SD
/*****************************************************************************/
void debug(const eint8 *format, ...)
{
eint8 dbgstring[90];
va_list ap;
euint8 i=0;
eint8 c;
va_start(ap, format);
vsprintf_P(dbgstring, format, ap);
va_end(ap);
while (( (c=dbgstring[i++]) && (i<90) ))
debug_sendByte(c);
if(i>=90)
debug(PSTR("<BREAK>\n"));
}
/*****************************************************************************/
void debug_init(void)
{
unsigned short ubrr;
ubrr = ((unsigned short)DEBUG_UBRR);
switch(DEBUG_PORT){
case 0:
UBRR0H = (euint8) (ubrr>>8);
UBRR0L = (euint8) (ubrr);
UCSR0B = ( (1<<RXEN) | (1<<TXEN) );
break;
case 1:
UBRR1H = (euint8) (ubrr>>8);
UBRR1L = (euint8) (ubrr);
UCSR1B = ( (1<<RXEN) | (1<<TXEN) );
break;
default:
/* INVALID CONFIG FILE */
break;
}
}
/*****************************************************************************/
void debug_end(void)
{
/* Nothing to do here, function is here for compatibility */
}
/*****************************************************************************/
void debug_sendByte(euint8 data)
{
/* If sending a newline, add a return first */
if(data=='\n')
debug_sendByte('\r');
switch(DEBUG_PORT){
case 0:
while ( !(UCSR0A & (1<<UDRE0)) )
_NOP(); /* Wait for empty transmit buffer */
UDR0 = data; /* Start transmittion */
break;
case 1:
while ( !(UCSR1A & (1<<UDRE1)) )
_NOP(); /* Wait for empty transmit buffer */
UDR1 = data; /* Start transmittion */
break;
default:
/* INVALID CONFIG FILE */
break;
}
}
/*****************************************************************************/
unsigned char debug_getByte()
{
switch(DEBUG_PORT){
case 0:
while ( !(UCSR0A & (1<<RXC0)) )
_NOP();
return(UDR0);
break;
case 1:
while ( !(UCSR1A & (1<<RXC1)) )
_NOP();
return(UDR1);
break;
}
}
/*****************************************************************************/
euint8 debug_getString(euint8 *data,euint16 length)
{
euint8 i=0;
euint8 c;
do
{
c=debug_getByte();
if(c!='\n' && c!='\r')
data[i++]=c;
debug_sendByte(c);
}
while(c!='\n' && c!='\r' && i<length);
data[i]='\0';
return(i);
}
/*****************************************************************************/
/*****************************************************************************/
#endif
#endif
/*****************************************************************************/
/*****************************************************************************/
#ifdef DEBUG
#ifdef HW_ENDPOINT_DSP_TI6713_SD
/*****************************************************************************/
void dbg(const char *format, ...)
{
printf(format);
}
/*****************************************************************************/
void debug_init()
{
}
/*****************************************************************************/
void debug_end()
{
}
/*****************************************************************************/
/*****************************************************************************/
#endif
#endif
/*****************************************************************************/

View File

@@ -0,0 +1,90 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : disc.c *
* Release : 0.3 - devel *
* Description : This file contains the functions regarding the whole disc *
* such as loading the MBR and performing read/write tests. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "disc.h"
/*****************************************************************************/
/* ****************************************************************************
* void disc_initDisc(Disc *disc,hcInterface* source)
* Description: This initialises the disc by loading the MBR and setting the
* pointer to the hardware object.
*/
void disc_initDisc(Disc *disc,IOManager* ioman)
{
disc->ioman=ioman;
disc_setError(disc,DISC_NOERROR);
}
/*****************************************************************************/
/* ****************************************************************************
* euint8 disc_findPartition(Disc *disc, euint8 partitionType, euint8 partitionIndex, euint32* startSector, euint32* sectorCount)
* Description: Locates partition of type partitionType w/ index partitionIndex on the disc and returns
* the startsector and the size to the caller.
*/
euint8 disc_findPartition(Disc *disc, euint8 partitionType, euint8 partitionIndex, euint32* startSector, euint32* sectorCount)
{
/* For now we ignore the partitionIndex */
/* Partition buffering is also not here for memory saving reasons.
Add it later with compile time option */
euint8 c, *buf, currentIndex=0;
PartitionField pf;
/* Get the MBR */
buf = ioman_getSector(disc->ioman,LBA_ADDR_MBR,IOM_MODE_READONLY|IOM_MODE_EXP_REQ);
for(c=0;c<4;c++){
ex_getPartitionField(buf+(c*SIZE_PARTITION_FIELD),&pf);
if(pf.type==partitionType){
if(partitionIndex==currentIndex){
ioman_releaseSector(disc->ioman,buf);
*startSector = pf.LBA_begin;
*sectorCount = pf.numSectors;
return(0);
}else{
currentIndex++;
}
}
}
ioman_releaseSector(disc->ioman,buf);
return(1); /* Nothing found */
}

View File

@@ -0,0 +1,90 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : disc.c *
* Release : 0.3 - devel *
* Description : This file contains the functions regarding the whole disc *
* such as loading the MBR and performing read/write tests. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "disc.h"
/*****************************************************************************/
/* ****************************************************************************
* void disc_initDisc(Disc *disc,hcInterface* source)
* Description: This initialises the disc by loading the MBR and setting the
* pointer to the hardware object.
*/
void disc_initDisc(Disc *disc,IOManager* ioman)
{
disc->ioman=ioman;
disc_setError(disc,DISC_NOERROR);
}
/*****************************************************************************/
/* ****************************************************************************
* euint8 disc_findPartition(Disc *disc, euint8 partitionType, euint8 partitionIndex, euint32* startSector, euint32* sectorCount)
* Description: Locates partition of type partitionType w/ index partitionIndex on the disc and returns
* the startsector and the size to the caller.
*/
euint8 disc_findPartition(Disc *disc, euint8 partitionType, euint8 partitionIndex, euint32* startSector, euint32* sectorCount)
{
/* For now we ignore the partitionIndex */
/* Partition buffering is also not here for memory saving reasons.
Add it later with compile time option */
euint8 c, *buf, currentIndex=0;
PartitionField pf;
/* Get the MBR */
buf = ioman_getSector(disc->ioman,LBA_ADDR_MBR,IOM_MODE_READONLY|IOM_MODE_EXP_REQ);
for(c=0;c<4;c++){
ex_getPartitionField(buf+(c*SIZE_PARTITION_FIELD),&pf);
if(pf.type==partitionType){
if(partitionIndex==currentIndex){
ioman_releaseSector(disc->ioman,buf);
*startSector = pf.LBA_begin;
*sectorCount = pf.numSectors;
return(0);
}else{
currentIndex++;
}
}
}
ioman_releaseSector(disc->ioman,buf);
return(1); /* Nothing found */
}

View File

@@ -0,0 +1,92 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : efs.c *
* Release : 0.3 - devel *
* Description : This should become the wrapper around efs. It will contain *
* functions like efs_init etc. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "efs.h"
/*****************************************************************************/
/* This stuff must be rewritten and causes compile errors while the datastructures are in flux */
#if 0
esint8 efsl_initStorage(efsl_storage *efsl_storage,efsl_storage_conf *config)
{
if(if_init(&(efsl_storage->interface),
config->hwObject,
config->if_init_fptr,
config->if_read_fptr,
config->if_write_fptr,
config->if_ioctl_fptr)
){
return(-1);
}
if(ioman_init(&(efsl_storage->ioman),
&(efsl_storage->interface),
config->ioman_bufmem)
){
return(-1);
}
disc_initDisc(&(efsl_storage->disc),&(efsl_storage->ioman));
return(0);
}
/*****************************************************************************/
esint8 efsl_initFs(efsl_fs *efsl_filesystem,efsl_fs_conf *config)
{
efsl_filesystem->storage=config->storage;
if(config->no_partitions){
efsl_filesystem->storage->disc.partitions[0].type=0x0B;
efsl_filesystem->storage->disc.partitions[0].LBA_begin=0;
efsl_filesystem->storage->disc.partitions[0].numSectors=
efsl_filesystem->storage->interface.sectorCount;
}
part_initPartition(
&(efsl_filesystem->partition),
&(efsl_filesystem->storage->disc)
);
if(fs_initFs(&(efsl_filesystem->filesystem),&(efsl_filesystem->partition))){
return(-1);
}
return(0);
}
/*****************************************************************************/
#endif

View File

@@ -0,0 +1,91 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : efs.c *
* Release : 0.3 - devel *
* Description : This should become the wrapper around efs. It will contain *
* functions like efs_init etc. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "efs.h"
/*****************************************************************************/
/* This stuff must be rewritten and causes compile errors while the datastructures are in flux */
esint8 efsl_initStorage(efsl_storage *efsl_storage,efsl_storage_conf *config)
{
if(if_init(&(efsl_storage->interface),
config->hwObject,
config->if_init_fptr,
config->if_read_fptr,
config->if_write_fptr,
config->if_ioctl_fptr)
){
return(-1);
}
if(ioman_init(&(efsl_storage->ioman),
&(efsl_storage->interface),
config->ioman_bufmem)
){
return(-1);
}
disc_initDisc(&(efsl_storage->disc),&(efsl_storage->ioman));
return(0);
}
/*****************************************************************************/
esint8 efsl_initFs(efsl_fs *efsl_filesystem,efsl_fs_conf *config)
{
efsl_filesystem->storage=config->storage;
if(config->no_partitions){
efsl_filesystem->storage->disc.partitions[0].type=0x0B;
efsl_filesystem->storage->disc.partitions[0].LBA_begin=0;
efsl_filesystem->storage->disc.partitions[0].numSectors=
efsl_filesystem->storage->interface.sectorCount;
}
part_initPartition(
&(efsl_filesystem->partition),
&(efsl_filesystem->storage->disc)
);
if(fs_initFs(&(efsl_filesystem->filesystem),&(efsl_filesystem->partition))){
return(-1);
}
return(0);
}
/*****************************************************************************/

View File

@@ -0,0 +1,57 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : extract.c *
* Release : 0.3 - devel *
* Description : This file contains functions to copy structures that get *
* corrupted when using direct memory copy *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "extract.h"
/*****************************************************************************/
#if !(defined(BYTE_ALIGNMENT))
#warning "Compiling f_setbxx"
void ex_setb16(euint8* buf,euint16 data)
{
buf[1] = data>>8;
buf[0] = data>>0;
}
void ex_setb32(euint8* buf,euint32 data)
{
buf[3] = data>>24;
buf[2] = data>>16;
buf[1] = data>>8;
buf[0] = data>>0;
}
#endif

View File

@@ -0,0 +1,104 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : debug.h *
* Release : 0.3 - devel *
* Description : These functions are used for debugging output on different *
* environments *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __DEBUG_H__
#define __DEBUG_H__
/*****************************************************************************/
#include "types.h"
#include "config.h"
/*****************************************************************************/
#ifndef DEBUG
#define TXT(x) ;
#define DBG(x) ;
#define FUNC_IN(x) ;
#define FUNC_OUT(x) ;
#endif
#ifdef DEBUG
#ifdef HW_ENDPOINT_ATMEGA128_SD
#include <avr/io.h>
#include <compat/ina90.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#define TXT(x) PSTR(x)
#define DBG(x) debug x
#define FUNC_IN(x) ;
#define FUNC_OUT(x) ;
#endif
#ifdef HW_ENDPOINT_LINUX
#include <stdio.h>
#include <stdarg.h>
#define TXT(x) x
#define DBG(x) debug x
#define FUNC_IN(x) debug_funcin(x)
#define FUNC_OUT(x) debug_funcout(x)
#endif
#ifdef HW_ENDPOINT_DSP_TI6713_SD
#include <stdio.h>
#include <stdarg.h>
#define TXT(x) x
#define DBG(x) printf x
#define FUNC_IN(x) ;
#define FUNC_OUT(x) ;
#endif
void debug(const eint8 *format, ...);
void debug_init();
void debug_end();
#ifdef HW_ENDPOINT_LINUX
FILE* debugfile;
volatile euint8 tw;
void debug_funcin(const eint8 *format, ...);
void debug_funcout(const eint8 *format, ...);
euint8 debug_getByte();
euint8 debug_getString(euint8 *data,euint16 length);
#endif
#ifdef HW_ENDPOINT_ATMEGA128_SD
void debug_initUART(euint16 baudrate );
void debug_sendByte(euint8 data );
#endif
#endif
#endif

View File

@@ -0,0 +1,91 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : disc.h *
* Release : 0.3 - devel *
* Description : This file contains the functions regarding the whole disc *
* such as loading the MBR and performing read/write tests. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __DISC_H_
#define __DISC_H_
/*****************************************************************************/
#include "config.h"
#include "types.h"
#include "extract.h"
#include "debug.h"
#include "error.h"
#include "interface.h"
#include "ioman.h"
/*****************************************************************************/
#define LBA_ADDR_MBR 0
#define PARTITION_TABLE_OFFSET 0x1BE
/**********************************************************\
PartitionField
------------
* uchar type Type of partition
* ulong LBA_begin LBA address of first sector.
* ulong numSectors Number of 512byte sectors
This structure is a literal representation of a 16 byte
partitionfield. Direct I/O is possible.
\**********************************************************/
struct _PartitionField{
euint8 bootFlag;
euint8 CHS_begin[3];
euint8 type;
euint8 CHS_end[3];
euint32 LBA_begin;
euint32 numSectors;
};
typedef struct _PartitionField PartitionField;
#define SIZE_PARTITION_FIELD 16
/***************************************************************************************\
Disc
--
* CompactFlash* sourcedisc Pointer to the hardwareobject that this disc is on.
* PartitionField* partitions Array of PartitionFields, containing the partition info
\***************************************************************************************/
struct _Disc{
IOManager *ioman;
DISC_ERR_EUINT8
};
typedef struct _Disc Disc;
void disc_initDisc(Disc *disc,IOManager *ioman);
euint8 disc_findPartition(Disc *disc, euint8 partitionType, euint8 partitionIndex, euint32* startSector, euint32* sectorCount);
#include "sextract.h"
#endif

View File

@@ -0,0 +1,91 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : disc.h *
* Release : 0.3 - devel *
* Description : This file contains the functions regarding the whole disc *
* such as loading the MBR and performing read/write tests. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __DISC_H_
#define __DISC_H_
/*****************************************************************************/
#include "config.h"
#include "types.h"
#include "extract.h"
#include "debug.h"
#include "error.h"
#include "interface.h"
#include "ioman.h"
/*****************************************************************************/
#define LBA_ADDR_MBR 0
#define PARTITION_TABLE_OFFSET 0x1BE
/**********************************************************\
PartitionField
------------
* uchar type Type of partition
* ulong LBA_begin LBA address of first sector.
* ulong numSectors Number of 512byte sectors
This structure is a literal representation of a 16 byte
partitionfield. Direct I/O is possible.
\**********************************************************/
struct _PartitionField{
euint8 bootFlag;
euint8 CHS_begin[3];
euint8 type;
euint8 CHS_end[3];
euint32 LBA_begin;
euint32 numSectors;
};
typedef struct _PartitionField PartitionField;
#define SIZE_PARTITION_FIELD 16
/***************************************************************************************\
Disc
--
* CompactFlash* sourcedisc Pointer to the hardwareobject that this disc is on.
* PartitionField* partitions Array of PartitionFields, containing the partition info
\***************************************************************************************/
struct _Disc{
IOManager *ioman;
DISC_ERR_EUINT8
};
typedef struct _Disc Disc;
void disc_initDisc(Disc *disc,IOManager *ioman);
euint8 disc_findPartition(euint8 partitionType, euint8 partitionIndex, euint32* startSector, euint32* sectorCount);
#include "sextract.h"
#endif

View File

@@ -0,0 +1,101 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : efs.c *
* Release : 0.3 - devel *
* Description : This should become the wrapper around efs. It will contain *
* functions like efs_init etc. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __EFS_H__
#define __EFS_H__
/*****************************************************************************/
#include "types.h"
#include "config.h"
#include "extract.h"
#include "sextract.h"
#include "interface.h"
#include "disc.h"
#include "partition.h"
/* WARNING !!!!
* These includes DO NOT BELONG HERE,
* remove them when the VFS layer is implemented !!!!
*/
#include "fs.h"
#include "file.h"
#include "time.h"
#include "ui.h"
/*****************************************************************************/
#define LINUX_FILE_CONFIG 0x00
#define AVR_SD_CONFIG 0x01
/*****************************************************************************/
struct _efsl_storage {
Interface interface;
IOManager ioman;
Disc disc;
};
typedef struct _efsl_storage efsl_storage;
struct _efsl_storage_conf {
void *hwObject;
esint8 (*if_init_fptr)(void*);
esint8 (*if_read_fptr)(void*,euint32,euint8*);
esint8 (*if_write_fptr)(void*,euint32,euint8*);
esint8 (*if_ioctl_fptr)(void*,euint16,void*);
void *ioman_bufmem;
};
typedef struct _efsl_storage_conf efsl_storage_conf;
struct _efsl_fs {
efsl_storage *storage;
Partition partition;
FileSystem filesystem;
};
typedef struct _efsl_fs efsl_fs;
struct _efsl_fs_conf {
efsl_storage *storage;
euint8 no_partitions;
};
typedef struct _efsl_fs_conf efsl_fs_conf;
/*****************************************************************************/
esint8 efsl_initStorage(efsl_storage *efsl_storage,efsl_storage_conf *config);
esint8 efsl_initFs(efsl_fs *efsl_filesystem,efsl_fs_conf *config);
#endif

View File

@@ -0,0 +1,101 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : extract.h *
* Release : 0.3 - devel *
* Description : This file contains functions to copy structures that get *
* corrupted when using direct memory copy *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __EXTRACT_H_
#define __EXTRACT_H_
/*****************************************************************************/
#include "config.h"
#include "types.h"
/*****************************************************************************/
#if !(defined(HOST_LITTLE_ENDIAN)) && !(defined(HOST_BIG_ENDIAN))
#error Endianess undefined, see config.h
#elif defined(HOST_LITTLE_ENDIAN) && (defined(HOST_BIG_ENDIAN))
#error Endianess defined as little and big, see config.h
#endif
/*****************************************************************************/
#define end_conv16(x) ((((euint16)(x) & 0xff00) >> 8) | \
(((euint16)(x) & 0x00ff) << 8))
#define end_conv32(x) ((((euint32)(x) & 0xff000000) >> 24) | \
(((euint32)(x) & 0x00ff0000) >> 8) | \
(((euint32)(x) & 0x0000ff00) << 8) | \
(((euint32)(x) & 0x000000ff) << 24))
/*****************************************************************************/
#if defined(BYTE_ALIGNMENT)
#define ex_getb16(buf) (*((euint16*)(buf)))
#define ex_setb16(buf,data) *((euint16*)(buf))=(data)
#define ex_getb32(buf) (*((euint32*)(buf)))
#define ex_setb32(buf,data) *((euint32*)(buf))=(data)
#else
#define ex_getb16(buf) \
((euint16)(*((euint8*)(buf)+1)<<8) + \
(euint16)(*((euint8*)(buf)+0)<<0))
void ex_setb16(euint8* buf,euint16 data);
#define ex_getb32(buf) \
((euint32)(*((euint8*)(buf)+3)<<24) + \
(euint32)(*((euint8*)(buf)+2)<<16) + \
(euint32)(*((euint8*)(buf)+1)<<8) + \
(euint32)(*((euint8*)(buf)+0)<<0))
void ex_setb32(euint8* buf,euint32 data);
#endif
#if defined(HOST_LITTLE_ENDIAN)
#define ex_lth16(buf) ex_getb16(buf)
#define ex_lth32(buf) ex_getb32(buf)
#define ex_bth16(buf) end_conv16(ex_getb16(buf))
#define ex_bth32(buf) end_conv32(ex_getb32(buf))
#define ex_htl16(buf) ex_setb16(buf)
#define ex_htl32(buf) ex_setb32(buf)
#define ex_htb16(buf) ex_setb16(end_conv16(buf))
#define ex_htb32(buf) ex_setb32(end_conv32(buf))
#elif defined(HOST_BIG_ENDIAN)
#define ex_lth16(buf) end_conv16(ex_getb16(buf))
#define ex_lth32(buf) end_conv32(ex_getb32(buf))
#define ex_bth16(buf) ex_getb16(buf)
#define ex_bth32(buf) ex_getb32(buf)
#define ex_htl16(buf) ex_setb16(end_conv16(buf))
#define ex_htl32(buf) ex_setb32(end_conv32(buf))
#define ex_htb16(buf) ex_setb16(buf)
#define ex_htb32(buf) ex_setb32(buf)
#endif
#endif

View File

@@ -0,0 +1,85 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : interface.c *
* Release : 0.3 - devel *
* Description : This file defines the general I/O interface functions *
* that can be performed on hardware. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "config.h"
#include "types.h"
#include "ioctl.h"
#ifndef MULTIPLE_INTERFACE_SUPPORT
#include HWIFUNC_HEADER
#endif
#ifndef __INTERFACE_H_
#define __INTERFACE_H_
/* If no multiple interfaces are defined, check if the
hw functions are defines */
#ifndef MULTIPLE_INTERFACE_SUPPORT
#ifndef HWIFUNC_INIT
#error "There is no HW_INIT function defined"
#endif
#ifndef HWIFUNC_READ
#error "There is no HW_READ function defined"
#endif
#ifndef HWIFUNC_WRITE
#error "There is no HW_WRITE function defined"
#endif
#endif
struct _Interface{
#ifdef MULTIPLE_INTERFACE_SUPPORT
esint8 (*initInterface)(void*);
esint8 (*readBuf)(void*,euint32,euint8*);
esint8 (*writeBuf)(void*,euint32,euint8*);
esint8 (*ioctl)(void*,euint16,void*);
#endif
void* interface_data;
euint32 sectorCount;
euint8 flags;
};
typedef struct _Interface Interface;
esint8 if_init(Interface *iface, void* hwData,
esint8 (*initInterface)(void*),
esint8 (*readBuf) (void*, euint32,euint8*),
esint8 (*writeBuf) (void*, euint32,euint8*),
esint8 (*ioctl) (void*,euint16, void*));
esint8 if_readBuf(Interface *iface, euint32 address, euint8* buf);
esint8 if_writeBuf(Interface *iface, euint32 address, euint8* buf);
#endif

View File

@@ -0,0 +1,140 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : ioman.c *
* Release : 0.3 - devel *
* Description : The IO Manager receives all requests for sectors in a central *
* allowing it to make smart decision regarding caching. *
* The IOMAN_NUMBUFFER parameter determines how many sectors *
* ioman can cache. ioman also supports overallocating and *
* backtracking sectors. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __IOMAN_H__
#define __IOMAN_H__
/*****************************************************************************/
#include "interface.h"
#include "error.h"
#include "plibc.h"
#include "debug.h"
#include "types.h"
#include "config.h"
/*****************************************************************************/
#define IOMAN_STATUS_ATTR_VALIDDATA 0
#define IOMAN_STATUS_ATTR_USERBUFFER 1
#define IOMAN_STATUS_ATTR_WRITE 2
#define IOM_MODE_READONLY 1
#define IOM_MODE_READWRITE 2
#define IOM_MODE_EXP_REQ 4
struct _IOManStack{
euint32 sector;
euint8 status;
euint8 usage;
};
typedef struct _IOManStack IOManStack;
struct _IOManager{
Interface *iface;
euint8 *bufptr;
euint16 numbuf;
euint16 numit;
IOMAN_ERR_EUINT8
IOManStack stack[IOMAN_NUMBUFFER][IOMAN_NUMITERATIONS];
euint32 sector[IOMAN_NUMBUFFER];
euint8 status[IOMAN_NUMBUFFER];
euint8 usage[IOMAN_NUMBUFFER];
euint8 reference[IOMAN_NUMBUFFER];
euint8 itptr[IOMAN_NUMBUFFER];
#ifdef IOMAN_DO_MEMALLOC
euint8 cache_mem[IOMAN_NUMBUFFER * 512];
#endif
};
typedef struct _IOManager IOManager;
#define IOBJ ioman
#define ioman_isValid(bp) ioman_getAttr(IOBJ,bp,IOMAN_STATUS_ATTR_VALIDDATA)
#define ioman_isUserBuf(bp) ioman_getAttr(IOBJ,bp,IOMAN_STATUS_ATTR_USERBUFFER)
#define ioman_isWritable(bp) ioman_getAttr(IOBJ,bp,IOMAN_STATUS_ATTR_WRITE)
#define ioman_setValid(bp) ioman_setAttr(IOBJ,bp,IOMAN_STATUS_ATTR_VALIDDATA,1)
#define ioman_setUserBuf(bp) ioman_setAttr(IOBJ,bp,IOMAN_STATUS_ATTR_USERBUFFER,1)
#define ioman_setWritable(bp) ioman_setAttr(IOBJ,bp,IOMAN_STATUS_ATTR_WRITE,1)
#define ioman_setNotValid(bp) ioman_setAttr(IOBJ,bp,IOMAN_STATUS_ATTR_VALIDDATA,0)
#define ioman_setNotUserBuf(bp) ioman_setAttr(IOBJ,bp,IOMAN_STATUS_ATTR_USERBUFFER,0)
#define ioman_setNotWritable(bp) ioman_setAttr(IOBJ,bp,IOMAN_STATUS_ATTR_WRITE,0)
#define ioman_isReqRo(mode) ((mode)&(IOM_MODE_READONLY))
#define ioman_isReqRw(mode) ((mode)&(IOM_MODE_READWRITE))
#define ioman_isReqExp(mode) ((mode)&(IOM_MODE_EXP_REQ))
esint8 ioman_init(IOManager *ioman, Interface *iface, euint8* bufferarea);
void ioman_reset(IOManager *ioman);
euint8* ioman_getBuffer(IOManager *ioman,euint8* bufferarea);
void ioman_setAttr(IOManager *ioman,euint16 bufplace,euint8 attribute,euint8 val);
euint8 ioman_getAttr(IOManager *ioman,euint16 bufplace,euint8 attribute);
euint8 ioman_getUseCnt(IOManager *ioman,euint16 bufplace);
void ioman_incUseCnt(IOManager *ioman,euint16 bufplace);
void ioman_decUseCnt(IOManager *ioman,euint16 bufplace);
void ioman_resetUseCnt(IOManager *ioman,euint16 bufplace);
euint8 ioman_getRefCnt(IOManager *ioman,euint16 bufplace);
void ioman_incRefCnt(IOManager *ioman,euint16 bufplace);
void ioman_decRefCnt(IOManager *ioman,euint16 bufplace);
void ioman_resetRefCnt(IOManager *ioman,euint16 bufplace);
esint8 ioman_pop(IOManager *ioman,euint16 bufplace);
esint8 ioman_push(IOManager *ioman,euint16 bufplace);
euint8* ioman_getPtr(IOManager *ioman,euint16 bufplace);
esint16 ioman_getBp(IOManager *ioman,euint8* buf);
esint8 ioman_readSector(IOManager *ioman,euint32 address,euint8* buf);
esint8 ioman_writeSector(IOManager *ioman, euint32 address, euint8* buf);
void ioman_resetCacheItem(IOManager *ioman,euint16 bufplace);
esint32 ioman_findSectorInCache(IOManager *ioman, euint32 address);
esint32 ioman_findFreeSpot(IOManager *ioman);
esint32 ioman_findUnusedSpot(IOManager *ioman);
esint32 ioman_findOverallocableSpot(IOManager *ioman);
esint8 ioman_putSectorInCache(IOManager *ioman,euint32 address, euint16 bufplace);
esint8 ioman_flushSector(IOManager *ioman, euint16 bufplace);
euint8* ioman_getSector(IOManager *ioman,euint32 address, euint8 mode);
esint8 ioman_releaseSector(IOManager *ioman,euint8* buf);
esint8 ioman_directSectorRead(IOManager *ioman,euint32 address, euint8* buf);
esint8 ioman_directSectorWrite(IOManager *ioman,euint32 address, euint8* buf);
esint8 ioman_flushRange(IOManager *ioman,euint32 address_low, euint32 address_high);
esint8 ioman_flushAll(IOManager *ioman);
void ioman_printStatus(IOManager *ioman);
#endif

View File

@@ -0,0 +1,97 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : ioman_small.c *
* Release : 0.3 - devel *
* Description : The IO Manager receives all requests for sectors in a central *
* allowing it to make smart decision regarding caching. *
* The IOMAN_NUMBUFFER parameter determines how many sectors *
* ioman can cache. ioman also supports overallocating and *
* backtracking sectors. *
* This is the small version of IOMan, for systems with limited *
* resources. It features only one fixed buffer, and has *
* simplified operation *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "interface.h"
#include "error.h"
#include "plibc.h"
#include "debug.h"
#include "types.h"
#include "config.h"
#define IOMAN_STATUS_ATTR_VALIDDATA 0
#define IOMAN_STATUS_ATTR_USERBUFFER 1
#define IOMAN_STATUS_ATTR_WRITE 2
#define IOM_MODE_READONLY 1
#define IOM_MODE_READWRITE 2
#define IOM_MODE_EXP_REQ 4
struct _IOManStack{
euint32 sector;
euint8 status;
};
typedef struct _IOManStack IOManStack;
struct _IOManager{
Interface *iface;
euint8 bufptr[512];
IOMAN_ERR_EUINT8
euint32 sector;
euint8 status;
euint8 itptr;
IOManStack stack;
};
typedef struct _IOManager IOManager;
#define IOBJ ioman
#define ioman_isValid() ioman_getAttr(IOBJ,IOMAN_STATUS_ATTR_VALIDDATA)
#define ioman_isUserBuf() ioman_getAttr(IOBJ,IOMAN_STATUS_ATTR_USERBUFFER)
#define ioman_isWritable() ioman_getAttr(IOBJ,IOMAN_STATUS_ATTR_WRITE)
#define ioman_setValid() ioman_setAttr(IOBJ,IOMAN_STATUS_ATTR_VALIDDATA,1)
#define ioman_setUserBuf() ioman_setAttr(IOBJ,IOMAN_STATUS_ATTR_USERBUFFER,1)
#define ioman_setWritable() ioman_setAttr(IOBJ,IOMAN_STATUS_ATTR_WRITE,1)
#define ioman_setNotValid() ioman_setAttr(IOBJ,IOMAN_STATUS_ATTR_VALIDDATA,0)
#define ioman_setNotUserBuf() ioman_setAttr(IOBJ,IOMAN_STATUS_ATTR_USERBUFFER,0)
#define ioman_setNotWritable() ioman_setAttr(IOBJ,IOMAN_STATUS_ATTR_WRITE,0)
#define ioman_isReqRo(mode) ((mode)&(IOM_MODE_READONLY))
#define ioman_isReqRw(mode) ((mode)&(IOM_MODE_READWRITE))
#define ioman_isReqExp(mode) ((mode)&(IOM_MODE_EXP_REQ))
esint8 ioman_init(IOManager *ioman, Interface *iface, euint8* bufferarea);
void ioman_reset(IOManager *ioman);
void ioman_setAttr(IOManager *ioman,euint8 attribute,euint8 val);
euint8 ioman_getAttr(IOManager *ioman,euint8 attribute);

View File

@@ -0,0 +1,80 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : partition.c *
* Release : 0.3 - devel *
* Description : These functions are partition specific. Searching FAT type *
* partitions and read/write functions to partitions. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __PARTITION_H__
#define __PARTITION_H__
/*****************************************************************************/
#include "config.h"
#include "error.h"
#include "interface.h"
#include "disc.h"
#include "types.h"
/*****************************************************************************/
#define PT_EMPTY 0x00
#define PT_FAT12 0x01
#define PT_FAT16A 0x04
#define PT_EXTENDED 0x05
#define PT_FAT16 0x06
#define PT_FAT32 0x0B
#define PT_FAT32A 0x5C
#define PT_FAT16B 0x5E
/*************************************************************************************\
Partition
-------
* Disc* disc Pointer to disc containing this partition.
* eint8 activePartition Array subscript for disc->partitions[activePartition]
\*************************************************************************************/
struct _Partition{
Disc *disc;
euint32 LBA_offset;
euint32 LBA_sectorcount;
};
typedef struct _Partition Partition;
void part_initPartition(Partition *part,Disc* refDisc);
euint8* part_getSect(Partition *part, euint32 address,euint8 mode);
esint8 part_relSect(Partition *part, euint8* buf);
esint8 part_flushPart(Partition *part,euint32 addr_l, euint32 addr_h);
esint8 part_directSectorRead(Partition *part, euint32 address, euint8* buf);
esint8 part_directSectorWrite(Partition *part, euint32 address, euint8* buf);
#include "extract.h"
#endif

View File

@@ -0,0 +1,81 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : partition.c *
* Release : 0.3 - devel *
* Description : These functions are partition specific. Searching FAT type *
* partitions and read/write functions to partitions. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __PARTITION_H__
#define __PARTITION_H__
/*****************************************************************************/
#include "config.h"
#include "error.h"
#include "interface.h"
#include "disc.h"
#include "types.h"
/*****************************************************************************/
#define PT_EMPTY 0x00
#define PT_FAT12 0x01
#define PT_FAT16A 0x04
#define PT_EXTENDED 0x05
#define PT_FAT16 0x06
#define PT_FAT32 0x0B
#define PT_FAT32A 0x5C
#define PT_FAT16B 0x5E
/*************************************************************************************\
Partition
-------
* Disc* disc Pointer to disc containing this partition.
* eint8 activePartition Array subscript for disc->partitions[activePartition]
\*************************************************************************************/
struct _Partition{
Disc *disc;
euint32 LBA_offset;
euint32 LBA_sectorcount;
};
typedef struct _Partition Partition;
void part_initPartition(Partition *part,Disc* refDisc);
euint8* part_getSect(Partition *part, euint32 address,euint8 mode);
esint8 part_relSect(Partition *part, euint8* buf);
esint8 part_flushPart(Partition *part,euint32 addr_l, euint32 addr_h);
esint8 part_directSectorRead(Partition *part, euint32 address, euint8* buf);
esint8 part_directSectorWrite(Partition *part, euint32 address, euint8* buf);
euint32 part_getRealLBA(Partition *part,euint32 address);
#include "extract.h"
#endif

View File

@@ -0,0 +1,49 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : plibc.c *
* Release : 0.3 - devel *
* Description : This file contains replacements of common c library functions *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __PLIBC_H__
#define __PLIBC_H__
/*****************************************************************************/
#include "debug.h"
#include "types.h"
#include "config.h"
/*****************************************************************************/
euint16 strMatch(eint8* bufa, eint8*bufb,euint32 n);
void memCpy(void* psrc, void* pdest, euint32 size);
void memClr(void *pdest,euint32 size);
void memSet(void *pdest,euint32 size,euint8 data);
#endif

View File

@@ -0,0 +1,52 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : sextract.c *
* Release : 0.3 - devel *
* Description : The function in this file are to load and set the structures *
* as found on the disc, only those structures for the entire *
* library are located here, filesystem specific ones are in *
* that filesystems directory *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#ifndef __SEXTRACT_H_
#define __SEXTRACT_H_
#include "config.h"
#include "types.h"
#include "extract.h"
#include "disc.h"
/*#include "partition.h"*/
void ex_setPartitionField(euint8* buf,PartitionField* pf);
void ex_getPartitionField(euint8* buf,PartitionField* pf);
#endif

View File

@@ -0,0 +1,83 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : interface.c *
* Release : 0.3 - devel *
* Description : This file defines the general I/O interface functions *
* that can be performed on hardware. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "interface.h"
esint8 if_init(Interface *iface, void* hwData,
esint8 (*initInterface)(void*),
esint8 (*readBuf) (void*, euint32,euint8*),
esint8 (*writeBuf) (void*, euint32,euint8*),
esint8 (*ioctl) (void*,euint16,void*))
{
esint8 r;
iface->flags=0;
iface->sectorCount=0;
iface->interface_data=hwData;
#ifdef MULTIPLE_INTERFACE_SUPPORT
iface->initInterface=initInterface;
iface->readBuf=readBuf;
iface->writeBuf=writeBuf;
iface->ioctl=ioctl;
r=iface->initInterface(iface->interface_data);
#else
r=HWIFUNC_INIT(iface->interface_data);
#endif
if(!r){ /* Init OK, try to get some info */
if(iface->ioctl(iface->interface_data,IOCTL_SECTORCOUNT,(void*)&(iface->sectorCount))){
iface->sectorCount=0; /* Device doesn't know */
}
}
return(r);
}
esint8 if_readBuf(Interface *iface, euint32 address, euint8* buf)
{
#ifdef MULTIPLE_INTERFACE_SUPPORT
return(iface->readBuf(iface->interface_data,address,buf));
#else
return(HWIFUNC_READ(iface->interface_data,address,buf));
#endif
}
esint8 if_writeBuf(Interface *iface, euint32 address, euint8* buf)
{
#ifdef MULTIPLE_INTERFACE_SUPPORT
return(iface->writeBuf(iface->interface_data,address,buf));
#else
return(HWIFUNC_WRITE(iface->interface_data,address,buf));
#endif
}

View File

@@ -0,0 +1,83 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : interface.c *
* Release : 0.3 - devel *
* Description : This file defines the general I/O interface functions *
* that can be performed on hardware. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "interface.h"
esint8 if_init(Interface *iface, void* hwData,
esint8 (*initInterface)(void*),
esint8 (*readBuf) (void*, euint32,euint8*),
esint8 (*writeBuf) (void*, euint32,euint8*),
esint8 (*ioctl) (void*,euint16,void*))
{
esint8 r;
iface->flags=0;
iface->sectorCount=0;
iface->interface_data=hwData;
#ifdef MULTIPLE_INTERFACE_SUPPORT
iface->initInterface=initInterface;
iface->readBuf=readBuf;
iface->writeBuf=writeBuf;
iface->ioctl=ioctl;
r=iface->initInterface(iface->interface_data);
#else
r=HWIFUNC_INIT(iface->interface_data);
#endif
if(!r){ /* Init OK, try to get some info */
if(iface->ioctl(iface->interface_data,IOCTL_SECTORCOUNT,(void*)&(iface->sectorCount))){
iface->sectorCount=0; /* Device doesn't know */
}
}
return(r);
}
esint8 if_readBuf(Interface *iface, euint32 address, euint8* buf)
{
#ifdef MULTIPLE_INTERFACE_SUPPORT
return(iface->readBuf(iface->interface_data,address,buf));
#else
return(HWIFUNC_READ(iface->interface_data,address,buf));
#endif
}
esint8 if_writeBuf(Interface *iface, euint32 address, euint8* buf)
{
#ifdef MULTIPLE_INTERFACE_SUPPORT
return(iface->writeBuf(iface->interface_data,address,buf));
#else
return(HWIFUNC_WRITE(iface->interface_data,address,buf));
#endif
}

View File

@@ -0,0 +1,595 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : ioman.c *
* Release : 0.3 - devel *
* Description : The IO Manager receives all requests for sectors in a central *
* allowing it to make smart decision regarding caching. *
* The IOMAN_NUMBUFFER parameter determines how many sectors *
* ioman can cache. ioman also supports overallocating and *
* backtracking sectors. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "ioman.h"
/*****************************************************************************/
esint8 ioman_init(IOManager *ioman, Interface *iface, euint8* bufferarea)
{
ioman->iface=iface;
ioman->bufptr = ioman_getBuffer(ioman,bufferarea);
ioman->numbuf = IOMAN_NUMBUFFER;
ioman->numit = IOMAN_NUMITERATIONS;
ioman_reset(ioman);
return(0);
}
/*****************************************************************************/
void ioman_reset(IOManager *ioman)
{
euint16 nb,ni;
memClr(ioman->sector,sizeof(euint32)*ioman->numbuf);
memClr(ioman->status,sizeof(euint8) *ioman->numbuf);
memClr(ioman->usage ,sizeof(euint8) *ioman->numbuf);
memClr(ioman->itptr ,sizeof(euint8) *ioman->numbuf);
ioman_setError(ioman,IOMAN_NOERROR);
for(nb=0;nb<ioman->numbuf;nb++){
for(ni=0;ni<ioman->numit;ni++){
ioman->stack[nb][ni].sector=0;
ioman->stack[nb][ni].status=0;
ioman->stack[nb][ni].usage =0;
}
}
}
/*****************************************************************************/
euint8* ioman_getBuffer(IOManager *ioman,euint8* bufferarea)
{
#ifdef IOMAN_DO_MEMALLOC
return(ioman->cache_mem);
#else
return(bufferarea);
#endif
}
/*****************************************************************************/
void ioman_setAttr(IOManager *ioman,euint16 bufplace,euint8 attribute,euint8 val)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_SETATTROUTOFBOUNDS);
return; /* Out of bounds */
}
if(val){
ioman->status[bufplace]|=1<<attribute;
}else{
ioman->status[bufplace]&=~(1<<attribute);
}
}
/*****************************************************************************/
euint8 ioman_getAttr(IOManager *ioman,euint16 bufplace,euint8 attribute)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_GETATTROUTOFBOUNDS);
return(0xFF); /* Out of bounds */
}
return(ioman->status[bufplace]&(1<<attribute));
}
/*****************************************************************************/
euint8 ioman_getUseCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return(0x00);
}
return(ioman->usage[bufplace]);
}
/*****************************************************************************/
void ioman_incUseCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
if(ioman->usage[bufplace]==0xFF)return;
else ioman->usage[bufplace]++;
}
/*****************************************************************************/
void ioman_decUseCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
if(ioman->usage[bufplace]==0x0)return;
else ioman->usage[bufplace]--;
}
/*****************************************************************************/
void ioman_resetUseCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
ioman->usage[bufplace]=0x00;
}
/*****************************************************************************/
euint8 ioman_getRefCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return(0x00);
}
return(ioman->reference[bufplace]);
}
/*****************************************************************************/
void ioman_incRefCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
if(ioman->reference[bufplace]==0xFF)return;
else ioman->reference[bufplace]++;
}
/*****************************************************************************/
void ioman_decRefCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
if(ioman->reference[bufplace]==0x00)return;
else ioman->reference[bufplace]--;
}
/*****************************************************************************/
void ioman_resetRefCnt(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
ioman->reference[bufplace]=0x00;
}
/*****************************************************************************/
esint8 ioman_pop(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_POPEMPTYSTACK);
return(-1);
}
if(ioman->itptr[bufplace]==0 || ioman->itptr[bufplace]>IOMAN_NUMITERATIONS)return(-1);
ioman->sector[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].sector;
ioman->status[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].status;
ioman->usage[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].usage;
ioman->itptr[bufplace]--;
return(0);
}
/*****************************************************************************/
esint8 ioman_push(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return(-1);
}
if(ioman->itptr[bufplace]>=IOMAN_NUMITERATIONS){
ioman_setError(ioman,IOMAN_ERR_PUSHBEYONDSTACK);
return(-1);
}
ioman->itptr[bufplace]++;
ioman->stack[bufplace][ioman->itptr[bufplace]].sector = ioman->sector[bufplace];
ioman->stack[bufplace][ioman->itptr[bufplace]].status = ioman->status[bufplace];
ioman->stack[bufplace][ioman->itptr[bufplace]].usage = ioman->usage[bufplace];
return(0);
}
/*****************************************************************************/
euint8* ioman_getPtr(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return(0);
}
return(ioman->bufptr+bufplace*512);
}
/*****************************************************************************/
esint16 ioman_getBp(IOManager *ioman,euint8* buf)
{
if(buf<(ioman->bufptr) || buf>=( ioman->bufptr+(ioman->numbuf*512) )){
ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
return(-1);
}
return((buf-(ioman->bufptr))/512);
}
/*****************************************************************************/
esint8 ioman_readSector(IOManager *ioman,euint32 address,euint8* buf)
{
esint8 r;
if(buf==0){
return(-1);
}
r=if_readBuf(ioman->iface,address,buf);
if(r!=0){
ioman_setError(ioman,IOMAN_ERR_READFAIL);
return(-1);
}
return(0);
}
/*****************************************************************************/
esint8 ioman_writeSector(IOManager *ioman, euint32 address, euint8* buf)
{
esint8 r;
if(buf==0)return(-1);
r=if_writeBuf(ioman->iface,address,buf);
if(r<=0){
ioman_setError(ioman,IOMAN_ERR_WRITEFAIL);
return(-1);
}
return(0);
}
/*****************************************************************************/
void ioman_resetCacheItem(IOManager *ioman,euint16 bufplace)
{
if(bufplace>=ioman->numbuf){
ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
return;
}
ioman->sector[bufplace] = 0;
ioman->status[bufplace] = 0;
ioman->usage[bufplace] = 0;
ioman->reference[bufplace] = 0;
}
/*****************************************************************************/
esint32 ioman_findSectorInCache(IOManager *ioman, euint32 address)
{
euint16 c;
for(c=0;c<ioman->numbuf;c++){
if(ioman_isValid(c) && ioman->sector[c] == address)return(c);
}
return(-1);
}
/*****************************************************************************/
esint32 ioman_findFreeSpot(IOManager *ioman)
{
euint16 c;
for(c=0;c<ioman->numbuf;c++){
if(!ioman_isValid(c))return(c);
}
return(-1);
}
/*****************************************************************************/
esint32 ioman_findUnusedSpot(IOManager *ioman)
{
esint32 r=-1;
euint16 c;
euint8 fr=0,lr=0xFF;
for(c=0;c<ioman->numbuf;c++){
if(ioman_getUseCnt(ioman,c)==0){
if(!ioman_isWritable(c) && !fr){
fr=1;
lr=0xFF;
r=-1;
}
if(ioman_isWritable(c) && !fr){
if(ioman_getRefCnt(ioman,c)<=lr){
r=c;
lr=ioman_getRefCnt(ioman,c);
}
}
if(fr && !ioman_isWritable(c)){
if(ioman_getRefCnt(ioman,c)<=lr){
r=c;
lr=ioman_getRefCnt(ioman,c);
}
}
}
}
return(r);
}
/*****************************************************************************/
esint32 ioman_findOverallocableSpot(IOManager *ioman)
{
euint8 points,lp=0xFF;
euint16 c;
esint32 r=-1;
for(c=0;c<ioman->numbuf;c++){
if(ioman->itptr[c]<ioman->numit){
points = 0;
if(ioman_isWritable(c))points+=0x7F;
points += ((euint16)(ioman->itptr[c]*0x4D))/(ioman->numit);
points += ((euint16)(ioman_getRefCnt(ioman,c)*0x33))/0xFF;
if(points<lp){
lp=points;
r=c;
}
}
}
return(r);
}
/*****************************************************************************/
esint8 ioman_putSectorInCache(IOManager *ioman, euint32 address, euint16 bufplace)
{
euint8* buf;
if((buf = ioman_getPtr(ioman,bufplace))==0){
ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
return(-1);
}
if((ioman_readSector(ioman,address,buf))){
ioman_setError(ioman,IOMAN_ERR_READFAIL);
return(-1);
}
ioman_setValid(bufplace);
ioman->sector[bufplace]=address;
return(0);
}
/***************** if(bufplace>=ioman->numbuf)return;
************************************************************/
esint8 ioman_flushSector(IOManager *ioman, euint16 bufplace)
{
euint8* buf;
if((buf = ioman_getPtr(ioman,bufplace))==0){
ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
return(-1);
}
if(!ioman_isWritable(bufplace)){
ioman_setError(ioman,IOMAN_ERR_WRITEREADONLYSECTOR);
return(-1);
}
if(!(ioman_writeSector(ioman,ioman->sector[bufplace],buf))){ /* ERROR HERE STILL TO BE FIXED -> ! must be removed! */
ioman_setError(ioman,IOMAN_ERR_WRITEFAIL);
return(-1);
}
if(ioman->usage==0)ioman_setNotWritable(bufplace);
return(0);
}
/*****************************************************************************/
esint8 ioman_flushRange(IOManager *ioman,euint32 address_low, euint32 address_high)
{
euint32 c;
if(address_low>address_high){
c=address_low; address_low=address_high;address_high=c;
}
for(c=0;c<ioman->numbuf;c++){
if((ioman->sector[c]>=address_low) && (ioman->sector[c]<=address_high) && (ioman_isWritable(c))){
if(ioman_flushSector(ioman,c)){
return(-1);
}
if(ioman->usage[c]==0)ioman_setNotWritable(c);
}
}
return(0);
}
/*****************************************************************************/
esint8 ioman_flushAll(IOManager *ioman)
{
euint16 c;
for(c=0;c<ioman->numbuf;c++){
if(ioman_isWritable(c)){
if(ioman_flushSector(ioman,c)){
return(-1);
}
if(ioman->usage[c]==0)ioman_setNotWritable(c);
}
}
return(0);
}
/*****************************************************************************/
euint8* ioman_getSector(IOManager *ioman,euint32 address, euint8 mode)
{
esint32 bp;
if((bp=ioman_findSectorInCache(ioman,address))!=-1){
if(ioman_isReqRw(mode)){
ioman_setWritable(bp);
}
ioman_incUseCnt(ioman,bp);
if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
return(ioman_getPtr(ioman,bp));
}
if((bp=ioman_findFreeSpot(ioman))==-1){
if(((bp=ioman_findUnusedSpot(ioman))!=-1)&&(ioman_isWritable(bp))){
ioman_flushSector(ioman,bp);
}
}
if(bp!=-1){
ioman_resetCacheItem(ioman,bp);
if((ioman_putSectorInCache(ioman,address,bp))){
return(0);
}
if(mode==IOM_MODE_READWRITE){
ioman_setWritable(bp);
}
ioman_incUseCnt(ioman,bp);
if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
return(ioman_getPtr(ioman,bp));
}
if((bp=ioman_findOverallocableSpot(ioman))!=-1){
if(ioman_isWritable(bp)){
ioman_flushSector(ioman,bp);
}
if(ioman_push(ioman,bp)){
return(0);
}
ioman_resetCacheItem(ioman,bp);
if((ioman_putSectorInCache(ioman,address,bp))){
return(0);
}
if(ioman_isReqRw(mode)){
ioman_setWritable(bp);
}
ioman_incUseCnt(ioman,bp);
if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
return(ioman_getPtr(ioman,bp));
}
ioman_setError(ioman,IOMAN_ERR_NOMEMORY);
return(0);
}
/*****************************************************************************/
esint8 ioman_releaseSector(IOManager *ioman,euint8* buf)
{
euint16 bp;
bp=ioman_getBp(ioman,buf);
ioman_decUseCnt(ioman,bp);
if(ioman_getUseCnt(ioman,bp)==0 && ioman->itptr[bp]!=0){
if(ioman_isWritable(bp)){
ioman_flushSector(ioman,bp);
}
ioman_pop(ioman,bp);
ioman_putSectorInCache(ioman,ioman->sector[bp],bp);
}
return(0);
}
/*****************************************************************************/
esint8 ioman_directSectorRead(IOManager *ioman,euint32 address, euint8* buf)
{
euint8* ibuf;
esint16 bp;
if((bp=ioman_findSectorInCache(ioman,address))!=-1){
ibuf=ioman_getPtr(ioman,bp);
memCpy(ibuf,buf,512);
return(0);
}
if((bp=ioman_findFreeSpot(ioman))!=-1){
if((ioman_putSectorInCache(ioman,address,bp))){
return(-1);
}
ibuf=ioman_getPtr(ioman,bp);
memCpy(ibuf,buf,512);
return(0);
}
if(ioman_readSector(ioman,address,buf)){
return(-1);
}
return(0);
}
/*****************************************************************************/
esint8 ioman_directSectorWrite(IOManager *ioman,euint32 address, euint8* buf)
{
euint8* ibuf;
esint16 bp;
if((bp=ioman_findSectorInCache(ioman,address))!=-1){
ibuf=ioman_getPtr(ioman,bp);
memCpy(buf,ibuf,512);
ioman_setWritable(bp);
return(0);
}
if((bp=ioman_findFreeSpot(ioman))!=-1){
ibuf=ioman_getPtr(ioman,bp);
memCpy(buf,ibuf,512);
ioman_resetCacheItem(ioman,bp);
ioman->sector[bp]=address;
ioman_setWritable(bp);
ioman_setValid(bp);
return(0);
}
if(ioman_writeSector(ioman,address,buf)){
return(-1);
}
return(0);
}
/*****************************************************************************/
void ioman_printStatus(IOManager *ioman)
{
euint16 c;
DBG((TXT("IO-Manager -- Report\n====================\n")));
DBG((TXT("Buffer is %i sectors, from %p to %p\n"),
ioman->numbuf,ioman->bufptr,ioman->bufptr+(ioman->numbuf*512)));
for(c=0;c<ioman->numbuf;c++){
if(ioman_isValid(c)){
DBG((TXT("BP %3i\t SC %8li\t\t US %i\t RF %i\t %s %s\n"),
c,ioman->sector[c],ioman_getUseCnt(ioman,c),ioman_getRefCnt(ioman,c),
ioman_isUserBuf(c) ? "USRBUF" : " ",
ioman_isWritable(c) ? "WRITABLE" : "READONLY"));
}
}
}
/*****************************************************************************/

View File

@@ -0,0 +1,119 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : ioman_small.c *
* Release : 0.3 - devel *
* Description : The IO Manager receives all requests for sectors in a central *
* allowing it to make smart decision regarding caching. *
* The IOMAN_NUMBUFFER parameter determines how many sectors *
* ioman can cache. ioman also supports overallocating and *
* backtracking sectors. *
* This is the small version of IOMan, for systems with limited *
* resources. It features only one fixed buffer, and has *
* simplified operation *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "ioman_small.h"
esint8 ioman_init(IOManager *ioman, Interface *iface, euint8* bufferarea)
{
ioman->iface=iface;
ioman_reset(ioman);
return(0);
}
/*****************************************************************************/
void ioman_reset(IOManager *ioman)
{
ioman->sector=ioman->status=ioman->itptr=0;
ioman->stack.sector=ioman->stack.status=0;
ioman_setError(ioman,IOMAN_NOERROR);
}
/*****************************************************************************/
void ioman_setAttr(IOManager *ioman,euint8 attribute,euint8 val)
{
if(val){
ioman->status|=1<<attribute;
}else{
ioman->status&=~(1<<attribute);
}
}
/*****************************************************************************/
euint8 ioman_getAttr(IOManager *ioman,euint8 attribute)
{
return(ioman->status&(1<<attribute));
}
/*****************************************************************************/
euint8* ioman_getSector(IOManager *ioman,euint32 address, euint8 mode)
{
if(address==ioman->sector){
if(mode==IOM_MODE_READWRITE)ioman_setWritable();
return(ioman->bufptr);
}
}
esint8 ioman_readSector(IOManager *ioman,euint32 address,euint8* buf)
{
esint8 r;
if(buf==0){
return(-1);
}
r=if_readBuf(ioman->iface,address,buf);
if(r!=0){
ioman_setError(ioman,IOMAN_ERR_READFAIL);
return(-1);
}
return(0);
}
/*****************************************************************************/
esint8 ioman_writeSector(IOManager *ioman, euint32 address, euint8* buf)
{
esint8 r;
if(buf==0)return(-1);
r=if_writeBuf(ioman->iface,address,buf);
if(r<=0){
ioman_setError(ioman,IOMAN_ERR_WRITEFAIL);
return(-1);
}
return(0);
}
/*****************************************************************************/

View File

@@ -0,0 +1,104 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : partition.c *
* Release : 0.3 - devel *
* Description : These functions are partition specific. Searching FAT type *
* partitions and read/write functions to partitions. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "partition.h"
/*****************************************************************************/
/* ****************************************************************************
* void part_initPartition(Partition *part,Disc* refDisc)
* Description: This function searches the 4 partitions for a FAT class partition
* and marks the first one found as the active to be used partition.
*/
void part_initPartition(Partition *part,Disc* refDisc)
{
eint16 c;
part->disc=refDisc;
part->LBA_offset=0;
part->LBA_sectorcount=0;
part_setError(part,PART_NOERROR);
}
/*****************************************************************************/
euint8 part_openPartitionType(Partition *part,euint8 type)
{
return(
disc_findPartition(part->disc,type,0,&(part->LBA_offset),&(part->LBA_sectorcount))
);
}
/* ****************************************************************************
* euint8* part_getSect(Partition *part, euint32 address, euint8 mode)
* Description: This function calls ioman_getSector, but recalculates the sector
* address to be partition relative.
* Return value: Whatever getSector returns. (pointer or 0)
*/
euint8* part_getSect(Partition *part, euint32 address, euint8 mode)
{
return(ioman_getSector(part->disc->ioman,part_getRealLBA(part,address),mode));
}
/* ****************************************************************************
* esint8 part_relSect(Partition *part, euint8* buf)
* Description: This function calls ioman_releaseSector.
* Return value: Whatever releaseSector returns.
*/
esint8 part_relSect(Partition *part, euint8* buf)
{
return(ioman_releaseSector(part->disc->ioman,buf));
}
esint8 part_flushPart(Partition *part,euint32 addr_l, euint32 addr_h)
{
return(
ioman_flushRange(part->disc->ioman,part_getRealLBA(part,addr_l),part_getRealLBA(part,addr_h))
);
}
esint8 part_directSectorRead(Partition *part,euint32 address, euint8* buf)
{
return(
ioman_directSectorRead(part->disc->ioman,part_getRealLBA(part,address),buf)
);
}
esint8 part_directSectorWrite(Partition *part,euint32 address, euint8* buf)
{
return(
ioman_directSectorWrite(part->disc->ioman,part_getRealLBA(part,address),buf)
);
}

View File

@@ -0,0 +1,104 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : partition.c *
* Release : 0.3 - devel *
* Description : These functions are partition specific. Searching FAT type *
* partitions and read/write functions to partitions. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "partition.h"
/*****************************************************************************/
/* ****************************************************************************
* void part_initPartition(Partition *part,Disc* refDisc)
* Description: This function searches the 4 partitions for a FAT class partition
* and marks the first one found as the active to be used partition.
*/
void part_initPartition(Partition *part,Disc* refDisc)
{
eint16 c;
part->disc=refDisc;
part->LBA_offset=0;
part->LBA_sectorcount=0;
part_setError(part,PART_NOERROR);
}
/*****************************************************************************/
euint8 part_openPartitionType(Partition *part,euint8 type)
{
return(
disc_findPartition(disc,type,0,&(part->LBA_offset),&(part->LBA_sectorcount))
);
}
/* ****************************************************************************
* euint8* part_getSect(Partition *part, euint32 address, euint8 mode)
* Description: This function calls ioman_getSector, but recalculates the sector
* address to be partition relative.
* Return value: Whatever getSector returns. (pointer or 0)
*/
euint8* part_getSect(Partition *part, euint32 address, euint8 mode)
{
return(ioman_getSector(part->disc->ioman,part_getRealLBA(part,address),mode));
}
/* ****************************************************************************
* esint8 part_relSect(Partition *part, euint8* buf)
* Description: This function calls ioman_releaseSector.
* Return value: Whatever releaseSector returns.
*/
esint8 part_relSect(Partition *part, euint8* buf)
{
return(ioman_releaseSector(part->disc->ioman,buf));
}
esint8 part_flushPart(Partition *part,euint32 addr_l, euint32 addr_h)
{
return(
ioman_flushRange(part->disc->ioman,part_getRealLBA(part,addr_l),part_getRealLBA(part,addr_h))
);
}
esint8 part_directSectorRead(Partition *part,euint32 address, euint8* buf)
{
return(
ioman_directSectorRead(part->disc->ioman,part_getRealLBA(part,address),buf)
);
}
esint8 part_directSectorWrite(Partition *part,euint32 address, euint8* buf)
{
return(
ioman_directSectorWrite(part->disc->ioman,part_getRealLBA(part,address),buf)
);
}

View File

@@ -0,0 +1,83 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : plibc.c *
* Release : 0.3 - devel *
* Description : This file contains replacements of common c library functions *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
/*****************************************************************************/
#include "plibc.h"
/*****************************************************************************/
/* ****************************************************************************
* unsigned short strMatch(char* bufa, char*bufb, unsigned long n)
* Description: Compares bufa and bufb for a length of n bytes.
* Return value: Returns the number of character NOT matching.
*/
euint16 strMatch(eint8* bufa, eint8*bufb,euint32 n)
{
euint32 c;
euint16 res=0;
for(c=0;c<n;c++)if(bufa[c]!=bufb[c])res++;
return(res);
}
/*****************************************************************************/
/* ****************************************************************************
* void memCpy(void* psrc, void* pdest, unsigned long size)
* Description: Copies the contents of psrc into pdest on a byte per byte basis.
* The total number of bytes copies is size.
*/
void memCpy(void* psrc, void* pdest, euint32 size)
{
while(size>0){
*((eint8*)pdest+size-1)=*((eint8*)psrc+size-1);
size--;
}
}
/*****************************************************************************/
void memClr(void *pdest,euint32 size)
{
while(size>0){
*(((eint8*)pdest)+size-1)=0x00;
size--;
}
}
void memSet(void *pdest,euint32 size,euint8 data)
{
while(size>0){
*(((eint8*)pdest)+size-1)=data;
size--;
}
}

View File

@@ -0,0 +1,70 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : sextract.c *
* Release : 0.3 - devel *
* Description : The function in this file are to load and set the structures *
* as found on the disc, only those structures for the entire *
* library are located here, filesystem specific ones are in *
* that filesystems directory *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "sextract.h"
void ex_setPartitionField(euint8* buf,PartitionField* pf)
{
*(buf) = pf->bootFlag;
*(buf+1) = pf->CHS_begin[0];
*(buf+2) = pf->CHS_begin[1];
*(buf+3) = pf->CHS_begin[2];
*(buf+4) = pf->type;
*(buf+5) = pf->CHS_end[0];
*(buf+6) = pf->CHS_end[1];
*(buf+7) = pf->CHS_end[2];
ex_setb32(buf+8,pf->LBA_begin);
ex_setb32(buf+12,pf->numSectors);
}
/*****************************************************************************/
void ex_getPartitionField(euint8* buf,PartitionField* pf)
{
pf->bootFlag = *(buf);
pf->CHS_begin[0] = *(buf + 1);
pf->CHS_begin[1] = *(buf + 2);
pf->CHS_begin[2] = *(buf + 3);
pf->type = *(buf + 4);
pf->CHS_end[0] = *(buf + 5);
pf->CHS_end[1] = *(buf + 6);
pf->CHS_end[2] = *(buf + 7);
pf->LBA_begin = ex_getb32(buf + 8);
pf->numSectors = ex_getb32(buf + 12);
}
/*****************************************************************************/

View File

@@ -0,0 +1,70 @@
/*****************************************************************************\
* EFSL - Embedded Filesystems Library *
* ----------------------------------- *
* *
* Filename : sextract.c *
* Release : 0.3 - devel *
* Description : The function in this file are to load and set the structures *
* as found on the disc, only those structures for the entire *
* library are located here, filesystem specific ones are in *
* that filesystems directory *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* As a special exception, if other files instantiate templates or *
* use macros or inline functions from this file, or you compile this *
* file and link it with other works to produce a work based on this file, *
* this file does not by itself cause the resulting work to be covered *
* by the GNU General Public License. However the source code for this *
* file must still be made available in accordance with section (3) of *
* the GNU General Public License. *
* *
* This exception does not invalidate any other reasons why a work based *
* on this file might be covered by the GNU General Public License. *
* *
* (c)2006 Lennart Yseboodt *
* (c)2006 Michael De Nil *
\*****************************************************************************/
#include "sextract.h"
void ex_setPartitionField(euint8* buf,PartitionField* pf)
{
*(buf) = pf->bootFlag;
*(buf+1) = pf->CHS_begin[0];
*(buf+2) = pf->CHS_begin[1];
*(buf+3) = pf->CHS_begin[2];
*(buf+4) = pf->type;
*(buf+5) = pf->CHS_end[0];
*(buf+6) = pf->CHS_end[1];
*(buf+7) = pf->CHS_end[2];
ex_setb32(buf+8,pf->LBA_begin);
ex_setb32(buf+12,pf->numSectors);
}
/*****************************************************************************/
void ex_getPartitionField(euint8* buf,PartitionField* pf)
{
pf->bootFlag = *(buf);
pf->CHS_begin[0] = *(buf + 1);
pf->CHS_begin[1] = *(buf + 2);
pf->CHS_begin[2] = *(buf + 3);
pf->type = *(buf + 4);
pf->CHS_end[0] = *(buf + 5);
pf->CHS_end[1] = *(buf + 6);
pf->CHS_end[2] = *(buf + 7);
pf->LBA_begin = ex_getb32(buf + 8);
pf->numSectors = ex_getb32(buf + 12);
}
/*****************************************************************************/