Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies to allow building with latest Rust version #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ include = ["src/**/*.rs", "tests/fixtures/*.img", "README.md", "LICENSE.Apache-2

[dependencies]
bitvec = "1.0.1"
bincode = "1.0.1"
serde = { version = "1.0.116", features = ["derive"] }
serde-big-array = ">= 0.4.1, < 0.6"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this shouldn't be upgraded now. Can you check the different versions to see which ones work?

Copy link
Author

Choose a reason for hiding this comment

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

Why do you think it shouldn't be upgraded?

Copy link
Member

Choose a reason for hiding this comment

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

No I meant the opposite. Should this be upgraded too, to 0.6 or up idk

Copy link
Author

Choose a reason for hiding this comment

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

There is no 0.6, 0.5.1 is the latest (https://docs.rs/serde-big-array/latest/serde_big_array/).

thiserror = "1.0.24"
bincode = { version = "2.0.0-rc.3", features = ["serde"] }
serde = { version = "1.0.210", features = ["derive"] }
serde-big-array = "0.5.1"
thiserror = "1.0.63"
78 changes: 46 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -156,7 +156,9 @@

#![deny(missing_docs)]

use bincode::{deserialize_from, serialize_into};
use bincode::config::legacy;
use bincode::error::{DecodeError, EncodeError};
use bincode::serde::{decode_from_std_read, encode_into_std_write};
use bitvec::prelude::*;
use serde::de::{SeqAccess, Visitor};
use serde::ser::SerializeTuple;
@@ -196,7 +198,10 @@ pub enum Error {
LBAExceedsMaximumCylinders,
/// Deserialization errors.
#[error("deserialization failed")]
Deserialize(#[from] bincode::Error),
Deserialize(#[from] DecodeError),
/// Serialization errors.
#[error("Serialization failed")]
Serialize(#[from] EncodeError),
/// I/O errors.
#[error("generic I/O error")]
Io(#[from] std::io::Error),
@@ -377,7 +382,7 @@ impl MBR {
S: Seek,
{
let disk_size = u32::try_from(seeker.seek(SeekFrom::End(0))? / u64::from(sector_size))
.unwrap_or(u32::max_value());
.unwrap_or(u32::MAX);
let header = MBRHeader::new(disk_signature);

Ok(MBR {
@@ -402,12 +407,12 @@ impl MBR {
/// let mbr = mbrman::MBR::read_from(&mut f, 512)
/// .expect("could not read the partition table");
/// ```
pub fn read_from<R: ?Sized>(mut reader: &mut R, sector_size: u32) -> Result<MBR>
pub fn read_from<R>(mut reader: &mut R, sector_size: u32) -> Result<MBR>
where
R: Read + Seek,
R: Read + Seek + ?Sized,
{
let disk_size = u32::try_from(reader.seek(SeekFrom::End(0))? / u64::from(sector_size))
.unwrap_or(u32::max_value());
.unwrap_or(u32::MAX);
let header = MBRHeader::read_from(&mut reader)?;

let mut logical_partitions = Vec::new();
@@ -537,9 +542,9 @@ impl MBR {
/// mbr.write_into(&mut cur)
/// .expect("could not write MBR to disk")
/// ```
pub fn write_into<W: ?Sized>(&mut self, mut writer: &mut W) -> Result<()>
pub fn write_into<W>(&mut self, mut writer: &mut W) -> Result<()>
where
W: Write + Seek,
W: Write + Seek + ?Sized,
{
self.header.write_into(&mut writer)?;

@@ -576,11 +581,10 @@ impl MBR {
writer.seek(SeekFrom::Start(u64::from(
l.absolute_ebr_lba * self.sector_size,
)))?;
serialize_into(&mut writer, &BootstrapCode446(l.bootstrap_code))?;
serialize_into(&mut writer, &partition)?;
encode_into_std_write(BootstrapCode446(l.bootstrap_code), &mut writer, legacy())?;
encode_into_std_write(&partition, &mut writer, legacy())?;
if let Some(next) = next {
serialize_into(
&mut writer,
encode_into_std_write(
&MBRPartitionEntry {
boot: BOOT_INACTIVE,
first_chs: next.ebr_first_chs,
@@ -591,12 +595,14 @@ impl MBR {
.saturating_sub(extended.starting_lba),
sectors: next.ebr_sectors.unwrap(),
},
&mut writer,
legacy(),
)?;
} else {
serialize_into(&mut writer, &MBRPartitionEntry::empty())?;
encode_into_std_write(MBRPartitionEntry::empty(), &mut writer, legacy())?;
}
writer.write_all(&[0; 16 * 2])?;
serialize_into(&mut writer, &BOOT_SIGNATURE)?;
encode_into_std_write(BOOT_SIGNATURE, &mut writer, legacy())?;
}
}

@@ -1073,12 +1079,12 @@ impl MBRHeader {

/// Attempt to read a MBR header from a reader. This operation will seek at the
/// correct location before trying to write to disk.
pub fn read_from<R: ?Sized>(mut reader: &mut R) -> Result<MBRHeader>
pub fn read_from<R>(mut reader: &mut R) -> Result<MBRHeader>
where
R: Read + Seek,
R: Read + Seek + ?Sized,
{
reader.seek(SeekFrom::Start(0))?;
let header: Self = deserialize_from(&mut reader)?;
let header: Self = decode_from_std_read(&mut reader, legacy())?;
header.check()?;
Ok(header)
}
@@ -1099,13 +1105,13 @@ impl MBRHeader {

/// Write the MBR header into a writer. This operation will seek at the
/// correct location before trying to write to disk.
pub fn write_into<W: ?Sized>(&self, mut writer: &mut W) -> Result<()>
pub fn write_into<W>(&self, mut writer: &mut W) -> Result<()>
where
W: Write + Seek,
W: Write + Seek + ?Sized,
{
self.check()?;
writer.seek(SeekFrom::Start(0))?;
serialize_into(&mut writer, &self)?;
encode_into_std_write(self, &mut writer, legacy())?;

Ok(())
}
@@ -1123,14 +1129,14 @@ impl Index<usize> for MBRHeader {
type Output = MBRPartitionEntry;

fn index(&self, i: usize) -> &Self::Output {
assert!(i != 0, "invalid partition index: 0");
assert_ne!(i, 0, "invalid partition index: 0");
self.get(i).expect("invalid partition")
}
}

impl IndexMut<usize> for MBRHeader {
fn index_mut(&mut self, i: usize) -> &mut Self::Output {
assert!(i != 0, "invalid partition index: 0");
assert_ne!(i, 0, "invalid partition index: 0");
self.get_mut(i).expect("invalid partition")
}
}
@@ -1147,11 +1153,11 @@ struct EBRHeader {
}

impl EBRHeader {
fn read_from<R: ?Sized>(reader: &mut R) -> Result<EBRHeader>
fn read_from<R>(reader: &mut R) -> Result<EBRHeader>
where
R: Read,
{
let header: Self = deserialize_from(reader)?;
let header: Self = decode_from_std_read(reader, legacy())?;
header.check()?;
Ok(header)
}
@@ -1507,6 +1513,7 @@ impl Serialize for CHS {
#[allow(clippy::cognitive_complexity)]
mod tests {
use super::*;
use bincode::serde::{decode_from_slice, encode_into_slice};
use std::fs::File;
use std::io::Cursor;

@@ -1515,7 +1522,7 @@ mod tests {

#[test]
fn deserialize_maximum_chs_value() {
let chs: CHS = bincode::deserialize(&[0xff, 0xff, 0xff]).unwrap();
let chs: CHS = decode_from_slice(&[0xff, 0xff, 0xff], legacy()).unwrap().0;
assert_eq!(
chs,
CHS {
@@ -1533,13 +1540,16 @@ mod tests {
head: 255,
sector: 63,
};
let out = bincode::serialize(&chs).unwrap();
assert_eq!(out, &[0xff, 0xff, 0xff]);
let mut slice = [0; 3];
encode_into_slice(chs, &mut slice, legacy()).unwrap();
for element in slice {
assert_eq!(element, 0xff);
}
}

#[test]
fn serialize_and_deserialize_some_chs_value() {
let chs: CHS = bincode::deserialize(&[0xaa, 0xaa, 0xaa]).unwrap();
let chs: CHS = decode_from_slice(&[0xaa, 0xaa, 0xaa], legacy()).unwrap().0;
assert_eq!(
chs,
CHS {
@@ -1548,8 +1558,11 @@ mod tests {
sector: 42,
}
);
let out = bincode::serialize(&chs).unwrap();
assert_eq!(out, &[0xaa, 0xaa, 0xaa]);
let mut slice = [0; 3];
encode_into_slice(chs, &mut slice, legacy()).unwrap();
for element in slice {
assert_eq!(element, 0xaa);
}
}

#[test]
@@ -1652,7 +1665,7 @@ mod tests {
assert_eq!(
CHS::from_lba_exact(
mbr.logical_partitions[2].partition.starting_lba,
u16::max_value(),
u16::MAX,
2,
3
)
@@ -1987,7 +2000,8 @@ mod tests {
mbr.header.partition_1.sys = 0x0f;
mbr.header.partition_1.starting_lba = 1;
mbr.header.partition_1.sectors = 10;
mbr.push(0x0f, 1, 9).unwrap().partition.boot = BOOT_ACTIVE | 0x01;
let partition = mbr.push(0x0f, 1, 9).unwrap();
partition.partition.boot = BOOT_ACTIVE | 0x01;
assert!(matches!(
mbr.write_into(&mut cur).unwrap_err(),
Error::InvalidBootFlag
Loading