Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../lib/operations.h"
- #include <stddef.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int get_index_parent_from_path(file_system *fs, char *path){
- int index_kid;
- int index_parent = fs->root_node; //fangen beim wurzel an
- char* path_temp[strlen(path)+1];
- strcpy(path_temp, path);
- char* parent_name = NULL;
- char* child_name = NULL;
- child_name = strtok(path_temp, "/");
- //bei pfad root/home/folder/...
- while (child_name!=NULL){
- parent_name = child_name;
- child_name = strtok(NULL, "/");
- // parent_name = root
- // child_name = home
- for (int i=0; i<DIRECT_BLOCKS_COUNT; i++){
- int block = fs->inodes[index_parent].direct_blocks[i]; //schauen in direct_blocks von root
- if (block == -1){ //block not here, haben ende erreicht
- break;
- }
- else{
- if(fs->inodes[block].n_type == "directory"){ //schauen nur auf verzeichnisse
- if (fs->inodes[block].name == child_name){ // wenn inodes name = home
- index_kid = block;
- break; //for schleife beenden
- }
- }
- }
- }
- char* temp = strtok(NULL, "/");
- if (temp != NULL) //übernächstes verzeichnis existiert
- {
- index_parent = index_kid;
- }
- }
- return index_parent;
- }
- void set_kid(file_system* fs, int index_parent, int index_kind){
- //size of array direct_blocks
- //int length = sizeof(fs->inodes[index_parent].direct_blocks)/ sizeof(fs->inodes[index_parent].direct_blocks[0]);
- for (int j = 0; j<DIRECT_BLOCKS_COUNT; j++){
- if (fs->inodes[index_parent].direct_blocks[j] == -1){ //no block
- fs->inodes[index_parent].direct_blocks[j] = index_kind;
- break;
- }
- }
- }
- int fs_mkdir(file_system *fs, char *path)
- {
- if (fs == NULL){
- return -1;
- }
- if(path == NULL){
- return -1;
- }
- int index = -1;
- //inode finden
- index = find_free_inode(fs);
- //if (index == -1){
- // return -1; //kein free inode gefunden
- //}
- //bestimmen parameter für diesen inode
- fs->inodes[index].n_type = 2; //type = directory
- //strncpy(fs->inodes[index].name, (char *) strrchr(path, '/') + 1, NAME_MAX_LENGTH); //name setzen SEGMENTATION FAULT??
- int index_parent = get_index_parent_from_path(fs, path);
- fs->inodes[index].parent = index_parent; //parent setzen
- //index_kid in parent.direct_blocks hinzufuegen
- set_kid(fs, index_parent, index);
- return 0; //wenn diese stelle erreicht alles gut
- }
- int
- fs_mkfile(file_system *fs, char *path_and_name)
- {
- return -1;
- }
- char *
- fs_list(file_system *fs, char *path)
- {
- return NULL;
- }
- int
- fs_writef(file_system *fs, char *filename, char *text)
- {
- return -1;
- }
- uint8_t *
- fs_readf(file_system *fs, char *filename, int *file_size)
- {
- return NULL;
- }
- int
- fs_rm(file_system *fs, char *path)
- {
- return -1;
- }
- int
- fs_import(file_system *fs, char *int_path, char *ext_path)
- {
- return -1;
- }
- int
- fs_export(file_system *fs, char *int_path, char *ext_path)
- {
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement