pub trait EditableFilesystem: Filesystem {
Show 31 methods
// Required methods
fn as_filesystem(&self) -> &dyn Filesystem;
fn as_filesystem_mut(&mut self) -> &mut dyn Filesystem;
fn create_file(
&mut self,
parent: &FileEntry,
name: &str,
data: &mut dyn Read,
data_len: u64,
options: &CreateFileOptions,
) -> Result<FileEntry, FilesystemError>;
fn create_directory(
&mut self,
parent: &FileEntry,
name: &str,
options: &CreateDirectoryOptions,
) -> Result<FileEntry, FilesystemError>;
fn delete_entry(
&mut self,
parent: &FileEntry,
entry: &FileEntry,
) -> Result<(), FilesystemError>;
fn sync_metadata(&mut self) -> Result<(), FilesystemError>;
fn free_space(&mut self) -> Result<u64, FilesystemError>;
// Provided methods
fn begin_bulk(&mut self) { ... }
fn end_bulk(&mut self) { ... }
fn delete_recursive(
&mut self,
parent: &FileEntry,
entry: &FileEntry,
) -> Result<(), FilesystemError> { ... }
fn rename(
&mut self,
_parent: &FileEntry,
_entry: &FileEntry,
_new_name: &str,
) -> Result<(), FilesystemError> { ... }
fn set_permissions(
&mut self,
_entry: &FileEntry,
_mode: u32,
) -> Result<(), FilesystemError> { ... }
fn set_owner(
&mut self,
_entry: &FileEntry,
_uid: u32,
_gid: u32,
) -> Result<(), FilesystemError> { ... }
fn set_xattr(
&mut self,
_entry: &FileEntry,
_name: &str,
_value: &[u8],
) -> Result<(), FilesystemError> { ... }
fn remove_xattr(
&mut self,
_entry: &FileEntry,
_name: &str,
) -> Result<(), FilesystemError> { ... }
fn set_type_creator(
&mut self,
_entry: &FileEntry,
_type_code: &str,
_creator_code: &str,
) -> Result<(), FilesystemError> { ... }
fn set_prodos_type(
&mut self,
_entry: &FileEntry,
_type_byte: u8,
_aux_type: u16,
) -> Result<(), FilesystemError> { ... }
fn set_prodos_access(
&mut self,
_entry: &FileEntry,
_access: u8,
) -> Result<(), FilesystemError> { ... }
fn write_resource_fork(
&mut self,
_entry: &FileEntry,
_data: &mut dyn Read,
_len: u64,
) -> Result<(), FilesystemError> { ... }
fn repair(&mut self) -> Result<RepairReport, FilesystemError> { ... }
fn set_blessed_folder(
&mut self,
_entry: &FileEntry,
) -> Result<(), FilesystemError> { ... }
fn write_boot_blocks(
&mut self,
_blocks: &[u8; 1024],
) -> Result<(), FilesystemError> { ... }
fn set_volume_name(
&mut self,
_new_name: &str,
) -> Result<(), FilesystemError> { ... }
fn set_finder_info(
&mut self,
_entry: &FileEntry,
_finfo: [u8; 16],
_fxinfo: [u8; 16],
) -> Result<(), FilesystemError> { ... }
fn set_amiga_protection(
&mut self,
_entry: &FileEntry,
_protection: u32,
) -> Result<(), FilesystemError> { ... }
fn set_dos_attributes(
&mut self,
_parent: &FileEntry,
_entry: &FileEntry,
_attrs: u16,
) -> Result<(), FilesystemError> { ... }
fn set_dates(
&mut self,
_entry: &FileEntry,
_create: u32,
_modify: u32,
_backup: u32,
) -> Result<(), FilesystemError> { ... }
fn supports_symlinks(&self) -> bool { ... }
fn stores_raw_names(&self) -> bool { ... }
fn create_symlink(
&mut self,
_parent: &FileEntry,
_name: &str,
_target: &str,
_options: &CreateFileOptions,
) -> Result<FileEntry, FilesystemError> { ... }
fn create_hardlink(
&mut self,
_parent: &FileEntry,
_name: &str,
_target: &FileEntry,
_options: &CreateFileOptions,
) -> Result<FileEntry, FilesystemError> { ... }
}Expand description
Trait for filesystems that support write operations (add/delete files and folders).
Individual mutation methods (create_file, delete_entry, etc.) modify in-memory
state only. The caller MUST call sync_metadata() after all mutations are complete
to flush changes to disk. This enables batching multiple edits into a single atomic
write.
Required Methods§
Sourcefn as_filesystem(&self) -> &dyn Filesystem
fn as_filesystem(&self) -> &dyn Filesystem
Upcast to a read-only Filesystem trait object.
A hand-rolled substitute for trait-upcasting coercion
(&dyn EditableFilesystem -> &dyn Filesystem), which is unstable
before Rust 1.86 — so the vintage macOS 10.7 build (Rust 1.73) can’t rely
on the coercion and calls this instead. Every impl is a trivial { self }
(the concrete type is Sized and already Filesystem, so the unsizing
coercion applies there). Modern builds could use the coercion directly,
but routing through this keeps a single code path.
Sourcefn as_filesystem_mut(&mut self) -> &mut dyn Filesystem
fn as_filesystem_mut(&mut self) -> &mut dyn Filesystem
Mutable form of as_filesystem.
Sourcefn create_file(
&mut self,
parent: &FileEntry,
name: &str,
data: &mut dyn Read,
data_len: u64,
options: &CreateFileOptions,
) -> Result<FileEntry, FilesystemError>
fn create_file( &mut self, parent: &FileEntry, name: &str, data: &mut dyn Read, data_len: u64, options: &CreateFileOptions, ) -> Result<FileEntry, FilesystemError>
Create a file in the given parent directory.
data is a reader providing the file contents; data_len is the total size.
Returns the new file’s entry.
Sourcefn create_directory(
&mut self,
parent: &FileEntry,
name: &str,
options: &CreateDirectoryOptions,
) -> Result<FileEntry, FilesystemError>
fn create_directory( &mut self, parent: &FileEntry, name: &str, options: &CreateDirectoryOptions, ) -> Result<FileEntry, FilesystemError>
Create a subdirectory in the given parent directory.
Sourcefn delete_entry(
&mut self,
parent: &FileEntry,
entry: &FileEntry,
) -> Result<(), FilesystemError>
fn delete_entry( &mut self, parent: &FileEntry, entry: &FileEntry, ) -> Result<(), FilesystemError>
Delete a file, empty directory, or symlink.
Returns an error if the entry is a non-empty directory.
Sourcefn sync_metadata(&mut self) -> Result<(), FilesystemError>
fn sync_metadata(&mut self) -> Result<(), FilesystemError>
Flush metadata (superblock, bitmaps, FAT tables, etc.) to disk.
Sourcefn free_space(&mut self) -> Result<u64, FilesystemError>
fn free_space(&mut self) -> Result<u64, FilesystemError>
Returns the number of free bytes available on the filesystem.
Provided Methods§
Sourcefn begin_bulk(&mut self)
fn begin_bulk(&mut self)
Enter “bulk” editing mode for a batch of operations whose atomicity the
caller guarantees as a whole (e.g. an importer that discards every
change if any single op fails). Implementations may use this to skip
per-operation rollback bookkeeping — for filesystems that snapshot the
whole metadata on each edit (classic HFS clones its multi-megabyte
catalog per create_file), that bookkeeping dominates a large import.
Contract: while in bulk mode a failed edit may leave in-memory state
inconsistent, so the caller MUST abandon the volume (not sync/commit) on
any error. Always pair with end_bulk. The default is
a no-op, so filesystems whose edits are already cheap need do nothing.
Sourcefn end_bulk(&mut self)
fn end_bulk(&mut self)
Leave bulk editing mode (see begin_bulk). Default
is a no-op.
Sourcefn delete_recursive(
&mut self,
parent: &FileEntry,
entry: &FileEntry,
) -> Result<(), FilesystemError>
fn delete_recursive( &mut self, parent: &FileEntry, entry: &FileEntry, ) -> Result<(), FilesystemError>
Recursively delete a directory and all its contents.
Default implementation lists children, recurses, then calls delete_entry.
Sourcefn rename(
&mut self,
_parent: &FileEntry,
_entry: &FileEntry,
_new_name: &str,
) -> Result<(), FilesystemError>
fn rename( &mut self, _parent: &FileEntry, _entry: &FileEntry, _new_name: &str, ) -> Result<(), FilesystemError>
Rename an entry within its parent directory, in place: the entry keeps
its identity and contents (start cluster / CNID / inode and file data
are untouched) — only the name in the parent’s directory listing
changes. new_name must validate via Filesystem::validate_name and
must not already name another entry in parent.
Default returns Unsupported so the GUI can gray out the action on
filesystems that haven’t implemented it yet.
Sourcefn set_permissions(
&mut self,
_entry: &FileEntry,
_mode: u32,
) -> Result<(), FilesystemError>
fn set_permissions( &mut self, _entry: &FileEntry, _mode: u32, ) -> Result<(), FilesystemError>
Set Unix permission bits on an entry. mode carries permission bits
only — implementations keep the inode’s file-type bits (see
[crate::fs::unix_common::inode::with_permission_bits]).
Implemented by ext, EFS, UFS, Minix, JFS, XFS and SquashFS; anything
else returns Unsupported so callers don’t silently lose mode
information.
Sourcefn set_owner(
&mut self,
_entry: &FileEntry,
_uid: u32,
_gid: u32,
) -> Result<(), FilesystemError>
fn set_owner( &mut self, _entry: &FileEntry, _uid: u32, _gid: u32, ) -> Result<(), FilesystemError>
Set the owning uid and gid on an entry.
Implemented by ext, EFS, UFS, Minix, JFS, XFS and SquashFS; others
return Unsupported so the UI can gate the control. Note the GUI
shows its Owner field whenever an entry carries a mode, which is a
read-side signal — that is how this went unimplemented on five Unix
filesystems whose editor fields rendered and then failed on apply.
Filesystems with narrow id fields (EFS and Minix hold 16 bits, Minix
V1’s gid is 8) reject an id that doesn’t fit rather than truncating
it: a wrapped uid lands on 0, which is root. See
[crate::fs::unix_common::inode::check_id_width].
Sourcefn set_xattr(
&mut self,
_entry: &FileEntry,
_name: &str,
_value: &[u8],
) -> Result<(), FilesystemError>
fn set_xattr( &mut self, _entry: &FileEntry, _name: &str, _value: &[u8], ) -> Result<(), FilesystemError>
Set (create or replace) an extended attribute on an entry. Override on
xattr-bearing filesystems (ext / XFS / SquashFS); others return
Unsupported. name must carry a valid namespace prefix
([crate::fs::xattr::has_valid_namespace]).
Sourcefn remove_xattr(
&mut self,
_entry: &FileEntry,
_name: &str,
) -> Result<(), FilesystemError>
fn remove_xattr( &mut self, _entry: &FileEntry, _name: &str, ) -> Result<(), FilesystemError>
Remove an extended attribute from an entry. Override on xattr-bearing
filesystems; others return Unsupported. Removing an absent attribute is
not an error.
Sourcefn set_type_creator(
&mut self,
_entry: &FileEntry,
_type_code: &str,
_creator_code: &str,
) -> Result<(), FilesystemError>
fn set_type_creator( &mut self, _entry: &FileEntry, _type_code: &str, _creator_code: &str, ) -> Result<(), FilesystemError>
Set HFS/HFS+ type and creator codes. Override on HFS/HFS+; other
filesystems return Unsupported so callers can branch on capability
rather than relying on silent no-ops.
Sourcefn set_prodos_type(
&mut self,
_entry: &FileEntry,
_type_byte: u8,
_aux_type: u16,
) -> Result<(), FilesystemError>
fn set_prodos_type( &mut self, _entry: &FileEntry, _type_byte: u8, _aux_type: u16, ) -> Result<(), FilesystemError>
Set ProDOS file type byte and aux type on an existing file.
Default returns Unsupported — override on ProDOS.
Sourcefn set_prodos_access(
&mut self,
_entry: &FileEntry,
_access: u8,
) -> Result<(), FilesystemError>
fn set_prodos_access( &mut self, _entry: &FileEntry, _access: u8, ) -> Result<(), FilesystemError>
Set the ProDOS access byte on an existing file or directory.
The access byte (offset 30 of a directory entry) is a bitmask:
0x80 = enable destroy, 0x40 = enable rename, 0x20 = backup
required (set when the file changes; cleared by backup software),
0x02 = enable write, 0x01 = enable read. Conventional values:
0xC3 = unlocked (read/write/destroy/rename), 0x21 = locked
(read + backup-required).
Default returns Unsupported — override on ProDOS.
Sourcefn write_resource_fork(
&mut self,
_entry: &FileEntry,
_data: &mut dyn Read,
_len: u64,
) -> Result<(), FilesystemError>
fn write_resource_fork( &mut self, _entry: &FileEntry, _data: &mut dyn Read, _len: u64, ) -> Result<(), FilesystemError>
Write resource fork data. Override on HFS/HFS+; other filesystems
return Unsupported rather than silently dropping the fork.
Sourcefn repair(&mut self) -> Result<RepairReport, FilesystemError>
fn repair(&mut self) -> Result<RepairReport, FilesystemError>
Attempt to repair filesystem issues found by fsck. Default returns an error indicating repair is not supported.
Sourcefn set_blessed_folder(
&mut self,
_entry: &FileEntry,
) -> Result<(), FilesystemError>
fn set_blessed_folder( &mut self, _entry: &FileEntry, ) -> Result<(), FilesystemError>
Mark a folder as the blessed (bootable) system folder. Override on
HFS/HFS+; other filesystems return Unsupported so the GUI can
gate the action and surface unexpected calls.
Sourcefn write_boot_blocks(
&mut self,
_blocks: &[u8; 1024],
) -> Result<(), FilesystemError>
fn write_boot_blocks( &mut self, _blocks: &[u8; 1024], ) -> Result<(), FilesystemError>
Stage the 1024-byte HFS boot-block region (sectors 0–1) for the
volume, written verbatim at sync_metadata time. Used to make a
classic-HFS volume bootable by copying a donor’s boot blocks. Override
on HFS/HFS+ (the only filesystems with a Mac boot region); others
return Unsupported so the GUI can gate the action.
Sourcefn set_volume_name(&mut self, _new_name: &str) -> Result<(), FilesystemError>
fn set_volume_name(&mut self, _new_name: &str) -> Result<(), FilesystemError>
Rename the volume. Override on filesystems where the volume name is
stored in metadata that the implementation can rewrite in place
(HFS today; others return Unsupported).
Sourcefn set_finder_info(
&mut self,
_entry: &FileEntry,
_finfo: [u8; 16],
_fxinfo: [u8; 16],
) -> Result<(), FilesystemError>
fn set_finder_info( &mut self, _entry: &FileEntry, _finfo: [u8; 16], _fxinfo: [u8; 16], ) -> Result<(), FilesystemError>
Overwrite the full 16-byte FInfo and 16-byte FXInfo Finder metadata
on a file’s catalog record. HFS today; others Unsupported. Used
by the MacBinary put path to apply Finder flags / location / folder
in one shot.
Sourcefn set_amiga_protection(
&mut self,
_entry: &FileEntry,
_protection: u32,
) -> Result<(), FilesystemError>
fn set_amiga_protection( &mut self, _entry: &FileEntry, _protection: u32, ) -> Result<(), FilesystemError>
Overwrite the create/modify/backup dates on a file’s catalog
record. Dates are Mac epoch (seconds since 1904-01-01 00:00 UTC).
HFS today; others Unsupported.
Set the DOS attribute bits on an entry: read-only 0x01, hidden 0x02,
system 0x04, archive 0x20.
Takes the parent because that is where the bits live — a FAT directory
entry is the record, and there is nothing else to address it by.
Structural bits (directory 0x10, volume-id 0x08) are the driver’s to
manage and are masked off rather than trusted from a caller.
Unsupported on filesystems with no such concept, which is most of them.
Set the AmigaDOS protection bits on an entry (the access longword:
HSPA RWED, held at offset 0x140 of the file header block).
Unsupported off the Amiga filesystems, which is everywhere else.
fn set_dos_attributes( &mut self, _parent: &FileEntry, _entry: &FileEntry, _attrs: u16, ) -> Result<(), FilesystemError>
fn set_dates( &mut self, _entry: &FileEntry, _create: u32, _modify: u32, _backup: u32, ) -> Result<(), FilesystemError>
Sourcefn supports_symlinks(&self) -> bool
fn supports_symlinks(&self) -> bool
Whether this filesystem can store symbolic links (i.e.
Self::create_symlink is actually implemented). Default false;
override to true alongside create_symlink. Lets callers (e.g. the
tar-import preflight) warn before a lossy import that symlinks will
be dropped, rather than discovering it entry-by-entry.
Sourcefn stores_raw_names(&self) -> bool
fn stores_raw_names(&self) -> bool
Whether names are stored as raw bytes via [crate::fs::raw_name] placeholders.
Only NeXT UFS volumes say yes; everywhere else a placeholder would land as junk.
Sourcefn create_symlink(
&mut self,
_parent: &FileEntry,
_name: &str,
_target: &str,
_options: &CreateFileOptions,
) -> Result<FileEntry, FilesystemError>
fn create_symlink( &mut self, _parent: &FileEntry, _name: &str, _target: &str, _options: &CreateFileOptions, ) -> Result<FileEntry, FilesystemError>
Create a symbolic link in parent pointing at target (a path
string interpreted by the filesystem’s own resolver semantics).
Returns the new symlink’s entry. Default returns Unsupported —
override on filesystems that support symlinks (PFS3, AFFS,
ext, etc).
Sourcefn create_hardlink(
&mut self,
_parent: &FileEntry,
_name: &str,
_target: &FileEntry,
_options: &CreateFileOptions,
) -> Result<FileEntry, FilesystemError>
fn create_hardlink( &mut self, _parent: &FileEntry, _name: &str, _target: &FileEntry, _options: &CreateFileOptions, ) -> Result<FileEntry, FilesystemError>
Create a hard link in parent pointing at an existing entry
already on this filesystem. target must be an entry returned
by a previous create_file / create_directory / list_directory
call on this same volume — its location identifies the inode /
anode / CNID that the new link references. Returns the new
hardlink’s entry. Default returns Unsupported — override on
filesystems that support hardlinks (PFS3, HFS+, ext, etc).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".