tape-kernel
1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
ffs.c
Go to the documentation of this file.
1
//ffs.c -- flat file system
2
#include "
ffs.h
"
3
#include "
ide.h
"
4
#include "
../lib/err.h
"
5
#include "
../io/io.h
"
6
7
/**
8
* @brief ffsinit initializes the flat filesystem on disk
9
*
10
* ffsinit is a function that reads and validates the boot sector
11
* checking for the 0x55 0xAA boot signature and verifying sector size
12
* it also creates an empty filesystem table if one doesnt exist yet
13
*
14
* using ffsinit is done with
15
* @code{.c}
16
* #include "../fs/ffs.h" //or just ffs.h
17
* ffsinit();
18
* @endcode
19
*
20
* @see ideinit(), fsinit(), boot.s
21
*/
22
void
__ffsinit
(
void
) {
23
uint8_t
sector[512];
//make sector val
24
25
//read boot sector
26
irsec
(0, sector);
//read via ide
27
28
//check boot signature
29
assert
(sector[510] == 0x55 && sector[511] == 0xAA,
"ffs: no boot signature"
);
30
31
//sanity check values
32
uint16_t
bps = sector[11] | (sector[12] << 8);
33
assert
(bps == 512,
"ffs: bytes per sector not 512"
);
34
35
uint8_t
spc = sector[13];
36
assert
(spc > 0 && spc <= 128,
"ffs: invalid sectors per cluster"
);
37
38
//create fs table if it doesnt exist
39
uint8_t
table[512];
40
irsec
(1, table);
41
if
(table[0] !=
'F'
|| table[1] !=
'S'
) {
42
//no filesystem yet, create empty one
43
for
(
int
i = 0; i < 512; i++) table[i] = 0;
44
table[0] =
'F'
;
45
table[1] =
'S'
;
46
table[2] = 0;
//file_count = 0
47
iwrt
(1, table);
48
}
49
}
50
51
/**
52
* @brief disksize returns the total disk size in kilobytes
53
*
54
* disksize is a function that queries the ide drive for its total sector count
55
* and converts it to kilobytes
56
*
57
* using disksize is done with
58
* @code{.c}
59
* #include "../fs/ffs.h" //or just ffs.h
60
* uint32_t dsize = disksize();
61
* @endcode
62
*
63
* @see idesize(), memsize()
64
*/
65
uint32_t
__disksize
(
void
) {
66
uint32_t
secs;
67
if
(
idesize
(&secs)) {
68
return
(secs * 512) / 1024;
//convert to kb
69
}
70
return
0;
71
}
72
err.h
assert
#define assert
Definition
err.h:4
__ffsinit
void __ffsinit(void)
ffsinit initializes the flat filesystem on disk
Definition
ffs.c:22
__disksize
uint32_t __disksize(void)
disksize returns the total disk size in kilobytes
Definition
ffs.c:65
ffs.h
ide.h
idesize
#define idesize
Definition
ide.h:20
iwrt
#define iwrt
Definition
ide.h:19
irsec
#define irsec
Definition
ide.h:18
io.h
uint16_t
unsigned short uint16_t
Definition
types.h:29
uint32_t
unsigned int uint32_t
Definition
types.h:30
uint8_t
unsigned char uint8_t
Definition
types.h:28
src
fs
ffs.c
Generated by
1.16.1