-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinode.c
More file actions
88 lines (83 loc) · 1.97 KB
/
Copy pathinode.c
File metadata and controls
88 lines (83 loc) · 1.97 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "globalConstants.h"
#include "utility.h"
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
extern inode *root;
extern inode *currdirectory;
extern superblock sfssuperblock;
int createInode(char * name, char * type)
{
inode *newInode = getInode();//from superblock
if(newInode==NULL)
{
return 0;
}
if(currdirectory->noOfInodes==0)
{
currdirectory->inodeList[0]=newInode->id;
currdirectory->noOfInodes++;
strcpy(newInode->name,name);
strcpy(newInode->type,type);
newInode->createtime=time(0);
newInode->noOfDatablocks=0;
newInode->noOfInodes=0;
newInode->parent=currdirectory->id;
newInode->fdcount=0;
return 1;
}
else
{
int i=0;
while(currdirectory->inodeList[i]!=-1)
{
if(strcmp(sfssuperblock.inodes[currdirectory->inodeList[i]].name,name)==0)
{
return 0;
}
i++;
}
if(i<5)
{
currdirectory->inodeList[i]=newInode->id;
strcpy(newInode->name,name);
strcpy(newInode->type,type);
newInode->createtime=time(0);
newInode->noOfDatablocks=0;
newInode->noOfInodes=0;
newInode->parent=currdirectory->id;
newInode->fdcount=0;
//Increasing the count of the number of inodes
currdirectory->noOfInodes+=1;
return 1;
}
return 0;
}
}
int deleteInode(inode *entry)
{
if(entry->noOfInodes!=0)
{
return 0;
}
if(strcmp(entry->type,"file")==0)
{
unlinkDataBlock(entry);
}
for(int i=0;i<5;i++)
{
if(currdirectory->inodeList[i]==entry->id)
{
sfssuperblock.inodelist[entry->id]=0;
sfssuperblock.no_of_free_inodes++;
currdirectory->noOfInodes--;
for(int k=i;k<4;k++)
{
currdirectory->inodeList[k]=currdirectory->inodeList[k+1];
}
currdirectory->inodeList[4]=-1;
return 1;
}
}
return 0;
}