Skip to content

amd-efs#99 Improve dumping of image contents with unknown parts. #100

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "amd-efs"
version = "0.3.1"
version = "0.3.2"
authors = ["Oxide Computer Company"]
edition = "2018"

Expand Down
21 changes: 20 additions & 1 deletion src/ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ macro_rules! make_bitfield_serde {(

#[cfg(feature = "serde")]
paste::paste! {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
Expand All @@ -748,6 +748,25 @@ macro_rules! make_bitfield_serde {(
)*
}
}

#[cfg(feature = "serde")]
paste::paste!{
/// Use this for serialization in order to make serde skip those fields
/// where the meaning of a raw value is unknown to us.
///
/// Caller can then override Serializer::skip_field and thus find out
/// which fields were skipped, inferring where errors were.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
pub(crate) struct [<SerdePermissiveSerializing $StructName>] {
$(
$(#[serde(skip_serializing_if="Option::is_none")] pub $field_name: Option<$field_ty>,)?
$(#[serde(skip_serializing_if="Option::is_none")] $(#[$serde_field_orig_meta])* pub $field_name: Option<$serde_ty>,)?
)*
}
}
}}

make_bitfield_serde! {
Expand Down
12 changes: 7 additions & 5 deletions src/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use crate::ondisk::*;

// Note: This is written such that it will fail if the underlying struct has fields added/removed/renamed--if those have a public setter.
macro_rules! make_serde{($StructName:ident, $SerdeStructName:ident, [$($field_name:ident),* $(,)?]
macro_rules! impl_struct_serde_conversion{($StructName:ident, $SerdeStructName:ident, $SerializingStructName:ident, [$($field_name:ident),* $(,)?]
) => (
paste::paste!{
#[cfg(feature = "serde")]
Expand All @@ -26,9 +26,9 @@ macro_rules! make_serde{($StructName:ident, $SerdeStructName:ident, [$($field_na
impl serde::Serialize for $StructName {
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where S: serde::Serializer, {
$SerdeStructName {
$SerializingStructName {
$(
$field_name: self.[<serde_ $field_name>]().map_err(|_| serde::ser::Error::custom("value unknown"))?.into(),
$field_name: self.[<serde_ $field_name>]().ok(),
)*
}.serialize(serializer)
}
Expand All @@ -48,14 +48,16 @@ macro_rules! make_serde{($StructName:ident, $SerdeStructName:ident, [$($field_na
}
)}

make_serde!(
impl_struct_serde_conversion!(
DirectoryAdditionalInfo,
SerdeDirectoryAdditionalInfo,
SerdePermissiveSerializingDirectoryAdditionalInfo,
[max_size, spi_block_size, base_address, address_mode, _reserved_0,]
);
make_serde!(
impl_struct_serde_conversion!(
PspSoftFuseChain,
SerdePspSoftFuseChain,
SerdePermissiveSerializingPspSoftFuseChain,
[
secure_debug_unlock,
_reserved_0,
Expand Down
26 changes: 16 additions & 10 deletions src/struct_accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,28 @@ macro_rules! make_accessors {(
)?
)*
}
// for serde
#[cfg(feature = "serde")]
paste::paste!{
/// Use this for serialization in order to make serde skip those fields
/// where the meaning of a raw value is unknown to us.
///
/// Caller can then override Serializer::skip_field and thus find out
/// which fields were skipped, inferring where errors were.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
// Doing remoting automatically would make it impossible for the user to use another one.
// Since the config format presumably needs to be
// backward-compatible, that wouldn't be such a great idea.
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
pub(crate) struct [<Serde $StructName>] {
// Rust's serde automatically has Options transparent--but not Results.
// See also <https://github.com/serde-rs/serde/issues/1042> for
// limitations (that don't hit us since our zerocopy structs
// can't have Option<Option<T>> anyway).
pub(crate) struct [<SerdePermissiveSerializing $StructName>] {
$(
$(pub $field_name: $field_ty,)?
$($(#[$serde_field_orig_meta])* pub $field_name: $serde_ty,)?
$(#[serde(skip_serializing_if="Option::is_none")]
pub $field_name: Option<$field_ty>,)?
$(#[serde(skip_serializing_if="Option::is_none")]
$(#[$serde_field_orig_meta])*
pub $field_name: Option<$serde_ty>,)?
)*
}
}
Expand Down