In this workshop you will be implementing a file system simulator, loosely based on historic file systems. The file system will be have the following properties:
struct entry
{
char user;
char name[9];
char extension[4];
short blockcount;
short block[8];
};
You are not supposed to implement the actual storage, only the control structures of the file system. When implementing the free bitmap you must use a bitmap, i.e. it should be an array, but each element of the array should represent several blocks.
When your program starts, it will assume that the disk is unformatted, you should provide a menu that imple- ments the following options:
Initialise Disk initialise disk control structures, setting the first block of the disk to used in the bitmap, and marking all directory entries as being available.
List Files in the Directory List the names, extensions and block counts of all the valid files in the directory.
Display the Free Bitmap print the value of each of the bits in the bitmap. This need not be pretty, just a long list of 1's and 0s is sufficient
Open/Create File scans the directory and if the name provided doesn't exist then adds that file to the directory. This file will be used in all subsequent operations until a new file is opened or it is deleted.
Read File list the blocks occupied by the currently open file (not the content of these blocks as you don't store this information)
Write File allocate another block to the currently open file. You should not preallocate blocks for the file, you should allocate the first available block, by scanning the bitmap for the first block that is available. Each write shall add another block to the file until there are no more slots to allocate blocks to, or the disk runs out of blocks. (There are only 8 slots available for each file.)
Delete File deallocate all blocks for the current file in the bitmap, and marks as free the directory entry for that file
You need to pay close attention to multiple boundary conditions, which exist in this file system, including the total size of the disk, maximum size of a file, maximum number of files etc.
#ifndef FS_H
#define FS_H
/ * Prevent multiple inclusion
* /
/ * fs.h
*
Various definitions for OSP Practical Case Study E
* /
/ * The bitmap
* /
extern unsigned char bitmap[8];
/ * 320Kb disk with 4Kb blocks-> 8 bytes for bitmap
* /
/ * The directory entry
* /
struct entry
{
char user;
char name[9];
char extension[4];
short blockcount;
short block[8];
};
/ * The Directory
* /
extern struct entry directory[128];
/ * extern means its defined in another
file, prevents multiple definition
errors
* /
int toggle_bit(int block);
/ * Toggles the value of the bit ’block’, in
the external array ’bitmap’.
returns the current value of the bit
Does NOT validate ’block’!!!
* /
int block_status(int block);
/ * Returns the status of ’block’,
in the external array bitmap
returns 0 if bitmap bit is 0,
not 0 if bitmap bit is 1
Does NOT validate block!!!
* /
#endif
/ * fs.c
Some useful functions for OSP Practical Case Study E
* /
#include"fs.h"
unsigned char bitmap[12];
struct entry directory[128];
int toggle_bit(int block)
{
int elem=block/8;
int pos=block%8;
int mask=1<bitmap[elem]ˆ=mask;
return bitmap[elem]&mask;
}
int block_status(int block)
{
int elem=block/8;
int pos=block%8;
int mask=1<return bitmap[elem]&mask;
}
#include< stdio.h>
/ * stdio.h will be found in the system path
* /
#include"fs.h"
/ * fs.h will be found in the local path
* /
int main(int ac, char ** av)
{
printf("Please make me usefuln");
return 0;
}
all: caseE
caseE: main.o fs.o
$(CC) -o $@ $ˆ