authorgravatar for ybham6@gmail.comfifty-six <ybham6@gmail.com> 2022-01-11 01:29:35-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-11 10:49:40-07:00
log73e4571b4c10fdbfe04eb9b339b288b719c3469c
tree7c8549cc88278b625713b25f52159f49991fd3d5
parent608fceffc4975e5aabbb5060b81fa933c6bdf46c

std/os/uefi: Add methods next() and size() to DevicePathProtocol

These are used for more easily dealing with a series of Device Path nodes.

1 files changed, 19 insertions(+), 0 deletions(-)

lib/std/os/uefi/protocols/device_path_protocol.zig+19
...@@ -15,6 +15,25 @@ pub const DevicePathProtocol = packed struct {...@@ -15,6 +15,25 @@ pub const DevicePathProtocol = packed struct {
15 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },15 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
16 };16 };
1717
18 /// Returns the next DevicePathProtocol node in the sequence, if any.
19 pub fn next(self: *DevicePathProtocol) ?*DevicePathProtocol {
20 if (self.type == .End and @intToEnum(EndDevicePath.Subtype, self.subtype) == .EndEntire)
21 return null;
22
23 return @ptrCast(*DevicePathProtocol, @ptrCast([*]u8, self) + self.length);
24 }
25
26 /// Calculates the total length of the device path structure in bytes, including the end of device path node.
27 pub fn size(self: *DevicePathProtocol) usize {
28 var node = self;
29
30 while (node.next()) |next_node| {
31 node = next_node;
32 }
33
34 return (@ptrToInt(node) + node.length) - @ptrToInt(self);
35 }
36
18 pub fn getDevicePath(self: *const DevicePathProtocol) ?DevicePath {37 pub fn getDevicePath(self: *const DevicePathProtocol) ?DevicePath {
19 return switch (self.type) {38 return switch (self.type) {
20 .Hardware => blk: {39 .Hardware => blk: {