forked from ParasharaRamesh/mySimpleFilesystem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatablock.c
More file actions
62 lines (55 loc) · 1.5 KB
/
Copy pathdatablock.c
File metadata and controls
62 lines (55 loc) · 1.5 KB
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
#include "globalConstants.h"
#include "utility.h"
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
extern superblock sfssuperblock;
char * readDataBlocks(inode *file)
{
if(strcmp(file->type,"file") == 0)//only if it is a file
{
char * concatenatedResult = (char *)malloc(sizeof(char)) ;
char *dataBlockContent = (char *)malloc(sizeof(char)*DATABLOCK_SIZE) ;//store intermediate data
int currdatablocklen=0;
int count=0;
while(file->datablocksarray[count]!=-1)
{
strcpy(dataBlockContent , sfssuperblock.datablocks[file->datablocksarray[count]].data);
currdatablocklen += strlen(dataBlockContent);
concatenatedResult=(char *)realloc(concatenatedResult,currdatablocklen);
strcat(concatenatedResult,dataBlockContent);
count++;
}
file->accesstime=time(0);
return concatenatedResult;
}
return NULL;
}
datablock* writeDataBlock(char *content)
{
int length = strlen(content);
datablock *newdb = getDatablock();
strcpy(newdb -> data,content);
newdb -> currsize = length;
return newdb;
}
int unlinkDataBlock(inode *file)
{
if(strcmp(file -> type, "file") == 0)
{
if(file->noOfDatablocks==0)
return 1;
int i=0;
for(int i=0;i<5;i++)
{
sfssuperblock.datablocks[file->datablocksarray[i]].id = 0;
file->datablocksarray[i]=-1;
}
file -> noOfDatablocks = 0;
return 1;
}
else
{
return 0;
}
}