This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Block device IO


Savin Zlobec <savin@elatec.si> writes:

> Now I'am thinking about a third layer to do the position ->
> block/offset translation.  Maybe it would be cleaner to put it into
> a library since the only way I see to set block numbers is trough
> set_config interface (?) .

> Is there any similar effort wich will be contributed back to eCos ?

I wrote the following simplistic code:

int bytes2sectors (char *oldbuf, unsigned int bytelen, unsigned int inpos,
		   char **newbuf, unsigned int *sectorlen, unsigned int *outpos)
{
    int sector_offset = 0;

    sector_offset = inpos - (*outpos * SECTOR_SIZE);
    *outpos = inpos / SECTOR_SIZE;
    *sectorlen = ((bytelen + sector_offset) / SECTOR_SIZE) + 1;
    *newbuf = malloc(*sectorlen * SECTOR_SIZE);
    if (*newbuf == NULL) {
	diag_printf("Error malloc'ing %d bytes in bytes2sectors\n",
		    *sectorlen * SECTOR_SIZE);
	return -1;
    }
    return 0;
}

int sector2bytes (char *newbuf, unsigned int newlen, unsigned int newpos,
		  char *oldbuf, unsigned int *oldlen, unsigned int oldpos)
{
    unsigned int sector_offset;

    sector_offset = oldpos - (newpos * SECTOR_SIZE);
    memcpy(oldbuf, newbuf + sector_offset, *oldlen);
    free(newbuf);
}

Basically the idea is that you hand it a buffer that is sized in
bytes, and it hands you back a buffer that is big enough to handle the
whole thing, rounded up to blocks.

I hope to publish my own floppy driver hack soon, too.

Ciao,
-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]