Replace file reopen concept with ReadAt/WriteAt traits

File reopening was conflating ownership of file-like types with the fact
that they support parallel reads and writes at arbitrary offsets.

The Reopen trait has now been replaced with ReadAt and WriteAt traits,
which are implemented for types that support parallel I/O. If a type
compatible with the standard Read/Write/Seek traits is needed, a new
UserPosFile type can act as the bridge by storing its own userspace file
offset. For the opposite bridge, there's MutexFile, which implements
ReadAt/WriteAt by using locks to make the operations sequential. This is
only really used in the tests though.

This eliminates the need for the PSeekFile and SharedCursor types. The
standard File and Cursor types can be used instead, and if shared
ownership is needed, Arc can be used.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
Andrew Gunnerson
2025-08-22 21:39:32 -04:00
parent 390dce5f0c
commit d874921a69
17 changed files with 630 additions and 631 deletions
+6 -4
View File
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 Andrew Gunnerson
// SPDX-FileCopyrightText: 2023-2025 Andrew Gunnerson
// SPDX-License-Identifier: GPL-3.0-only
#[cfg(not(windows))]
@@ -7,7 +7,7 @@ mod fuzz {
use avbroot::{
format::fec::FecImage,
stream::{FromReader, SharedCursor, WriteZerosExt},
stream::{FromReader, MutexFile, UserPosFile, WriteZerosExt},
};
use honggfuzz::fuzz;
@@ -18,12 +18,14 @@ mod fuzz {
let reader = Cursor::new(data);
if let Ok(fec) = FecImage::from_reader(reader) {
let mut input = SharedCursor::new();
let input = MutexFile::new(Cursor::new(Vec::new()));
// Allow verify() to get further, but don't blow up the host
// with excessive memory usage.
if fec.data_size < 64 * 1024 * 1024 {
input.write_zeros_exact(fec.data_size).unwrap();
UserPosFile::new(&input)
.write_zeros_exact(fec.data_size)
.unwrap();
}
let _ = fec.verify(&input, &cancel_signal);