Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <float.h>
- #include <string.h>
- #include <stdbool.h>
- #define EXIT 0
- #define INFO 1
- #define SIZE 2
- #define LS 3
- #define CD 4
- #define CREAT 5
- #define MKDIR 6
- #define OPEN 7
- #define CLOSE 8
- #define READ 9
- #define WRITE 10
- #define RM 11
- #define RMDIR 12
- #define FILE_READ 1
- #define FILE_WRITE 2
- #define FILE_READWRITE 3
- struct FAT32BootRegion{
- unsigned char jmpBoot[3];
- unsigned char oem[8];
- unsigned short bytes_per_sector;
- unsigned char sectors_per_cluster;
- unsigned short reserved_sectors;
- unsigned char number_of_fats;
- unsigned short root_dir_entries;
- unsigned short num_of_sectors;
- unsigned char media;
- unsigned short fat_size_count_short;
- unsigned short sectors_per_track;
- unsigned short num_of_heads;
- unsigned int hidden_sectors;
- unsigned int total_sectors;
- //Extended BPB Structure
- unsigned int BPB_FATSz32;
- unsigned short BPB_ExtFlags;
- unsigned short BPB_FSVer;
- unsigned int BPB_RootCluster;
- unsigned short BPB_FSInfo;
- unsigned short backup_BS_sector;
- unsigned char reserved_0[12];
- unsigned char drive_number;
- unsigned char reserved_1;
- unsigned char boot_signature;
- unsigned int volume_id;
- char volume_label[11];
- char fs_type[8];
- char misc_boot_code[420];
- unsigned short signature_word;
- }__attribute__((packed));
- struct FAT32Dir{
- unsigned char Name[11];
- unsigned char Attr;
- unsigned char NTRes;
- unsigned char CrtTimeTenth;
- unsigned short CrtTime;
- unsigned short CrtDate;
- unsigned short LsrAccDate;
- unsigned short FstClusHI;
- unsigned short WrtTime;
- unsigned short WrtDate;
- unsigned short FstClusLO;
- unsigned int FileSize;
- }__attribute__((packed));
- struct FAT32File{
- int mode;
- char * name;
- int first_cluster_num;
- };
- //***********************GLOBAL VARIABLES***************************
- struct FAT32BootRegion boot_region;
- FILE * fp;
- static char * commands[13] = {"exit", "info", "size", "ls", "cd", "creat", "mkdir", "open", "close", "read", "write", "rm", "rmdir"};
- struct FAT32File openFiles[500] = {{0}};
- //**********************HELPER FUNCTIONS*****************************
- void parseBootSector(){
- fread(&boot_region, sizeof(struct FAT32BootRegion), 1, fp);
- }
- void prompt(){
- printf("FAT32-SHELL~> ");
- }
- //Separates tokens by space
- int getTokens(char ** tokens){
- char raw_input[1000];
- char * command;
- char * token;
- char * pre_processed_cmd;
- int token_count = 0;
- fgets(raw_input, 999, stdin);
- command = strtok(raw_input, "\n");
- if (command == NULL)
- return 0;
- pre_processed_cmd = strdup(command);
- token = strtok(command, " ");
- if(token != NULL && !strcmp(token, "write")){
- char * write_string;
- while(token != NULL && token[0] != '"'){
- printf("Token: %s\n", token);
- tokens[token_count++] = strdup(token);
- token = strtok(NULL, " ");
- }
- write_string = strchr(pre_processed_cmd, '"');
- if(write_string != NULL){
- token = strtok(write_string+1, "\"");
- tokens[token_count++] = strdup(token);
- return token_count;
- }
- }
- while(token != NULL){
- tokens[token_count++] = strdup(token);
- token = strtok(NULL, " ");
- }
- return token_count;
- }
- //First Sector of Cluster given
- unsigned int getFirstSectorofCluster(int cluster){
- unsigned int FirstDataSector = boot_region.reserved_sectors + (boot_region.number_of_fats*boot_region.BPB_FATSz32);
- unsigned int FirstSectorofCluster = ((cluster-2) * boot_region.sectors_per_cluster) + FirstDataSector;
- return FirstSectorofCluster*boot_region.bytes_per_sector;
- }
- //get FAT[clus] or next cluster in chain
- unsigned int getFatEntry(int cluster){
- unsigned int fatEntry;
- unsigned int fatOffset = cluster * 4;
- unsigned int fatSector = boot_region.reserved_sectors*boot_region.bytes_per_sector + fatOffset;
- fseek(fp,fatSector, SEEK_SET);
- fread(&fatEntry, sizeof(int), 1, fp);
- //printf("Fat Entry at cluster[%d]: %d\n",cluster, fatEntry);
- return fatEntry & 0x0FFFFFFF;
- }
- void setFatEntry(unsigned int cluster, unsigned int entry){
- int fatOffset = boot_region.reserved_sectors + boot_region.bytes_per_sector * cluster*4;
- fseek(fp, fatOffset, SEEK_SET);
- fwrite(&entry, sizeof(unsigned int), 1, fp);
- }
- //Converts stored file name into 8.3 format
- char * getFileName(char * storedFileName){
- int i = 0;
- char * fileNameFormatted = strdup(storedFileName);
- for(i = 0; i < strlen(storedFileName); i++){
- if(!isspace(storedFileName[i]))
- fileNameFormatted[i] = tolower(storedFileName[i]);
- else if(isspace(storedFileName[i])){
- if(!isspace(storedFileName[i+1]) && (i < strlen(storedFileName)-1) )
- fileNameFormatted[i] = '.';
- else
- fileNameFormatted[i] = '\0';
- }
- else
- fileNameFormatted[i] = tolower(storedFileName[i]);
- }
- return fileNameFormatted;
- }
- //Converts stored file name into 8.3 format
- char * getDirName(char * storedDirName){
- int i;
- char * dirNameFormatted = strdup(storedDirName);
- for(i = 0; i < strlen(storedDirName); i++){
- if(isspace(storedDirName[i]))
- dirNameFormatted[i] = '\0';
- else if(isalpha(storedDirName[i])){
- dirNameFormatted[i] = tolower(storedDirName[i]);
- }
- else
- dirNameFormatted[i] = storedDirName[i];
- }
- return dirNameFormatted;
- }
- //Read 32 byte FAT directory entries until we find a match by name
- struct FAT32Dir getDirectory(unsigned int cluster, char * directoryName){
- int i = 0;
- struct FAT32Dir directory;
- struct FAT32Dir emptyDir = {{0}};
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(cluster);
- unsigned int FATEntry = getFatEntry(cluster);
- fseek(fp, FirstSectorofCluster, SEEK_SET);
- while(i*sizeof(struct FAT32Dir) < boot_region.bytes_per_sector){
- fread(&directory, sizeof(struct FAT32Dir), 1, fp);
- if(!strcmp(getDirName(directory.Name), directoryName))
- return directory;
- i++;
- }
- if( FATEntry != 0x0FFFFFF8 && FATEntry != 0x00000000 && FATEntry != 0xFFFFFFFF)
- return getDirectory(FATEntry, directoryName);
- return emptyDir;
- }
- bool hasCorrectFormat(int command, int token_count){
- switch(command){
- case INFO:
- return (token_count == 1);
- case SIZE:
- return (token_count == 2);
- case LS:
- return (token_count == 2 || token_count == 1);
- case CD:
- return (token_count == 2);
- case CREAT:
- return (token_count == 2);
- case MKDIR:
- return (token_count == 2);
- case OPEN:
- return (token_count == 3);
- case CLOSE:
- return (token_count == 2);
- case READ:
- return (token_count == 4);
- case WRITE:
- return (token_count == 5);
- case RM:
- return (token_count == 2);
- case RMDIR:
- return (token_count == 2);
- }
- return 0;
- }
- void run_ls(unsigned int cluster_num){
- int i = 0;
- struct FAT32Dir directory;
- unsigned int fatEntry = getFatEntry(cluster_num);
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(cluster_num);
- fseek(fp, FirstSectorofCluster,SEEK_SET);
- while(i*sizeof( struct FAT32Dir) < boot_region.bytes_per_sector){
- fread(&directory, sizeof(struct FAT32Dir), 1, fp);
- if(directory.Name[0] == 0x00){
- ++ i;
- continue;
- }
- if(directory.Attr == 0x10){
- printf("\e[1;34m%s\e[0m\n", getDirName((char *)directory.Name));
- }
- else
- printf("%s\n", getFileName((char *)directory.Name));
- i++;
- }
- if(fatEntry != 0x0FFFFFF8 &&fatEntry != 0x0FFFFFFF &&fatEntry != 0x00000000)
- run_ls(fatEntry);
- }
- //*************************** FILE SYSTEM COMMANDS********************************
- void info(){
- printf("Bytes per sector: %d\n",boot_region.bytes_per_sector);
- printf("Sectors per cluster: %hu\n",boot_region.sectors_per_cluster);
- printf("Reserved Sector Count: %d\n",boot_region.reserved_sectors);
- printf("Number of fats: %d\n",boot_region.number_of_fats);
- printf("Total Sectors: %d\n",boot_region.total_sectors);
- printf("FAT Size: %d\n", (boot_region.fat_size_count_short == 0) ? boot_region.BPB_FATSz32 : boot_region.fat_size_count_short == 0);
- printf("Root Cluster: %d\n", boot_region.BPB_RootCluster);
- }
- unsigned int cd(unsigned int cluster, char * directoryName){
- printf("Changing directory to: %s\n", directoryName);
- struct FAT32Dir dir = getDirectory(cluster, directoryName);
- printf("Found Directory: %s\n", dir.Name);
- printf("Directory Attribute: %c\n", dir.Attr);
- if(dir.Attr == 0x10 && strcmp(getDirName((char *)dir.Name), directoryName) == 0){
- if(dir.FstClusHI+dir.FstClusLO == 0)
- return boot_region.BPB_RootCluster;
- return dir.FstClusHI*0x100 + dir.FstClusLO;
- }
- else{
- if(strcmp(directoryName, "."))
- printf("Error! Directory not found\n");
- return cluster;
- }
- }
- void size(unsigned int current_cluster, char * directoryName){
- struct FAT32Dir directory = getDirectory(current_cluster, directoryName);
- if(!strcmp(getFileName((char *)directory.Name), directoryName) && directory.Attr != 0x10)
- printf("Size of [%s]: %d bytes\n", directoryName, directory.FileSize);
- else
- printf("[%s] is not a file.\n");
- }
- void ls(unsigned int root_cluster, unsigned int current_cluster, int token_count, char ** tokens){
- if(token_count == 1)
- run_ls(current_cluster);
- else{
- if(!strcmp(tokens[1], ".")){
- run_ls(current_cluster);
- return;
- }
- unsigned int next_cluster = cd(current_cluster, tokens[1]);
- if(next_cluster != current_cluster){
- root_cluster = current_cluster;
- current_cluster = next_cluster;
- run_ls(current_cluster);
- current_cluster = root_cluster;
- }
- else{
- printf("%s: Is not a directory.\n",tokens[1]);
- }
- }
- }
- int findEmptyCluster(){
- int i;
- unsigned int fatStart = boot_region.reserved_sectors * boot_region.bytes_per_sector;
- unsigned fatEnd = fatStart + boot_region.total_sectors;
- for(i = 0; fatStart + i * (sizeof(int)) < fatEnd; i++){
- if(!getFatEntry(i))
- return i;
- }
- return -1;
- }
- void linkNewCluster(unsigned int parent_cluster, unsigned int new_cluster){
- unsigned int lastEntry = 0x0FFFFFFF;
- setFatEntry(parent_cluster, new_cluster);
- setFatEntry(new_cluster, lastEntry);
- }
- int findFirstEmptyDirEntry(unsigned int current_cluster){
- int i = 0;
- int next_free_cluster;
- struct FAT32Dir directory;
- unsigned int fatEntry = getFatEntry(current_cluster);
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(current_cluster);
- printf("First sector of cluster: %u\n", FirstSectorofCluster);
- fseek(fp, FirstSectorofCluster, SEEK_SET);
- while(i * sizeof(struct FAT32Dir) < boot_region.bytes_per_sector){
- fread(&directory, sizeof(struct FAT32Dir), 1, fp);
- printf("Directory name: %s\n", directory.Name);
- if(directory.Name[0] == 0x00){
- return (i * sizeof(struct FAT32Dir)) + current_cluster;
- }
- i++;
- }
- if(fatEntry != 0x0FFFFFF8 &&fatEntry != 0x0FFFFFFF)
- findFirstEmptyDirEntry(fatEntry);
- //CLuster is full, get next free cluster
- if(fatEntry == 0x0FFFFFF8 || fatEntry == 0x0FFFFFFF){
- next_free_cluster = findEmptyCluster();
- linkNewCluster(current_cluster, next_free_cluster);
- return getFirstSectorofCluster(next_free_cluster);
- }
- return -1;
- }
- void makeNewDirectory(struct FAT32Dir* directory, unsigned char attr, char * name, unsigned short FstClusHI, unsigned FstClusLO){
- strcpy((char *) directory-> Name, name);
- directory->Attr = attr;
- directory->FstClusHI = FstClusHI;
- directory->FstClusLO = FstClusLO;
- }
- void mkdir(unsigned int current_cluster, char * directoryName){
- int firstEmptyDirectory;
- int nextFreeCluster;
- struct FAT32Dir newDir, dotDir, doubleDotDir;
- struct FAT32Dir test_directory = getDirectory(current_cluster, directoryName);
- if(!strcmp(getDirName(test_directory.Name), directoryName)){
- printf("%s\n", "Directory Already Exists!");
- return;
- }
- //Write new directory into free space
- firstEmptyDirectory = findFirstEmptyDirEntry(current_cluster);
- //nextFreeCluster = findEmptyCluster();
- //setFatEntry(nextFreeCluster, 0x0FFFFFF8);
- makeNewDirectory(&newDir, 0x10, directoryName, nextFreeCluster/0x100, nextFreeCluster%0x100);
- fseek(fp, firstEmptyDirectory, SEEK_SET);
- fwrite(&newDir, sizeof(struct FAT32Dir), 1, fp);
- //Add '.' and '..' entries for new directory
- makeNewDirectory(&dotDir, 0x10, ".", nextFreeCluster/0x100, nextFreeCluster&0x100);
- firstEmptyDirectory = findFirstEmptyDirEntry(nextFreeCluster);
- fseek(fp, firstEmptyDirectory, SEEK_SET);
- fwrite(&dotDir, sizeof(struct FAT32Dir), 1, fp);
- makeNewDirectory(&doubleDotDir, 0x10, "..", nextFreeCluster/0x100, nextFreeCluster&0x100);
- firstEmptyDirectory = findFirstEmptyDirEntry(nextFreeCluster);
- fseek(fp, firstEmptyDirectory, SEEK_SET);
- fwrite(&dotDir, sizeof(struct FAT32Dir), 1, fp);
- }
- void open( char * fileName, char * mode, unsigned int current_cluster){
- struct FAT32File file;
- struct FAT32Dir directory;
- int m;
- if(!strcmp(mode, "r"))
- m = FILE_READ;
- else if (!strcmp(mode, "w"))
- m = FILE_WRITE;
- else if(!strcmp(mode, "rw") || !strcmp(mode, "wr"))
- m = FILE_READWRITE;
- else{
- printf("Error! Mode is not valid.");
- return;
- }
- directory = getDirectory(current_cluster, fileName);
- if (!strcmp(getFileName(directory.Name), fileName)){
- printf("Found directory: %s\n", getFileName(directory.Name));
- file.name = strdup(fileName);
- file.first_cluster_num = directory.FstClusHI*0x100 + directory.FstClusLO;
- file.mode = m;
- } else {
- printf("Error! File [%s] does not exist\n", (char *)fileName);
- }
- int i;
- for(i = 0; i < 500; i++){
- if(openFiles[i].name != NULL && !strcmp(openFiles[i].name, getFileName(directory.Name))){
- if(m == openFiles[i].mode){
- printf("File [%s] is already in mode [%s]\n", fileName, mode);
- return;
- }
- openFiles[i].mode = m;
- return;
- }
- }
- for(i = 0; i < 500; i++){
- if(openFiles[i].name == NULL){
- openFiles[i] = file;
- break;
- }
- }
- }
- void close(char * fileName){
- int i;
- for(i = 0; i < 500; i++){
- if(openFiles[i].name == NULL){
- continue;
- }
- if(!strcmp(fileName, openFiles[i].name)){
- openFiles[i].name = NULL;
- openFiles[i].mode = 0;
- openFiles[i].first_cluster_num = 0;
- return;
- }
- }
- printf("File [%s] was not opened!\n", fileName);
- }
- void run_read(char * string, unsigned int current_cluster, int offset, int length){
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(current_cluster);
- unsigned int fatEntry = getFatEntry(current_cluster);
- unsigned int new_file_cluster;
- fseek(fp, FirstSectorofCluster+offset, SEEK_SET);
- if(length + offset > boot_region.bytes_per_sector){
- fread(strlen(string)+string,(boot_region.bytes_per_sector-offset), 1, fp);
- printf("%.*s", length, string + offset);
- length = length - (boot_region.bytes_per_sector-offset);
- }
- else{
- fread(string, length , 1, fp);
- printf("%.*s\n", length, string + offset);
- return;
- }
- if(fatEntry != 0x0FFFFFF8 || fatEntry != 0x0FFFFFFF || fatEntry != 0x00000000){
- run_read(string, fatEntry,0,length);
- }
- }
- void read(unsigned int current_cluster, char * fileName, int offset, int length) // wil
- {
- int i = 0;
- int flag = 0;
- bool found = false;
- char * formatString;
- struct FAT32Dir directory = getDirectory(current_cluster, fileName);
- unsigned int fatEntry = getFatEntry(current_cluster);
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(current_cluster);
- if(offset > directory.FileSize)
- {
- printf("Error! OFFSET is larger than file size\n");
- return;
- }
- if(!strcmp(getFileName((char *)directory.Name), fileName)) // check if file exist
- {
- if(directory.Attr != 0x10){
- if(length > directory.FileSize || offset+length > directory.FileSize){
- length = directory.FileSize - offset;
- formatString = (char *)calloc(length+1, sizeof(char));
- }
- //else
- {
- for(i = 0; i < 500; i++){
- if(openFiles[i].name != NULL && !strcmp(openFiles[i].name, getFileName(directory.Name))){
- if(openFiles[i].mode == FILE_READ || openFiles[i].mode == FILE_READWRITE){
- fatEntry = openFiles[i].first_cluster_num;
- flag = offset/boot_region.bytes_per_sector;
- while(flag != 0){
- if(fatEntry == 0x00000000 || fatEntry == 0xFFFFFFF8){
- return;
- }
- fatEntry = getFatEntry(fatEntry);
- flag--;
- }
- run_read(formatString, fatEntry, (offset%boot_region.bytes_per_sector), length);
- found = true;
- break;
- /*
- long int hex = FirstSectorofCluster + (openFiles[i].first_cluster_num - 2) * (boot_region.bytes_per_sector * boot_region.sectors_per_cluster);
- unsigned char buffer[5000000];
- fseek(fp, hex, SEEK_SET);
- fread(buffer,sizeof(buffer), 1, fp);
- printf("%.*s\n", len, buffer + offs);
- */
- }
- }
- }
- if(found == false)
- printf("File [%s] is not in reading mode\n", fileName);
- }
- }
- else
- printf("Error! [%s] is a directory.\n", fileName);
- }
- else
- printf("Error! [%s] does not exist.\n", fileName);
- }
- void run_write(unsigned int current_cluster, int offset, int len, char * string){
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(current_cluster);
- unsigned int fatEntry = getFatEntry(current_cluster);
- unsigned int new_file_cluster;
- int string_offset;
- fseek(fp, FirstSectorofCluster+offset, SEEK_SET);
- if(len + offset > boot_region.bytes_per_sector){
- fwrite(string,boot_region.bytes_per_sector-offset, 1, fp);
- string_offset = (boot_region.bytes_per_sector-offset);
- len = len - (boot_region.bytes_per_sector-offset);
- }
- else{
- fwrite(string, len , 1, fp);
- return;
- }
- if(fatEntry != 0x0FFFFFF8 || fatEntry != 0x0FFFFFFF || fatEntry != 0x00000000){
- run_write(fatEntry, 0, len, string + string_offset);
- }
- if(fatEntry == 0x0FFFFFF8 || fatEntry == 0x0FFFFFFF ){
- new_file_cluster = findEmptyCluster();
- linkNewCluster(current_cluster, new_file_cluster);
- run_write(new_file_cluster, 0, len, string+string_offset);
- }
- }
- void updateDirectory(struct FAT32Dir directory, unsigned int current_cluster){
- int i = 0;
- int next_free_cluster;
- struct FAT32Dir temp;
- unsigned int fatEntry = getFatEntry(current_cluster);
- unsigned int FirstSectorofCluster = getFirstSectorofCluster(current_cluster);
- fseek(fp, FirstSectorofCluster, SEEK_SET);
- while(i * sizeof(struct FAT32Dir) < boot_region.bytes_per_sector){
- fread(&temp, sizeof(struct FAT32Dir), 1, fp);
- if(!strcmp(getFileName(temp.Name), getFileName(directory.Name) )){
- fseek(fp, i*sizeof(struct FAT32Dir)+ FirstSectorofCluster, SEEK_SET);
- fwrite(&directory, sizeof(struct FAT32Dir), 1, fp);
- }
- i++;
- }
- if(fatEntry != 0x0FFFFFF8 &&fatEntry != 0x0FFFFFFF)
- updateDirectory(directory, fatEntry);
- }
- void write(unsigned int current_cluster, char * fileName, int offs, int len, char * string) // wil
- {
- //char * dup;
- int i = 0;
- int flag = 0;
- unsigned int fatEntry;
- char * formatString;
- struct FAT32Dir directory = getDirectory(current_cluster, fileName);
- if(strlen(string) <= len){
- formatString = (char *)calloc(len, sizeof(char));
- strcpy(formatString, string);
- }
- if(!strcmp(getFileName((char *)directory.Name), fileName))
- {
- if(directory.Attr != 0x10)
- {
- if(offs > directory.FileSize)
- printf("Error! OFFSET is larger than file size\n");
- else
- {
- bool found = false;
- for(i = 0; i < 500; i++)
- {
- if(openFiles[i].name != NULL && !strcmp(openFiles[i].name, getFileName(directory.Name)))
- {
- if(openFiles[i].mode == FILE_WRITE || openFiles[i].mode == FILE_READWRITE)
- {
- fatEntry = openFiles[i].first_cluster_num;
- flag = offs/boot_region.bytes_per_sector;
- while(flag != 0){
- if(fatEntry == 0x00000000 || fatEntry == 0xFFFFFFF8){
- return;
- }
- fatEntry = getFatEntry(fatEntry);
- flag --;
- }
- run_write(fatEntry, (offs%boot_region.bytes_per_sector), len, formatString);
- if(offs + len > directory.FileSize)
- {
- directory.FileSize = directory.FileSize + (strlen(string) - directory.FileSize) + offs;
- directory.Attr = 0x20;
- updateDirectory(directory, current_cluster);
- found = true;
- break;
- }
- }
- }
- if(found == false)
- printf("File [%s] is not in writing mode\n", fileName);
- }
- }
- }
- else
- printf("Error! [%s] is a directory.\n", fileName);
- }
- else
- printf("Error! [%s] does not exist.\n", fileName);
- }
- void rm();
- int main(int argc, char *argv[])
- {
- unsigned int root_cluster;
- unsigned int current_cluster;
- char * tokens[5];
- int token_count;
- int command = -1;
- if(argv[1] == NULL){
- printf("No image file found!\nUse format: [executable] [FAT32 Image]\n");
- exit(0);
- }
- fp = fopen(argv[1], "r+");
- if(fp == NULL){
- printf("%s\n\n", "Could not open file");
- }
- parseBootSector();
- root_cluster = boot_region.BPB_RootCluster;
- current_cluster = root_cluster;
- while(1){
- prompt();
- token_count = getTokens(tokens);
- printf("This the number of tokens: %d\n", token_count);
- if (token_count == 0)
- continue;
- int i;
- for(i = 0; i < 13; i++){
- if(!strcmp(commands[i], tokens[0])){
- command = i;
- break;
- }
- }
- //EXIT
- if (command == 0)
- break;
- if(!(hasCorrectFormat(command, token_count))){
- printf("%s\n", "Error! Invalid Command.");
- continue;
- }
- switch(command){
- case INFO:
- info();
- break;
- case SIZE:
- size(current_cluster, tokens[1]);
- break;
- case LS:
- ls(root_cluster, current_cluster, token_count, tokens);
- break;
- case CD:
- current_cluster = cd(current_cluster, tokens[1]);
- break;
- case MKDIR:
- mkdir(current_cluster, tokens[1]);
- break;
- case OPEN:
- open(tokens[1], tokens[2], current_cluster);
- break;
- case CLOSE:
- close(tokens[1]);
- break;
- case READ:
- read(current_cluster, tokens[1], atoi(tokens[2]), atoi(tokens[3]));
- break;
- case WRITE:
- write(current_cluster, tokens[1], atoi(tokens[2]), atoi(tokens[3]), tokens[4]);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement