Skip to content

Commit

Permalink
fix some clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenmeier committed Apr 21, 2024
1 parent 0aed703 commit 77c7214
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
tests/header
Cargo.lock
/.vscode
6 changes: 3 additions & 3 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub(crate) fn read_primary_header<D: Read + Seek>(
file: &mut D,
sector_size: disk::LogicalBlockSize,
) -> Result<Header, HeaderError> {
let cur = file.seek(SeekFrom::Current(0)).unwrap_or(0);
let cur = file.stream_position().unwrap_or(0);
let offset: u64 = sector_size.into();
let res = file_read_header(file, offset);
let _ = file.seek(SeekFrom::Start(cur));
Expand All @@ -308,7 +308,7 @@ pub(crate) fn read_backup_header<D: Read + Seek>(
file: &mut D,
sector_size: disk::LogicalBlockSize,
) -> Result<Header, HeaderError> {
let cur = file.seek(SeekFrom::Current(0)).unwrap_or(0);
let cur = file.stream_position().unwrap_or(0);
let h2sect = find_backup_lba(file, sector_size)?;
let offset = h2sect
.checked_mul(sector_size.into())
Expand Down Expand Up @@ -380,7 +380,7 @@ pub(crate) fn find_backup_lba<D: Read + Seek>(
) -> Result<u64, HeaderError> {
trace!("querying file size to find backup header location");
let lb_size: u64 = sector_size.into();
let old_pos = f.seek(std::io::SeekFrom::Current(0))?;
let old_pos = f.stream_position()?;
let len = f.seek(std::io::SeekFrom::End(0))?;
f.seek(std::io::SeekFrom::Start(old_pos))?;
// lba0: prot mbr, lba1: prim, .., lba-1: backup
Expand Down
6 changes: 1 addition & 5 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ pub mod pub_macros {
match res_u {
Ok(u) => return u,
Err(_) => {
// const_panic requires 1.57
#[allow(unconditional_panic)]
["string was not an uuid"][1];
// never type
loop {}
panic!("string was not an uuid");
},
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/mbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl ProtectiveMBR {
) -> Result<Self, MBRError> {
let totlen: u64 = sector_size.into();
let mut buf = vec![0_u8; totlen as usize];
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;

device.seek(io::SeekFrom::Start(0))?;
device.read_exact(&mut buf)?;
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ProtectiveMBR {
///
/// This will not write the entire lba0 if the sector size is 4096
pub fn overwrite_lba0<D: DiskDevice>(&self, device: &mut D) -> Result<usize, MBRError> {
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;
let _ = device.seek(io::SeekFrom::Start(0))?;
let data = self.to_bytes();
device.write_all(&data)?;
Expand All @@ -246,7 +246,7 @@ impl ProtectiveMBR {
/// This overwrites the four MBR partition records and the
/// well-known signature, leaving all other MBR bits as-is.
pub fn update_conservative<D: DiskDevice>(&self, device: &mut D) -> Result<usize, MBRError> {
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;
// Seek to first partition record.
// (GPT spec 2.7 - sec. 5.2.3 - table 15)
let _ = device.seek(io::SeekFrom::Start(446))?;
Expand Down Expand Up @@ -371,7 +371,7 @@ impl PartRecord {
/// Return the 440 bytes of BIOS bootcode.
pub fn read_bootcode<D: DiskDevice>(device: &mut D) -> io::Result<[u8; 440]> {
let bootcode_offset = 0;
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;
let _ = device.seek(io::SeekFrom::Start(bootcode_offset))?;
let mut bootcode = [0x00; 440];
device.read_exact(&mut bootcode)?;
Expand All @@ -383,7 +383,7 @@ pub fn read_bootcode<D: DiskDevice>(device: &mut D) -> io::Result<[u8; 440]> {
/// Write the 440 bytes of BIOS bootcode.
pub fn write_bootcode<D: DiskDevice>(device: &mut D, bootcode: &[u8; 440]) -> io::Result<()> {
let bootcode_offset = 0;
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;
let _ = device.seek(io::SeekFrom::Start(bootcode_offset))?;
device.write_all(bootcode)?;
device.flush()?;
Expand All @@ -395,7 +395,7 @@ pub fn write_bootcode<D: DiskDevice>(device: &mut D, bootcode: &[u8; 440]) -> io
/// Read the 4 bytes of MBR disk signature.
pub fn read_disk_signature<D: DiskDevice>(device: &mut D) -> io::Result<[u8; 4]> {
let dsig_offset = 440;
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;
let _ = device.seek(io::SeekFrom::Start(dsig_offset))?;
let mut dsig = [0x00; 4];
device.read_exact(&mut dsig)?;
Expand All @@ -408,7 +408,7 @@ pub fn read_disk_signature<D: DiskDevice>(device: &mut D) -> io::Result<[u8; 4]>
#[cfg_attr(feature = "cargo-clippy", allow(clippy::trivially_copy_pass_by_ref))]
pub fn write_disk_signature<D: DiskDevice>(device: &mut D, sig: &[u8; 4]) -> io::Result<()> {
let dsig_offset = 440;
let cur = device.seek(io::SeekFrom::Current(0))?;
let cur = device.stream_position()?;
let _ = device.seek(io::SeekFrom::Start(dsig_offset))?;
device.write_all(sig)?;
device.flush()?;
Expand Down

0 comments on commit 77c7214

Please sign in to comment.