int mcd(int argc, char** argv) { int inumber; char* filename; if(argc < 1) { strcpy(current_path, "/"); return 1; } if(argv[1][0] == '/') { inumber = inumber_of_path(argv[1]); if(inumber > 0) { strcpy(current_path, argv[1]); } } else { filename = malloc((strlen(current_path) + strlen(argv[1])) * sizeof(char)); strcat(filename, current_path); strcat(filename, argv[1]); inumber = inumber_of_path(filename); if(inumber > 0) { strcpy(current_path, filename); } } return 1; }
void cd(const char** arg) { int inumber; char* filename; if(arg == NULL) { return; } if(arg[1][0] == '/') { inumber = inumber_of_path(arg[1]); if(inumber > 0) { current_path = arg[1]; } } else { filename = malloc((strlen(current_path) + strlen(arg[1])) * sizeof(char)); strcat(filename, current_path); strcat(filename, arg[1]); inumber = inumber_of_path(filename); if(inumber > 0) { current_path = filename; } } }
int main(int argc, char** argv) { int inumber; if(argc != 2) { printf("%s <absolute_path>\n", argv[0]); return EXIT_FAILURE; } mount(); if((inumber = inumber_of_path(argv[1])) != 0) { file_desc_t fd; if(open_ifile(&fd, inumber) != RETURN_FAILURE) { struct entry_s entry; while(read_ifile(&fd, &entry, sizeof(struct entry_s)) > 0) { if(entry.inumber != 0) printf("%s\n", entry.name); } close_ifile(&fd); } } else PRINT_FATAL_ERROR("Not a valid path"); return EXIT_SUCCESS; }