xref: /haiku/headers/private/kernel/platform/efi/protocol/file.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <efi/types.h>
8 #include <efi/boot-services.h>
9 #include <efi/runtime-services.h>
10 
11 #define EFI_FILE_PROTOCOL_REVISION        0x00010000
12 #define EFI_FILE_PROTOCOL_REVISION2       0x00020000
13 #define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
14 
15 #define EFI_FILE_MODE_READ   0x0000000000000001
16 #define EFI_FILE_MODE_WRITE  0x0000000000000002
17 #define EFI_FILE_MODE_CREATE 0x8000000000000000
18 
19 #define EFI_FILE_READ_ONLY  0x0000000000000001
20 #define EFI_FILE_HIDDEN     0x0000000000000002
21 #define EFI_FILE_SYSTEM     0x0000000000000004
22 #define EFI_FILE_RESERVED   0x0000000000000008
23 #define EFI_FILE_DIRECTORY  0x0000000000000010
24 #define EFI_FILE_ARCHIVE    0x0000000000000020
25 #define EFI_FILE_VALID_ATTR 0x0000000000000037
26 
27 typedef struct {
28     efi_event Event;
29     efi_status Status;
30     size_t BufferSize;
31     void* Buffer;
32 } efi_file_io_token;
33 
34 #define EFI_FILE_INFO_GUID \
35     {0x09576e92, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
36 extern efi_guid FileInfoGuid;
37 
38 typedef struct {
39     uint64_t Size;
40     uint64_t FileSize;
41     uint64_t PhysicalSize;
42     efi_time CreateTime;
43     efi_time LastAccessTime;
44     efi_time ModificationTime;
45     uint64_t Attribute;
46     char16_t FileName[];
47 } efi_file_info;
48 
49 #define EFI_FILE_SYSTEM_INFO_GUID \
50     {0x09576e93, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
51 extern efi_guid FileSystemInfoGuid;
52 
53 typedef struct {
54     uint64_t Size;
55     bool ReadOnly;
56     uint64_t VolumeSize;
57     uint64_t FreeSpace;
58     uint32_t BlockSize;
59     char16_t* VolumeLabel[];
60 } efi_file_system_info;
61 
62 typedef struct efi_file_protocol {
63     uint64_t Revision;
64 
65     efi_status (*Open) (struct efi_file_protocol* self, struct efi_file_protocol** new_handle,
66                         const char16_t* filename, uint64_t open_mode, uint64_t attributes) EFIAPI;
67 
68     efi_status (*Close) (struct efi_file_protocol* self) EFIAPI;
69 
70     efi_status (*Delete) (struct efi_file_protocol* self) EFIAPI;
71 
72     efi_status (*Read) (struct efi_file_protocol* self, size_t* len, void* buf) EFIAPI;
73 
74     efi_status (*Write) (struct efi_file_protocol* self, size_t* len, void* buf) EFIAPI;
75 
76     efi_status (*GetPosition) (struct efi_file_protocol* self, uint64_t* position) EFIAPI;
77 
78     efi_status (*SetPosition) (struct efi_file_protocol* self, uint64_t position) EFIAPI;
79 
80     efi_status (*GetInfo) (struct efi_file_protocol* self, efi_guid* info_type,
81                            size_t* buf_size, void* buf) EFIAPI;
82 
83     efi_status (*SetInfo) (struct efi_file_protocol* self, efi_guid* info_type,
84                            size_t buf_size, void* buf) EFIAPI;
85 
86     efi_status (*Flush) (struct efi_file_protocol* self) EFIAPI;
87 
88     efi_status (*OpenEx) (struct efi_file_protocol* self, struct efi_file_protocol* new_handle,
89                           char16_t* filename, uint64_t open_mode, uint64_t attributes,
90                           efi_file_io_token* token) EFIAPI;
91 
92     efi_status (*ReadEx) (struct efi_file_protocol* self, efi_file_io_token* token) EFIAPI;
93 
94     efi_status (*WriteEx) (struct efi_file_protocol* self, efi_file_io_token* token) EFIAPI;
95 
96     efi_status (*FlushEx) (struct efi_file_protocol* self, efi_file_io_token* token) EFIAPI;
97 } efi_file_protocol;
98