Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int get_index_parent_from_path(file_system *fs, char *path){
- //printf("ANFANG GET INDEX PARENT\n");
- //printf("PATH = %s\n", path);
- int index_current = fs->root_node; //fangen beim wurzel an
- //printf("INDEX CURRENT = %d\n", index_current);
- char* path_temp = strdup(path);
- char* token = NULL;
- char* last_token = (char *)strrchr(path_temp, '/')+1;
- //printf("last_token = %s\n", last_token);
- token = strtok(path_temp, "/");
- //printf("token = %s\n", token);
- if(last_token == token) {
- //printf("gleich, return 0\n");
- return 0;
- }
- //bei pfad /root/home/folder/...
- while (token!=last_token){ //durchlaufen path
- printf("TOCKEN = %s\n", token);
- int flag = 0; //zeigt, ob wir das kind von current_node gefunden haben
- for (int i=0; i<DIRECT_BLOCKS_COUNT; i++){
- printf("i = %d\n", i);
- int block_num = fs->inodes[index_current].direct_blocks[i]; //schauen in direct_blocks von root
- printf("BLOCK_NUM = %d\n", block_num);
- printf("index_current = %d\n", index_current);
- if (block_num != -1){ //if block exist
- if(fs->inodes[block_num].n_type == directory){ //schauen nur auf verzeichnisse
- if (strcmp(fs->inodes[block_num].name, token) == 0){ // wenn inodes name = home
- printf("CHILD GEFUNDEN\n");
- index_current = block_num;
- flag = 1;
- token = strtok(NULL, "/");
- break; //for schleife beenden
- }
- }
- }
- else if(i>=DIRECT_BLOCKS_COUNT-1) flag = 0;
- }
- printf("WEITER GEHTS\n");
- if(flag != 1){ //es wurde in current directory kein kind gefunden
- index_current = -1;
- break; // etwas schief, raus aus while schleife
- }
- }
- printf("index_current = %d\n", index_current);
- free(path_temp);
- return index_current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement