-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuffer.c
More file actions
69 lines (61 loc) · 1.32 KB
/
buffer.c
File metadata and controls
69 lines (61 loc) · 1.32 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
#include "lib.h"
#include "buffer.h"
#include "fat32.h"
#include "io.h"
#include "radix.h"
#include "superblock.h"
#include "dir.h"
#include "page.h"
#include <string.h>
#ifdef DEBUG_MEMORY_USAGE
unsigned int memory_usage = 0;
#endif
struct inode fd_pool[MAX_FD];
void direct_read_sector(void *buf, unsigned int sector)
{
BUG_ON(buf == NULL);
read8blocks(buf, sector);
}
void direct_read(void *buf, unsigned int cluster)
{
unsigned int sector = fat_get_sec(cluster);
BUG_ON(buf == NULL);
read8blocks(buf, sector);
}
struct address_space *bread_sector(unsigned int sector)
{
int create;
struct address_space *addr;
if (sector >= RADIX_SIZE * RADIX_SIZE * RADIX_SIZE) {
addr = alloc_address_space();
addr->data = alloc_page();
direct_read_sector(addr->data, sector);
return addr;
}
addr = lookup(sector, &create);
if (create == NEW_NODE) {
addr->data = alloc_page();
direct_read_sector(addr->data, sector);
return addr;
} else { // find_node
return addr;
}
}
void init_all()
{
#ifdef DEBUG_MEMORY_USAGE
memory_usage = 0;
#endif
memset((void*)&fd_pool[0], 0, sizeof(fd_pool));
init_disk();
init_superblock();
init_fat();
init_address_space();
init_radix_allocator();
init_radix_tree();
}
void test_direct_read()
{
unsigned char *buf = alloc_page();
direct_read(buf, 2);
}