From a98f3511d0e1a4815c0c1b75a190a71513512759 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 29 Feb 2016 05:37:59 -0300 Subject: Fix indentation and max column lenght --- block_walker.c | 104 +++++------ dir.c | 83 ++++---- file.c | 92 ++++----- fusewrapper.c | 582 ++++++++++++++++++++++++++++----------------------------- inode.c | 107 +++++------ log.c | 44 ++--- medianin.c | 454 ++++++++++++++++++++++---------------------- medianin.h | 5 +- 8 files changed, 740 insertions(+), 731 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); } diff --git a/dir.c b/dir.c index 4b692bb..891072f 100644 --- a/dir.c +++ b/dir.c @@ -51,16 +51,16 @@ uint16_t dir_add_direntry(const char *disk_mem, dir *d, const char *name, assert (strlen(name) < NAME_LENGTH); walker = bwalker_create(disk_mem, d->size, &(d->indirect)); - - if(bwalker_direct_length(walker)*BLOCK_SIZEsize+32){ + + if(bwalker_direct_length(walker)*BLOCK_SIZEsize+32){ block = bwalker_allocate_block(walker); }else{ block = bwalker_last_block(walker); - if(!block) + if(!block) goto CLEAN; - } - + } + dentry = (direntry *) disk_mem + BLOCKPOOL_OFFSET + (block * BLOCK_SIZE); for(i = 0; i < 16; i++){ @@ -73,7 +73,7 @@ uint16_t dir_add_direntry(const char *disk_mem, dir *d, const char *name, result = 1; goto CLEAN; } - } + } CLEAN: bwalker_destroy(walker); @@ -96,12 +96,12 @@ uint16_t dir_remove_direntry(const char *disk_mem, dir *d, const char *name) assert(strlen(name) < NAME_LENGTH); walker = bwalker_create(disk_mem, d->size, &(d->indirect)); - + /* Conseguimos el ultimo direntry */ block = bwalker_last_block(walker); assert(block != 0); last_dentry = (direntry *) disk_mem + BLOCKPOOL_OFFSET + - (block * BLOCK_SIZE); + (block * BLOCK_SIZE); assert(last_dentry[0].inum != 0); for(i = 0; i < 16; i++){ if(last_dentry[i].inum == 0) @@ -113,7 +113,7 @@ uint16_t dir_remove_direntry(const char *disk_mem, dir *d, const char *name) while((block = bwalker_next(walker))) { rm_dentry = (direntry *) disk_mem + BLOCKPOOL_OFFSET + - (block * BLOCK_SIZE); + (block * BLOCK_SIZE); for(i = 0; i < 16; i++) if(strcmp(name, rm_dentry[i].name) == 0) { @@ -129,13 +129,13 @@ uint16_t dir_remove_direntry(const char *disk_mem, dir *d, const char *name) last_dentry->name[0] = '\0'; last_dentry->inum = 0; last_dentry->symlink = 0; - + goto END; } if(bwalker_block_is_last(walker)) break; - } + } END: bwalker_destroy(walker); return result; @@ -144,27 +144,27 @@ END: dir *dir_get_from_path(const char *disk_mem, const char *path) { - uint16_t inum = 0; + uint16_t inum = 0; char *dir_name = NULL; - + assert (disk_mem != NULL); assert (path != NULL); dir_name = calloc(strlen(path) + 1, sizeof(char)); strcpy(dir_name, path); inum = get_inode_from_path(disk_mem, dirname(dir_name), 1); - free(dir_name); + free(dir_name); if(inum==0){ - return NULL; - } - return ((dir *)disk_mem+INODEPOOL_OFFSET+INODE_SIZE*inum); - + return NULL; + } + return ((dir *)disk_mem+INODEPOOL_OFFSET+INODE_SIZE*inum); + } uint16_t dir_search(const char *disk_mem, dir *idir,const char *name) { - bwalker *bw = NULL; - direntry *dentry; - uint16_t bnum, i; + bwalker *bw = NULL; + direntry *dentry; + uint16_t bnum, i; assert(disk_mem != NULL); @@ -176,24 +176,24 @@ uint16_t dir_search(const char *disk_mem, dir *idir,const char *name) /* Salimos si esto esta vacio obviamente. */ if(idir->size == 0){ return 0; - } - + } + bw = bwalker_create(disk_mem, idir->size, &(idir->indirect)); - while ((bnum = bwalker_next(bw))) + while ((bnum = bwalker_next(bw))) { - dentry=(direntry *) disk_mem + BLOCKPOOL_OFFSET + (bnum*BLOCK_SIZE); - for(i=0; i<16; i++){ - if(strcmp(name, dentry[i].name) == 0){ + dentry=(direntry *) disk_mem + BLOCKPOOL_OFFSET + (bnum*BLOCK_SIZE); + for(i=0; i<16; i++){ + if(strcmp(name, dentry[i].name) == 0){ bwalker_destroy(bw); - return dentry[i].inum; - } - } + return dentry[i].inum; + } + } if(bwalker_block_is_last(bw)) break; } bwalker_destroy(bw); - return 0; + return 0; } int dir_rename_inode(const char *disk_mem, dir *d, @@ -214,28 +214,29 @@ int dir_rename_inode(const char *disk_mem, dir *d, /* Salimos si esto esta vacio obviamente. */ if(d->size == 0){ return 0; - } - + } + bw = bwalker_create(disk_mem, d->size, &(d->indirect)); - while ((bnum = bwalker_next(bw))) + while ((bnum = bwalker_next(bw))) { - dentry=(direntry *) disk_mem + BLOCKPOOL_OFFSET + (bnum*BLOCK_SIZE); - for(i=0; i<16; i++){ - if(strcmp(old_name, dentry[i].name) == 0){ + dentry=(direntry *) disk_mem + BLOCKPOOL_OFFSET + (bnum*BLOCK_SIZE); + for(i=0; i<16; i++){ + if(strcmp(old_name, dentry[i].name) == 0){ bwalker_destroy(bw); strcpy(dentry[i].name,new_name); return 1; - } - } + } + } if(bwalker_block_is_last(bw)) break; } bwalker_destroy(bw); - return 0; + return 0; } -uint16_t dir_readdir(const char *disk_mem, dir *d, void *buf, fuse_fill_dir_t filler) +uint16_t dir_readdir(const char *disk_mem, dir *d, void *buf, + fuse_fill_dir_t filler) { bwalker *bw = NULL; diff --git a/file.c b/file.c index 71f84ac..e7998da 100644 --- a/file.c +++ b/file.c @@ -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(offsetsize=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=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(offsetsize=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=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; diff --git a/fusewrapper.c b/fusewrapper.c index 604f4a2..1837495 100644 --- a/fusewrapper.c +++ b/fusewrapper.c @@ -26,197 +26,197 @@ medianin *fs = NULL; static int fs_getattr(const char *path, struct stat *stbuf) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("getattr:%s", path); - rta = medianin_getattr(fs, path, stbuf); - debug2(" -> mode:%o size:%li", stbuf->st_mode, (long)stbuf->st_size); - debug3(" returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("getattr:%s", path); + rta = medianin_getattr(fs, path, stbuf); + debug2(" -> mode:%o size:%li", stbuf->st_mode, (long)stbuf->st_size); + debug3(" returns:%i", rta); + debug1("\n"); + return rta; } static int fs_readlink(const char *path, char *buf, size_t size) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("readlink:%s size:%li", path, (long)size); - rta = medianin_readlink(fs, path, buf, size); - debug2(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("readlink:%s size:%li", path, (long)size); + rta = medianin_readlink(fs, path, buf, size); + debug2(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_mknod(const char *path, mode_t mode, dev_t rdev) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("mknod:%s mode:%o", path, mode); - rta = medianin_mknod(fs, path, mode); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("mknod:%s mode:%o", path, mode); + rta = medianin_mknod(fs, path, mode); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_unlink(const char *path) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("unlink_file:%s", path); - rta = medianin_unlink(fs, path); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("unlink_file:%s", path); + rta = medianin_unlink(fs, path); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_symlink(const char *from, const char *to) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("symlink from:%s to:%s", from, to); - rta = medianin_symlink(fs, from, to); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("symlink from:%s to:%s", from, to); + rta = medianin_symlink(fs, from, to); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_rename(const char *from, const char *to) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("rename from:%s to:%s", from, to); - rta = medianin_rename(fs, from, to); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("rename from:%s to:%s", from, to); + rta = medianin_rename(fs, from, to); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_link(const char *from, const char *to) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("link from:%s to:%s", from, to); - rta = medianin_link(fs, from, to); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("link from:%s to:%s", from, to); + rta = medianin_link(fs, from, to); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_chmod(const char *path, mode_t mode) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("chmod:%s modo:%o", path, mode); - rta = medianin_chmod(fs, path, mode); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("chmod:%s modo:%o", path, mode); + rta = medianin_chmod(fs, path, mode); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_chown(const char *path, uid_t uid, gid_t gid) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("chown:%s uid:%i gid:%i", path, uid, gid); - rta = medianin_chown(fs, path, uid, gid); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("chown:%s uid:%i gid:%i", path, uid, gid); + rta = medianin_chown(fs, path, uid, gid); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_truncate(const char *path, off_t size) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("truncate:%s size:%li", path, (long)size); - rta = medianin_truncate(fs, path, size); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("truncate:%s size:%li", path, (long)size); + rta = medianin_truncate(fs, path, size); + debug1("\n"); + return rta; } static int fs_utime(const char *path, struct utimbuf *utb) { - int rta = 0; - struct timespec tv[2]; - tv[0].tv_sec = utb->actime; - tv[0].tv_nsec = 0; - tv[1].tv_sec = utb->modtime; - tv[1].tv_nsec = 0; - debug3("[%li] ", time(NULL)); - debug1("utime:%s atime:%li mtime:%li", - path, (long)utb->actime, (long)utb->modtime); - rta = medianin_utimens(fs, path, tv); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + struct timespec tv[2]; + tv[0].tv_sec = utb->actime; + tv[0].tv_nsec = 0; + tv[1].tv_sec = utb->modtime; + tv[1].tv_nsec = 0; + debug3("[%li] ", time(NULL)); + debug1("utime:%s atime:%li mtime:%li", + path, (long)utb->actime, (long)utb->modtime); + rta = medianin_utimens(fs, path, tv); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_open(const char *path, struct fuse_file_info *fi) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("*open:%s flags:%i", path, fi->flags); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("*open:%s flags:%i", path, fi->flags); + debug1("\n"); + return rta; } static int fs_read(const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int rta = 0; - (void) fi; - debug3("[%li] ", time(NULL)); - debug1("read:%s size:%li offset:%li", path, (long)size, (long)offset); - rta = medianin_read(fs, path, buf, size, offset); - debug2(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + (void) fi; + debug3("[%li] ", time(NULL)); + debug1("read:%s size:%li offset:%li", path, (long)size, (long)offset); + rta = medianin_read(fs, path, buf, size, offset); + debug2(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_write(const char *path, const char *buf, size_t size,off_t offset, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { - int rta = 0; - (void) fi; - debug3("[%li] ", time(NULL)); - debug1("write:%s size:%li offset:%li", path, (long)size, (long)offset); - rta = medianin_write(fs, path, buf, size, offset); - debug2(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + (void) fi; + debug3("[%li] ", time(NULL)); + debug1("write:%s size:%li offset:%li", path, (long)size, (long)offset); + rta = medianin_write(fs, path, buf, size, offset); + debug2(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_statfs(const char *path, struct statvfs *stbuf) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("statfs:%s", path); - rta = medianin_statfs(fs, path, stbuf); - debug2(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("statfs:%s", path); + rta = medianin_statfs(fs, path, stbuf); + debug2(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_release(const char *path, struct fuse_file_info *fi) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("*release:%s flags:%i", path, fi->flags); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("*release:%s flags:%i", path, fi->flags); + debug1("\n"); + return rta; } static int fs_utimens(const char *path, const struct timespec tv[2]) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("utimens:%s atime:%li mtime:%li", - path, (long)tv[0].tv_sec, (long)tv[1].tv_sec); - rta = medianin_utimens(fs, path, tv); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("utimens:%s atime:%li mtime:%li", + path, (long)tv[0].tv_sec, (long)tv[1].tv_sec); + rta = medianin_utimens(fs, path, tv); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } /* @@ -225,188 +225,188 @@ static int fs_utimens(const char *path, const struct timespec tv[2]) static int fs_mkdir(const char *path, mode_t mode) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("mkdir:%s mode:%o", path, mode); - rta = medianin_mkdir(fs, path, mode); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("mkdir:%s mode:%o", path, mode); + rta = medianin_mkdir(fs, path, mode); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_rmdir(const char *path) { - int rta = 0; - debug3("[%li] ", time(NULL)); - debug1("rmdir:%s", path); - rta = medianin_rmdir(fs, path); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + debug3("[%li] ", time(NULL)); + debug1("rmdir:%s", path); + rta = medianin_rmdir(fs, path); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static int fs_readdir(const char *path, void *buf, - fuse_fill_dir_t filler, off_t offset, - struct fuse_file_info *fi) + fuse_fill_dir_t filler, off_t offset, + struct fuse_file_info *fi) { - int rta = 0; - (void) fi; /* Para que no diga que la variable está sin usar */ - debug3("[%li] ", time(NULL)); - debug1("readdir:%s", path); - rta = medianin_readdir(fs, path, buf, filler); - debug3(" -> returns:%i", rta); - debug1("\n"); - return rta; + int rta = 0; + (void) fi; /* Para que no diga que la variable está sin usar */ + debug3("[%li] ", time(NULL)); + debug1("readdir:%s", path); + rta = medianin_readdir(fs, path, buf, filler); + debug3(" -> returns:%i", rta); + debug1("\n"); + return rta; } static struct fuse_operations fs_oper = { - /* Operaciones sobre archivos, NI = no implementada */ - .getattr = fs_getattr, /* Done */ - .readlink = fs_readlink, - .mknod = fs_mknod, /* Done */ - .unlink = fs_unlink, - .symlink = fs_symlink, - .rename = fs_rename, - .link = fs_link, - .chmod = fs_chmod, /* Almost done */ - .chown = fs_chown, /* Almost done */ - .truncate = fs_truncate, - .utime = fs_utime, /* Almost done */ - .open = fs_open, /* NI */ - .read = fs_read, - .write = fs_write, - .statfs = fs_statfs, /* Done */ - .release = fs_release, /* NI */ - .utimens = fs_utimens, /* Almost done */ - /* Operaciones sobre directorios */ - .mkdir = fs_mkdir, - .rmdir = fs_rmdir, - .readdir = fs_readdir, + /* Operaciones sobre archivos, NI = no implementada */ + .getattr = fs_getattr, /* Done */ + .readlink = fs_readlink, + .mknod = fs_mknod, /* Done */ + .unlink = fs_unlink, + .symlink = fs_symlink, + .rename = fs_rename, + .link = fs_link, + .chmod = fs_chmod, /* Almost done */ + .chown = fs_chown, /* Almost done */ + .truncate = fs_truncate, + .utime = fs_utime, /* Almost done */ + .open = fs_open, /* NI */ + .read = fs_read, + .write = fs_write, + .statfs = fs_statfs, /* Done */ + .release = fs_release, /* NI */ + .utimens = fs_utimens, /* Almost done */ + /* Operaciones sobre directorios */ + .mkdir = fs_mkdir, + .rmdir = fs_rmdir, + .readdir = fs_readdir, }; /* !! end Rafa !! */ int main(int argc, char *argv[]) { - /* Cheat es una variable al estilo de argv pero solo con argumentos - * parseados como validos. La uso para trabajar menos - */ - char *cheat[10]; /* 10 es un indice que nunca se alcanza */ - int i = 1; - int argi = 1; - char *logfilename = NULL; - char *mountpoint = NULL; - char *tailptr = NULL; /* Variable temporal usada pora strtol */ - int loglevel = 3; /* default loglevel */ - fs_oper.utimens = 0; - cheat[0] = argv[0]; - - /* i==1 && argi == 1 i se usa con cheat y argi con argv */ - /* cuando consumo un argumento aumento argi */ - /* cuando agrego uno para fusemain aumento i */ - while (argi < argc) - { - if (strcmp(argv[argi], "-h") == 0) - { - printf("uso: %s [opciones] mountpoint\n" - "opciones:\n" - "\t-h\t\tImprime esta ayuda.\n\n" - "\t-logfile file\n" - "\t-l file\t\tGuarda los logs en el archivo" - " especificado.\n\n" - "\t-loglevel num\n" - "\t-n num\t\tEspecifica el nivel de log. " - "Por defecto es 3.\n\n" - , argv[0]); - return 1; - } - else if (strcmp(argv[argi], "-logfile") == 0 - || strcmp(argv[argi], "-l") == 0) - { - argi++; - if(argi < argc) logfilename = argv[argi]; - else - { - fprintf(stderr, "Se debe especificar un nombre" - " de archivo\n"); - return 1; - } - loglevel=1; /* Para evitar malos usos */ - } - else if (strcmp(argv[argi], "-loglevel") == 0 - || strcmp(argv[argi], "-n") == 0) - { - argi++; - if (argi < argc) - { - loglevel = (int)strtol(argv[argi], &tailptr, 10); - if (tailptr == argv[argi]) - { - fprintf(stderr, - "El nivel de log debe" - "ser ún numero\n"); - return 1; - } - if (loglevel < 0) - { - fprintf(stderr, - "El nivel de log debe" - "ser un número natural\n"); - return 1; - } - } - else - { - fprintf(stderr, "Se debe especificar un nivel" - " de log\n"); - return 1; - } - } - else if (argv[argi][0] == '-') - { - fprintf(stderr, "Opción no reconocida:" - "%s\n",argv[argi]); - return 1; - } - else if (mountpoint == NULL) - { - mountpoint = argv[argi]; - } - argi++; - } - if(mountpoint == NULL) - { - fprintf(stderr, "Argumentos insuficientes: " - "hace falta un mountpoint\n"); - return 1; - } - cheat[i++] = mountpoint; - if (loglevel != 0) - { - cheat[i++] = "-f"; - } - cheat[i] = NULL; - - if (log_open(logfilename, loglevel)!=0) - { - fprintf(stderr, "Advertencia! no se pudo inicializar el log\n"); - } - - debug3("Los numeros a la izquierda indican el momento en que la " - "llamada a la\nfunción se efectuó según time(NULL).\n"); - - fs = medianin_create(); - if (fs == NULL) - { - return ENOMEM; - } - - fuse_main(i, cheat, &fs_oper, NULL); /* El corazón del programa */ - - medianin_destroy(fs); - log_close(); - - return 0; + /* Cheat es una variable al estilo de argv pero solo con argumentos + * parseados como validos. La uso para trabajar menos + */ + char *cheat[10]; /* 10 es un indice que nunca se alcanza */ + int i = 1; + int argi = 1; + char *logfilename = NULL; + char *mountpoint = NULL; + char *tailptr = NULL; /* Variable temporal usada pora strtol */ + int loglevel = 3; /* default loglevel */ + fs_oper.utimens = 0; + cheat[0] = argv[0]; + + /* i==1 && argi == 1 i se usa con cheat y argi con argv */ + /* cuando consumo un argumento aumento argi */ + /* cuando agrego uno para fusemain aumento i */ + while (argi < argc) + { + if (strcmp(argv[argi], "-h") == 0) + { + printf("uso: %s [opciones] mountpoint\n" + "opciones:\n" + "\t-h\t\tImprime esta ayuda.\n\n" + "\t-logfile file\n" + "\t-l file\t\tGuarda los logs en el archivo" + " especificado.\n\n" + "\t-loglevel num\n" + "\t-n num\t\tEspecifica el nivel de log. " + "Por defecto es 3.\n\n" + , argv[0]); + return 1; + } + else if (strcmp(argv[argi], "-logfile") == 0 + || strcmp(argv[argi], "-l") == 0) + { + argi++; + if(argi < argc) logfilename = argv[argi]; + else + { + fprintf(stderr, "Se debe especificar un nombre" + " de archivo\n"); + return 1; + } + loglevel=1; /* Para evitar malos usos */ + } + else if (strcmp(argv[argi], "-loglevel") == 0 + || strcmp(argv[argi], "-n") == 0) + { + argi++; + if (argi < argc) + { + loglevel = (int)strtol(argv[argi], &tailptr, 10); + if (tailptr == argv[argi]) + { + fprintf(stderr, + "El nivel de log debe" + "ser ún numero\n"); + return 1; + } + if (loglevel < 0) + { + fprintf(stderr, + "El nivel de log debe" + "ser un número natural\n"); + return 1; + } + } + else + { + fprintf(stderr, "Se debe especificar un nivel" + " de log\n"); + return 1; + } + } + else if (argv[argi][0] == '-') + { + fprintf(stderr, "Opción no reconocida:" + "%s\n",argv[argi]); + return 1; + } + else if (mountpoint == NULL) + { + mountpoint = argv[argi]; + } + argi++; + } + if(mountpoint == NULL) + { + fprintf(stderr, "Argumentos insuficientes: " + "hace falta un mountpoint\n"); + return 1; + } + cheat[i++] = mountpoint; + if (loglevel != 0) + { + cheat[i++] = "-f"; + } + cheat[i] = NULL; + + if (log_open(logfilename, loglevel)!=0) + { + fprintf(stderr, "Advertencia! no se pudo inicializar el log\n"); + } + + debug3("Los numeros a la izquierda indican el momento en que la " + "llamada a la\nfunción se efectuó según time(NULL).\n"); + + fs = medianin_create(); + if (fs == NULL) + { + return ENOMEM; + } + + fuse_main(i, cheat, &fs_oper, NULL); /* El corazón del programa */ + + medianin_destroy(fs); + log_close(); + + return 0; } diff --git a/inode.c b/inode.c index 556aad3..aee299e 100644 --- a/inode.c +++ b/inode.c @@ -21,19 +21,19 @@ int16_t inode_search(const char *disk_mem, inode *current, char *path); int16_t name_check(char *path, direntry *entry_block) { - int16_t result=-1; + int16_t result=-1; int i = 0; - + assert(path != NULL); assert(entry_block != NULL); - for(i=0; i<16 && entry_block[i].inum != 0; i++){ - if(strcmp(entry_block[i].name, path)){ - result=entry_block[i].inum; - break; - } - } - return result; + for(i=0; i<16 && entry_block[i].inum != 0; i++){ + if(strcmp(entry_block[i].name, path)){ + result=entry_block[i].inum; + break; + } + } + return result; } int16_t inode_search(const char *disk_mem, inode *current, char *path) @@ -41,33 +41,34 @@ int16_t inode_search(const char *disk_mem, inode *current, char *path) bwalker *bw = NULL; direntry *dentry = NULL; - int16_t result = -1; - uint16_t block; + int16_t result = -1; + uint16_t block; assert (disk_mem != NULL); assert (current != NULL); assert (path != NULL); - bw=bwalker_create(disk_mem, current->size, &(current->indirect)); + bw=bwalker_create(disk_mem, current->size, &(current->indirect)); - while(result==-1 && (block=bwalker_next(bw))!=0){ - dentry=(direntry *)disk_mem+BLOCKPOOL_OFFSET+(block*BLOCK_SIZE); - result=name_check(path, dentry); - } - bwalker_destroy (bw); + while(result==-1 && (block=bwalker_next(bw))!=0){ + dentry=(direntry *)disk_mem+BLOCKPOOL_OFFSET+(block*BLOCK_SIZE); + result=name_check(path, dentry); + } + bwalker_destroy (bw); - return result; + return result; } /* Publico. */ /*Parse*/ -int16_t get_inode_from_path(const char *disk_mem, char *path, int16_t current_inum) +int16_t get_inode_from_path(const char *disk_mem, char *path, + int16_t current_inum) { - int16_t i=1, path_len=strlen(path), result=0; - char *path_mod = NULL; - inode *current=(inode *)disk_mem+INODEPOOL_OFFSET+current_inum*INODE_SIZE; - + int16_t i=1, path_len=strlen(path), result=0; + char *path_mod = NULL; + inode *current=(inode *)disk_mem+INODEPOOL_OFFSET+current_inum*INODE_SIZE; + assert (disk_mem != NULL); assert (path != NULL); @@ -77,35 +78,35 @@ int16_t get_inode_from_path(const char *disk_mem, char *path, int16_t current_in /* Vamos a ponerle 2 mas por las moscas :) */ path_mod = calloc(path_len + 2, sizeof(char)); - strcpy(path_mod, path); - - while(idisk_mem = NULL; - result->disk_fd = open(MDFS_FILENAME, O_RDWR); - map=mmap(NULL, BLOCKS*BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, result->disk_fd, 0); - /*Nos aseguramos que el mapeo se realize correctamente*/ - if(map==MAP_FAILED) - perror("mmap"); - - result->disk_mem = map; - - result->mount_time = time(NULL); - - assert(result != NULL); - assert(INVREP(result)); - - return result; + medianin *result = NULL; + void *map; + + result = calloc(1, sizeof(*result)); + + result->disk_mem = NULL; + result->disk_fd = open(MDFS_FILENAME, O_RDWR); + map=mmap(NULL, BLOCKS*BLOCK_SIZE, PROT_READ|PROT_WRITE, + MAP_SHARED, result->disk_fd, 0); + /*Nos aseguramos que el mapeo se realize correctamente*/ + if(map==MAP_FAILED) + perror("mmap"); + + result->disk_mem = map; + + result->mount_time = time(NULL); + + assert(result != NULL); + assert(INVREP(result)); + + return result; } void medianin_destroy(medianin *self) { - assert(INVREP(self)); - - close (self->disk_fd); - /*Cerramos el fd, y guardamos los cambios*/ - if(msync(self->disk_mem, BLOCKS*BLOCK_SIZE, MS_SYNC) == -1) + assert(INVREP(self)); + + close (self->disk_fd); + /*Cerramos el fd, y guardamos los cambios*/ + if(msync(self->disk_mem, BLOCKS*BLOCK_SIZE, MS_SYNC) == -1) perror("msync"); - if(munmap(self->disk_mem, BLOCKS*BLOCK_SIZE) == -1) + if(munmap(self->disk_mem, BLOCKS*BLOCK_SIZE) == -1) perror("munmap"); - free(self); self = NULL; + free(self); self = NULL; } /* @@ -117,24 +118,24 @@ int medianin_getattr(medianin *self, const char *path, struct stat *stbuf) } pdir = dir_get_from_path(self->disk_mem, path); - + if (!pdir) return -ENOENT; - + path_c=calloc(NAME_LENGTH, sizeof(char)); strcpy(path_c, path); - - + + name=calloc(NAME_LENGTH, sizeof(char)); strcpy (name, basename(path_c)); - + block = dir_search(self->disk_mem, pdir, name); free(path_c); free(name); - + if (!block){ return -ENOENT; - } + } ind = (inode *) self->disk_mem + INODEPOOL_OFFSET + (block * INODE_SIZE); @@ -148,9 +149,9 @@ int medianin_readlink(medianin *self, const char *path, char *buf, size_t size) file *f = NULL; char name[26]; - assert(INVREP(self)); - assert(path!=NULL); - assert(buf!=NULL); + assert(INVREP(self)); + assert(path!=NULL); + assert(buf!=NULL); parent_dir = dir_get_from_path(self->disk_mem, path); @@ -168,131 +169,132 @@ int medianin_readlink(medianin *self, const char *path, char *buf, size_t size) if(S_ISDIR(inode_get_mode((inode *) f))) return -EISDIR; - return file_read(self->disk_mem, f, buf, size, 0); + return file_read(self->disk_mem, f, buf, size, 0); } int medianin_mknod(medianin *self, const char *path, mode_t mode) { - dir *idir = NULL; - uint16_t ifile = 0; - char bname[26]; - - assert(INVREP(self)); - assert(path!=NULL); - + dir *idir = NULL; + uint16_t ifile = 0; + char bname[26]; + + assert(INVREP(self)); + assert(path!=NULL); + strncpy(&(bname[0]),basename((char *) path), 26); - - if(strlen(bname)>25){ - return -ENAMETOOLONG; - } - - idir=dir_get_from_path(self->disk_mem, path); - - if(dir_search(self->disk_mem ,idir, bname)){ - return -EEXIST; - } - - if((ifile=file_create(self->disk_mem, mode))==0){ - return -ENOSPC; - } - - if((dir_add_direntry(self->disk_mem, idir, bname, ifile, 0))==0){ - inode_free_block(self->disk_mem, ifile); - return -ENOSPC; - } - - return 0; + + if(strlen(bname)>25){ + return -ENAMETOOLONG; + } + + idir=dir_get_from_path(self->disk_mem, path); + + if(dir_search(self->disk_mem ,idir, bname)){ + return -EEXIST; + } + + if((ifile=file_create(self->disk_mem, mode))==0){ + return -ENOSPC; + } + + if((dir_add_direntry(self->disk_mem, idir, bname, ifile, 0))==0){ + inode_free_block(self->disk_mem, ifile); + return -ENOSPC; + } + + return 0; } int medianin_unlink(medianin *self, const char *path) { - int result = 0; - assert(INVREP(self)); - assert(path!=NULL); + int result = 0; + assert(INVREP(self)); + assert(path!=NULL); - result = 0; - return result; + result = 0; + return result; } int medianin_symlink(medianin *self, const char *from, const char *to) { - int result = 0; - assert(INVREP(self)); - assert(from!=NULL && to!=NULL); + int result = 0; + assert(INVREP(self)); + assert(from!=NULL && to!=NULL); - result = 0; - return result; + result = 0; + return result; } int medianin_rename(medianin *self, const char *from, const char *to) { - int result = 0; + int result = 0; - assert(INVREP(self)); - assert(from!=NULL && to!=NULL); + assert(INVREP(self)); + assert(from!=NULL && to!=NULL); - result = 0; - return result; + result = 0; + return result; } int medianin_link(medianin *self, const char *from, const char *to) { - int result = 0; - char *to_c = NULL; + int result = 0; + char *to_c = NULL; char *from_c = NULL; - uint16_t inum_from; - dir *from_dir, *to_dir; - file *f; - time_t itime; - - assert(INVREP(self)); - assert(from!=NULL && to!=NULL); - - - if(strlen(basename((char *)to))>25){ - return -ENAMETOOLONG; - } - + uint16_t inum_from; + dir *from_dir, *to_dir; + file *f; + time_t itime; + + assert(INVREP(self)); + assert(from!=NULL && to!=NULL); + + + if(strlen(basename((char *)to))>25){ + return -ENAMETOOLONG; + } + to_c = calloc(NAME_LENGTH, sizeof(char)); from_c = calloc(NAME_LENGTH, sizeof(char)); - strcpy(to_c, to); - strcpy(from_c, from); + strcpy(to_c, to); + strcpy(from_c, from); - from_dir=dir_get_from_path(self->disk_mem, to); - - if((inum_from=dir_search(self->disk_mem, from_dir, basename((char *)from)))==0){ - result = -ENOENT; + from_dir = dir_get_from_path(self->disk_mem, to); + inum_from = dir_search(self->disk_mem, from_dir, basename((char *)from)); + if(inum_from == 0){ + result = -ENOENT; goto CLEAN; - } - - f=(file *)self->disk_mem+INODEPOOL_OFFSET+inum_from*INODE_SIZE; - - if(S_ISDIR(f->mode)==1){ - result = -EPERM; + } + + f=(file *)self->disk_mem+INODEPOOL_OFFSET+inum_from*INODE_SIZE; + + if(S_ISDIR(f->mode)==1){ + result = -EPERM; goto CLEAN; - } - - if((to_dir=dir_get_from_path(self->disk_mem, to))==NULL){ - result = -ENOENT; + } + + if((to_dir=dir_get_from_path(self->disk_mem, to))==NULL){ + result = -ENOENT; goto CLEAN; - } - - if(!dir_add_direntry(self->disk_mem, to_dir, basename((char *)to), inum_from, 0)){ - result = -ENOSPC; + } + + if(!dir_add_direntry(self->disk_mem, to_dir, + basename((char *)to), inum_from, 0)){ + result = -ENOSPC; goto CLEAN; - } - - itime=NEW_TIME; - - f->nlinks+=1; - f->atime=itime; - f->mtime=itime; - + } + + itime=NEW_TIME; + + f->nlinks+=1; + f->atime=itime; + f->mtime=itime; + CLEAN: free(to_c); free(from_c); - return result; + return result; } int medianin_chmod(medianin *self, const char *path, mode_t mode) @@ -312,10 +314,10 @@ int medianin_chmod(medianin *self, const char *path, mode_t mode) } pdir = dir_get_from_path(self->disk_mem, path); - + if (!pdir) return -ENOENT; - + name = calloc(NAME_LENGTH, sizeof(char)); strncpy (name, basename((char *) path), NAME_LENGTH); @@ -326,7 +328,7 @@ int medianin_chmod(medianin *self, const char *path, mode_t mode) return -ENOENT; ind = (inode *) self->disk_mem + INODEPOOL_OFFSET + (block * INODE_SIZE); - return inode_chmod(ind, mode); + return inode_chmod(ind, mode); } int medianin_chown(medianin *self,const char *path, uid_t uid, gid_t gid) @@ -346,10 +348,10 @@ int medianin_chown(medianin *self,const char *path, uid_t uid, gid_t gid) } pdir = dir_get_from_path(self->disk_mem, path); - + if (!pdir) return -ENOENT; - + name = calloc(NAME_LENGTH, sizeof(char)); strncpy (name, basename((char *) path), 24); @@ -361,7 +363,7 @@ int medianin_chown(medianin *self,const char *path, uid_t uid, gid_t gid) ind = (inode *) self->disk_mem + INODEPOOL_OFFSET + (block * INODE_SIZE); - return inode_chown(ind, uid, gid); + return inode_chown(ind, uid, gid); } int medianin_truncate(medianin *self, const char *path, off_t size) @@ -371,8 +373,8 @@ int medianin_truncate(medianin *self, const char *path, off_t size) char *name = NULL; uint16_t file_pos = 0; - assert(INVREP(self)); - assert(path!=NULL); + assert(INVREP(self)); + assert(path!=NULL); if(strcmp(path,"/") == 0) return -EISDIR; @@ -399,16 +401,16 @@ int medianin_truncate(medianin *self, const char *path, off_t size) } int medianin_read(medianin *self, const char *path, - char *buffer, size_t size, off_t offset) + char *buffer, size_t size, off_t offset) { uint16_t inode_block = 0; dir *parent_dir = NULL; file *f = NULL; char *name = NULL; - assert(INVREP(self)); - assert(path!=NULL); - assert(buffer!=NULL); + assert(INVREP(self)); + assert(path!=NULL); + assert(buffer!=NULL); parent_dir = dir_get_from_path(self->disk_mem, path); @@ -428,20 +430,20 @@ int medianin_read(medianin *self, const char *path, if(S_ISDIR(inode_get_mode((inode *) f))) return -EISDIR; - return file_read(self->disk_mem, f, buffer, size, offset); + return file_read(self->disk_mem, f, buffer, size, offset); } int medianin_write(medianin *self, const char *path, - const char *buffer, size_t size, off_t offset) + const char *buffer, size_t size, off_t offset) { uint16_t inode_block = 0, result = 0; dir *parent_dir = NULL; file *f = NULL; char *name = NULL; - assert(INVREP(self)); - assert(path!=NULL); - assert(buffer!=NULL); + assert(INVREP(self)); + assert(path!=NULL); + assert(buffer!=NULL); parent_dir = dir_get_from_path(self->disk_mem, path); @@ -454,35 +456,36 @@ int medianin_write(medianin *self, const char *path, inode_block = dir_search(self->disk_mem, parent_dir, name); free(name); - + if(inode_block == 0) return -ENOENT; f = (file *) self->disk_mem + INODEPOOL_OFFSET + (inode_block*INODE_SIZE); if(S_ISDIR(inode_get_mode((inode *)f))) return -EISDIR; - - - if(file_truncate(self->disk_mem, f, f->size+size)!=0){ - return -ENOSPC; - } - - result=file_write(self->disk_mem, f, (char *)buffer, size, offset); - - return result; + + + if(file_truncate(self->disk_mem, f, f->size+size)!=0){ + return -ENOSPC; + } + + result=file_write(self->disk_mem, f, (char *)buffer, size, offset); + + return result; } int medianin_statfs(medianin *self, const char *path, struct statvfs *stbuf) { - int result = 0; - uint16_t free_blocks=free_blocks_count(self->disk_mem), free_inodes=free_inodes_count(self->disk_mem); - - assert(INVREP(self)); - assert(path!=NULL); - assert(stbuf!=NULL); - - - /* man statvfs */ - stbuf->f_bsize=BLOCK_SIZE; + int result = 0; + uint16_t free_blocks = free_blocks_count(self->disk_mem) + uint16_t free_inodes = free_inodes_count(self->disk_mem); + + assert(INVREP(self)); + assert(path!=NULL); + assert(stbuf!=NULL); + + + /* man statvfs */ + stbuf->f_bsize=BLOCK_SIZE; stbuf->f_frsize=BLOCK_SIZE; stbuf->f_blocks=(fsblkcnt_t)BLOCKS; stbuf->f_bfree=(fsblkcnt_t)free_blocks; @@ -490,22 +493,24 @@ int medianin_statfs(medianin *self, const char *path, struct statvfs *stbuf) { stbuf->f_files=(fsblkcnt_t)INODE_ENTRIES; stbuf->f_ffree=(fsblkcnt_t)free_inodes; stbuf->f_ffree=(fsblkcnt_t)free_inodes; - stbuf->f_flag=S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH | S_IFDIR; + stbuf->f_flag = S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | + S_IRGRP | S_IROTH | S_IXOTH | S_IFDIR; stbuf->f_namemax=26; - result = 0; - return result; + result = 0; + return result; } -int medianin_utimens(medianin *self, const char *path, const struct timespec tv[2]) +int medianin_utimens(medianin *self, const char *path, + const struct timespec tv[2]) { char *name = NULL; dir *parent_dir = NULL; inode *in = NULL; uint16_t inode_block = 0; - assert(INVREP(self)); - assert(path!=NULL); + assert(INVREP(self)); + assert(path!=NULL); if(strcmp(path, "/")) { @@ -528,7 +533,7 @@ int medianin_utimens(medianin *self, const char *path, const struct timespec tv[ return -ENOENT; in = (inode *) self->disk_mem + INODEPOOL_OFFSET + - (inode_block*INODE_SIZE); + (inode_block*INODE_SIZE); return inode_utime(in, tv); } @@ -540,45 +545,45 @@ int medianin_mkdir(medianin *self, const char *path, mode_t mode) { int result = 0; dir *idir = NULL; - uint16_t inode_dir = 0; - char *name = NULL; - - assert(INVREP(self)); - assert(path!=NULL); + uint16_t inode_dir = 0; + char *name = NULL; + + assert(INVREP(self)); + assert(path!=NULL); if(S_ISDIR(mode) == 0) mode = mode | S_IFDIR; name = calloc(NAME_LENGTH, sizeof(char)); strncpy (name, basename((char *) path), NAME_LENGTH); - if(strlen(name) > 25){ - result = -ENAMETOOLONG; + if(strlen(name) > 25){ + result = -ENAMETOOLONG; goto CLEAN; - } - - idir=dir_get_from_path(self->disk_mem, path); - - if(dir_search(self->disk_mem ,idir, name)){ - result = -EEXIST; + } + + idir=dir_get_from_path(self->disk_mem, path); + + if(dir_search(self->disk_mem ,idir, name)){ + result = -EEXIST; goto CLEAN; - } - - if((inode_dir=dir_create(self->disk_mem, mode))==0){ - result = -ENOSPC; + } + + if((inode_dir=dir_create(self->disk_mem, mode))==0){ + result = -ENOSPC; goto CLEAN; - } - - if((dir_add_direntry(self->disk_mem, idir, name, inode_dir, 0))==0){ - inode_free_block(self->disk_mem, inode_dir); - result = -ENOSPC; + } + + if((dir_add_direntry(self->disk_mem, idir, name, inode_dir, 0))==0){ + inode_free_block(self->disk_mem, inode_dir); + result = -ENOSPC; goto CLEAN; - } + } assert(GET_BIT(self->disk_mem + FIB_OFFSET, inode_dir) == 1); CLEAN: - free(name); - return result; + free(name); + return result; } int medianin_rmdir(medianin *self, const char *path) @@ -591,7 +596,7 @@ int medianin_rmdir(medianin *self, const char *path) inode *i; assert(INVREP(self)); - assert(path!=NULL); + assert(path!=NULL); parent_dir = dir_get_from_path(self->disk_mem, path); @@ -621,21 +626,21 @@ int medianin_rmdir(medianin *self, const char *path) inode_free_block(self->disk_mem, inum); assert(inum == search_num); - return result; + return result; } int medianin_readdir(medianin *self, const char *path, void *buf, fuse_fill_dir_t filler) { - int result = 0; - dir *parent_dir = NULL; + int result = 0; + dir *parent_dir = NULL; dir *my_dir = NULL; uint16_t dir_inumber = 0; char *name = NULL; - assert(INVREP(self)); - assert(path!=NULL && buf!=NULL); - + assert(INVREP(self)); + assert(path!=NULL && buf!=NULL); + if(strcmp(path, "/") == 0) { /* Root dir */ @@ -655,7 +660,8 @@ int medianin_readdir(medianin *self, const char *path, void *buf, if(!dir_inumber) return -ENOENT; - my_dir = (dir *) self->disk_mem + INODEPOOL_OFFSET + (dir_inumber * INODE_SIZE); + my_dir = (dir *) self->disk_mem + INODEPOOL_OFFSET + + (dir_inumber * INODE_SIZE); FILL: filler(buf, ".", NULL, 0); @@ -663,5 +669,5 @@ FILL: dir_readdir(self->disk_mem, my_dir, buf, filler); - return result; + return result; } diff --git a/medianin.h b/medianin.h index e0b070b..60f2234 100644 --- a/medianin.h +++ b/medianin.h @@ -33,12 +33,13 @@ int medianin_read(medianin *self, const char *path, int medianin_write(medianin *self, const char *path, const char *buffer, size_t size, off_t offset); int medianin_statfs(medianin *self, const char *path, struct statvfs *stbuf); -int medianin_utimens(medianin *self, const char *path, const struct timespec tv[2]); +int medianin_utimens(medianin *self, const char *path, + const struct timespec tv[2]); /* Operaciones sobre Directorios */ int medianin_mkdir(medianin *self, const char *path, mode_t mode); int medianin_rmdir(medianin *self, const char *path); int medianin_readdir(medianin *self, const char *path, void *buf, - fuse_fill_dir_t filler); + fuse_fill_dir_t filler); #endif /* __MEDIANIN_H */ -- cgit v1.2.3-70-g09d2