-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesys.h
More file actions
137 lines (94 loc) · 3.03 KB
/
filesys.h
File metadata and controls
137 lines (94 loc) · 3.03 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
128
129
130
131
132
133
134
135
136
137
/* filesys.h
*
* describes FAT structures
* http://www.c-jump.com/CIS24/Slides/FAT/lecture.html#F01_0020_fat
* http://www.tavi.co.uk/phobos/fat.html
*/
#ifndef FILESYS_H
#define FILESYS_H
#include <time.h>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define MAXBLOCKS 1024
#define BLOCKSIZE 1024
#define FATENTRYCOUNT (BLOCKSIZE / sizeof(fatentry_t))
#define DIRENTRYCOUNT ((BLOCKSIZE - (2*sizeof(int)) ) / sizeof(direntry_t))
#define MAXNAME 256
#define MAXPATHLENGTH 1024
#define UNUSED -1
#define ENDOFCHAIN 0
typedef unsigned char Byte ;
/* create a type fatentry_t, we set this currently to short (16-bit)
*/
typedef short fatentry_t ;
// a FAT block is a list of 16-bit entries that form a chain of disk addresses
//const int fatentrycount = (blocksize / sizeof(fatentry_t)) ;
typedef fatentry_t fatblock_t [ FATENTRYCOUNT ] ;
/* create a type direntry_t
*/
typedef struct direntry {
int entrylength ; // records length of this entry (can be used with names of variables length)
Byte isdir ;
Byte unused ;
time_t modtime ;
int filelength ;
fatentry_t firstblock ;
char name [MAXNAME] ;
} direntry_t ;
// a directory block is an array of directory entries
//const int direntrycount = (blocksize - (2*sizeof(int)) ) / sizeof(direntry_t) ;
typedef struct dirblock {
int isdir ;
int nextEntry ;
direntry_t entrylist [ DIRENTRYCOUNT ] ; // the first two integer are marker and endpos
} dirblock_t ;
// a data block holds the actual data of a filelength, it is an array of 8-bit (byte) elements
typedef Byte datablock_t [ BLOCKSIZE ] ;
// a diskblock can be either a directory block, a FAT block or actual data
typedef union block {
datablock_t data ;
dirblock_t dir ;
fatblock_t fat ;
} diskblock_t ;
// finally, this is the disk: a list of diskblocks
// the disk is declared as extern, as it is shared in the program
// it has to be defined in the main program filelength
extern diskblock_t virtualDisk [ MAXBLOCKS ] ;
// when a file is opened on this disk, a file handle has to be
// created in the opening program
typedef struct filedescriptor {
char mode[3] ;
fatentry_t blockno ; // block no
int pos ; // byte within a block
diskblock_t buffer ;
char filename [MAXNAME] ;
} MyFILE ;
void format() ;
void writedisk ( const char * filename ) ;
void printBlock ( int blockIndex );
MyFILE myfopen( char * filename, char mode);
void myfputc(char * data, MyFILE fileManager, long int size);
int findblock();
int findRootDirEntry();
void updateFAT();
void updateDIR();
void myfgetc(MyFILE fileManager);
void myfclose(MyFILE fileManager);
int findDirEntry(int dirBlockIndex);
void checkPath(char * filename);
char ** allocateStrings(int numberOfStrings, int stringsLength);
char ** mylistDir(char * path);
void mymkdir(char * path);
#endif
/*
#define NUM_TYPES (sizeof types / sizeof types[0])
static* int types[] = {
1,
2,
3,
4 };
*/