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
|
#include <u.h>
#include "fns.h"
#include "efi.h"
typedef struct {
UINT64 Revision;
void *Open;
void *Close;
void *Delete;
void *Read;
void *Write;
void *GetPosition;
void *SetPosition;
void *GetInfo;
void *SetInfo;
void *Flush;
void *OpenEx;
void *ReadEx;
void *WriteEx;
void *FlushEx;
} EFI_FILE_PROTOCOL;
typedef struct {
UINT64 Revision;
void *OpenVolume;
} EFI_SIMPLE_FILE_SYSTEM_PROTOCOL;
static
EFI_GUID EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID = {
0x0964e5b22, 0x6459, 0x11d2,
0x8e, 0x39, 0x00, 0xa0,
0xc9, 0x69, 0x72, 0x3b,
};
static
EFI_FILE_PROTOCOL *fsroot;
static void
towpath(CHAR16 *w, int nw, char *s)
{
int i;
for(i=0; *s && i<nw-1; i++){
*w = *s++;
if(*w == '/')
*w = '\\';
w++;
}
*w = 0;
}
static void*
fsopen(char *name)
{
CHAR16 wname[MAXPATH];
EFI_FILE_PROTOCOL *fp;
if(fsroot == nil)
return nil;
towpath(wname, MAXPATH, name);
fp = nil;
if(eficall(fsroot->Open, fsroot, &fp, wname, (UINT64)1, (UINT64)1))
return nil;
return fp;
}
static int
fsread(void *f, void *data, int len)
{
UINTN size;
size = len;
if(eficall(((EFI_FILE_PROTOCOL*)f)->Read, f, &size, data))
return 0;
return (int)size;
}
static void
fsclose(void *f)
{
eficall(((EFI_FILE_PROTOCOL*)f)->Close, f);
}
int
fsinit(void **pf)
{
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
fs = nil;
fsroot = nil;
if(eficall(ST->BootServices->LocateProtocol,
&EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, nil, &fs))
return -1;
if(eficall(fs->OpenVolume, fs, &fsroot)){
fsroot = nil;
return -1;
}
read = fsread;
close = fsclose;
open = fsopen;
if(pf != nil)
*pf = fsopen("/plan9.ini");
return 0;
}
|