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>
- char* strannocopy(char* dst, const char* src, size_t nmax) {
- size_t i;
- for(i = 0; i < nmax; ++i) {
- if (src[i] == 0) break;
- dst[i] = src[i];
- printf("element = ");
- printf(dst[i]);
- printf("\n");
- }
- while(i < nmax) {
- dst[i] = 0;
- ++i;
- }
- return dst;
- }
- 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){ //if block exist
- 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 || 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 = directory; //type = directory
- //fs->inodes[index].name = (char *) malloc(NAME_MAX_LENGTH);
- printf(strrchr(path, '/'));
- strannocopy(fs->inodes[index].name, strrchr(path, '/')+1, NAME_MAX_LENGTH);
- //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