forked from ParasharaRamesh/mySimpleFilesystem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
automount.c
64 lines (61 loc) · 1.12 KB
/
automount.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "sfs.h"
#include "utility.h"
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/time.h>
#include<unistd.h>
#include "globalConstants.h"
extern filetable FileTable[5];
extern superblock sfssuperblock;
extern inode *currdirectory;
int superblockDiskRead(char *disk)
{
FILE *file = fopen(disk, "rb");
if(file == NULL)
{
return 0;
}
if(fseek( file , L_SUPERBLOCK , SEEK_SET) != 0 )
{
return 0;
}
if(fread(&sfssuperblock , sizeof(superblock), 1 , file) != 1)
{
return 0;
}
fclose(file);
currdirectory=&sfssuperblock.inodes[0];
return 1;
}
int filetableDiskRead(char *disk)
{
FILE *file = fopen(disk, "rb");
if(file == NULL)
{
return 0;
}
if(fseek( file , L_FILETABLE , SEEK_SET) != 0 )
{
return 0;
}
if(fread(FileTable, sizeof(filetable)*5 , 1 , file) != 1)
{
return 0;
}
fclose(file);
return 1;
}
int automount()
{
char *disk="PersistantDisk.txt";
if(!superblockDiskRead(disk))
{
return 0;
}
if(!filetableDiskRead(disk))
{
return 0;
}
return 1;
}