RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
FileSystemWrap.c
Go to the documentation of this file.
1 
12 #include "EfiScannerHeaders.h"
13 
14 
15 #define PrintX Print
16 
17 
18 //
19 // globals
20 //
21 
22 extern EFI_HANDLE gImageHandle;
23 
24 EFI_LOADED_IMAGE *gSelfLoadedImage = 0;
25 
26 
27 EFI_FILE_HANDLE gRoot = 0;
28 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *gVolFileSystemProto = 0;
29 
30 EFI_FILE_PROTOCOL *gLogFile;
31 
32 
33 
34 
35 
46 EFI_STATUS OpenVolume(EFI_DEVICE_PATH_PROTOCOL *Device)
47 {
48  EFI_STATUS Status;
49  EFI_HANDLE Handle;
50 
51  Handle = gSelfLoadedImage->DeviceHandle;
52 
53  Status = gBS->HandleProtocol(Handle,
54  &gEfiSimpleFileSystemProtocolGuid,
55  (VOID**)&gVolFileSystemProto);
56 
57  if (EFI_ERROR(Status))
58  {
59 #if DEBUG_ON == 1
60  PrintX(L"Error: %s->HandleProtocol, status = %08x\r\n", __FUNCTION__, Status);
61 #endif
62  return Status;
63  }
64 
65 
66 #if DEBUG_ON == 1
67  PrintX(L"Opening volume\r\n");
68 #endif
69 
70  gRoot = NULL;
71  Status = gVolFileSystemProto->OpenVolume(gVolFileSystemProto, &gRoot);
72 
73 
74 #if DEBUG_ON == 1
75  PrintX(L"Opened volume, status = %08x, root = %08x\r\n", Status, gRoot);
76 #endif
77 
78  ASSERT_EFI_ERROR(Status);
79  ASSERT(gRoot != NULL);
80 
81  return Status;
82 
83 }
84 
85 
86 
87 
103 EFI_STATUS OpenFile(CHAR16 *FilePathName,
104  UINT64 OpenMode,
105  EFI_FILE_PROTOCOL **File)
106 {
107  EFI_STATUS Status;
108 
109  ASSERT (gRoot != NULL);
110 
111  *File = NULL;
112  Status = gRoot->Open(gRoot, File, FilePathName, OpenMode, 0);
113 
114  if (EFI_ERROR (Status))
115  {
116 #if DEBUG_ON == 1
117  PrintX(L"Error: OpenFile->gRoot->Open, status = %08x.\r\n", Status);
118 #endif
119 
120  *File = NULL;
121  }
122 
123  //gRoot->Close(gRoot); //fix
124  return Status;
125 }
126 
127 
128 
138 {
139  UINTN Size;
140  EFI_STATUS Status;
141 
142  // check the policy first
144  return EFI_NOT_FOUND;
145 
146  if (gSelfLoadedImage->DeviceHandle && gVolFileSystemProto)
147  gBS->CloseProtocol(gSelfLoadedImage->DeviceHandle,
148  &gEfiSimpleFileSystemProtocolGuid,
150  gImageHandle);
151 
152  if (gRoot)
153  gRoot->Close(gRoot);
154 
155  Status = OpenVolume(gSelfLoadedImage->FilePath);
156  ASSERT(!EFI_ERROR(Status));
157 
158 
159  Status = OpenFile(LOG_FILE,
160  EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ | EFI_FILE_MODE_CREATE,
161  &gLogFile);
162 
163  if (EFI_ERROR(Status))
164  {
165  PRINT_FUNC(L"%a: unable to create log file, status = %08x \r\n",
166  __FUNCTION__, Status);
167  return Status;
168  }
169 
170 
171  // seek to the end of file
172  gLogFile->SetPosition(gLogFile, 0xFFFFFFFFFFFFFFFF);
173 
174  Size = sizeof(LOG_INIT_LINE)-1;
175  Status = gLogFile->Write(gLogFile, &Size, LOG_INIT_LINE);
176 
177 
178  if (EFI_ERROR(Status))
179  {
180  PRINT_FUNC(L"%a: unable to write, status = %08x \r\n",
181  __FUNCTION__, Status);
182  return Status;
183  }
184 
185  return Status;
186 }
187 
188 
198 {
199  UINTN Size;
200 
201  // check the policy first
203  return EFI_NOT_FOUND;
204 
205 
206  Size = sizeof(LOG_EXIT_LINE)-1;
207  gLogFile->Write(gLogFile, &Size, LOG_EXIT_LINE);
208  gLogFile->Close(gLogFile);
209 
210  return EFI_SUCCESS;
211 }
212 
213 
226 {
227  CHAR8 Buffer[2014];
228  UINTN Size;
229 
230  // check the policy first
232  return EFI_NOT_FOUND;
233 
234 
235 
236  UnicodeStrToAsciiStr(Data, Buffer);
237 
238  Size = strlen(Buffer);
239  gLogFile->Write(gLogFile, &Size, Buffer);
240  gLogFile->Flush(gLogFile);
241 
242  return EFI_SUCCESS;
243 }
244 
245 
257 {
258  UINTN Size;
259 
260  // check the policy first
262  return EFI_NOT_FOUND;
263 
264 
265  Size = strlen(Data);
266  gLogFile->Write(gLogFile, &Size, Data);
267  gLogFile->Flush(gLogFile);
268 
269  return EFI_SUCCESS;
270 }
271 
272