-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_op_table.h
155 lines (123 loc) · 3.02 KB
/
file_op_table.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef _FILE_OP_TABLE_H
#define _FILE_OP_TABLE_H
#include "lib.h"
#include "idt_handler.h"
#include "rtc.h"
#include "file_system.h"
#include "terminal.h"
#include "file_desc.h"
#define debug_fread_f_d 0
#define debug_fread_f_d_freq 51
#if debug_fread_f_d
static int32_t debug_fread_f_d_k=debug_fread_f_d_freq;
#endif
static int32_t fopen_f_d(filedescriptor_t* fdstruct,void* buf)
{
return -1;
}
static int32_t fread_f_d(filedescriptor_t* fdstruct, void* buf, uint32_t n_bytes)
{
//char buff[n_bytes];
//char * pointer =(char *) buf;
//int32_t h;
uint32_t temp;
//uint32_t temp2;
//uint32_t inode = fdstruct->inode_pointer;
//uint32_t n_bytes1 = n_bytes;
//printf("indoe %d",fdstruct->inode_pointer);
//printf("fb %x",(uint32_t)*(uint32_t*)(fdstruct->inode_pointer));
if(fdstruct->inode_pointer == 0)
{
//printf( "directory: %d",fdstruct->file_position);
temp = read_data(fdstruct->inode_pointer, fdstruct->file_position, (uint8_t*) buf, n_bytes);
fdstruct->file_position += n_bytes;
}
else
{
temp = read_data(fdstruct->inode_pointer, fdstruct->file_position, (uint8_t*) buf, n_bytes);
fdstruct->file_position += temp;
if(temp == 0)
{
//printf( "cao ni ma quan jia ");
}
}
// don grep excutebe file
if(*(uint32_t*) buf == 0x464c457f )
return 0;
//temp2 = fdstruct->file_position;
// if(temp == -1)
// fdstruct->file_position = 0;
// for(h = temp; h < strlen((uint8_t*)buf); h++)
// pointer[h]=0;
//printf( "%c",*pointer);
#if debug_fread_f_d
debug_fread_f_d_k--;
if (debug_fread_f_d_k==0) {
printf("Buf is %s\n",buf);
printf("return data byte read:%d\n",temp);
while(1);
}
#endif
//printf( "\n %s ",buf);
return temp;
}
static int32_t fwrite_f_d(filedescriptor_t* fdstruct, const void* buf, uint32_t n_bytes)
{
return -1;
}
static int32_t fopen_rtc(filedescriptor_t* fdstruct,void* buf)
{
return 0;
}
static int32_t fread_rtc(filedescriptor_t* fdstruct, void* buf, uint32_t n_bytes)
{
sti();
read_rtc();
cli();
return 0;
}
static int32_t fwrite_rtc(filedescriptor_t* fdstruct, const void* buf, uint32_t n_bytes)
{
// printf( "fwrite_rtc %d",(int)*(int*)buf);
// char *type = NULL;
// char temp =*type;
cli();
write_rtc((int)*(int*)buf);
sti();
return 0;
}
static int32_t termin_read(filedescriptor_t* fdstruct, void* buf, uint32_t n_bytes)
{
sti();
return r_terminal(0x00,(uint8_t*) buf, n_bytes);
}
static int32_t termin_open(filedescriptor_t* fdstruct,void* buf)
{
open_terminal(0x00);
return 0;
}
static int32_t termin_write(filedescriptor_t* fdstruct, const void* buf, uint32_t n_bytes)
{
printf( "%s",buf);
return 0;
}
//no
file_type_op_action_t RTC_type_op = {
.open =&fopen_rtc,
.write= &fwrite_rtc,
.read= &fread_rtc};
//DIRECTORY
file_type_op_action_t directry_type_op = {
.open = &fopen_f_d,
.write= &fwrite_f_d,
.read = &fread_f_d};
//REGULER FILE
file_type_op_action_t file_type_op = {
.open = &fopen_f_d,
.write= &fwrite_f_d,
.read = &fread_f_d};
file_type_op_action_t terminal_type_op = {
.open = &termin_open,
.write= &termin_write,
.read = &termin_read};
#endif