Skip to content

std.os.uefi.protocol.block_io

Standard libraryZig 0.17.0Official documentation
Sourcestd/os/uefi/protocol/block_io.zig

Source line 1

std.os.uefi.protocol.block_io.BlockIo

container

Source line 6

Fields

revision: u64
media: *BlockMedia
_reset: *const fn (*BlockIo, extended_verification: bool) callconv(cc) Status
_read_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(cc) Status
_write_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]const u8) callconv(cc) Status
_flush_blocks: *const fn (*BlockIo) callconv(cc) Status

std.os.uefi.protocol.block_io.BlockIo.BlockMedia

container

Source line 91

Fields

media_id: u32

The current media ID. If the media changes, this value is changed.

removable_media: bool

true if the media is removable; otherwise, false.

media_present: bool

true if there is a media currently present in the device

logical_partition: bool

true if the BlockIo was produced to abstract partition structures on the disk. false if the BlockIo was produced to abstract the logical blocks on a hardware device.

read_only: bool

true if the media is marked read-only otherwise, false. This field shows the read-only status as of the most recent WriteBlocks()

write_caching: bool

true if the WriteBlocks() function caches write data.

block_size: u32

The intrinsic block size of the device. If the media changes, then this

io_align: u32

Supplies the alignment requirement for any buffer used in a data transfer. IoAlign values of 0 and 1 mean that the buffer can be placed anywhere in memory. Otherwise, IoAlign must be a power of 2, and the requirement is that the start address of a buffer must be evenly divisible by IoAlign with no remainder.

last_block: u64

The last LBA on the device. If the media changes, then this field is updated.

lowest_aligned_lba: u64
logical_blocks_per_physical_block: u32
optimal_transfer_length_granularity: u32

std.os.uefi.protocol.block_io.BlockIo.flushBlocks

function

Source line 73

Flushes all modified data to a physical block device.

pub fn flushBlocks(self: *Self) FlushBlocksError!void

Parameters

self: *Self

Errors

DeviceError
NoMedia
Unexpected UnexpectedError

std.os.uefi.protocol.block_io.BlockIo.FlushBlocksError

error-set

Source line 32

Errors

DeviceError
NoMedia
Unexpected UnexpectedError

std.os.uefi.protocol.block_io.BlockIo.guid

constant

Source line 82

std.os.uefi.protocol.block_io.BlockIo.readBlocks

function

Source line 47

Reads the number of requested blocks from the device.

pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buf: []u8) ReadBlocksError!void

Parameters

self: *Self
media_id: u32
lba: u64
buf: []u8

Errors

BadBufferSize
DeviceError
InvalidParameter
NoMedia
Unexpected UnexpectedError

std.os.uefi.protocol.block_io.BlockIo.ReadBlocksError

error-set

Source line 18

Errors

BadBufferSize
DeviceError
InvalidParameter
NoMedia
Unexpected UnexpectedError

std.os.uefi.protocol.block_io.BlockIo.reset

function

Source line 38

Resets the block device hardware.

pub fn reset(self: *Self, extended_verification: bool) ResetError!void

Parameters

self: *Self
extended_verification: bool

Errors

DeviceError
Unexpected UnexpectedError

std.os.uefi.protocol.block_io.BlockIo.ResetError

error-set

Source line 17

Errors

DeviceError
Unexpected UnexpectedError

std.os.uefi.protocol.block_io.BlockIo.Self

alias

Source line 7

Alias of std.os.uefi.protocol.block_io.BlockIo

std.os.uefi.protocol.block_io.BlockIo.writeBlocks

function

Source line 59

Writes a specified number of blocks to the device.

pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buf: []const u8) WriteBlocksError!void

Parameters

self: *Self
media_id: u32
lba: u64
buf: []const u8

Errors

BadBufferSize
DeviceError
InvalidParameter
MediaChanged
NoMedia
Unexpected UnexpectedError
WriteProtected

std.os.uefi.protocol.block_io.BlockIo.WriteBlocksError

error-set

Source line 24

Errors

BadBufferSize
DeviceError
InvalidParameter
MediaChanged
NoMedia
Unexpected UnexpectedError
WriteProtected

std.os.uefi.protocol.block_io.cc

alias

Source line 4

Alias of std.os.uefi.cc

std.os.uefi.protocol.block_io.Status

alias

Source line 3

Alias of std.os.uefi.Status

std.os.uefi.protocol.block_io.std

alias

Source line 1

Alias of std

std.os.uefi.protocol.block_io.uefi

alias

Source line 2

Alias of std.os.uefi

Source code

std/os/uefi/protocol/block_io.zig

const std = @import("std");
const uefi = std.os.uefi;
const Status = uefi.Status;
const cc = uefi.cc;

pub const BlockIo = extern struct {
    const Self = @This();

    revision: u64,
    media: *BlockMedia,

    _reset: *const fn (*BlockIo, extended_verification: bool) callconv(cc) Status,
    _read_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(cc) Status,
    _write_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]const u8) callconv(cc) Status,
    _flush_blocks: *const fn (*BlockIo) callconv(cc) Status,

    pub const ResetError = uefi.UnexpectedError || error{DeviceError};
    pub const ReadBlocksError = uefi.UnexpectedError || error{
        DeviceError,
        NoMedia,
        BadBufferSize,
        InvalidParameter,
    };
    pub const WriteBlocksError = uefi.UnexpectedError || error{
        WriteProtected,
        NoMedia,
        MediaChanged,
        DeviceError,
        BadBufferSize,
        InvalidParameter,
    };
    pub const FlushBlocksError = uefi.UnexpectedError || error{
        DeviceError,
        NoMedia,
    };

    /// Resets the block device hardware.
    pub fn reset(self: *Self, extended_verification: bool) ResetError!void {
        switch (self._reset(self, extended_verification)) {
            .success => {},
            .device_error => return error.DeviceError,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// Reads the number of requested blocks from the device.
    pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buf: []u8) ReadBlocksError!void {
        switch (self._read_blocks(self, media_id, lba, buf.len, buf.ptr)) {
            .success => {},
            .device_error => return error.DeviceError,
            .no_media => return error.NoMedia,
            .bad_buffer_size => return error.BadBufferSize,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// Writes a specified number of blocks to the device.
    pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buf: []const u8) WriteBlocksError!void {
        switch (self._write_blocks(self, media_id, lba, buf.len, buf.ptr)) {
            .success => {},
            .write_protected => return error.WriteProtected,
            .no_media => return error.NoMedia,
            .media_changed => return error.MediaChanged,
            .device_error => return error.DeviceError,
            .bad_buffer_size => return error.BadBufferSize,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// Flushes all modified data to a physical block device.
    pub fn flushBlocks(self: *Self) FlushBlocksError!void {
        switch (self._flush_blocks(self)) {
            .success => {},
            .device_error => return error.DeviceError,
            .no_media => return error.NoMedia,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const guid align(8) = uefi.Guid{
        .time_low = 0x964e5b21,
        .time_mid = 0x6459,
        .time_high_and_version = 0x11d2,
        .clock_seq_high_and_reserved = 0x8e,
        .clock_seq_low = 0x39,
        .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
    };

    pub const BlockMedia = extern struct {
        /// The current media ID. If the media changes, this value is changed.
        media_id: u32,

        /// `true` if the media is removable; otherwise, `false`.
        removable_media: bool,
        /// `true` if there is a media currently present in the device
        media_present: bool,
        /// `true` if the `BlockIo` was produced to abstract
        /// partition structures on the disk. `false` if the `BlockIo` was
        /// produced to abstract the logical blocks on a hardware device.
        logical_partition: bool,
        /// `true` if the media is marked read-only otherwise, `false`. This field
        /// shows the read-only status as of the most recent `WriteBlocks()`
        read_only: bool,
        /// `true` if the WriteBlocks() function caches write data.
        write_caching: bool,

        /// The intrinsic block size of the device. If the media changes, then this
        // field is updated. Returns the number of bytes per logical block.
        block_size: u32,
        /// Supplies the alignment requirement for any buffer used in a data
        /// transfer. IoAlign values of 0 and 1 mean that the buffer can be
        /// placed anywhere in memory. Otherwise, IoAlign must be a power of
        /// 2, and the requirement is that the start address of a buffer must be
        /// evenly divisible by IoAlign with no remainder.
        io_align: u32,
        /// The last LBA on the device. If the media changes, then this field is updated.
        last_block: u64,

        // Revision 2
        lowest_aligned_lba: u64,
        logical_blocks_per_physical_block: u32,
        optimal_transfer_length_granularity: u32,
    };
};