-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
127 lines (100 loc) · 3.09 KB
/
Copy pathcommon.h
File metadata and controls
127 lines (100 loc) · 3.09 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#define SIZE 1024*1024
#define DATA_BLOCK_SIZE 128
#define DIRECT_DATA_BLOCK_NUMBER 32
#define FILE_SYSTEM_ALREADY_INITIALIZED 1111
#define FILE_SYSTEM_NOT_INITIALIZED 2222
#define NO_OF_INODES 1024
#define NO_OF_DATA_BLOCKS 1024
#define FILE_MODE 0
#define FOLDER_MODE 1
#define DIRECTORY_INDICATOR '/'
#define FREE 0
#define OCCUPIED 1
#define Malloc(n,type) (type *) malloc( (unsigned) ((n)*sizeof(type)))
#define DIRECTORY_ENTRY_LENGTH 16
#define INODE_NO_STRING_SIZE 4
#define FILE_NAME_STRING_SIZE 12
#define FILE_NAME "S3R.fs"
#define MAXPATHLENGTH 100
/* Define some specific offsets for file handling
#define SUPER_BLOCK_START_OFFSET INTEGER_SIZE
#define SUPER_BLOCK_SIZE (8+1024+1024)*INTEGER_SIZE
#define INODE_SIZE ((32+3)*INTEGER_SIZE)
#define INODE_ARRAY_START_OFFSET (SUPER_BLOCK_START_OFFSET+SUPER_BLOCK_SIZE)
#define INODE_ARRAY_SIZE INODE_SIZE*NO_OF_INODES
#define DATA_BLOCK_ARRAY_START_OFFSET INODE_ARRAY_START_OFFSET+INODE_ARRAY_SIZE
#define DATA_BLOCK_ARRAY_SIZE DATA_BLOCK_SIZE*NO_OF_DATA_BLOCKS
*/
// just buffer
typedef struct DATABLOCK // size = 128
{
char content[DATA_BLOCK_SIZE];
}DataBlock;
typedef struct INODE // 140 (35*4)
{
int fileMode; // file or directory
int linkCount; // no of open instances
int fileSize; // file size in bytes
/*Later purpose */
/*
int uid;
int gid;
time_t aTime;
time_t mTime;
time_t cTime;
*/
// list of data blocks
int directDBIndex[DIRECT_DATA_BLOCK_NUMBER];
//int indirect2DBIndex[2ND_DIRECT_DATA_BLOCK_NUMBER];
}Inode;
typedef struct SUPERBLOCK // size (8+1024+1024)*sizeof(int) = 8224
{
// int magic;
//inode
int inodeCount;
int freeInodeCount;
int iNodeOffset;
// data blocks
int dataBlockOffset;
int dataBlockCount;
int freeDataBlockCount;
// free lists
int inodeList[NO_OF_INODES];
int dataBlockList[NO_OF_DATA_BLOCKS];
int iNodeSize;
int dataBlockSize;
}SuperBlock;
typedef struct WHOLEFS
{
SuperBlock sb;
Inode ib[NO_OF_INODES];
char* fileSystemName;
DataBlock db[NO_OF_DATA_BLOCKS];
int pwdInodeNumber;
char pwdPath[MAXPATHLENGTH];
}WholeFS;
Inode* strToInode(char* buffer,int len);
int getPwdInodeNumber(WholeFS* fs);
WholeFS* readFS(char const *fileName, int* i);
void writeInode(WholeFS* fs,int index,int mode);
void writeDataBlock(WholeFS* fs,int index,int offset,char* content,int len);
DataBlock* readDataBlock(WholeFS* fs,int index);
int getFirstFreeInodeIndex(WholeFS* fs);
int getFirstFreeDataBlockIndex(WholeFS* fs);
int getParentInode(WholeFS* fs);
Inode* getInode(WholeFS* fs,int index);
int isDBlockFree(Inode* i,int index);
void calculateDataBlockNoAndOffsetToWrite(WholeFS* fs,Inode* i,int inodeIndex, int* index,int* offset);
int searchFilenameInDataBlock(char* db,char* name,int len);
int getDBlockNumberFromSize(WholeFS* fs, int inodeIndex, int nDataBlock);
void writeFS(WholeFS *fs, int inodeIndex);
void readSuperBlock(WholeFS* fs);
#endif