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


David N. Welton wrote:

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 have written a caching layer to do the block memory management.
Now I just need a simple byte access - my FAT16 needs it and I would
like my code to be in sync as much as possible with the "eCos tendencies".

I'am thinking about doing something like:

cyg_io_set_config(disk_h, CYG_IO_SET_CONFIG_DISK_CURRENT_BLOCK, &block, &l);
cyg_io_bread(disk_h, buf, &len, pos);


len and pos would be in bytes and in case of current position being greater than block size the
current block number would be adjusted.



savin




--
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]