aboutsummaryrefslogtreecommitdiff
path: root/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'inode.c')
-rw-r--r--inode.c107
1 files changed, 54 insertions, 53 deletions
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(i<path_len){
- /*el while empieza desde i=1, se come el primer slash, necesario
- * para usar basename*/
- if(path_mod[i] == '/'){
- /*NULL-terminamos el string para conseguir solo ese dir/file*/
- path_mod[i]='\0';
- break;
- }
- i++;
- }
-
- result=inode_search(disk_mem, current, path_mod);
+ strcpy(path_mod, path);
+
+ while(i<path_len){
+ /*el while empieza desde i=1, se come el primer slash, necesario
+ * para usar basename*/
+ if(path_mod[i] == '/'){
+ /*NULL-terminamos el string para conseguir solo ese dir/file*/
+ path_mod[i]='\0';
+ break;
+ }
+ i++;
+ }
+
+ result=inode_search(disk_mem, current, path_mod);
free(path_mod);
-
- if(i < path_len){
- /* *si no se llego al final, se busca el dir actual, y se continua
- * la busqueda*/
- /*RECURSION FTW!*/
- return get_inode_from_path(disk_mem, path + i, result);
- }
-
- /*si se llego al final, devolvemos el inodo correspondiente a la
- * iteracion*/
-
-
- return result;
-}
+
+ if(i < path_len){
+ /* *si no se llego al final, se busca el dir actual, y se continua
+ * la busqueda*/
+ /*RECURSION FTW!*/
+ return get_inode_from_path(disk_mem, path + i, result);
+ }
+
+ /*si se llego al final, devolvemos el inodo correspondiente a la
+ * iteracion*/
+
+
+ return result;
+}
int inode_getattr(inode *f, ino_t inum, struct stat *stbuf)
{
@@ -129,7 +130,7 @@ uint16_t inode_allocate_block(const char *disk_mem)
{
uint16_t result = 0;
uint16_t i = 0;
-
+
assert (disk_mem != NULL);
/* Solo queremos desde el segundo inodo para
* que tengamos como error el 0 */
@@ -142,7 +143,7 @@ uint16_t inode_allocate_block(const char *disk_mem)
break;
}
assert(GET_BIT(disk_mem + FIB_OFFSET, i) == 1);
-
+
return (result);
}