Advertisement
madegoff

sysprog2ha_nicht_fertig

Jul 6th, 2023 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.32 KB | None | 0 0
  1. #include "../lib/operations.h"
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. int get_index_parent_from_path(file_system *fs, char *path){
  9.  
  10.     int index_kid;
  11.     int index_parent = fs->root_node; //fangen beim wurzel an
  12.     char* path_temp[strlen(path)+1];
  13.     strcpy(path_temp, path);
  14.  
  15.     char* parent_name = NULL;
  16.     char* child_name = NULL;
  17.  
  18.     child_name = strtok(path_temp, "/");
  19.  
  20.     //bei pfad root/home/folder/...
  21.  
  22.     while (child_name!=NULL){
  23.  
  24.         parent_name = child_name;
  25.         child_name = strtok(NULL, "/");
  26.  
  27.         // parent_name = root
  28.         // child_name = home
  29.  
  30.         for (int i=0; i<DIRECT_BLOCKS_COUNT; i++){
  31.             int block = fs->inodes[index_parent].direct_blocks[i]; //schauen in direct_blocks von root
  32.             if (block == -1){ //block not here, haben ende erreicht
  33.                 break;
  34.             }
  35.             else{
  36.                 if(fs->inodes[block].n_type == "directory"){ //schauen nur auf verzeichnisse
  37.                     if (fs->inodes[block].name == child_name){ // wenn inodes name = home
  38.                         index_kid = block;
  39.                         break; //for schleife beenden
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.         char* temp = strtok(NULL, "/");
  45.         if (temp != NULL) //übernächstes verzeichnis existiert
  46.         {
  47.             index_parent = index_kid;
  48.         }
  49.     }
  50.  
  51.     return index_parent;
  52. }
  53.  
  54. void set_kid(file_system* fs, int index_parent, int index_kind){
  55.  
  56.     //size of array direct_blocks
  57.     //int length = sizeof(fs->inodes[index_parent].direct_blocks)/ sizeof(fs->inodes[index_parent].direct_blocks[0]);
  58.         for (int j = 0; j<DIRECT_BLOCKS_COUNT; j++){
  59.                 if (fs->inodes[index_parent].direct_blocks[j] == -1){ //no block
  60.                         fs->inodes[index_parent].direct_blocks[j] = index_kind;
  61.                         break;
  62.                 }
  63.             }
  64. }
  65.  
  66. int fs_mkdir(file_system *fs, char *path)
  67. {
  68.     if (fs == NULL){
  69.         return -1;
  70.     }
  71.     if(path == NULL){
  72.         return -1;
  73.     }
  74.  
  75.     int index = -1;
  76.  
  77.     //inode finden
  78.     index = find_free_inode(fs);
  79.  
  80.     //if (index == -1){
  81.     //    return -1; //kein free inode gefunden
  82.     //}
  83.  
  84.     //bestimmen parameter für diesen inode
  85.     fs->inodes[index].n_type = 2; //type = directory
  86.     //strncpy(fs->inodes[index].name, (char *) strrchr(path, '/') + 1, NAME_MAX_LENGTH); //name setzen SEGMENTATION FAULT??
  87.     int index_parent = get_index_parent_from_path(fs, path);
  88.     fs->inodes[index].parent = index_parent; //parent setzen
  89.  
  90.     //index_kid in parent.direct_blocks hinzufuegen
  91.     set_kid(fs, index_parent, index);
  92.  
  93.     return 0; //wenn diese stelle erreicht alles gut
  94. }
  95.  
  96. int
  97. fs_mkfile(file_system *fs, char *path_and_name)
  98. {
  99.     return -1;
  100. }
  101.  
  102. char *
  103. fs_list(file_system *fs, char *path)
  104. {
  105.     return NULL;
  106. }
  107.  
  108. int
  109. fs_writef(file_system *fs, char *filename, char *text)
  110. {
  111.     return -1;
  112. }
  113.  
  114. uint8_t *
  115. fs_readf(file_system *fs, char *filename, int *file_size)
  116. {
  117.     return NULL;
  118. }
  119.  
  120.  
  121. int
  122. fs_rm(file_system *fs, char *path)
  123. {
  124.     return -1;
  125. }
  126.  
  127. int
  128. fs_import(file_system *fs, char *int_path, char *ext_path)
  129. {
  130.     return -1;
  131. }
  132.  
  133. int
  134. fs_export(file_system *fs, char *int_path, char *ext_path)
  135. {
  136.     return -1;
  137. }
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement