]> git.lizzy.rs Git - plan9front.git/blob - sys/src/boot/efi/fs.c
efi: change eficonfig ordering so memconf() is first, dont fallback to fs when /cfg...
[plan9front.git] / sys / src / boot / efi / fs.c
1 #include <u.h>
2 #include "fns.h"
3 #include "efi.h"
4
5 typedef struct {
6         UINT64          Revision;
7         void            *Open;
8         void            *Close;
9         void            *Delete;
10         void            *Read;
11         void            *Write;
12         void            *GetPosition;
13         void            *SetPosition;
14         void            *GetInfo;
15         void            *SetInfo;
16         void            *Flush;
17         void            *OpenEx;
18         void            *ReadEx;
19         void            *WriteEx;
20         void            *FlushEx;
21 } EFI_FILE_PROTOCOL;
22
23 typedef struct {
24         UINT64          Revision;
25         void            *OpenVolume;
26 } EFI_SIMPLE_FILE_SYSTEM_PROTOCOL;
27
28 static
29 EFI_GUID EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID = {
30         0x0964e5b22, 0x6459, 0x11d2,
31         0x8e, 0x39, 0x00, 0xa0,
32         0xc9, 0x69, 0x72, 0x3b,
33 };
34
35 static
36 EFI_FILE_PROTOCOL *fsroot;
37
38 static void
39 towpath(CHAR16 *w, int nw, char *s)
40 {
41         int i;
42
43         for(i=0; *s && i<nw-1; i++){
44                 *w = *s++;
45                 if(*w == '/')
46                         *w = '\\';
47                 w++;
48         }
49         *w = 0;
50 }
51
52 static void*
53 fsopen(char *name)
54 {
55         CHAR16 wname[MAXPATH];
56         EFI_FILE_PROTOCOL *fp;
57
58         if(fsroot == nil)
59                 return nil;
60
61         towpath(wname, MAXPATH, name);
62
63         fp = nil;
64         if(eficall(fsroot->Open, fsroot, &fp, wname, (UINT64)1, (UINT64)1))
65                 return nil;
66         return fp;
67 }
68
69 static int
70 fsread(void *f, void *data, int len)
71 {
72         UINTN size;
73
74         size = len;
75         if(eficall(((EFI_FILE_PROTOCOL*)f)->Read, f, &size, data))
76                 return 0;
77         return (int)size;
78 }
79
80 static void
81 fsclose(void *f)
82 {
83         eficall(((EFI_FILE_PROTOCOL*)f)->Close, f);
84 }
85
86 int
87 fsinit(void **pf)
88 {
89         EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
90
91         fs = nil;
92         fsroot = nil;
93         if(eficall(ST->BootServices->LocateProtocol,
94                 &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, nil, &fs))
95                 return -1;
96         if(eficall(fs->OpenVolume, fs, &fsroot)){
97                 fsroot = nil;
98                 return -1;
99         }
100
101         read = fsread;
102         close = fsclose;
103         open = fsopen;
104
105         if(pf != nil)
106                 *pf = fsopen("/plan9.ini");
107
108         return 0;
109 }