diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 92 |
1 files changed, 46 insertions, 46 deletions
@@ -69,8 +69,8 @@ size_t file_read (const char *disk_mem, file *f, char *buf, size -= len; offset = 0; if(bwalker_block_is_last(bw)){ - break; - } + break; + } } @@ -80,49 +80,49 @@ size_t file_read (const char *disk_mem, file *f, char *buf, int file_truncate (const char *disk_mem, file *f, off_t size) { - bwalker *walker; - uint16_t offset, i, fb_size, block=0; + bwalker *walker; + uint16_t offset, i, fb_size, block=0; assert(disk_mem != NULL); assert(f != NULL); - - walker=bwalker_create(disk_mem, f->size, &(f->indirect)); - /*el tamaño en bytes de la cantidad de bloques que ocupa el file - * siempre es >= file_size*/ - fb_size=(bwalker_direct_length(walker)*BLOCK_SIZE); - - if(f->size < size){ - /*si el pedacito que jode...*/ - offset=size-f->size; - /*es menor que 512, y ademas el nuevo tamaño no pasa al fb_size - * no es neceasrio alocar bloques, solo se cambia el tamaño*/ - if(offset<BLOCK_SIZE&&size<=fb_size){ - f->size=size; - bwalker_destroy(walker); - return 0; - } - for(i=0; i<(DIV_CEIL(offset, BLOCK_SIZE)); i++){ - /*aloca lo que necesita*/ - block=bwalker_allocate_block(walker); - } - /*change size*/ - f->size=size; - }else{ - /*idem, pero al verez*/ - offset=f->size-size; - f->size=size; - if(offset<BLOCK_SIZE&&size>=fb_size){ - f->size=size; - bwalker_destroy(walker); - return 0; - } - for(i=0; i<(DIV_CEIL(offset, BLOCK_SIZE)); i++){ - bwalker_free_block(walker); - } - f->size=size; - } - bwalker_destroy(walker); - return 0; + + walker=bwalker_create(disk_mem, f->size, &(f->indirect)); + /*el tamaño en bytes de la cantidad de bloques que ocupa el file + * siempre es >= file_size*/ + fb_size=(bwalker_direct_length(walker)*BLOCK_SIZE); + + if(f->size < size){ + /*si el pedacito que jode...*/ + offset=size-f->size; + /*es menor que 512, y ademas el nuevo tamaño no pasa al fb_size + * no es neceasrio alocar bloques, solo se cambia el tamaño*/ + if(offset<BLOCK_SIZE&&size<=fb_size){ + f->size=size; + bwalker_destroy(walker); + return 0; + } + for(i=0; i<(DIV_CEIL(offset, BLOCK_SIZE)); i++){ + /*aloca lo que necesita*/ + block=bwalker_allocate_block(walker); + } + /*change size*/ + f->size=size; + }else{ + /*idem, pero al verez*/ + offset=f->size-size; + f->size=size; + if(offset<BLOCK_SIZE&&size>=fb_size){ + f->size=size; + bwalker_destroy(walker); + return 0; + } + for(i=0; i<(DIV_CEIL(offset, BLOCK_SIZE)); i++){ + bwalker_free_block(walker); + } + f->size=size; + } + bwalker_destroy(walker); + return 0; } size_t file_write (const char *disk_mem, file *f, char *buf, @@ -140,7 +140,7 @@ size_t file_write (const char *disk_mem, file *f, char *buf, bw = bwalker_create (disk_mem, f->size, &(f->indirect)); - + while (size > 0 && (bnum = bwalker_next(bw))) { assert(bnum != f->indirect); @@ -164,11 +164,11 @@ size_t file_write (const char *disk_mem, file *f, char *buf, offset = 0; if(bwalker_direct_length(bw)<=1){ - break; - } + break; + } } - + f->atime = new_time; f->mtime = new_time; |