Skip to main content

uefi_raw/protocol/
shell.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! EFI Shell Protocol v2.2
4
5use core::ffi::c_void;
6
7use crate::{Char8, Char16, Event, Guid, Handle, Status, guid};
8
9use super::device_path::DevicePathProtocol;
10use super::file_system::FileInfo;
11use super::shell_params::ShellFileHandle;
12
13use bitflags::bitflags;
14
15/// List Entry for File Lists
16#[derive(Debug)]
17#[repr(C)]
18pub struct ListEntry {
19    pub f_link: *mut ListEntry,
20    pub b_link: *mut ListEntry,
21}
22
23/// ShellFileInfo for File Lists
24#[derive(Debug)]
25#[repr(C)]
26pub struct ShellFileInfo {
27    pub link: ListEntry,
28    pub status: Status,
29    pub full_name: *mut Char16,
30    pub file_name: *mut Char16,
31    pub handle: ShellFileHandle,
32    pub info: FileInfo,
33}
34
35bitflags! {
36    /// Specifies the source of the component name
37    #[repr(transparent)]
38    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
39    pub struct ShellDeviceNameFlags: u32 {
40        /// Use Component Name
41        const USE_COMPONENT_NAME = 0x0000001;
42        /// Use Device Path
43        const USE_DEVICE_PATH = 0x0000002;
44    }
45}
46
47/// Shell Protocol
48#[derive(Debug)]
49#[repr(C)]
50pub struct ShellProtocol {
51    pub execute: unsafe extern "efiapi" fn(
52        parent_image_handle: *const Handle,
53        command_line: *const Char16,
54        environment: *const *const Char16,
55        status_code: *mut Status,
56    ) -> Status,
57    pub get_env: unsafe extern "efiapi" fn(name: *const Char16) -> *const Char16,
58    pub set_env: unsafe extern "efiapi" fn(
59        name: *const Char16,
60        value: *const Char16,
61        volatile: bool,
62    ) -> Status,
63    pub get_alias: unsafe extern "efiapi" fn(alias: *const Char16, volatile: bool) -> *const Char16,
64    pub set_alias: unsafe extern "efiapi" fn(
65        command: *const Char16,
66        alias: *const Char16,
67        replace: bool,
68        volatile: bool,
69    ) -> Status,
70    pub get_help_text: unsafe extern "efiapi" fn(
71        command: *const Char16,
72        sections: *const Char16,
73        help_text: *mut *mut Char16,
74    ) -> Status,
75    pub get_device_path_from_map:
76        unsafe extern "efiapi" fn(mapping: *const Char16) -> *const DevicePathProtocol,
77    pub get_map_from_device_path:
78        unsafe extern "efiapi" fn(device_path: *mut *mut DevicePathProtocol) -> *const Char16,
79    pub get_device_path_from_file_path:
80        unsafe extern "efiapi" fn(path: *const Char16) -> *const DevicePathProtocol,
81    pub get_file_path_from_device_path:
82        unsafe extern "efiapi" fn(path: *const DevicePathProtocol) -> *const Char16,
83    pub set_map: unsafe extern "efiapi" fn(
84        device_path: *const DevicePathProtocol,
85        mapping: *const Char16,
86    ) -> Status,
87
88    pub get_cur_dir: unsafe extern "efiapi" fn(file_system_mapping: *const Char16) -> *const Char16,
89    pub set_cur_dir:
90        unsafe extern "efiapi" fn(file_system: *const Char16, dir: *const Char16) -> Status,
91    pub open_file_list: unsafe extern "efiapi" fn(
92        path: *const Char16,
93        open_mode: u64,
94        file_list: *mut *mut ShellFileInfo,
95    ) -> Status,
96    pub free_file_list: unsafe extern "efiapi" fn(file_list: *const *const ShellFileInfo) -> Status,
97    pub remove_dup_in_file_list:
98        unsafe extern "efiapi" fn(file_list: *const *const ShellFileInfo) -> Status,
99
100    pub batch_is_active: unsafe extern "efiapi" fn() -> bool,
101    pub is_root_shell: unsafe extern "efiapi" fn() -> bool,
102    pub enable_page_break: unsafe extern "efiapi" fn(),
103    pub disable_page_break: unsafe extern "efiapi" fn(),
104    pub get_page_break: unsafe extern "efiapi" fn() -> bool,
105    pub get_device_name: unsafe extern "efiapi" fn(
106        device_handle: Handle,
107        flags: ShellDeviceNameFlags,
108        language: *const Char8,
109        best_device_name: *mut *mut Char16,
110    ) -> Status,
111
112    pub get_file_info: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> *const FileInfo,
113    pub set_file_info: unsafe extern "efiapi" fn(
114        file_handle: ShellFileHandle,
115        file_info: *const FileInfo,
116    ) -> Status,
117    pub open_file_by_name: unsafe extern "efiapi" fn(
118        file_name: *const Char16,
119        file_handle: *mut ShellFileHandle,
120        open_mode: u64,
121    ) -> Status,
122    pub close_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status,
123    pub create_file: unsafe extern "efiapi" fn(
124        file_name: *const Char16,
125        file_attribs: u64,
126        file_handle: *mut ShellFileHandle,
127    ) -> Status,
128    pub read_file: unsafe extern "efiapi" fn(
129        file_handle: ShellFileHandle,
130        read_size: *mut usize,
131        buffer: *mut c_void,
132    ) -> Status,
133    pub write_file: unsafe extern "efiapi" fn(
134        file_handle: ShellFileHandle,
135        buffer_size: *mut usize,
136        buffer: *mut c_void,
137    ) -> Status,
138    pub delete_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status,
139    pub delete_file_by_name: unsafe extern "efiapi" fn(file_name: *const Char16) -> Status,
140    pub get_file_position:
141        unsafe extern "efiapi" fn(file_handle: ShellFileHandle, position: *mut u64) -> Status,
142    pub set_file_position:
143        unsafe extern "efiapi" fn(file_handle: ShellFileHandle, position: u64) -> Status,
144    pub flush_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status,
145    pub find_files: unsafe extern "efiapi" fn(
146        file_pattern: *const Char16,
147        file_list: *mut *mut ShellFileInfo,
148    ) -> Status,
149    pub find_files_in_dir: unsafe extern "efiapi" fn(
150        file_dir_handle: ShellFileHandle,
151        file_list: *mut *mut ShellFileInfo,
152    ) -> Status,
153    pub get_file_size:
154        unsafe extern "efiapi" fn(file_handle: ShellFileHandle, size: *mut u64) -> Status,
155
156    pub open_root: unsafe extern "efiapi" fn(
157        device_path: *const DevicePathProtocol,
158        file_handle: *mut ShellFileHandle,
159    ) -> Status,
160    pub open_root_by_handle: unsafe extern "efiapi" fn(
161        device_handle: Handle,
162        file_handle: *mut ShellFileHandle,
163    ) -> Status,
164
165    pub execution_break: Event,
166
167    pub major_version: u32,
168    pub minor_version: u32,
169    pub register_guid_name:
170        unsafe extern "efiapi" fn(guid: *const Guid, guid_name: *const Char16) -> Status,
171    pub get_guid_name:
172        unsafe extern "efiapi" fn(guid: *const Guid, guid_name: *mut *mut Char16) -> Status,
173    pub get_guid_from_name:
174        unsafe extern "efiapi" fn(guid_name: *const Char16, guid: *mut Guid) -> Status,
175    pub get_env_ex:
176        unsafe extern "efiapi" fn(name: *const Char16, attributes: *mut u32) -> *const Char16,
177}
178
179impl ShellProtocol {
180    pub const GUID: Guid = guid!("6302d008-7f9b-4f30-87ac-60c9fef5da4e");
181}