From 2a34972da36afffc121eeff04164f28bd0aaa88b Mon Sep 17 00:00:00 2001 From: Pragyan Poudyal Date: Tue, 17 Mar 2026 11:23:35 +0530 Subject: [PATCH] Add `repr(c)` for SplitStream header structs While trying out https://github.com/composefs/composefs-rs/pull/263 locally, I found that Rust is rearranging the SplitStreamHeader struct's fields to the following ``` [32, 0, 0, 0, 0, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 112, 108, 105, 116, 83, 116, 114, 101, 97, 109, 0, 2, 12] ``` The first two U64 are the start and end of the field `info` when `info` is the last field in the struct; then comes the flags which is the third field... We probably don't want this undeterministic behaviour, which might also change from arch to arch Signed-off-by: Pragyan Poudyal --- crates/composefs/src/splitstream.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/composefs/src/splitstream.rs b/crates/composefs/src/splitstream.rs index a0b44d1b..827a02ac 100644 --- a/crates/composefs/src/splitstream.rs +++ b/crates/composefs/src/splitstream.rs @@ -41,6 +41,7 @@ const SPLITSTREAM_MAGIC: [u8; 11] = *b"SplitStream"; const LG_BLOCKSIZE: u8 = 12; // TODO: hard-coded 4k. make this generic later... // Nearly everything in the file is located at an offset indicated by a FileRange. +#[repr(C)] #[derive(Debug, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)] struct FileRange { start: U64, @@ -48,6 +49,7 @@ struct FileRange { } // The only exception is the header: it is a fixed sized and comes at the start (offset 0). +#[repr(C)] #[derive(Debug, FromBytes, Immutable, IntoBytes, KnownLayout)] struct SplitstreamHeader { pub magic: [u8; 11], // Contains SPLITSTREAM_MAGIC @@ -59,6 +61,7 @@ struct SplitstreamHeader { } // The info block can be located anywhere, indicated by the "info" FileRange in the header. +#[repr(C)] #[derive(Debug, FromBytes, Immutable, IntoBytes, KnownLayout)] struct SplitstreamInfo { pub stream_refs: FileRange, // location of the stream references array