Skip to content

Commit ac8bd2f

Browse files
committed
Initial commit - forked from Expos
0 parents  commit ac8bd2f

40 files changed

+5311
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

FileSystemCode/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DISK = disk
2+
3+
all: fileSystem
4+
5+
fileSystem: fileSystem.h fileSystem.c fileUtility.h fileUtility.h interface.h interface.c createDisk.h createDisk.c
6+
gcc fileSystem.c fileUtility.c interface.c createDisk.c -o fileSystem
7+
cp -f fileSystem ../
8+
9+
clean:
10+
rm -rf $(DISK) *.o fileSystem 2> /dev/null

FileSystemCode/README

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Compiler: gcc 4.4.3(recomended)
2+
Platform: Linux 2.6(recomended)
3+
4+
NOTE:
5+
1. The disk file is named as "disk". To change it make changes in:
6+
a) First line of the Makefile
7+
b) DISK_NAME constant in fileSystem.h
8+
9+
2. The entire code works by fist writing to a memory copy before committing to the actual disk file.
10+
11+
Compiling:
12+
1. cd to directory.
13+
2. Type 'make' and press enter.
14+
15+
Run:
16+
1. Compile by following the above steps.
17+
2. Run ./fileSystem on the terminal.
18+
3. Follow the menu.
19+

FileSystemCode/ToDo

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Things to do
2+
1. Add -1 as basic block entry for empty entries in spec.
3+
2. Interface for data blocks if required.
4+
4. New line problem in file name. Copying the code from disk to memory appends a new line to the end of everyline. So the data section
5+
contains the string with a newline. This can cause problems when comparing with strings read from terminal. This was avoided temporarily
6+
by appending a newline to the string read using SIN in the machine.

FileSystemCode/createDisk.c

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "createDisk.h"
2+
3+
4+
/*
5+
createDisk creates the disk file if not present.
6+
if format is equal to zero then the function creates the disk but does not format it.
7+
if format is not equal to zero then the function will create and format the disk.
8+
Formatting is done as follows:
9+
1. A memory copy of the disk is maintained. This copy contains NO_BLOCKS_TO_COPY + EXTRA_BLOCKS (in this case 13 + 1) blocks.
10+
The extra block is a temporary block. This memory copy is called the virtual disk. This is first cleared.
11+
2. Then the memory freelist is initialised.
12+
3. The fat blocks are also initialised. The basic block entries are all set to -1. The memory copy is then committed to the
13+
disk file.
14+
4. Finally the entry for init process is made.
15+
*/
16+
void createDisk(int format){
17+
int fd;
18+
if(format){
19+
fd = open(DISK_NAME, O_CREAT | O_TRUNC | O_SYNC, 0666);
20+
clearVirtDisk();
21+
close(fd);
22+
// loadFileToVirtualDisk(); note: commented this line
23+
int i=0,j=0;
24+
for(j=0; j<NO_OF_FREE_LIST_BLOCKS; j++){
25+
if(j == 0)
26+
for(i=0;i<DATA_START_BLOCK + INIT_SIZE ;i++)
27+
storeInteger(disk[FREE_LIST_START_BLOCK].word[i], 1);
28+
else
29+
i=0;
30+
31+
for( ;i<BLOCK_SIZE;i++)
32+
storeInteger(disk[FREE_LIST_START_BLOCK + j].word[i], 0);
33+
writeToDisk(FREE_LIST_START_BLOCK + j, FREE_LIST_START_BLOCK+j);
34+
}
35+
36+
37+
for(j=0; j<NO_OF_FAT_BLOCKS; j++){
38+
for(i=FAT_BASICBLOCK; i<BLOCK_SIZE; i=i+FAT_ENTRY_SIZE){
39+
storeInteger(disk[FAT_START_BLOCK + j].word[i], -1);
40+
}
41+
writeToDisk(FAT_START_BLOCK+j, FAT_START_BLOCK+j);
42+
}
43+
44+
initializeINIT();
45+
}
46+
else
47+
{
48+
fd = open(DISK_NAME, O_CREAT, 0666);
49+
close(fd);
50+
}
51+
52+
}
53+
54+

FileSystemCode/createDisk.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef CREATEDISK_H
2+
#define CREATEDISK_H
3+
4+
#include <stdio.h>
5+
#include "fileSystem.h"
6+
#include <string.h>
7+
#include "fileUtility.h"
8+
#include <fcntl.h>
9+
10+
11+
/*
12+
This function creates the disk file if not present. It also has an option for formatting or not.
13+
*/
14+
void createDisk(int format);
15+
16+
#endif

FileSystemCode/disk.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define DISK_NAME "disk"
2+
#define BOOT_BLOCK 0

FileSystemCode/fileSystem

16.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)