Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions library/std/src/sys/fs/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,24 @@ impl File {
unsupported()
}

pub fn seek(&self, _pos: SeekFrom) -> io::Result<u64> {
unsupported()
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
const NEG_OFF_ERR: io::Error =
io::const_error!(io::ErrorKind::InvalidInput, "cannot seek to negative offset.");

let off = match pos {
SeekFrom::Start(p) => p,
SeekFrom::End(p) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could special-case SeekFrom::End(0) here and use 0xFFFFFFFFFFFFFFFF as offset, since that causes the position to be set to the end of the file without having to look up the length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

// Seeking to position 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
if p == 0 {
0xFFFFFFFFFFFFFFFF
} else {
self.file_attr()?.size().checked_add_signed(p).ok_or(NEG_OFF_ERR)?
}
}
SeekFrom::Current(p) => self.tell()?.checked_add_signed(p).ok_or(NEG_OFF_ERR)?,
};

self.0.set_position(off).map(|_| off)
}

pub fn size(&self) -> Option<io::Result<u64>> {
Expand Down Expand Up @@ -755,6 +771,12 @@ mod uefi_fs {
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(pos) }
}

pub(crate) fn set_position(&self, pos: u64) -> io::Result<()> {
let file_ptr = self.protocol.as_ptr();
let r = unsafe { ((*file_ptr).set_position)(file_ptr, pos) };
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
}

pub(crate) fn delete(self) -> io::Result<()> {
let file_ptr = self.protocol.as_ptr();
let r = unsafe { ((*file_ptr).delete)(file_ptr) };
Expand Down
Loading