RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
FileSystemWrap.c File Reference

File system wrappers. More...

Include dependency graph for FileSystemWrap.c:

Go to the source code of this file.

Macros

#define PrintX   Print
 

Functions

EFI_STATUS OpenVolume (EFI_DEVICE_PATH_PROTOCOL *Device)
 
EFI_STATUS OpenFile (CHAR16 *FilePathName, UINT64 OpenMode, EFI_FILE_PROTOCOL **File)
 
EFI_STATUS InitializeLogFile (VOID)
 
EFI_STATUS CloseLogFile (VOID)
 
EFI_STATUS WriteLogFile16 (CHAR16 *Data)
 
EFI_STATUS WriteLogFile (CHAR8 *Data)
 

Variables

EFI_HANDLE gImageHandle
 
EFI_LOADED_IMAGE * gSelfLoadedImage = 0
 
EFI_FILE_HANDLE gRoot = 0
 
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * gVolFileSystemProto = 0
 
EFI_FILE_PROTOCOL * gLogFile
 

Detailed Description

File system wrappers.

Author
Piotr Bania
Date
Feb 2013 Wrapper for EFI file system functions.

Definition in file FileSystemWrap.c.

Macro Definition Documentation

#define PrintX   Print

Definition at line 15 of file FileSystemWrap.c.

Referenced by OpenFile(), and OpenVolume().

Function Documentation

EFI_STATUS CloseLogFile ( VOID  )

Function closes the log file.

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 197 of file FileSystemWrap.c.

References gEfiScannerPolicy, gLogFile, LOG_EXIT_LINE, and _policy::OpUseLog.

Referenced by EfiScannerEntryPoint().

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 }

Here is the caller graph for this function:

EFI_STATUS InitializeLogFile ( VOID  )

Function initializes the log file

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 137 of file FileSystemWrap.c.

References EFI_STATUS(), gEfiScannerPolicy, gImageHandle, gLogFile, gRoot, gSelfLoadedImage, gVolFileSystemProto, LOG_FILE, LOG_INIT_LINE, OpenFile(), OpenVolume(), _policy::OpUseLog, and PRINT_FUNC.

Referenced by EfiScannerInitialize().

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 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS OpenFile ( CHAR16 *  FilePathName,
UINT64  OpenMode,
EFI_FILE_PROTOCOL **  File 
)

Function opens selected file. OpenVolume function needs to be executed before. The file must be located on the previously opened volume.

Parameters
FilePathNameUnicode file path
OpenModeSpecified file mode
FileOn success this variable is initialized with EFI_FILE_PROTOCOL*
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 103 of file FileSystemWrap.c.

References EFI_STATUS(), gRoot, and PrintX.

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 }

Here is the call graph for this function:

EFI_STATUS OpenVolume ( EFI_DEVICE_PATH_PROTOCOL *  Device)

Function opens selected volume.

Parameters
DeviceEFI Device Path to selected device.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 46 of file FileSystemWrap.c.

References EFI_STATUS(), gRoot, gSelfLoadedImage, gVolFileSystemProto, and PrintX.

Referenced by InitializeLogFile().

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 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS WriteLogFile ( CHAR8 *  Data)

Function writes ascii null-terminated string to the log file.

Parameters
DataAscii string to write.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 256 of file FileSystemWrap.c.

References gEfiScannerPolicy, gLogFile, and _policy::OpUseLog.

Referenced by LogFileAscii(), and LogFullAscii().

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 }

Here is the caller graph for this function:

EFI_STATUS WriteLogFile16 ( CHAR16 *  Data)

Function writes unicode string to the log file.

Parameters
DataUnicode string to write.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 225 of file FileSystemWrap.c.

References gEfiScannerPolicy, gLogFile, and _policy::OpUseLog.

Referenced by LogFullUnicode().

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 }

Here is the caller graph for this function:

Variable Documentation

EFI_HANDLE gImageHandle
EFI_FILE_PROTOCOL* gLogFile

Definition at line 30 of file FileSystemWrap.c.

Referenced by CloseLogFile(), InitializeLogFile(), WriteLogFile(), and WriteLogFile16().

EFI_FILE_HANDLE gRoot = 0

Definition at line 27 of file FileSystemWrap.c.

Referenced by InitializeLogFile(), OpenFile(), and OpenVolume().

EFI_LOADED_IMAGE* gSelfLoadedImage = 0

Definition at line 24 of file FileSystemWrap.c.

Referenced by EfiScannerInitialize(), InitializeLogFile(), and OpenVolume().

EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* gVolFileSystemProto = 0

Definition at line 28 of file FileSystemWrap.c.

Referenced by InitializeLogFile(), and OpenVolume().