iPXE
Data Structures | Macros | Functions | Variables
efi_file.c File Reference

EFI file protocols. More...

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <wchar.h>
#include <ipxe/image.h>
#include <ipxe/cpio.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/SimpleFileSystem.h>
#include <ipxe/efi/Protocol/BlockIo.h>
#include <ipxe/efi/Protocol/DiskIo.h>
#include <ipxe/efi/Guid/FileInfo.h>
#include <ipxe/efi/Guid/FileSystemInfo.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_file.h>

Go to the source code of this file.

Data Structures

struct  efi_file_reader
 An EFI virtual file reader. More...
 
struct  efi_file
 An EFI file. More...
 

Macros

#define EFI_MEDIA_ID_MAGIC   0x69505845
 EFI media ID. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void efi_file_free (struct refcnt *refcnt)
 Free EFI file. More...
 
static const char * efi_file_name (struct efi_file *file)
 Get EFI file name (for debugging) More...
 
static struct imageefi_file_find (const char *name)
 Find EFI file image. More...
 
static size_t efi_file_len (struct efi_file *file)
 Get length of EFI file. More...
 
static size_t efi_file_read_chunk (struct efi_file_reader *reader, userptr_t data, size_t len)
 Read chunk of EFI file. More...
 
static size_t efi_file_read_image (struct efi_file_reader *reader)
 Read from image-backed file. More...
 
static size_t efi_file_read_initrd (struct efi_file_reader *reader)
 Read from magic initrd file. More...
 
static EFI_STATUS efi_file_open_fixed (struct efi_file *file, EFI_FILE_PROTOCOL **new)
 Open fixed file. More...
 
static void efi_file_image (struct efi_file *file, struct image *image)
 Associate file with image. More...
 
static EFI_STATUS EFIAPI efi_file_open (EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new, CHAR16 *wname, UINT64 mode, UINT64 attributes __unused)
 Open file. More...
 
static EFI_STATUS EFIAPI efi_file_close (EFI_FILE_PROTOCOL *this)
 Close file. More...
 
static EFI_STATUS EFIAPI efi_file_delete (EFI_FILE_PROTOCOL *this)
 Close and delete file. More...
 
static EFI_STATUS efi_file_varlen (UINT64 *base, size_t base_len, const char *name, UINTN *len, VOID *data)
 Return variable-length data structure. More...
 
static EFI_STATUS efi_file_info (struct efi_file *file, UINTN *len, VOID *data)
 Return file information structure. More...
 
static EFI_STATUS efi_file_read_dir (struct efi_file *file, UINTN *len, VOID *data)
 Read directory entry. More...
 
static EFI_STATUS EFIAPI efi_file_read (EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data)
 Read from file. More...
 
static EFI_STATUS EFIAPI efi_file_write (EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data __unused)
 Write to file. More...
 
static EFI_STATUS EFIAPI efi_file_set_position (EFI_FILE_PROTOCOL *this, UINT64 position)
 Set file position. More...
 
static EFI_STATUS EFIAPI efi_file_get_position (EFI_FILE_PROTOCOL *this, UINT64 *position)
 Get file position. More...
 
static EFI_STATUS EFIAPI efi_file_get_info (EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN *len, VOID *data)
 Get file information. More...
 
static EFI_STATUS EFIAPI efi_file_set_info (EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN len __unused, VOID *data __unused)
 Set file information. More...
 
static EFI_STATUS EFIAPI efi_file_flush (EFI_FILE_PROTOCOL *this)
 Flush file modified data. More...
 
static EFI_STATUS EFIAPI efi_file_open_volume (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *filesystem __unused, EFI_FILE_PROTOCOL **file)
 Open root directory. More...
 
static EFI_STATUS EFIAPI efi_block_io_reset (EFI_BLOCK_IO_PROTOCOL *this __unused, BOOLEAN extended)
 Dummy block I/O reset. More...
 
static EFI_STATUS EFIAPI efi_block_io_read_blocks (EFI_BLOCK_IO_PROTOCOL *this __unused, UINT32 MediaId, EFI_LBA lba, UINTN len, VOID *data)
 Dummy block I/O read. More...
 
static EFI_STATUS EFIAPI efi_block_io_write_blocks (EFI_BLOCK_IO_PROTOCOL *this __unused, UINT32 MediaId, EFI_LBA lba, UINTN len, VOID *data)
 Dummy block I/O write. More...
 
static EFI_STATUS EFIAPI efi_block_io_flush_blocks (EFI_BLOCK_IO_PROTOCOL *this __unused)
 Dummy block I/O flush. More...
 
static EFI_STATUS EFIAPI efi_disk_io_read_disk (EFI_DISK_IO_PROTOCOL *this __unused, UINT32 MediaId, UINT64 offset, UINTN len, VOID *data)
 Dummy disk I/O read. More...
 
static EFI_STATUS EFIAPI efi_disk_io_write_disk (EFI_DISK_IO_PROTOCOL *this __unused, UINT32 MediaId, UINT64 offset, UINTN len, VOID *data)
 Dummy disk I/O write. More...
 
int efi_file_install (EFI_HANDLE handle)
 Install EFI simple file system protocol. More...
 
void efi_file_uninstall (EFI_HANDLE handle)
 Uninstall EFI simple file system protocol. More...
 

Variables

static struct efi_file efi_file_root
 Root directory. More...
 
static struct efi_file efi_file_initrd
 Magic initrd file. More...
 
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
 EFI simple file system protocol. More...
 
static EFI_BLOCK_IO_MEDIA efi_block_io_media
 Dummy block I/O media. More...
 
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
 Dummy EFI block I/O protocol. More...
 
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
 Dummy EFI disk I/O protocol. More...
 

Detailed Description

EFI file protocols.

Definition in file efi_file.c.

Macro Definition Documentation

◆ EFI_MEDIA_ID_MAGIC

#define EFI_MEDIA_ID_MAGIC   0x69505845

EFI media ID.

Definition at line 52 of file efi_file.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_file_free()

static void efi_file_free ( struct refcnt refcnt)
static

Free EFI file.

Parameters
refcntReference count

Definition at line 95 of file efi_file.c.

95  {
96  struct efi_file *file =
97  container_of ( refcnt, struct efi_file, refcnt );
98 
99  image_put ( file->image );
100  free ( file );
101 }
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:221
An EFI file.
Definition: efi_file.c:67

References container_of, efi_file::file, free, and image_put().

Referenced by efi_file_open().

◆ efi_file_name()

static const char* efi_file_name ( struct efi_file file)
static

Get EFI file name (for debugging)

Parameters
fileEFI file
Return values
nameName

Definition at line 109 of file efi_file.c.

109  {
110 
111  return ( file == &efi_file_root ? "<root>" : file->name );
112 }
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87

References efi_file_root, and efi_file::file.

Referenced by efi_file_close(), efi_file_delete(), efi_file_flush(), efi_file_get_info(), efi_file_open(), efi_file_open_fixed(), efi_file_read(), efi_file_read_initrd(), efi_file_set_info(), efi_file_set_position(), and efi_file_write().

◆ efi_file_find()

static struct image* efi_file_find ( const char *  name)
static

Find EFI file image.

Parameters
nameFilename
Return values
imageImage, or NULL

Definition at line 120 of file efi_file.c.

120  {
121  struct image *image;
122 
123  /* Find image */
125  if ( strcasecmp ( image->name, name ) == 0 )
126  return image;
127  }
128 
129  return NULL;
130 }
const char * name
Definition: ath9k_hw.c:1984
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
An executable image.
Definition: image.h:24
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
struct list_head images
List of registered images.
Definition: image.c:56
struct list_head list
List of registered images.
Definition: image.h:29
char * name
Name.
Definition: image.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References images, image::list, list_for_each_entry, image::name, name, NULL, and strcasecmp().

Referenced by efi_file_open().

◆ efi_file_len()

static size_t efi_file_len ( struct efi_file file)
static

Get length of EFI file.

Parameters
fileEFI file
Return values
lenLength of file

Definition at line 138 of file efi_file.c.

138  {
139  struct efi_file_reader reader;
140 
141  /* If this is the root directory, then treat as length zero */
142  if ( ! file->read )
143  return 0;
144 
145  /* Initialise reader */
146  reader.file = file;
147  reader.pos = 0;
148  reader.data = NULL;
149  reader.len = 0;
150 
151  /* Perform dummy read to determine file length */
152  file->read ( &reader );
153 
154  return reader.pos;
155 }
An EFI virtual file reader.
Definition: efi_file.c:55
size_t pos
Current file position.
Definition: efi_file.c:77
struct efi_file * file
EFI file.
Definition: efi_file.c:57
size_t(* read)(struct efi_file_reader *reader)
Read from file.
Definition: efi_file.c:84
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References efi_file_reader::data, efi_file_reader::file, efi_file_reader::len, NULL, efi_file_reader::pos, and efi_file::read.

Referenced by efi_file_info(), and efi_file_set_position().

◆ efi_file_read_chunk()

static size_t efi_file_read_chunk ( struct efi_file_reader reader,
userptr_t  data,
size_t  len 
)
static

Read chunk of EFI file.

Parameters
readerEFI file reader
dataInput data, or UNULL to zero-fill
lenLength of input data
Return values
lenLength of output data

Definition at line 165 of file efi_file.c.

166  {
167  struct efi_file *file = reader->file;
168  size_t offset;
169 
170  /* Calculate offset into input data */
171  offset = ( file->pos - reader->pos );
172 
173  /* Consume input data range */
174  reader->pos += len;
175 
176  /* Calculate output length */
177  if ( offset < len ) {
178  len -= offset;
179  } else {
180  len = 0;
181  }
182  if ( len > reader->len )
183  len = reader->len;
184 
185  /* Copy or zero output data */
186  if ( data ) {
187  copy_from_user ( reader->data, data, offset, len );
188  } else {
189  memset ( reader->data, 0, len );
190  }
191 
192  /* Consume output buffer */
193  file->pos += len;
194  reader->data += len;
195  reader->len -= len;
196 
197  return len;
198 }
void * data
Output data buffer.
Definition: efi_file.c:61
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
struct efi_file * file
EFI file.
Definition: efi_file.c:57
size_t len
Length of output data buffer.
Definition: efi_file.c:63
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
size_t pos
Position within virtual file.
Definition: efi_file.c:59
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
An EFI file.
Definition: efi_file.c:67
void * memset(void *dest, int character, size_t len) __nonnull

References copy_from_user(), data, efi_file_reader::data, efi_file_reader::file, efi_file::file, len, efi_file_reader::len, memset(), offset, and efi_file_reader::pos.

Referenced by efi_file_read_image(), and efi_file_read_initrd().

◆ efi_file_read_image()

static size_t efi_file_read_image ( struct efi_file_reader reader)
static

Read from image-backed file.

Parameters
readerEFI file reader
Return values
lenLength read

Definition at line 206 of file efi_file.c.

206  {
207  struct efi_file *file = reader->file;
208  struct image *image = file->image;
209 
210  /* Read from file */
211  return efi_file_read_chunk ( reader, image->data, image->len );
212 }
userptr_t data
Raw file image.
Definition: image.h:41
An executable image.
Definition: image.h:24
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
struct efi_file * file
EFI file.
Definition: efi_file.c:57
static size_t efi_file_read_chunk(struct efi_file_reader *reader, userptr_t data, size_t len)
Read chunk of EFI file.
Definition: efi_file.c:165
size_t len
Length of raw file image.
Definition: image.h:43
struct image * image
Image (if any)
Definition: efi_file.c:73
An EFI file.
Definition: efi_file.c:67

References image::data, efi_file_read_chunk(), efi_file_reader::file, efi_file::file, efi_file::image, and image::len.

Referenced by efi_file_image().

◆ efi_file_read_initrd()

static size_t efi_file_read_initrd ( struct efi_file_reader reader)
static

Read from magic initrd file.

Parameters
readerEFI file reader
Return values
lenLength read

Definition at line 220 of file efi_file.c.

220  {
221  struct efi_file *file = reader->file;
222  struct cpio_header cpio;
223  struct image *image;
224  const char *name;
225  size_t pad_len;
226  size_t cpio_len;
227  size_t name_len;
228  size_t len;
229 
230  /* Read from file */
231  len = 0;
232  for_each_image ( image ) {
233 
234  /* Ignore currently executing image */
235  if ( image == current_image )
236  continue;
237 
238  /* Pad to alignment boundary */
239  pad_len = ( ( -reader->pos ) & ( INITRD_ALIGN - 1 ) );
240  if ( pad_len ) {
241  DBGC ( file, "EFIFILE %s [%#08zx,%#08zx) pad\n",
242  efi_file_name ( file ), reader->pos,
243  ( reader->pos + pad_len ) );
244  }
245  len += efi_file_read_chunk ( reader, UNULL, pad_len );
246 
247  /* Read CPIO header, if applicable */
248  cpio_len = cpio_header ( image, &cpio );
249  if ( cpio_len ) {
250  name = cpio_name ( image );
251  name_len = cpio_name_len ( image );
252  pad_len = ( cpio_len - sizeof ( cpio ) - name_len );
253  DBGC ( file, "EFIFILE %s [%#08zx,%#08zx) %s header\n",
254  efi_file_name ( file ), reader->pos,
255  ( reader->pos + cpio_len ), image->name );
256  len += efi_file_read_chunk ( reader,
257  virt_to_user ( &cpio ),
258  sizeof ( cpio ) );
259  len += efi_file_read_chunk ( reader,
260  virt_to_user ( name ),
261  name_len );
262  len += efi_file_read_chunk ( reader, UNULL, pad_len );
263  }
264 
265  /* Read file data */
266  DBGC ( file, "EFIFILE %s [%#08zx,%#08zx) %s\n",
267  efi_file_name ( file ), reader->pos,
268  ( reader->pos + image->len ), image->name );
269  len += efi_file_read_chunk ( reader, image->data, image->len );
270  }
271 
272  return len;
273 }
size_t cpio_name_len(struct image *image)
Get CPIO image filename.
Definition: cpio.c:56
const char * name
Definition: ath9k_hw.c:1984
struct image * current_image
Currently-executing image.
Definition: image.c:59
userptr_t data
Raw file image.
Definition: image.h:41
A CPIO archive header.
Definition: cpio.h:19
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
struct efi_file * file
EFI file.
Definition: efi_file.c:57
static size_t efi_file_read_chunk(struct efi_file_reader *reader, userptr_t data, size_t len)
Read chunk of EFI file.
Definition: efi_file.c:165
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:157
size_t len
Length of raw file image.
Definition: image.h:43
size_t pos
Position within virtual file.
Definition: efi_file.c:59
long pad_len
Definition: bigint.h:30
#define INITRD_ALIGN
Alignment for CPIO archives within an initrd.
Definition: cpio.h:57
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint32_t len
Length.
Definition: ena.h:14
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
char * name
Name.
Definition: image.h:34
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109
size_t cpio_header(struct image *image, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
Definition: cpio.c:107
static const char * cpio_name(struct image *image)
Get CPIO image name.
Definition: cpio.h:66

References cpio_header(), cpio_name(), cpio_name_len(), current_image, image::data, DBGC, efi_file_name(), efi_file_read_chunk(), efi_file_reader::file, efi_file::file, for_each_image, INITRD_ALIGN, len, image::len, image::name, name, pad_len, efi_file_reader::pos, UNULL, and virt_to_user().

◆ efi_file_open_fixed()

static EFI_STATUS efi_file_open_fixed ( struct efi_file file,
EFI_FILE_PROTOCOL **  new 
)
static

Open fixed file.

Parameters
fileEFI file
newNew EFI file
Return values
efircEFI status code

Definition at line 282 of file efi_file.c.

283  {
284 
285  /* Increment reference count */
286  ref_get ( &file->refcnt );
287 
288  /* Return opened file */
289  *new = &file->file;
290 
291  DBGC ( file, "EFIFILE %s opened\n", efi_file_name ( file ) );
292  return 0;
293 }
struct refcnt refcnt
Reference count.
Definition: efi_file.c:69
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References DBGC, efi_file_name(), efi_file::file, ref_get, and efi_file::refcnt.

Referenced by efi_file_open(), and efi_file_open_volume().

◆ efi_file_image()

static void efi_file_image ( struct efi_file file,
struct image image 
)
static

Associate file with image.

Parameters
fileEFI file
imageImage

Definition at line 301 of file efi_file.c.

301  {
302 
303  file->image = image;
304  file->name = image->name;
305  file->read = efi_file_read_image;
306 }
An executable image.
Definition: image.h:24
static size_t efi_file_read_image(struct efi_file_reader *reader)
Read from image-backed file.
Definition: efi_file.c:206
struct image * image
Image (if any)
Definition: efi_file.c:73
size_t(* read)(struct efi_file_reader *reader)
Read from file.
Definition: efi_file.c:84
char * name
Name.
Definition: image.h:34
const char * name
Filename.
Definition: efi_file.c:75

References efi_file_read_image(), efi_file::image, image::name, efi_file::name, and efi_file::read.

Referenced by efi_file_open(), and efi_file_read_dir().

◆ efi_file_open()

static EFI_STATUS EFIAPI efi_file_open ( EFI_FILE_PROTOCOL this,
EFI_FILE_PROTOCOL **  new,
CHAR16 wname,
UINT64  mode,
UINT64 attributes  __unused 
)
static

Open file.

Parameters
thisEFI file
Return values
newNew EFI file
Parameters
wnameFilename
modeFile mode
attributesFile attributes (for newly-created files)
Return values
efircEFI status code

Definition at line 319 of file efi_file.c.

320  {
321  struct efi_file *file = container_of ( this, struct efi_file, file );
322  char buf[ wcslen ( wname ) + 1 /* NUL */ ];
323  struct efi_file *new_file;
324  struct image *image;
325  char *name;
326 
327  /* Convert name to ASCII */
328  snprintf ( buf, sizeof ( buf ), "%ls", wname );
329  name = buf;
330 
331  /* Initial '\' indicates opening from the root directory */
332  while ( *name == '\\' ) {
333  file = &efi_file_root;
334  name++;
335  }
336 
337  /* Allow root directory itself to be opened */
338  if ( ( name[0] == '\0' ) || ( name[0] == '.' ) )
339  return efi_file_open_fixed ( &efi_file_root, new );
340 
341  /* Fail unless opening from the root */
342  if ( file != &efi_file_root ) {
343  DBGC ( file, "EFIFILE %s is not a directory\n",
344  efi_file_name ( file ) );
345  return EFI_NOT_FOUND;
346  }
347 
348  /* Fail unless opening read-only */
349  if ( mode != EFI_FILE_MODE_READ ) {
350  DBGC ( file, "EFIFILE %s cannot be opened in mode %#08llx\n",
351  name, mode );
352  return EFI_WRITE_PROTECTED;
353  }
354 
355  /* Allow magic initrd to be opened */
356  if ( strcasecmp ( name, efi_file_initrd.name ) == 0 )
357  return efi_file_open_fixed ( &efi_file_initrd, new );
358 
359  /* Identify image */
360  image = efi_file_find ( name );
361  if ( ! image ) {
362  DBGC ( file, "EFIFILE %s does not exist\n", name );
363  return EFI_NOT_FOUND;
364  }
365 
366  /* Allocate and initialise file */
367  new_file = zalloc ( sizeof ( *new_file ) );
368  if ( ! new_file )
369  return EFI_OUT_OF_RESOURCES;
370  ref_init ( &file->refcnt, efi_file_free );
371  memcpy ( &new_file->file, &efi_file_root.file,
372  sizeof ( new_file->file ) );
373  efi_file_image ( new_file, image_get ( image ) );
374  *new = &new_file->file;
375  DBGC ( new_file, "EFIFILE %s opened\n", efi_file_name ( new_file ) );
376 
377  return 0;
378 }
static void efi_file_free(struct refcnt *refcnt)
Free EFI file.
Definition: efi_file.c:95
struct refcnt refcnt
Reference count.
Definition: efi_file.c:69
const char * name
Definition: ath9k_hw.c:1984
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:211
#define DBGC(...)
Definition: compiler.h:505
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
static EFI_STATUS efi_file_open_fixed(struct efi_file *file, EFI_FILE_PROTOCOL **new)
Open fixed file.
Definition: efi_file.c:282
An executable image.
Definition: image.h:24
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:129
size_t wcslen(const wchar_t *string)
Calculate length of wide-character string.
Definition: wchar.c:41
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
#define EFI_WRITE_PROTECTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:128
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static struct efi_file efi_file_initrd
Magic initrd file.
Definition: efi_file.c:88
#define EFI_NOT_FOUND
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:134
#define EFI_FILE_MODE_READ
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
static struct image * efi_file_find(const char *name)
Find EFI file image.
Definition: efi_file.c:120
An EFI file.
Definition: efi_file.c:67
const char * name
Filename.
Definition: efi_file.c:75
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109
static void efi_file_image(struct efi_file *file, struct image *image)
Associate file with image.
Definition: efi_file.c:301

References container_of, DBGC, efi_file_find(), efi_file_free(), efi_file_image(), efi_file_initrd, EFI_FILE_MODE_READ, efi_file_name(), efi_file_open_fixed(), efi_file_root, EFI_NOT_FOUND, EFI_OUT_OF_RESOURCES, EFI_WRITE_PROTECTED, efi_file::file, image_get(), memcpy(), efi_file::name, name, ref_init, efi_file::refcnt, snprintf(), strcasecmp(), wcslen(), and zalloc().

◆ efi_file_close()

static EFI_STATUS EFIAPI efi_file_close ( EFI_FILE_PROTOCOL this)
static

Close file.

Parameters
thisEFI file
Return values
efircEFI status code

Definition at line 386 of file efi_file.c.

386  {
387  struct efi_file *file = container_of ( this, struct efi_file, file );
388 
389  /* Close file */
390  DBGC ( file, "EFIFILE %s closed\n", efi_file_name ( file ) );
391  ref_put ( &file->refcnt );
392 
393  return 0;
394 }
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An EFI file.
Definition: efi_file.c:67
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References container_of, DBGC, efi_file_name(), efi_file::file, and ref_put.

Referenced by efi_file_delete().

◆ efi_file_delete()

static EFI_STATUS EFIAPI efi_file_delete ( EFI_FILE_PROTOCOL this)
static

Close and delete file.

Parameters
thisEFI file
Return values
efircEFI status code

Definition at line 402 of file efi_file.c.

402  {
403  struct efi_file *file = container_of ( this, struct efi_file, file );
404 
405  DBGC ( file, "EFIFILE %s cannot be deleted\n", efi_file_name ( file ) );
406 
407  /* Close file */
408  efi_file_close ( this );
409 
410  /* Warn of failure to delete */
412 }
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static EFI_STATUS EFIAPI efi_file_close(EFI_FILE_PROTOCOL *this)
Close file.
Definition: efi_file.c:386
#define EFI_WARN_DELETE_FAILURE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:155
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References container_of, DBGC, efi_file_close(), efi_file_name(), EFI_WARN_DELETE_FAILURE, and efi_file::file.

◆ efi_file_varlen()

static EFI_STATUS efi_file_varlen ( UINT64 base,
size_t  base_len,
const char *  name,
UINTN len,
VOID data 
)
static

Return variable-length data structure.

Parameters
baseBase data structure (starting with UINT64)
base_lenLength of base data structure
nameName to append to base data structure
lenLength of data buffer
dataData buffer
Return values
efircEFI status code

Definition at line 424 of file efi_file.c.

425  {
426  size_t name_len;
427 
428  /* Calculate structure length */
429  name_len = strlen ( name );
430  *base = ( base_len + ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );
431  if ( *len < *base ) {
432  *len = *base;
433  return EFI_BUFFER_TOO_SMALL;
434  }
435 
436  /* Copy data to buffer */
437  *len = *base;
438  memcpy ( data, base, base_len );
439  efi_snprintf ( ( data + base_len ), ( name_len + 1 /* NUL */ ),
440  "%s", name );
441 
442  return 0;
443 }
const char * name
Definition: ath9k_hw.c:1984
#define EFI_BUFFER_TOO_SMALL
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:125
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int efi_snprintf(wchar_t *wbuf, size_t wsize, const char *fmt,...)
Write a formatted string to a buffer.
Definition: efi_strings.c:104
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint16_t base
Base address.
Definition: edd.h:14
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References base, data, EFI_BUFFER_TOO_SMALL, efi_snprintf(), len, memcpy(), name, and strlen().

Referenced by efi_file_get_info(), and efi_file_info().

◆ efi_file_info()

static EFI_STATUS efi_file_info ( struct efi_file file,
UINTN len,
VOID data 
)
static

Return file information structure.

Parameters
fileEFI file
lenLength of data buffer
dataData buffer
Return values
efircEFI status code

Definition at line 453 of file efi_file.c.

454  {
456  size_t file_len;
457 
458  /* Get file length */
459  file_len = efi_file_len ( file );
460 
461  /* Populate file information */
462  memset ( &info, 0, sizeof ( info ) );
463  info.FileSize = file_len;
464  info.PhysicalSize = file_len;
465  info.Attribute = EFI_FILE_READ_ONLY;
466  if ( file == &efi_file_root )
467  info.Attribute |= EFI_FILE_DIRECTORY;
468 
470  file->name, len, data );
471 }
u32 info
Definition: ar9003_mac.h:67
#define EFI_FILE_READ_ONLY
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define EFI_FILE_DIRECTORY
#define SIZE_OF_EFI_FILE_INFO
The FileName field of the EFI_FILE_INFO data structure is variable length.
Definition: FileInfo.h:69
static size_t efi_file_len(struct efi_file *file)
Get length of EFI file.
Definition: efi_file.c:138
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
static EFI_STATUS efi_file_varlen(UINT64 *base, size_t base_len, const char *name, UINTN *len, VOID *data)
Return variable-length data structure.
Definition: efi_file.c:424
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
void * memset(void *dest, int character, size_t len) __nonnull

References data, EFI_FILE_DIRECTORY, efi_file_len(), EFI_FILE_READ_ONLY, efi_file_root, efi_file_varlen(), efi_file::file, info, len, memset(), and SIZE_OF_EFI_FILE_INFO.

Referenced by efi_file_get_info(), and efi_file_read_dir().

◆ efi_file_read_dir()

static EFI_STATUS efi_file_read_dir ( struct efi_file file,
UINTN len,
VOID data 
)
static

Read directory entry.

Parameters
fileEFI file
lenLength to read
dataData buffer
Return values
efircEFI status code

Definition at line 481 of file efi_file.c.

482  {
483  EFI_STATUS efirc;
484  struct efi_file entry;
485  struct image *image;
486  unsigned int index;
487 
488  /* Construct directory entries for image-backed files */
489  index = file->pos;
490  for_each_image ( image ) {
491  if ( index-- == 0 ) {
492  efi_file_image ( &entry, image );
493  efirc = efi_file_info ( &entry, len, data );
494  if ( efirc == 0 )
495  file->pos++;
496  return efirc;
497  }
498  }
499 
500  /* No more entries */
501  *len = 0;
502  return 0;
503 }
An executable image.
Definition: image.h:24
static EFI_STATUS efi_file_info(struct efi_file *file, UINTN *len, VOID *data)
Return file information structure.
Definition: efi_file.c:453
size_t pos
Current file position.
Definition: efi_file.c:77
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:157
union aes_table_entry entry[256]
Table entries, indexed by S(N)
Definition: aes.c:26
uint32_t len
Length.
Definition: ena.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
An EFI file.
Definition: efi_file.c:67
static void efi_file_image(struct efi_file *file, struct image *image)
Associate file with image.
Definition: efi_file.c:301

References data, efi_file_image(), efi_file_info(), entry, for_each_image, index, len, and efi_file::pos.

Referenced by efi_file_read().

◆ efi_file_read()

static EFI_STATUS EFIAPI efi_file_read ( EFI_FILE_PROTOCOL this,
UINTN len,
VOID data 
)
static

Read from file.

Parameters
thisEFI file
lenLength to read
dataData buffer
Return values
efircEFI status code

Definition at line 513 of file efi_file.c.

514  {
515  struct efi_file *file = container_of ( this, struct efi_file, file );
516  struct efi_file_reader reader;
517  size_t pos = file->pos;
518 
519  /* If this is the root directory, then construct a directory entry */
520  if ( ! file->read )
521  return efi_file_read_dir ( file, len, data );
522 
523  /* Initialise reader */
524  reader.file = file;
525  reader.pos = 0;
526  reader.data = data;
527  reader.len = *len;
528 
529  /* Read from the file */
530  DBGC ( file, "EFIFILE %s read [%#08zx,%#08zx)\n",
531  efi_file_name ( file ), pos, file->pos );
532  *len = file->read ( &reader );
533  assert ( ( pos + *len ) == file->pos );
534 
535  return 0;
536 }
An EFI virtual file reader.
Definition: efi_file.c:55
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
size_t pos
Current file position.
Definition: efi_file.c:77
struct efi_file * file
EFI file.
Definition: efi_file.c:57
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static EFI_STATUS efi_file_read_dir(struct efi_file *file, UINTN *len, VOID *data)
Read directory entry.
Definition: efi_file.c:481
size_t pos
Position within virtual file.
Definition: efi_file.c:59
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
size_t(* read)(struct efi_file_reader *reader)
Read from file.
Definition: efi_file.c:84
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References assert(), container_of, data, efi_file_reader::data, DBGC, efi_file_name(), efi_file_read_dir(), efi_file_reader::file, efi_file::file, len, efi_file_reader::len, efi_file_reader::pos, efi_file::pos, and efi_file::read.

◆ efi_file_write()

static EFI_STATUS EFIAPI efi_file_write ( EFI_FILE_PROTOCOL this,
UINTN len,
VOID *data  __unused 
)
static

Write to file.

Parameters
thisEFI file
lenLength to write
dataData buffer
Return values
efircEFI status code

Definition at line 546 of file efi_file.c.

547  {
548  struct efi_file *file = container_of ( this, struct efi_file, file );
549 
550  DBGC ( file, "EFIFILE %s cannot write [%#08zx, %#08zx)\n",
551  efi_file_name ( file ), file->pos,
552  ( ( size_t ) ( file->pos + *len ) ) );
553  return EFI_WRITE_PROTECTED;
554 }
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define EFI_WRITE_PROTECTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:128
uint32_t len
Length.
Definition: ena.h:14
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References container_of, DBGC, efi_file_name(), EFI_WRITE_PROTECTED, efi_file::file, and len.

◆ efi_file_set_position()

static EFI_STATUS EFIAPI efi_file_set_position ( EFI_FILE_PROTOCOL this,
UINT64  position 
)
static

Set file position.

Parameters
thisEFI file
positionNew file position
Return values
efircEFI status code

Definition at line 563 of file efi_file.c.

564  {
565  struct efi_file *file = container_of ( this, struct efi_file, file );
566  size_t len;
567 
568  /* Get file length */
569  len = efi_file_len ( file );
570 
571  /* Check for the magic end-of-file value */
572  if ( position == 0xffffffffffffffffULL )
573  position = len;
574 
575  /* Fail if we attempt to seek past the end of the file (since
576  * we do not support writes).
577  */
578  if ( position > len ) {
579  DBGC ( file, "EFIFILE %s cannot seek to %#08llx of %#08zx\n",
580  efi_file_name ( file ), position, len );
581  return EFI_UNSUPPORTED;
582  }
583 
584  /* Set position */
585  file->pos = position;
586  DBGC ( file, "EFIFILE %s position set to %#08zx\n",
587  efi_file_name ( file ), file->pos );
588 
589  return 0;
590 }
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
static size_t efi_file_len(struct efi_file *file)
Get length of EFI file.
Definition: efi_file.c:138
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
uint32_t len
Length.
Definition: ena.h:14
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References container_of, DBGC, efi_file_len(), efi_file_name(), EFI_UNSUPPORTED, efi_file::file, and len.

◆ efi_file_get_position()

static EFI_STATUS EFIAPI efi_file_get_position ( EFI_FILE_PROTOCOL this,
UINT64 position 
)
static

Get file position.

Parameters
thisEFI file
Return values
positionNew file position
efircEFI status code

Definition at line 599 of file efi_file.c.

600  {
601  struct efi_file *file = container_of ( this, struct efi_file, file );
602 
603  *position = file->pos;
604  return 0;
605 }
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An EFI file.
Definition: efi_file.c:67

References container_of, and efi_file::file.

◆ efi_file_get_info()

static EFI_STATUS EFIAPI efi_file_get_info ( EFI_FILE_PROTOCOL this,
EFI_GUID type,
UINTN len,
VOID data 
)
static

Get file information.

Parameters
thisEFI file
typeType of information
lenBuffer size
dataBuffer
Return values
efircEFI status code

Definition at line 616 of file efi_file.c.

618  {
619  struct efi_file *file = container_of ( this, struct efi_file, file );
620  EFI_FILE_SYSTEM_INFO fsinfo;
621  struct image *image;
622 
623  /* Determine information to return */
624  if ( memcmp ( type, &efi_file_info_id, sizeof ( *type ) ) == 0 ) {
625 
626  /* Get file information */
627  DBGC ( file, "EFIFILE %s get file information\n",
628  efi_file_name ( file ) );
629  return efi_file_info ( file, len, data );
630 
631  } else if ( memcmp ( type, &efi_file_system_info_id,
632  sizeof ( *type ) ) == 0 ) {
633 
634  /* Get file system information */
635  DBGC ( file, "EFIFILE %s get file system information\n",
636  efi_file_name ( file ) );
637  memset ( &fsinfo, 0, sizeof ( fsinfo ) );
638  fsinfo.ReadOnly = 1;
640  fsinfo.VolumeSize += image->len;
641  return efi_file_varlen ( &fsinfo.Size,
643  len, data );
644  } else {
645 
646  DBGC ( file, "EFIFILE %s cannot get information of type %s\n",
647  efi_file_name ( file ), efi_guid_ntoa ( type ) );
648  return EFI_UNSUPPORTED;
649  }
650 }
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
BOOLEAN ReadOnly
TRUE if the volume only supports read access.
EFI_GUID efi_file_system_info_id
File system information GUID.
Definition: efi_guid.c:306
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
static EFI_STATUS efi_file_info(struct efi_file *file, UINTN *len, VOID *data)
Return file information structure.
Definition: efi_file.c:453
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:157
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
static EFI_STATUS efi_file_varlen(UINT64 *base, size_t base_len, const char *name, UINTN *len, VOID *data)
Return variable-length data structure.
Definition: efi_file.c:424
size_t len
Length of raw file image.
Definition: image.h:43
UINT64 VolumeSize
The number of bytes managed by the file system.
uint32_t len
Length.
Definition: ena.h:14
EFI_GUID efi_file_info_id
File information GUID.
Definition: efi_guid.c:303
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
UINT64 Size
The size of the EFI_FILE_SYSTEM_INFO structure, including the Null-terminated VolumeLabel string.
An EFI file.
Definition: efi_file.c:67
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
The VolumeLabel field of the EFI_FILE_SYSTEM_INFO data structure is variable length.
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109
void * memset(void *dest, int character, size_t len) __nonnull

References container_of, data, DBGC, efi_file_info(), efi_file_info_id, efi_file_name(), efi_file_system_info_id, efi_file_varlen(), efi_guid_ntoa(), EFI_UNSUPPORTED, efi_file::file, for_each_image, len, image::len, memcmp(), memset(), EFI_FILE_SYSTEM_INFO::ReadOnly, EFI_FILE_SYSTEM_INFO::Size, SIZE_OF_EFI_FILE_SYSTEM_INFO, type, and EFI_FILE_SYSTEM_INFO::VolumeSize.

◆ efi_file_set_info()

static EFI_STATUS EFIAPI efi_file_set_info ( EFI_FILE_PROTOCOL this,
EFI_GUID type,
UINTN len  __unused,
VOID *data  __unused 
)
static

Set file information.

Parameters
thisEFI file
typeType of information
lenBuffer size
dataBuffer
Return values
efircEFI status code

Definition at line 662 of file efi_file.c.

663  {
664  struct efi_file *file = container_of ( this, struct efi_file, file );
665 
666  DBGC ( file, "EFIFILE %s cannot set information of type %s\n",
668  return EFI_WRITE_PROTECTED;
669 }
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define EFI_WRITE_PROTECTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:128
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References container_of, DBGC, efi_file_name(), efi_guid_ntoa(), EFI_WRITE_PROTECTED, efi_file::file, and type.

◆ efi_file_flush()

static EFI_STATUS EFIAPI efi_file_flush ( EFI_FILE_PROTOCOL this)
static

Flush file modified data.

Parameters
thisEFI file
typeType of information
lenBuffer size
dataBuffer
Return values
efircEFI status code

Definition at line 680 of file efi_file.c.

680  {
681  struct efi_file *file = container_of ( this, struct efi_file, file );
682 
683  DBGC ( file, "EFIFILE %s flushed\n", efi_file_name ( file ) );
684  return 0;
685 }
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An EFI file.
Definition: efi_file.c:67
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
Definition: efi_file.c:109

References container_of, DBGC, efi_file_name(), and efi_file::file.

◆ efi_file_open_volume()

static EFI_STATUS EFIAPI efi_file_open_volume ( EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *filesystem  __unused,
EFI_FILE_PROTOCOL **  file 
)
static

Open root directory.

Parameters
filesystemEFI simple file system
Return values
fileEFI file handle
efircEFI status code

Definition at line 736 of file efi_file.c.

737  {
738 
739  DBGC ( &efi_file_root, "EFIFILE open volume\n" );
741 }
#define DBGC(...)
Definition: compiler.h:505
static EFI_STATUS efi_file_open_fixed(struct efi_file *file, EFI_FILE_PROTOCOL **new)
Open fixed file.
Definition: efi_file.c:282
EFI_FILE_PROTOCOL file
EFI file protocol.
Definition: efi_file.c:71
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87

References DBGC, efi_file_open_fixed(), efi_file_root, and efi_file::file.

◆ efi_block_io_reset()

static EFI_STATUS EFIAPI efi_block_io_reset ( EFI_BLOCK_IO_PROTOCOL *this  __unused,
BOOLEAN  extended 
)
static

Dummy block I/O reset.

Definition at line 751 of file efi_file.c.

751  {
752 
753  DBGC ( &efi_file_root, "EFIFILE block %sreset\n",
754  ( extended ? "extended " : "" ) );
755  return 0;
756 }
#define DBGC(...)
Definition: compiler.h:505
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87

References DBGC, and efi_file_root.

◆ efi_block_io_read_blocks()

static EFI_STATUS EFIAPI efi_block_io_read_blocks ( EFI_BLOCK_IO_PROTOCOL *this  __unused,
UINT32  MediaId,
EFI_LBA  lba,
UINTN  len,
VOID data 
)
static

Dummy block I/O read.

Definition at line 760 of file efi_file.c.

761  {
762 
763  DBGC ( &efi_file_root, "EFIFILE block read ID %#08x LBA %#08llx -> "
764  "%p+%zx\n", MediaId, ( ( unsigned long long ) lba ),
765  data, ( ( size_t ) len ) );
766  return EFI_NO_MEDIA;
767 }
uint32_t lba
Start address.
Definition: scsi.h:23
#define DBGC(...)
Definition: compiler.h:505
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:132
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, DBGC, efi_file_root, EFI_NO_MEDIA, lba, and len.

◆ efi_block_io_write_blocks()

static EFI_STATUS EFIAPI efi_block_io_write_blocks ( EFI_BLOCK_IO_PROTOCOL *this  __unused,
UINT32  MediaId,
EFI_LBA  lba,
UINTN  len,
VOID data 
)
static

Dummy block I/O write.

Definition at line 771 of file efi_file.c.

773  {
774 
775  DBGC ( &efi_file_root, "EFIFILE block write ID %#08x LBA %#08llx <- "
776  "%p+%zx\n", MediaId, ( ( unsigned long long ) lba ),
777  data, ( ( size_t ) len ) );
778  return EFI_NO_MEDIA;
779 }
uint32_t lba
Start address.
Definition: scsi.h:23
#define DBGC(...)
Definition: compiler.h:505
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:132
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, DBGC, efi_file_root, EFI_NO_MEDIA, lba, and len.

◆ efi_block_io_flush_blocks()

static EFI_STATUS EFIAPI efi_block_io_flush_blocks ( EFI_BLOCK_IO_PROTOCOL *this  __unused)
static

Dummy block I/O flush.

Definition at line 783 of file efi_file.c.

783  {
784 
785  DBGC ( &efi_file_root, "EFIFILE block flush\n" );
786  return 0;
787 }
#define DBGC(...)
Definition: compiler.h:505
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87

References DBGC, and efi_file_root.

◆ efi_disk_io_read_disk()

static EFI_STATUS EFIAPI efi_disk_io_read_disk ( EFI_DISK_IO_PROTOCOL *this  __unused,
UINT32  MediaId,
UINT64  offset,
UINTN  len,
VOID data 
)
static

Dummy disk I/O read.

Definition at line 809 of file efi_file.c.

810  {
811 
812  DBGC ( &efi_file_root, "EFIFILE disk read ID %#08x offset %#08llx -> "
813  "%p+%zx\n", MediaId, ( ( unsigned long long ) offset ),
814  data, ( ( size_t ) len ) );
815  return EFI_NO_MEDIA;
816 }
#define DBGC(...)
Definition: compiler.h:505
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:132
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, DBGC, efi_file_root, EFI_NO_MEDIA, len, and offset.

◆ efi_disk_io_write_disk()

static EFI_STATUS EFIAPI efi_disk_io_write_disk ( EFI_DISK_IO_PROTOCOL *this  __unused,
UINT32  MediaId,
UINT64  offset,
UINTN  len,
VOID data 
)
static

Dummy disk I/O write.

Definition at line 820 of file efi_file.c.

821  {
822 
823  DBGC ( &efi_file_root, "EFIFILE disk write ID %#08x offset %#08llx <- "
824  "%p+%zx\n", MediaId, ( ( unsigned long long ) offset ),
825  data, ( ( size_t ) len ) );
826  return EFI_NO_MEDIA;
827 }
#define DBGC(...)
Definition: compiler.h:505
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:132
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, DBGC, efi_file_root, EFI_NO_MEDIA, len, and offset.

◆ efi_file_install()

int efi_file_install ( EFI_HANDLE  handle)

Install EFI simple file system protocol.

Parameters
handleEFI handle
Return values
rcReturn status code

Definition at line 842 of file efi_file.c.

842  {
844  union {
845  EFI_DISK_IO_PROTOCOL *diskio;
846  void *interface;
847  } diskio;
848  EFI_STATUS efirc;
849  int rc;
850 
851  /* Reset root directory state */
852  efi_file_root.pos = 0;
853 
854  /* Install the simple file system protocol, block I/O
855  * protocol, and disk I/O protocol. We don't have a block
856  * device, but large parts of the EDK2 codebase make the
857  * assumption that file systems are normally attached to block
858  * devices, and so we create a dummy block device on the same
859  * handle just to keep things looking normal.
860  */
861  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
862  &handle,
869  rc = -EEFI ( efirc );
870  DBGC ( handle, "Could not install simple file system "
871  "protocols: %s\n", strerror ( rc ) );
872  goto err_install;
873  }
874 
875  /* The FAT filesystem driver has a bug: if a block device
876  * contains no FAT filesystem but does have an
877  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instance, the FAT driver
878  * will assume that it must have previously installed the
879  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. This causes the FAT
880  * driver to claim control of our device, and to refuse to
881  * stop driving it, which prevents us from later uninstalling
882  * correctly.
883  *
884  * Work around this bug by opening the disk I/O protocol
885  * ourselves, thereby preventing the FAT driver from opening
886  * it.
887  *
888  * Note that the alternative approach of opening the block I/O
889  * protocol (and thereby in theory preventing DiskIo from
890  * attaching to the block I/O protocol) causes an endless loop
891  * of calls to our DRIVER_STOP method when starting the EFI
892  * shell. I have no idea why this is.
893  */
894  if ( ( efirc = bs->OpenProtocol ( handle, &efi_disk_io_protocol_guid,
895  &diskio.interface, efi_image_handle,
896  handle,
897  EFI_OPEN_PROTOCOL_BY_DRIVER ) ) != 0){
898  rc = -EEFI ( efirc );
899  DBGC ( handle, "Could not open disk I/O protocol: %s\n",
900  strerror ( rc ) );
902  goto err_open;
903  }
904  assert ( diskio.diskio == &efi_disk_io_protocol );
905 
906  return 0;
907 
910  err_open:
912  handle,
919  err_install:
920  return rc;
921 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:798
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1915
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:286
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:830
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:144
size_t pos
Current file position.
Definition: efi_file.c:77
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:124
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:232
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
This protocol is used to abstract Block I/O interfaces.
Definition: DiskIo.h:106
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:108
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:744
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC_EFI_OPENERS, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_file_root, efi_image_handle, EFI_OPEN_PROTOCOL_BY_DRIVER, efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, handle, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_file::pos, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

◆ efi_file_uninstall()

void efi_file_uninstall ( EFI_HANDLE  handle)

Uninstall EFI simple file system protocol.

Parameters
handleEFI handle

Definition at line 928 of file efi_file.c.

928  {
930  EFI_STATUS efirc;
931  int rc;
932 
933  /* Close our own disk I/O protocol */
936 
937  /* We must install the file system protocol first, since
938  * otherwise the EDK2 code will attempt to helpfully uninstall
939  * it when the block I/O protocol is uninstalled, leading to a
940  * system lock-up.
941  */
942  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
943  handle,
949  &efi_block_io_protocol, NULL ) ) != 0 ) {
950  rc = -EEFI ( efirc );
951  DBGC ( handle, "Could not uninstall simple file system "
952  "protocols: %s\n", strerror ( rc ) );
953  /* Oh dear */
954  }
955 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:798
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:830
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:144
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:232
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:108
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:744
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_image_handle, efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, handle, NULL, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

Variable Documentation

◆ efi_file_root

static struct efi_file efi_file_root
static
Initial value:
= {
.refcnt = REF_INIT ( ref_no_free ),
.file = {
.Open = efi_file_open,
.Close = efi_file_close,
.Delete = efi_file_delete,
.Read = efi_file_read,
.Write = efi_file_write,
.GetPosition = efi_file_get_position,
.SetPosition = efi_file_set_position,
.GetInfo = efi_file_get_info,
.SetInfo = efi_file_set_info,
.Flush = efi_file_flush,
},
.image = NULL,
.name = "",
}
static EFI_STATUS EFIAPI efi_file_set_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN len __unused, VOID *data __unused)
Set file information.
Definition: efi_file.c:662
static EFI_STATUS EFIAPI efi_file_open(EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new, CHAR16 *wname, UINT64 mode, UINT64 attributes __unused)
Open file.
Definition: efi_file.c:319
static EFI_STATUS EFIAPI efi_file_get_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN *len, VOID *data)
Get file information.
Definition: efi_file.c:616
static EFI_STATUS EFIAPI efi_file_get_position(EFI_FILE_PROTOCOL *this, UINT64 *position)
Get file position.
Definition: efi_file.c:599
static EFI_STATUS EFIAPI efi_file_read(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data)
Read from file.
Definition: efi_file.c:513
static EFI_STATUS EFIAPI efi_file_set_position(EFI_FILE_PROTOCOL *this, UINT64 position)
Set file position.
Definition: efi_file.c:563
static EFI_STATUS EFIAPI efi_file_close(EFI_FILE_PROTOCOL *this)
Close file.
Definition: efi_file.c:386
static EFI_STATUS EFIAPI efi_file_flush(EFI_FILE_PROTOCOL *this)
Flush file modified data.
Definition: efi_file.c:680
static EFI_STATUS EFIAPI efi_file_write(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data __unused)
Write to file.
Definition: efi_file.c:546
#define EFI_FILE_PROTOCOL_REVISION
static EFI_STATUS EFIAPI efi_file_delete(EFI_FILE_PROTOCOL *this)
Close and delete file.
Definition: efi_file.c:402
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition: refcnt.c:101
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

Root directory.

Definition at line 87 of file efi_file.c.

Referenced by efi_block_io_flush_blocks(), efi_block_io_read_blocks(), efi_block_io_reset(), efi_block_io_write_blocks(), efi_disk_io_read_disk(), efi_disk_io_write_disk(), efi_file_info(), efi_file_install(), efi_file_name(), efi_file_open(), and efi_file_open_volume().

◆ efi_file_initrd

static struct efi_file efi_file_initrd
static
Initial value:
= {
.refcnt = REF_INIT ( ref_no_free ),
.file = {
.Open = efi_file_open,
.Close = efi_file_close,
.Delete = efi_file_delete,
.Read = efi_file_read,
.Write = efi_file_write,
.GetPosition = efi_file_get_position,
.SetPosition = efi_file_set_position,
.GetInfo = efi_file_get_info,
.SetInfo = efi_file_set_info,
.Flush = efi_file_flush,
},
.image = NULL,
.name = "initrd.magic",
}
static EFI_STATUS EFIAPI efi_file_set_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN len __unused, VOID *data __unused)
Set file information.
Definition: efi_file.c:662
static EFI_STATUS EFIAPI efi_file_open(EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new, CHAR16 *wname, UINT64 mode, UINT64 attributes __unused)
Open file.
Definition: efi_file.c:319
static EFI_STATUS EFIAPI efi_file_get_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN *len, VOID *data)
Get file information.
Definition: efi_file.c:616
static EFI_STATUS EFIAPI efi_file_get_position(EFI_FILE_PROTOCOL *this, UINT64 *position)
Get file position.
Definition: efi_file.c:599
static EFI_STATUS EFIAPI efi_file_read(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data)
Read from file.
Definition: efi_file.c:513
static EFI_STATUS EFIAPI efi_file_set_position(EFI_FILE_PROTOCOL *this, UINT64 position)
Set file position.
Definition: efi_file.c:563
static EFI_STATUS EFIAPI efi_file_close(EFI_FILE_PROTOCOL *this)
Close file.
Definition: efi_file.c:386
static EFI_STATUS EFIAPI efi_file_flush(EFI_FILE_PROTOCOL *this)
Flush file modified data.
Definition: efi_file.c:680
static EFI_STATUS EFIAPI efi_file_write(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data __unused)
Write to file.
Definition: efi_file.c:546
#define EFI_FILE_PROTOCOL_REVISION
static EFI_STATUS EFIAPI efi_file_delete(EFI_FILE_PROTOCOL *this)
Close and delete file.
Definition: efi_file.c:402
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77
static size_t efi_file_read_initrd(struct efi_file_reader *reader)
Read from magic initrd file.
Definition: efi_file.c:220
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition: refcnt.c:101
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

Magic initrd file.

Definition at line 88 of file efi_file.c.

Referenced by efi_file_open().

◆ efi_simple_file_system_protocol

EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
static
Initial value:
= {
.OpenVolume = efi_file_open_volume,
}
static EFI_STATUS EFIAPI efi_file_open_volume(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *filesystem __unused, EFI_FILE_PROTOCOL **file)
Open root directory.
Definition: efi_file.c:736
#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION

EFI simple file system protocol.

Definition at line 744 of file efi_file.c.

Referenced by efi_file_install(), and efi_file_uninstall().

◆ efi_block_io_media

EFI_BLOCK_IO_MEDIA efi_block_io_media
static
Initial value:
= {
.MediaId = EFI_MEDIA_ID_MAGIC,
.MediaPresent = TRUE,
.ReadOnly = TRUE,
.BlockSize = 1,
}
#define TRUE
Definition: tlan.h:46
#define EFI_MEDIA_ID_MAGIC
EFI media ID.
Definition: efi_file.c:52

Dummy block I/O media.

Definition at line 790 of file efi_file.c.

◆ efi_block_io_protocol

EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
static
Initial value:
= {
.Media = &efi_block_io_media,
.ReadBlocks = efi_block_io_read_blocks,
.WriteBlocks = efi_block_io_write_blocks,
.FlushBlocks = efi_block_io_flush_blocks,
}
static EFI_STATUS EFIAPI efi_block_io_read_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused, UINT32 MediaId, EFI_LBA lba, UINTN len, VOID *data)
Dummy block I/O read.
Definition: efi_file.c:760
static EFI_STATUS EFIAPI efi_block_io_write_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused, UINT32 MediaId, EFI_LBA lba, UINTN len, VOID *data)
Dummy block I/O write.
Definition: efi_file.c:771
static EFI_STATUS EFIAPI efi_block_io_reset(EFI_BLOCK_IO_PROTOCOL *this __unused, BOOLEAN extended)
Dummy block I/O reset.
Definition: efi_file.c:751
static EFI_STATUS EFIAPI efi_block_io_flush_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused)
Dummy block I/O flush.
Definition: efi_file.c:783
#define EFI_BLOCK_IO_PROTOCOL_REVISION
Definition: BlockIo.h:210
static EFI_BLOCK_IO_MEDIA efi_block_io_media
Dummy block I/O media.
Definition: efi_file.c:790

Dummy EFI block I/O protocol.

Definition at line 798 of file efi_file.c.

Referenced by efi_file_install(), and efi_file_uninstall().

◆ efi_disk_io_protocol

EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
static
Initial value:
= {
.ReadDisk = efi_disk_io_read_disk,
.WriteDisk = efi_disk_io_write_disk,
}
static EFI_STATUS EFIAPI efi_disk_io_read_disk(EFI_DISK_IO_PROTOCOL *this __unused, UINT32 MediaId, UINT64 offset, UINTN len, VOID *data)
Dummy disk I/O read.
Definition: efi_file.c:809
static EFI_STATUS EFIAPI efi_disk_io_write_disk(EFI_DISK_IO_PROTOCOL *this __unused, UINT32 MediaId, UINT64 offset, UINTN len, VOID *data)
Dummy disk I/O write.
Definition: efi_file.c:820
#define EFI_DISK_IO_PROTOCOL_REVISION
Definition: DiskIo.h:96

Dummy EFI disk I/O protocol.

Definition at line 830 of file efi_file.c.

Referenced by efi_file_install(), and efi_file_uninstall().