block: takes an offset in blocks and not in bytes (to be able to manage SCSI disk)

This commit is contained in:
Laurent Vivier
2008-02-14 19:46:10 +00:00
parent 1ff43d1924
commit 7e4c1ca39c
3 changed files with 12 additions and 8 deletions

View File

@@ -46,7 +46,7 @@ block_FILE *block_open(device_io_t *device, char *path)
block->size = size; block->size = size;
block->device = device; block->device = device;
block->current = -1; block->current = -1;
block->buffer_size = NB_SECTORS * blocksize; block->buffer_size = NB_SECTORS;
return block; return block;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* *
* (c) 2005 Laurent Vivier <Laurent@lvivier.info> * (c) 2005-2008 Laurent Vivier <Laurent@lvivier.info>
* *
*/ */
@@ -11,22 +11,26 @@
size_t block_read(block_FILE *file, void *ptr, size_t size) size_t block_read(block_FILE *file, void *ptr, size_t size)
{ {
int part;
int block_nb;
int block_offset;
int read = 0; int read = 0;
int ret; int ret;
int blocksize = file->device->get_blocksize(file->device->data); int blocksize = file->device->get_blocksize(file->device->data);
while (size != 0) while (size != 0)
{ {
int part; block_nb = (file->base +
int block_nb = (file->offset + file->base) / file->buffer_size; file->offset / blocksize) / file->buffer_size;
int block_offset = (file->offset + file->base) % file->buffer_size; block_offset = (file->base - block_nb * file->buffer_size) *
blocksize + file->offset;
if (block_nb != file->current) if (block_nb != file->current)
{ {
ret = file->device->read_sector(file->device->data, ret = file->device->read_sector(file->device->data,
(block_nb * file->buffer_size) / blocksize, block_nb * file->buffer_size,
file->buffer, file->buffer,
file->buffer_size); file->buffer_size * blocksize);
if (ret == -1) if (ret == -1)
return read; return read;
file->current = block_nb; file->current = block_nb;

View File

@@ -166,7 +166,7 @@ char* emile_floppy_add(int fd, char *image)
if (size == -1) if (size == -1)
return NULL; return NULL;
sprintf(buf, "block:(fd0)0x%lx,0x%zx", offset, size); sprintf(buf, "block:(fd0)0x%lx,0x%zx", offset / 512, size);
return strdup(buf); return strdup(buf);
} }