mirror of
https://github.com/vivier/EMILE.git
synced 2025-01-22 00:32:15 +00:00
make algorith simplier
This commit is contained in:
parent
f112a09c5d
commit
9137bb1863
@ -45,7 +45,5 @@ container_FILE *container_open(device_io_t *device, char *path)
|
||||
file->offset = 0;
|
||||
file->device = device;
|
||||
file->current_block = 0;
|
||||
file->last_current = 0;
|
||||
file->last_index = 0;
|
||||
return file;
|
||||
}
|
||||
|
@ -6,9 +6,12 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libcontainer.h"
|
||||
|
||||
extern void error(char *x) __attribute__ ((noreturn));
|
||||
|
||||
static unsigned long seek_block(container_FILE *file)
|
||||
{
|
||||
struct emile_container *container = file->container;
|
||||
@ -17,19 +20,14 @@ static unsigned long seek_block(container_FILE *file)
|
||||
unsigned long offset = file->offset;
|
||||
int block_size = file->device->get_blocksize(file->device->data);
|
||||
|
||||
/* search forward */
|
||||
|
||||
for (i = file->last_index,
|
||||
current = file->last_current;
|
||||
i < container->blocks[i].count; i++)
|
||||
for (i = 0, current = 0;
|
||||
container->blocks[i].offset != 0; i++)
|
||||
{
|
||||
int extent_size = block_size *
|
||||
container->blocks[i].count;
|
||||
|
||||
if ( (current <= offset) && (offset < current + extent_size) )
|
||||
{
|
||||
file->last_current = current;
|
||||
file->last_index = i;
|
||||
return container->blocks[i].offset +
|
||||
(offset - current) / block_size;
|
||||
}
|
||||
@ -37,25 +35,6 @@ static unsigned long seek_block(container_FILE *file)
|
||||
current += extent_size;
|
||||
}
|
||||
|
||||
/* search backward */
|
||||
|
||||
for (i = file->last_index,
|
||||
current = file->last_current;
|
||||
i > 0; i--)
|
||||
{
|
||||
int extent_size = block_size *
|
||||
container->blocks[i - 1].count;
|
||||
|
||||
current -= extent_size;
|
||||
|
||||
if ( (current <= offset) && (offset < current + extent_size) )
|
||||
{
|
||||
file->last_current = current;
|
||||
file->last_index = i - 1;
|
||||
return container->blocks[i].offset +
|
||||
(offset - current) / block_size;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -68,8 +47,17 @@ ssize_t container_read(container_FILE *file, void *ptr, size_t size)
|
||||
|
||||
while (size != 0)
|
||||
{
|
||||
unsigned long block_nb = seek_block(file);
|
||||
int block_offset = file->offset % block_size;
|
||||
unsigned long block_nb;
|
||||
int block_offset;
|
||||
|
||||
if (file->offset >= file->container->size)
|
||||
return read;
|
||||
|
||||
block_nb = seek_block(file);
|
||||
block_offset = file->offset % block_size;
|
||||
|
||||
if (block_nb == 0)
|
||||
error("BUG in libcontainer !!!");
|
||||
|
||||
if (block_nb != file->current_block)
|
||||
{
|
||||
|
@ -25,8 +25,6 @@ typedef struct {
|
||||
unsigned long offset;
|
||||
device_io_t *device;
|
||||
struct emile_container* container;
|
||||
unsigned long last_current;
|
||||
unsigned long last_index;
|
||||
unsigned long current_block;
|
||||
char *buffer[0];
|
||||
} container_FILE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user