| ... | ... | @@ -0,0 +1,80 @@ |
| 1 | const std = @import("std"); |
| 2 | const uefi = std.os.uefi; |
| 3 | const Status = uefi.Status; |
| 4 | |
| 5 | const EfiBlockMedia = extern struct { |
| 6 | /// The current media ID. If the media changes, this value is changed. |
| 7 | media_id: u32, |
| 8 | |
| 9 | /// `true` if the media is removable; otherwise, `false`. |
| 10 | removable_media: bool, |
| 11 | /// `true` if there is a media currently present in the device |
| 12 | media_present: bool, |
| 13 | /// `true` if the `BlockIoProtocol` was produced to abstract |
| 14 | /// partition structures on the disk. `false` if the `BlockIoProtocol` was |
| 15 | /// produced to abstract the logical blocks on a hardware device. |
| 16 | logical_partition: bool, |
| 17 | /// `true` if the media is marked read-only otherwise, `false`. This field |
| 18 | /// shows the read-only status as of the most recent `WriteBlocks()` |
| 19 | read_only: bool, |
| 20 | /// `true` if the WriteBlocks() function caches write data. |
| 21 | write_caching: bool, |
| 22 | |
| 23 | /// The intrinsic block size of the device. If the media changes, then this |
| 24 | // field is updated. Returns the number of bytes per logical block. |
| 25 | block_size: u32, |
| 26 | /// Supplies the alignment requirement for any buffer used in a data |
| 27 | /// transfer. IoAlign values of 0 and 1 mean that the buffer can be |
| 28 | /// placed anywhere in memory. Otherwise, IoAlign must be a power of |
| 29 | /// 2, and the requirement is that the start address of a buffer must be |
| 30 | /// evenly divisible by IoAlign with no remainder. |
| 31 | io_align: u32, |
| 32 | /// The last LBA on the device. If the media changes, then this field is updated. |
| 33 | last_block: u64, |
| 34 | |
| 35 | // Revision 2 |
| 36 | lowest_aligned_lba: u64, |
| 37 | logical_blocks_per_physical_block: u32, |
| 38 | optimal_transfer_length_granularity: u32, |
| 39 | }; |
| 40 | |
| 41 | const BlockIoProtocol = extern struct { |
| 42 | const Self = @This(); |
| 43 | |
| 44 | revision: u64, |
| 45 | media: *EfiBlockMedia, |
| 46 | |
| 47 | _reset: fn (*BlockIoProtocol, extended_verification: bool) callconv(.C) Status, |
| 48 | _read_blocks: fn (*BlockIoProtocol, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(.C) Status, |
| 49 | _write_blocks: fn (*BlockIoProtocol, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(.C) Status, |
| 50 | _flush_blocks: fn (*BlockIoProtocol) callconv(.C) Status, |
| 51 | |
| 52 | /// Resets the block device hardware. |
| 53 | pub fn reset(self: *Self, extended_verification: bool) Status { |
| 54 | return self._reset(self, extended_verification); |
| 55 | } |
| 56 | |
| 57 | /// Reads the number of requested blocks from the device. |
| 58 | pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status { |
| 59 | return self._read_blocks(self, media_id, lba, buffer_size, buf); |
| 60 | } |
| 61 | |
| 62 | /// Writes a specified number of blocks to the device. |
| 63 | pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status { |
| 64 | return self._write_blocks(self, media_id, lba, buffer_size, buf); |
| 65 | } |
| 66 | |
| 67 | /// Flushes all modified data to a physical block device. |
| 68 | pub fn flushBlocks(self: *Self) Status { |
| 69 | return self._flush_blocks(self); |
| 70 | } |
| 71 | |
| 72 | pub const guid align(8) = uefi.Guid{ |
| 73 | .time_low = 0x964e5b21, |
| 74 | .time_mid = 0x6459, |
| 75 | .time_high_and_version = 0x11d2, |
| 76 | .clock_seq_high_and_reserved = 0x8e, |
| 77 | .clock_seq_low = 0x39, |
| 78 | .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, |
| 79 | }; |
| 80 | }; |