aboutsummaryrefslogtreecommitdiff
path: root/block_walker.c
diff options
context:
space:
mode:
Diffstat (limited to 'block_walker.c')
-rw-r--r--block_walker.c104
1 files changed, 52 insertions, 52 deletions
diff --git a/block_walker.c b/block_walker.c
index b4c2682..6a4d793 100644
--- a/block_walker.c
+++ b/block_walker.c
@@ -13,9 +13,9 @@ struct _block_walker {
const char *fbb;
const char *ipool;
const char *bpool;
-
+
uint16_t *indblock_mem;
-
+
GList *block_list;
GList *indirect_list;
}PACKED;
@@ -28,7 +28,7 @@ uint16_t allocate_block(bwalker *bw)
{
uint16_t result = 0;
uint16_t i = 0;
-
+
assert (bw != NULL);
/* Solo queremos desde el segundo inodo para
* que tengamos como error el 0 */
@@ -42,7 +42,7 @@ uint16_t allocate_block(bwalker *bw)
}
/* Tiene que estar seteado a 1 */
assert(GET_BIT(bw->fbb, i) == 1);
-
+
return (result);
}
@@ -71,19 +71,19 @@ bwalker *bwalker_create(const char *base_mem, size_t size, uint16_t *indirect_me
unsigned int i = 0;
uint16_t *indirect_ptr;
uint16_t indirect_num = 0;
-
+
bw = calloc(1, sizeof(struct _block_walker));
-
+
assert (bw != NULL);
bw->fbb = (char *)base_mem + FBB_OFFSET;
bw->fib = (char *)base_mem + FIB_OFFSET;
bw->ipool = (char *)base_mem + INODEPOOL_OFFSET;
bw->bpool = (char *)base_mem + BLOCKPOOL_OFFSET;
-
+
bw->indblock_mem = indirect_mem;
bw->block_list = NULL;
bw->indirect_list = NULL;
-
+
if (size == 0)
{
/* No hay bloques, no hay nada,
@@ -92,15 +92,15 @@ bwalker *bwalker_create(const char *base_mem, size_t size, uint16_t *indirect_me
}
/* Deberia tener al menos un bloque indirecto. */
assert ((*indirect_mem) != 0);
-
+
indirect_num = *indirect_mem;
bw->indirect_list = g_list_append (bw->indirect_list,
- GUINT_TO_POINTER(indirect_num));
+ GUINT_TO_POINTER(indirect_num));
assert(indirect_num == GPOINTER_TO_UINT(bw->indirect_list->data));
indirect_ptr = (uint16_t *) bw->bpool + (BLOCK_SIZE*indirect_num);
-
+
while (size > 0)
{
/* Empezamos a meterles bloques */
@@ -108,28 +108,28 @@ bwalker *bwalker_create(const char *base_mem, size_t size, uint16_t *indirect_me
{
if (indirect_ptr[i] != 0){
bw->block_list = g_list_append (bw->block_list,
- GUINT_TO_POINTER(indirect_ptr[i]));
+ GUINT_TO_POINTER(indirect_ptr[i]));
}
if(indirect_ptr[i]==0){
- break;
- }
-
+ break;
+ }
+
if(size > BLOCK_SIZE){
size -= BLOCK_SIZE;
}else{
size = 0;
- }
+ }
}
-
+
if(size != 0 && size>0)
- if(indirect_ptr[255] != 0)
+ if(indirect_ptr[255] != 0)
- {
- bw->indirect_list = g_list_append (bw->indirect_list,
- GUINT_TO_POINTER(indirect_ptr[255]));
- indirect_ptr = (uint16_t *) bw->bpool + (BLOCK_SIZE*indirect_ptr[255]);
- }
+ {
+ bw->indirect_list = g_list_append (bw->indirect_list,
+ GUINT_TO_POINTER(indirect_ptr[255]));
+ indirect_ptr = (uint16_t *) bw->bpool + (BLOCK_SIZE*indirect_ptr[255]);
+ }
}
@@ -137,20 +137,20 @@ bwalker *bwalker_create(const char *base_mem, size_t size, uint16_t *indirect_me
/*assert (*indirect_mem == GPOINTER_TO_UINT(g_list_first(bw->indirect_list)->data));*/
/*assert (g_list_length(bw->indirect_list) > 0);
- assert (g_list_length(bw->block_list) > 0);*/
-
+ assert (g_list_length(bw->block_list) > 0);*/
+
return (bw);
}
void bwalker_destroy (bwalker *bw)
{
assert (bw != NULL);
-
+
if(bw->block_list != NULL)
g_list_free(g_list_first(bw->block_list));
if(bw->indirect_list != NULL)
g_list_free(g_list_first(bw->indirect_list));
-
+
free(bw);
bw = NULL;
}
@@ -188,7 +188,7 @@ uint16_t bwalker_allocate_block(bwalker *bw)
for(i = 0; i < 255; i++){
if(buf[i] == 0)
goto ALLOCATE_BLOCK;
- }
+ }
/* Si llegamos aca, aloca un indirecto y encima _no_ es el primero :B */
ALLOCATE_INDBLK:
@@ -225,7 +225,7 @@ ALLOCATE_BLOCK:
goto ENOBLK;
}
buf[i] = block;
-
+
bw->block_list = g_list_append(bw->block_list, GUINT_TO_POINTER(block));
assert(block != 0);
@@ -237,7 +237,7 @@ ENOBLK:
void bwalker_free_block(bwalker *bw)
{
- uint16_t list_length_b, list_length_i;
+ uint16_t list_length_b, list_length_i;
uint16_t *buf = NULL;
uint16_t block = 0;
uint16_t i = 0;
@@ -246,9 +246,9 @@ void bwalker_free_block(bwalker *bw)
if(g_list_length(bw->block_list) == 0)
return;
-
- list_length_b=g_list_length(bw->block_list);
- list_length_i=g_list_length(bw->indirect_list);
+
+ list_length_b=g_list_length(bw->block_list);
+ list_length_i=g_list_length(bw->indirect_list);
/* Aca tenemos que ver si necesitamos deallocar un
* bloque indirecto. */
auxlist = g_list_last(bw->indirect_list);
@@ -264,7 +264,7 @@ void bwalker_free_block(bwalker *bw)
/*no se actualiza la lista. mirenlo a ver que onda,
* me parecio que era asi, pero no me hace caso*/
bw->block_list=g_list_remove(bw->block_list, g_list_last(bw->block_list)->data);
-
+
buf[i-1] = 0;
}
@@ -272,31 +272,31 @@ void bwalker_free_block(bwalker *bw)
{
free_block(bw, buf[0]);
bw->block_list=g_list_remove(bw->block_list, g_list_last(bw->block_list)->data);
-
+
buf[0] = 0;
-
+
if((auxlist = g_list_previous(auxlist)))
{
block = (uint16_t) auxlist->data;
buf = (uint16_t *) bw->bpool +
- (block*BLOCK_SIZE);
+ (block*BLOCK_SIZE);
free_block(bw, buf[255]);
/*el indirecto == buf[255]???*/
bw->indirect_list=g_list_remove(bw->indirect_list, g_list_last(bw->indirect_list)->data);
-
+
buf[255] = 0;
}
else
{
free_block(bw, *bw->indblock_mem);
bw->indirect_list=g_list_remove(bw->indirect_list, bw->indblock_mem);
-
+
*bw->indblock_mem = 0;
}
-
+
}
-
+
}
uint16_t bwalker_next(bwalker *bw)
@@ -306,16 +306,16 @@ uint16_t bwalker_next(bwalker *bw)
assert (bw != NULL);
if(g_list_length(bw->block_list) == 0)
return 0;
-
- if(g_list_length(bw->block_list) == 1){
- return (uint16_t)GPOINTER_TO_UINT(bw->block_list->data);
- }
+
+ if(g_list_length(bw->block_list) == 1){
+ return (uint16_t)GPOINTER_TO_UINT(bw->block_list->data);
+ }
if(bw->block_list!=g_list_last(bw->block_list)){
- assert(*(bw->indblock_mem)!=GPOINTER_TO_UINT(bw->block_list->data));
+ assert(*(bw->indblock_mem)!=GPOINTER_TO_UINT(bw->block_list->data));
result = (uint16_t)GPOINTER_TO_UINT(bw->block_list->data);
- bw->block_list = g_list_next(bw->block_list);
- }
+ bw->block_list = g_list_next(bw->block_list);
+ }
return (result);
}
@@ -337,15 +337,15 @@ uint16_t bwalker_prev(bwalker *bw)
uint16_t bwalker_last_indirect (bwalker *bw)
{
uint16_t result = 0;
- assert(bw != NULL);
+ assert(bw != NULL);
assert(g_list_length(bw->indirect_list) > 0);
if(g_list_last(bw->indirect_list))
{
result = (uint16_t)
GPOINTER_TO_UINT(g_list_last(bw->indirect_list)->data);
}
-
- return result;
+
+ return result;
}
uint16_t bwalker_last_block (bwalker *bw)
@@ -364,5 +364,5 @@ uint16_t bwalker_block_is_last(bwalker *bw)
}
void bwalker_set_first(bwalker *bw)
{
- bw->block_list=g_list_first(bw->block_list);
+ bw->block_list=g_list_first(bw->block_list);
}