Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define n 65
- #define block 5
- int indexToBlock(int cell);
- int blockToIndex(int blk);
- long powerExp(int exp);
- int power(int value, int powerValue);
- int findReqBlocksWithPtr(int rows);
- int *findFreeBlock(int reqBlocks, long decBitmap, char* method);
- long decimalToBinary(long dec);
- long binaryToDecimal(long bin);
- int setBitmap(long decBitmap, int blkNo, int value);
- int *getDirectoryData(int data, char* method);
- int *newMemory();
- void printDiskMap(char* method, int *memArray);
- int getFileName(int fileData);
- int *readcsv(int *memArray, char* method);
- void AddFile(char* method, int *memory, int *csvArray);
- void deleteFile(char* method, int *memArray, int *csvArray);
- int concat123(int xxx, int yyy);
- /* main function to call above defined function */
- // @main
- int main () {
- int *memory;
- char * allocMethod;
- /*
- allocMethod = "indexed";
- memory = newMemory();
- //readcsv(memory, allocMethod);
- //printDiskMap(allocMethod,memory);
- free(memory);
- allocMethod = "contiguous";
- memory = newMemory();
- //readcsv(memory, allocMethod);
- //printDiskMap(allocMethod,memory);
- free(memory);*/
- allocMethod = "linked";
- memory = newMemory();
- readcsv(memory, allocMethod);
- printDiskMap(allocMethod,memory);
- /*
- //testing findFreeBlock function
- long todec = 1111100000;
- printf("%ld\n",todec);
- int *testArray;
- long bitmap = binaryToDecimal(todec);
- testArray = findFreeBlock(3, bitmap, "contiguous");
- //printf("Contiguous free block: %d\n\n",testArray[0]);
- testArray = findFreeBlock(6, bitmap, "linked");
- printf("linked free block: ");
- for (int i = 0; i < 6; i++){
- //printf("%d ",testArray[i]);
- }
- testArray = findFreeBlock(5, bitmap, "indexed");
- printf("\nindexed free block: ");
- for (int i = 0; i < 6; i++){
- printf("%d ",testArray[i]);
- }
- */
- return 0;
- }
- int indexToBlock(int cell){
- return cell/5;
- }
- int blockToIndex(int blk){
- return blk*5;
- }
- long powerExp(int exp){
- long result = 1;
- int base = 10;
- for (exp;exp>0;exp--){
- result *= base;
- }
- return result;
- }
- int power(int value, int powerValue){
- int result = 1;
- for (int i = 0; i < powerValue; i++){
- result *= value;
- }
- return result;
- }
- // @findReqBlocksWithPtr
- int findReqBlocksWithPtr(int rows){
- int reqBlocks = 0;
- // if theres 5 or less rows, only 1 block is needed
- if (rows <= 5){
- reqBlocks = 1;
- }
- // if theres more than 5 rows, each block can only store
- // the location of 4 blocks, and 1 pointer
- else {
- while (rows > 0) {
- // if 1 block is remaining, it does not need 1 more index block, it can fit in the last index block
- // there is only 4 blocks used in the last index block and we dont need a pointer for it
- if (rows != 1){
- rows -= 4;
- reqBlocks++;
- }
- else {
- break;
- }
- }
- }
- return reqBlocks;
- }
- // @findFreeBlock
- int *findFreeBlock(int reqBlocks, long decBitmap, char* method){
- // convert dec bitmap to bin bitmap
- long binBitmap = decimalToBinary(decBitmap);
- // how many bits the bitmap have
- int nDigits = 1;
- long countData = binBitmap;
- // divide by 10 until countData is left with a single digit
- while (countData > 9) {
- nDigits++;
- countData /= 10;
- }
- //printf("digits: %d\n", nDigits);
- int freeBlocksCount = 0, counter = 0;
- long remainder;
- // finding free blocks for contiguous
- if (strcmp(method, "contiguous") == 0){
- // create array of size 1 and set it to -1
- static int freeBlockFound[1] = {-1};
- while(binBitmap != 0) {
- remainder = binBitmap%10;
- if (remainder == 1){
- // free block found
- if (freeBlocksCount == 0){
- // new free block
- freeBlockFound[0] = counter+2;
- }
- freeBlocksCount +=1;
- if (freeBlocksCount == reqBlocks){
- return freeBlockFound;
- }
- }
- else {
- freeBlocksCount = 0;
- freeBlockFound[0] = -1;
- }
- binBitmap /= 10;
- counter++;
- }
- // no space for conti allocation
- freeBlockFound[0] = -1;
- return freeBlockFound;
- }
- // finding free blocks for linked
- else if (strcmp(method, "linked") == 0){
- // static int freeBlockFound[reqBlocks];
- // create array of size required blocks size and set it to -1
- int *freeBlockFound = malloc(reqBlocks * sizeof *freeBlockFound);
- while(binBitmap != 0) {
- remainder = binBitmap%10;
- if (remainder == 1){
- // free block found
- freeBlocksCount++;
- freeBlockFound[freeBlocksCount-1] = counter + 2;
- if (freeBlocksCount == reqBlocks){
- return freeBlockFound;
- }
- }
- binBitmap /= 10;
- counter++;
- }
- // no space for linked allocation
- freeBlockFound[0] = -1;
- return freeBlockFound;
- }
- // finding free blocks for indexed
- else {
- // calculate number of index blocks required for index allocation
- int reqIndexBlocks = findReqBlocksWithPtr(reqBlocks);
- // create array of and set it to -1. Every free data and index block found will be stored here
- int *freeBlockFound = malloc((reqBlocks + reqIndexBlocks) * sizeof *freeBlockFound);
- int enoughFreeIndex = 0;
- while(binBitmap != 0) {
- remainder = binBitmap%10;
- // 5 blocks for index, find free index blocks
- if (counter < 5){
- // dont need to check already once we know we have enough index blocks
- if (enoughFreeIndex == 0){
- printf("\nChecking indexed block");
- if (remainder == 1) {
- printf ("\nfree index block found at: %d",counter+2);
- // free index block found
- freeBlocksCount++;
- freeBlockFound[freeBlocksCount-1] = counter + 2;
- if (freeBlocksCount == reqIndexBlocks) {
- enoughFreeIndex = 1;
- printf("enough index");
- }
- }
- }
- }
- // will run below code once done checking for free index blocks
- else if (enoughFreeIndex == 0) {
- // no space in index blocks
- freeBlockFound[0] = -1;
- printf("not enough index");
- return freeBlockFound;
- }
- else {
- if (remainder == 1) {
- printf ("\nfree data block found at: %d",counter+2);
- freeBlocksCount++;
- freeBlockFound[freeBlocksCount-1] = counter + 2;
- if (freeBlocksCount == reqBlocks + reqIndexBlocks){
- return freeBlockFound;
- }
- }
- }
- binBitmap /= 10;
- counter++;
- }
- // no space for indexed allocation
- freeBlockFound[0] = -1;
- return freeBlockFound;
- }
- }
- /* Function to convert a decinal number to binary number */
- long decimalToBinary(long dec) {
- long remainder;
- long binary = 0, i = 1;
- while(dec != 0) {
- remainder = dec % 2;
- dec /= 2;
- binary += (remainder*i);
- i = i*10;
- }
- return binary;
- }
- /* Function to convert a binary number to decimal number */
- long binaryToDecimal(long bin) {
- long remainder;
- long decimal = 0, i = 0;
- while(bin != 0) {
- remainder = bin % 10;
- bin /= 10;
- decimal += (remainder*power(2,i));
- ++i;
- }
- return decimal;
- }
- // @setBitmap
- int setBitmap(long decBitmap, int blkNo,int value){
- long binBitmap = decimalToBinary(decBitmap);
- // how many digits the data have
- int nDigits = 1, countData = binBitmap;
- while (countData > 9) {
- nDigits++;
- countData /= 10;
- }
- // extracting individual digits into array
- int digitsArray[11] = {0};
- //memset( digitsArray, 0,nDigits*sizeof(int) );
- int digitsArrayInd = 10;
- int remainder;
- while(binBitmap != 0)
- {
- remainder = binBitmap%10;
- digitsArray[digitsArrayInd--] = remainder;
- binBitmap /= 10;
- }
- digitsArray[12 - blkNo] = value;
- // putting bitmap back into 1 number
- long newBitmap = 0;
- for (int i = 0; i < 11; i++){
- if (digitsArray[i] == 1){
- newBitmap += powerExp(10-i);
- }
- }
- printf("%ld\n",newBitmap);
- return binaryToDecimal(newBitmap);
- }
- // @getDirectoryData
- int *getDirectoryData(int data, char* method){
- // how many digits the data have
- int nDigits = 1, countData = data;
- while (countData > 9) {
- nDigits++;
- countData /= 10;
- }
- // printf("digits: %d\n", nDigits);
- // extracting individual digits
- int digitsArray[nDigits];
- memset( digitsArray, 0,nDigits*sizeof(int) );
- int digitsArrayInd = nDigits - 1;
- int remainder;
- while(data != 0)
- {
- remainder = data%10;
- digitsArray[digitsArrayInd--] = remainder;
- data /= 10;
- }
- // converting individual digits into correct data
- static int dataArray[3] = {0};
- int dataArrayInd = nDigits -1;
- if (strcmp(method, "indexed") == 0){
- // INDEXED
- // e.g. [1,2,3,4,5] = filename: 123, indexedLocation: 45
- dataArray[0] = 0;
- dataArray[1] = digitsArray[dataArrayInd--] + (digitsArray[dataArrayInd--]*10);
- for (int i = 0; i < nDigits-2; i++){
- if (i == 0){
- dataArray[0] += digitsArray[dataArrayInd--];
- }
- else {
- dataArray[0] += (digitsArray[dataArrayInd--] * powerExp(i));
- }
- }
- }
- else {
- // CONTIGUOUS/LINKED
- // e.g. [1,2,3,4,5,6,7] = filename: 123, start: 45, end: 67
- dataArray[0] = 0;
- dataArray[2] = digitsArray[dataArrayInd--] + (digitsArray[dataArrayInd--]*10);
- dataArray[1] = digitsArray[dataArrayInd--] + (digitsArray[dataArrayInd--]*10);
- for (int i = 0; i < nDigits-4; i++){
- if (i == 0){
- dataArray[0] += digitsArray[dataArrayInd--];
- }
- else {
- dataArray[0] += (digitsArray[dataArrayInd--] * powerExp(i));
- }
- }
- }
- return dataArray;
- }
- int *newMemory(){
- int *mem = malloc(n * sizeof *mem);
- // all allocation methods will have 1 block reserved for directory
- for (int i = 0; i < block; i++){
- // -1 meaning empty
- mem[i] = -1;
- }
- // all allocation methods will have 1 block reserved for bitmap
- for (int i = block; i < 2*block; i++){
- // every entry is pointing to next entry (empty space)
- if (i == block){
- // only first cell of bitmap block will be used
- mem[i] = binaryToDecimal(11111111111);
- }
- else {
- // the rest set as -1
- mem[i] = -1;
- }
- }
- // everything else will be empty data blocks
- for (int i = 2*block; i < n; i++){
- mem[i] = -1;
- }
- return mem;
- }
- // @printDiskMap
- void printDiskMap(char* method, int *memArray){
- printf("-Disk map for %s allocation method-\n", method);
- int *dataArray;
- //printing directory
- if (strcmp("indexed",method) == 0){
- for (int i = 0; i < block; i++){
- if (memArray[i] < 0){
- printf("%2d - B%-2d - %s \n",i,indexToBlock(i),"empty");
- }
- else {
- dataArray = getDirectoryData(memArray[i],method);
- printf("%2d - B%-2d - %d, %d \n",i,indexToBlock(i),dataArray[0],dataArray[1]);
- }
- }
- }
- else {
- for (int i = 0; i < block; i++){
- if (memArray[i] < 0){
- printf("%2d - B%-2d - %s \n",i,indexToBlock(i),"empty");
- }
- else {
- dataArray = getDirectoryData(memArray[i],method);
- printf("%2d - B%-2d - %d, %d, %d \n",i,indexToBlock(i),dataArray[0],dataArray[1],dataArray[2]);
- }
- }
- }
- // printing bitmap block
- printf("%2d - B%-2d - ",block,indexToBlock(block));
- // convert dec bitmap to bin bitmap
- long binBitmap = decimalToBinary(memArray[block]);
- // how many bits the bitmap have
- int nDigits = 1;
- long countData = binBitmap;
- // divide by 10 until countData is left with a single digit
- while (countData > 9) {
- nDigits++;
- countData /= 10;
- }
- for (int i = 11-nDigits; i > 0; i--){
- printf("0");
- }
- printf("%ld\n", binBitmap);
- for (int i = block+1; i < 2*block; i++){
- printf("%2d - B%-2d - Unused\n",i,indexToBlock(i));
- }
- // printing index and data
- for (int i = 2*block; i < n; i++){
- printf("%2d - B%-2d - %d\n",i,indexToBlock(i),memArray[i]);
- }
- }
- int getFileName(int fileData){
- return (fileData/100)*100;
- }
- // @readcsv
- int *readcsv(int *memArray, char* method){
- int command[3];
- FILE *fp;
- char buffer[255];
- char * split;
- char * retrieveData;
- fp = fopen("../data.csv", "r");
- // if there is no such file available
- // display an error message, break from the method
- if (fp == NULL) {
- printf("Unable to open file.\n");
- return 0;
- }
- else {
- //while (!feof(fp)) {
- while ( fgets( buffer, sizeof( buffer ), fp ) != NULL ) {
- retrieveData = "";
- int count = 0;
- // removes \n at the end of the line
- buffer[strcspn(buffer, "\n")] = 0;
- // splits the line with comma and space as the delimiter
- split = strtok(buffer, ", ");
- while (split != NULL) {
- retrieveData = split;
- split = strtok(NULL, ", ");
- if (count == 0){
- // start of new line, obtain command
- //printf("%s, ",retrieveData);
- if (strcmp(retrieveData,"add") == 0){
- command[0] = 0;
- }
- else if (strcmp(retrieveData,"read") == 0){
- command[0] = 1;
- }
- else {
- command[0] = 2;
- }
- }
- else if (count == 1){
- // obtain file name
- //printf("%s, ",retrieveData);
- command[1] = atoi(retrieveData);
- }
- if (split == NULL){
- // last entry of the line
- //printf("%s\n",retrieveData);
- if (count != 1){
- command[2] = atoi(retrieveData);
- }
- else {
- command[2] = -1;
- }
- }
- else {
- count++;
- }
- }
- if (command[0] == 0){
- // call add function
- printf("ADD FILE %d\n",command[1]);
- AddFile(method, memArray, command);
- }
- else if (command[0] == 1){
- // call read function
- printf("READ FILE %d\n",command[1]);
- }
- else {
- // call delete function
- printf("DELETE FILE %d\n",command[1]);
- // deleteFile(method, memArray, command);
- }
- }
- }
- fclose(fp);
- }
- // @concat123
- int concat123(int xxx, int yyy){
- int temp=0;
- int z=xxx;
- while(yyy>0)
- {
- // take reciprocal of y into temp
- temp=(temp*10)+(yyy%10);
- yyy=yyy/10;
- }
- while(temp>0)
- {
- // take each number from last of temp and add to last of z
- z=(z*100)+(temp%10);
- temp=temp/10;
- }
- return z;
- //printf("%d\n",z);
- }
- // @addFile
- void AddFile(char* method, int *memory, int *csvArray) {
- // Universal code: Works for all 3 methods, dont need to repeat
- // result stores how many data files we need to add
- int result = csvArray[2] - csvArray[1];
- int blockcounter;
- if(strcmp(method, "linked") == 0){
- blockcounter = findReqBlocksWithPtr(result);
- }
- else {
- // blockcounter stores how many data blocks are needed
- blockcounter = 0;
- if (result % 5 == 0){
- blockcounter = result / 5;
- }
- else {
- blockcounter = (result / 5 )+ 1;
- }
- }
- printf("csv[1], csv[2]: %d, %d\n",csvArray[1], csvArray[2]);
- // obtaining array of free blocks
- int* freeBlocks;
- freeBlocks = findFreeBlock(blockcounter, memory[5], method);
- if (freeBlocks[0] == -1){
- // no free space, exit function
- printf("Disk full, unable to add file.\n");
- return;
- }
- // @addFile conti
- if(strcmp(method, "contiguous") == 0){
- int firstFreeBlock = freeBlocks[0];
- // join numbers together and store in directory
- int firstconcat = concat123(csvArray[1],firstFreeBlock);
- int secondconcat = concat123(firstconcat,blockcounter);
- //printf("%d\n", firstconcat);
- //printf("%d\n", secondconcat);
- // look for free directory space and update directory entries
- int freeDirectoryFound = 0;
- for (int i = 0; i < block; i++) {
- if (memory[i] == -1) {
- memory[i] = secondconcat;
- //printf("%d\n", memory[i]);
- freeDirectoryFound = 1;
- break;
- }
- }
- if (freeDirectoryFound == 0){
- printf("Not enough directory space.\n");
- return;
- }
- csvArray[1]++;
- for (int i = firstFreeBlock * block; i < firstFreeBlock * block + result; i++) {
- memory[i] = csvArray[1]++;
- // if multiple of 5, update bitmap
- if (i % 5 == 0){
- memory[5] = setBitmap(memory[5], i/5, 0);
- }
- }
- }
- // @addFile linked
- else if(strcmp(method, "linked") == 0){
- int firstFreeBlock = freeBlocks[0];
- int endingblock = firstFreeBlock-1 + blockcounter;
- printf("patrickk%d\n",endingblock);
- // join numbers together and store in directory
- int firstconcat = concat123(csvArray[1], firstFreeBlock);
- int secondconcat = concat123(firstconcat, endingblock);
- printf("spongebob%d\n",secondconcat);
- // look for free directory space
- int freeDirectoryFound = 0;
- for (int i = 0; i < block; i++) {
- if (memory[i] == -1) {
- memory[i] = secondconcat;
- freeDirectoryFound = 1;
- break;
- }
- }
- if (freeDirectoryFound == 0) {
- printf("Not enough directory space.\n");
- return;
- }
- //////////////////////////
- int toadd = ++csvArray[1];
- int curDataBlock;
- printf("\n\n\n");
- // loop freeBlocks
- //printf("kfc%d", csvArray[0]);
- printf("Adding file100 and found free B1,B4 with %d entries\n", blockcounter);
- printf("Added file100 at B1(101,102,103,104), B04(105,106) %d\n", memory[curDataBlock]);
- for (int c = 0; c < blockcounter; c++) {
- curDataBlock = blockToIndex(freeBlocks[c]);
- for (int a = 0; a < 4; a++) {
- if (toadd <= csvArray[2]) {
- //printf("Adding %d to curDataBlock %d\n",toadd, curDataBlock);
- memory[curDataBlock++] = toadd++;
- }
- else {
- memory[5] = setBitmap(memory[5], freeBlocks[0], 0);
- return;
- }
- }
- if (c == blockcounter -1){
- if (toadd <= csvArray[2]){
- memory[curDataBlock++] = toadd++;
- memory[5] = setBitmap(memory[5], freeBlocks[0], 0);
- }
- return;
- }
- else {
- memory[curDataBlock++] = freeBlocks[c+1] * -1;
- //printf("AFTER ADDINGGGG: %d\n\n\n", memory[curDataBlock]);
- curDataBlock++;
- }
- memory[5] = setBitmap(memory[5], freeBlocks[c], 0);
- memory[5] = setBitmap(memory[5], freeBlocks[c+1], 0);
- }
- }
- // @addFile indexed
- else{
- int firstFreeBlock = freeBlocks[0];
- // look for free directory space and update directory entries
- int firstconcat = concat123(csvArray[1],firstFreeBlock);
- int reqIndexBlocks = findReqBlocksWithPtr(blockcounter);
- printf("\n\nRequired Blocks: %d", blockcounter);
- printf("\nRequired Index Blocks: %d\n\n", reqIndexBlocks);
- // look for free directory space
- int freeDirectoryFound = 0;
- for (int i = 0; i < block; i++) {
- if (memory[i] == -1) {
- memory[i] = firstconcat;
- freeDirectoryFound = 1;
- break;
- }
- }
- if (freeDirectoryFound == 0){
- printf("Not enough directory space.\n");
- return;
- }
- printf("blockcounter: %d\n",blockcounter);
- printf("freeblocks: ");
- for (int i = 0; i < (blockcounter + reqIndexBlocks); i++){
- printf("%d ", freeBlocks[i]);
- }
- // insert pointers into index blocks
- int remainingDataBlocks = blockcounter;
- int curIndexEntry;
- int addDataBlock = reqIndexBlocks;
- // loop through index block location in freeBlocks array
- for (int i = 0; i < reqIndexBlocks; i++){
- // index location where I need to add the pointer to my data blocks
- curIndexEntry = blockToIndex(freeBlocks[i]);
- // loop 4 times, adding pointers of data blocks
- for (int j = 0; j < 4; j++){
- if (remainingDataBlocks < 1){
- break;
- }
- // adding in index entry
- memory[curIndexEntry] = freeBlocks[addDataBlock];
- memory[5] = setBitmap(memory[5],(curIndexEntry/5),0);
- curIndexEntry++;
- addDataBlock++;
- remainingDataBlocks--;
- }
- // if left 1 data block remaining, dont need it to be pointer already
- if (remainingDataBlocks == 1){
- memory[curIndexEntry] = freeBlocks[addDataBlock];
- memory[5] = setBitmap(memory[5],(curIndexEntry/5),0);
- curIndexEntry++;
- addDataBlock++;
- remainingDataBlocks--;
- }
- else if (i != reqIndexBlocks - 1){
- memory[curIndexEntry] = (freeBlocks[i+1]) * -1;
- curIndexEntry = freeBlocks[i+1];
- }
- }
- // insert into data blocks
- int doneAdding = 0;
- int curIndexBlock = freeBlocks[0];
- int actualData = csvArray[1]+1;
- while (doneAdding == 0){
- int indexEntry = blockToIndex(curIndexBlock);
- for (int i = indexEntry; i < indexEntry + 5; i++){
- if (memory[i] == -1) {
- doneAdding = 1;
- break;
- }
- else if (memory[i] > 0) {
- for (int j = blockToIndex(memory[i]); j < blockToIndex(memory[i])+5; j++){
- memory[j] = actualData++;
- memory[5] = setBitmap(memory[5],(j/5),0);
- if (actualData > csvArray[2]){
- return;
- }
- }
- }
- else {
- curIndexBlock = memory[i] * -1;
- break;
- }
- }
- }
- //put counter for time here for adding
- }
- }
- // @deleteFile
- void deleteFile(char* method, int *memArray, int *csvArray) {
- int foundStart, foundEnd;
- int startIndex;
- int fileToDelete = csvArray[1];
- int fileFound = 0;
- // searching for file in directory, then clear that directory entry
- for (int i = 0; i < 5; i++) {
- if (fileToDelete == getDirectoryData(memArray[i], method)[0]) {
- foundStart = getDirectoryData(memArray[i], method)[1]; // start block;
- foundEnd = getDirectoryData(memArray[i], method)[2];
- memArray[i] = -1;
- startIndex = blockToIndex(foundStart);
- fileFound = 1;
- //printf("%d", startIndex);
- }
- }
- if (fileFound == 0){
- printf("File do not exists.\n");
- return;
- }
- // @deleteFile linked
- if (strcmp(method, "linked") == 0) {
- while (foundStart != foundEnd) {
- foundStart = memArray[startIndex + 4];
- for (int i = startIndex; i < startIndex + 5; i++) {
- memArray[i] = -1;
- if (i % 5 == 0){
- memArray[5] = setBitmap(memArray[5], i/5, 1);
- }
- }
- startIndex = blockToIndex(foundStart);
- printf("%d", foundStart);
- }
- for (int i = startIndex; i < (foundEnd-foundStart) ; i++) {
- memArray[i] = -1;
- if (i % 5 == 0){
- memArray[5] = setBitmap(memArray[5], i/5, 1);
- }
- }
- }
- // @deleteFile conti
- else if (strcmp(method, "contiguous") == 0) {
- for (int i = startIndex; i < (foundStart*5) + startIndex; i++){
- memArray[i] = -1;
- // if multiple of 5, update bitmap
- if (i % 5 == 0){
- memArray[5] = setBitmap(memArray[5], i/5, 1);
- }
- }
- }
- // @deleteFile indexed
- else if (strcmp(method, "indexed") == 0) {
- int doneDeleting = 0;
- int curIndexBlock = foundStart;
- printf("%d", curIndexBlock);
- while (doneDeleting ==0) {
- int indexEntry = blockToIndex(curIndexBlock);
- printf("%d", indexEntry);
- for ( int i= indexEntry; i< indexEntry +5; i++) {
- if(memArray[i] == -1) {
- doneDeleting = 1;
- break;
- }
- else if(memArray[i] > 0) {
- int blockToDelete = memArray[i];
- int blockDeleteIndex = blockToIndex(blockToDelete);
- for (int j = blockDeleteIndex; j < blockDeleteIndex+5; j++) {
- memArray[j]= -1;
- // if multiple of 5, update bitmap
- if (i % 5 == 0){
- memArray[5] = setBitmap(memArray[5], j/5, 1);
- }
- }
- memArray[i]=-1;
- if (i % 5 == 0){
- memArray[5] = setBitmap(memArray[5], i/5, 1);
- }
- }
- else {
- curIndexBlock = memArray[i] * -1;
- }
- memArray[i]=-1;
- if (i % 5 == 0){
- memArray[5] = setBitmap(memArray[5], i/5, 1);
- }
- }
- }
- }
- }
- /*****************************************************************
- /* NOTES / TO-DO / QUESTIONS
- /*****************************************************************
- [Directory data - Block 0]
- When empty: -1
- When not empty:
- Indexed: 543289
- (5432 - file name[1-4 digits], immediately followed by 89 - index location[MUST be 2 digits])
- Linked & Contiguous: 54326789
- (5432 - file name[1-4 digits], immediately followed by 67 - start[Must be 2 digits], then 89 - end[Must be 2 digits])
- [Bitmap - Block 1]
- 1 representing empty space, 0 representing used space
- Read backwards - LSB is block 2
- [Index]
- When empty: -1
- When not empty: pointer to data location
- [File data]
- When empty: -1
- when not empty: a positive number
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement