forked from ParasharaRamesh/mySimpleFilesystem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdumpfs.c
46 lines (43 loc) · 1.03 KB
/
dumpfs.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
#include "globalConstants.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern filetable FileTable[5];
extern superblock sfssuperblock;
extern inode * currdirectory;
int diskWrite(char *disk)
{
FILE *file = fopen(disk, "w+b");
if( file == NULL)
{
printf("failed to open the file for persistence!\n");
return 0;
}
if( fseek( file , L_SUPERBLOCK , SEEK_SET) != 0 )
{
printf("failed to lseek for writing superblock\n");
return 0;
}
if( fwrite(&sfssuperblock, sizeof(superblock), 1 , file) != 1)
{
printf("failed to write the superblock!\n");
return 0;
}
if( fseek( file , L_FILETABLE , SEEK_SET) != 0 )
{
printf("failed to lseek for writing filetable\n");
return 0;
}
if(fwrite(FileTable, sizeof(filetable)*5, 1 , file) != 1)
{
printf("failed to write filetable!\n");
return 0;
}
fclose(file);
return 1;
}
int dumpfs()
{
char *disk="PersistantDisk.txt";
return diskWrite(disk);
}