pub struct LocalFsBackend { /* private fields */ }Expand description
Local-filesystem backend, sandboxed at a single root directory.
Handles set access and write times on every host. The creation time is set on Windows and macOS; other hosts have no call that sets it, so a requested creation time is ignored there and the other times still apply. The host keeps the change time.
On Unix, FIFOs, sockets and device nodes are listed, and an open of one,
or of a symlink to one, fails with STATUS_IO_REPARSE_TAG_NOT_HANDLED.
On Linux, an open that conflicts with a file lease (F_SETLEASE) fails
with STATUS_SHARING_VIOLATION instead of waiting; the kernel starts
breaking the lease, so a retry succeeds once the holder releases it.
On Linux, the backend reports BackendCapabilities::block_cloning when
the filesystem of the share root clones ranges between files, as Btrfs and
XFS with reflinks do. It asks the kernel once, when it is made, with two
temporary files that have no name in the share root, so a share root the
server cannot create files in, or one on a filesystem without unnamed
temporary files, reports none. A read-only backend reports none.
On Windows, it reports block_cloning when the volume of the share root
reports FILE_SUPPORTS_BLOCK_REFCOUNTING, which ReFS does. A clone of a
sparse file makes the target sparse first.
On Linux, a file’s or directory’s named streams are its extended
attributes named user.DosStream.<name>:$DATA, each holding the
stream’s data followed by one NUL byte. A share moves between this
server and Samba’s vfs_streams_xattr with its streams. Of attributes
whose names differ only in case, the one that sorts first in byte order
is the stream; removing or replacing the stream removes them all.
A stream that outgrows its extended attribute, past 65535 bytes or past
the room the filesystem gives a file’s extended attributes (one block
for all of them on ext4), moves to the stream store, and stays there
until it is removed or cut to zero. The store is the directory
.smb-streams in the share root, mode 0700, or the one
LocalFsBackend::stream_store names, made with the first request to a
writable share. Clients cannot open, list or rename into it under any
name, and cannot create its name in the share root; with a store, paths
are looked up one name at a time from the share root, each directory
opened from the one before. The store has a directory per file, named by
a random id that the file keeps in the extended attribute
user.smb-server.streams (its record) with its identity, so its streams
follow it through renames and hard links. A file that carries another
file’s record, as a copy with its extended attributes does, reads that
file’s streams, and gets an id of its own with a copy of them before any
of them changes. The identity is the file handle where the filesystem
gives one, else the inode number and birth time; on filesystems whose
inode numbers or handles change, such as some FUSE filesystems, every
file looks like a copy and copies its streams once more each time, and a
file in a snapshot reads the live file’s streams in the store. A record
of another store is left alone, and that file’s streams stay in extended
attributes. Removed files leave their streams in the store until
LocalFsBackend::sweep_streams removes them. A stream whose name
takes more than 126 bytes in UTF-8 cannot move to the store, and a
write past what its extended attribute holds fails with
STATUS_DISK_FULL, as does a new stream on a file with 4096. A rename
between the default stream and a named one copies at most 64 MiB where
the filesystem cannot clone the data.
Whether the share has named streams is decided once, by probing the share root for user extended attributes. Below the root, a mount without them lists no streams, and a stream request there fails with STATUS_ACCESS_DENIED.
On macOS, a file’s or directory’s named streams are its extended
attributes, and the host’s Finder shows the tags, comments, labels and
icons clients set. AFP_AfpInfo is com.apple.FinderInfo, in the
60-byte AfpInfo layout around its 32 bytes: a write must be those 60
bytes at offset 0, starting with AFP\0, or it fails with
STATUS_INVALID_PARAMETER, and Finder info of all zeros, a cut to zero
or an overwrite removes the attribute. An AFP_AfpInfo stream without
the attribute reads as AfpInfo with Finder info of all zeros and is not
listed; a client can create it, and the first write stores it.
AFP_Resource is com.apple.ResourceFork, which holds no empty fork:
an AFP_Resource stream exists once it has data. Directories have no
resource fork. Any other stream is the attribute of the same name, with
the characters macOS clients send as U+F001 to U+F029 mapped back, so
com.apple.metadata\u{F022}_kMDItemUserTags is the attribute
com.apple.metadata:_kMDItemUserTags, and attributes list under those
names. A stream name holds such characters only that way: a*b is an
invalid name, and a\u{F021}b names the attribute a*b. Attribute
names no stream name leads to, and com.apple.FinderInfo and
com.apple.ResourceFork spelled in another case, are left out; a
stream name that maps to one of them, or to more than 127 bytes, is
invalid. Attributes whose names differ only in case are one stream, as
on Linux. A write or size change that would leave AFP_Resource larger
than 16 MiB, or another stream larger than 1 MiB, fails with
STATUS_DISK_FULL, as does a rename that moves more than the target
holds, and a read of a stream other than those two that the host made
larger than 1 MiB fails with STATUS_ACCESS_DENIED. Reads of a resource
fork stop at 4 GiB. An overwrite or supersede of a file removes every
attribute it lists as a stream, com.apple.quarantine and others the
host set included. A share on a volume that keeps extended attributes
only in ._ files, such as FAT or exFAT, has no named streams.
On Windows, a file’s or directory’s named streams are its NTFS alternate data streams, under the names clients send, each opened relative to a handle of its file inside the share without following reparse points. NTFS compares stream names by the uppercase form of each character and keeps the spelling a stream was made with; names that differ only in a character without a one-character uppercase form, such as U+00DF and U+1E9E, are two streams to NTFS and one to the server’s share modes and locks, while U+03C2 and U+03C3 are one stream to NTFS and two to the server. A file lists at most 4096 named streams, and a new stream past that fails with STATUS_DISK_FULL. Whether the share has named streams is decided once, from the volume of the share root: FAT and exFAT volumes have none. ReFS cannot rename streams: a stream rename there fails with STATUS_INVALID_PARAMETER, and a stream larger than the volume holds fails with STATUS_DISK_FULL.
On Linux, a file’s or directory’s extended attributes are its extended
attributes named user.<name>, the layout Samba uses, when the
filesystem of the share root stores user extended attributes. Names
compare without regard to ASCII case: a set or a removal acts on the
attribute as the host spells it, and a new one keeps the client’s
spelling. Of attributes whose names differ only in case, the one that
sorts first in byte order is listed, and a set or removal of the name
replaces or removes them all. Names longer than 250 bytes fail with
STATUS_INVALID_EA_NAME. These host attributes are hidden, and a set of
one of their names fails with STATUS_ACCESS_DENIED, in any case: names
clients cannot send, user.DosStream.*, user.smb-server.*, and
Samba’s user.DOSATTRIB, user.SAMBA_PAI, user.SAMBA_STREAMS,
user.SmbReparse and user.org.netatalk.Metadata. FILE_NEED_EA is not
kept. A set that does not fit, past the room the filesystem gives a
file’s extended attributes (one block for all of them on ext4), fails
with STATUS_EA_TOO_LARGE and changes nothing. A set on a read-only file
fails with STATUS_ACCESS_DENIED unless the server may write the file
whatever its mode.
On Windows, a share root may be a UNC path or a mapped drive. A lookup holds each directory on its way open without delete sharing until it ends, so the server’s account needs traverse rights on the share’s directories, and a rename or delete of a directory a lookup is passing through fails with STATUS_SHARING_VIOLATION.
On Windows, a rename refused with STATUS_ACCESS_DENIED, as a directory rename is while another program has an entry below it open, is tried again for up to one second before it fails.
On Windows, where the share root is on another machine, the SMB client
of Windows can store a new name in the case another program uses to
open it at the same moment, as a virus scanner does, and can drop a
rename that changes only the case of a name. So after each create and
rename of a file, a directory or a named stream there, the backend
reads back the name the server stored. A name stored in another
spelling is renamed to ~smb-<32 hex digits> in its directory, or among
the streams of its file, then to the name asked for. In between, the
entry lists under the temporary name and an open of its name can miss
it; if the server stops then, the entry stays under the temporary name
in its directory, where nothing removes it. A case-only rename that
cannot be corrected fails and leaves the name as it was. A create whose
entry another program holds open without sharing delete access
succeeds under the spelling the server stored, with a warning logged. A
create whose name another client takes during the correction fails
with STATUS_SHARING_VIOLATION, and the entry it made is deleted.
On Windows, where the volume of the share root refuses POSIX deletes,
as an SMB share does, a delete moves the entry into the hidden directory
.smb-deleted in the share root and marks it to be deleted when its
last handle closes, so its name is free at once; the file system
removes it at that close. The first delete that needs .smb-deleted
makes it, and the backend keeps it open from then on and deletes what
earlier runs left in it, except a directory that still has entries,
which stays with a warning logged. If something else has that name,
deleted names stay until their last handle closes. A read-only backend
never makes it. On every Windows volume, clients cannot open, list or
rename into .smb-deleted under any spelling, and cannot create its
name in the share root.
On Windows, extended attributes are the NTFS ones, on volumes that store them; NTFS keeps the letters a-z of their names in uppercase. macOS hosts have none: every extended attribute there is a named stream.
Implementations§
Source§impl LocalFsBackend
impl LocalFsBackend
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Open path as the share root. Errors if the path does not exist or is
not a directory.
Sourcepub fn read_only(self) -> Self
pub fn read_only(self) -> Self
Mark the backend as read-only. All write-class opens and writes return an access-denied SMB error.
Sourcepub fn watch_host_changes(self, enabled: bool) -> Self
pub fn watch_host_changes(self, enabled: bool) -> Self
Report changes made to the share’s directories outside the server,
by other programs on the host or through other shares, to clients
that watch them. On Linux only, through inotify: only the entries
directly in a watched directory are seen. The parent of each watched
directory, the share root’s parent included, is watched too, to see
the directory deleted. The backend holds at most 4096 kernel
watches; a directory past that, or one the kernel will not watch,
past fs.inotify.max_user_watches or fs.inotify.max_user_instances
or without /proc, gets only the changes made through the server,
with a warning logged once. On by default.
Sourcepub fn stream_store(self, path: impl AsRef<Path>) -> Result<Self>
pub fn stream_store(self, path: impl AsRef<Path>) -> Result<Self>
Keep the named streams that do not fit in an extended attribute in
the directory path instead of .smb-streams in the share root.
The directory must exist, lie outside the share, belong to the
server’s user and give no access to group or others. Space taken
there does not count against the share’s filesystem or its quotas
when it is on another filesystem. Backends that name the same
directory share it, and LocalFsBackend::sweep_streams on one of
them removes what none of its own files refers to, so each needs
its own directory unless their shares are swept together. Linux
only; elsewhere the directory is opened and not used.
Sourcepub async fn sweep_streams(&self) -> Result<usize>
pub async fn sweep_streams(&self) -> Result<usize>
Remove what the stream store keeps for files that are gone: files deleted, through the server or on the host, or replaced without their extended attributes. Returns how many files’ streams went.
An entry of the store goes once two sweeps in a row found no file
referring to it and no request used it in between, so a file moved
while one sweep walked the share keeps its streams; space a deleted
file took comes back after the second sweep. The walk reads an
extended attribute of every file and directory of the share and
holds nothing; the pass over the store that follows makes stream
requests that use the store wait until it is done, a pause that
grows with the number of entries and with the size of those it
removes. Any user.smb-server.streams attribute keeps the entry it
names. A file or directory the walk cannot read fails the sweep
before anything is removed; a failure in the pass over the store
leaves the entries it had not reached yet. Linux only; elsewhere it
removes nothing.
Trait Implementations§
Source§fn open<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
opts: OpenOptions,
) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn open<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
opts: OpenOptions,
) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn unlink<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn unlink<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 SmbPath,
to: &'life2 SmbPath,
replace_if_exists: bool,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 SmbPath,
to: &'life2 SmbPath,
replace_if_exists: bool,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn capabilities(&self) -> BackendCapabilities
fn capabilities(&self) -> BackendCapabilities
is_read_only is set.Source§fn volume_info<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = SmbResult<VolumeInfo>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn volume_info<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = SmbResult<VolumeInfo>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
VolumeInfo::default.Source§fn copy_range<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
src: &'life1 dyn Handle,
src_offset: u64,
dst: &'life2 dyn Handle,
dst_offset: u64,
len: u64,
) -> Pin<Box<dyn Future<Output = SmbResult<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn copy_range<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
src: &'life1 dyn Handle,
src_offset: u64,
dst: &'life2 dyn Handle,
dst_offset: u64,
len: u64,
) -> Pin<Box<dyn Future<Output = SmbResult<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
len bytes from src_offset of src to dst_offset of
dst inside the storage, for a client’s server-side copy, and
returns the number copied. dst is a handle this backend gave. src
may be a handle of another backend or share, or of the same file as
dst. A copy past the end of dst leaves a gap that reads as
zeros, as Handle::write does. Read moreSource§fn clone_range<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
src: &'life1 dyn Handle,
src_offset: u64,
dst: &'life2 dyn Handle,
dst_offset: u64,
len: u64,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn clone_range<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
src: &'life1 dyn Handle,
src_offset: u64,
dst: &'life2 dyn Handle,
dst_offset: u64,
len: u64,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
len bytes at dst_offset of dst share their storage
with the len bytes at src_offset of src, for a client’s
duplicate extents request: the bytes read the same, and a later write
to either file leaves the other as it is. dst is a handle this
backend gave. src may be a handle of another backend or share. Read moreSource§fn open_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
file: Box<dyn Handle>,
path: &'life1 SmbPath,
stream: &'life2 StreamName,
opts: OpenOptions,
) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn open_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
file: Box<dyn Handle>,
path: &'life1 SmbPath,
stream: &'life2 StreamName,
opts: OpenOptions,
) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
stream of the file or directory at
path. file is the handle open just gave for path, opened for
reading. The backend owns it and closes it, also when this fails; it
may keep it for as long as the stream’s handle lasts, so the stream
follows the file through renames. opts.intent applies to the
stream; opts.directory and opts.non_directory are false. The
handle reads and writes the stream: its stat reports the file’s
times, attributes and id with the stream’s sizes, set_times and
set_attributes change the file, and truncate the stream. A
write or size change of the stream updates the file’s last write
time, which the protocol layer reports as a change of the file. Read moreSource§fn remove_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
file_index: u64,
stream: &'life2 StreamName,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn remove_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
file_index: u64,
stream: &'life2 StreamName,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
path that
stream names, whatever the case of its spelling. Fail with
SmbError::NotFound when the file has no such stream. Read moreSource§fn rename_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
file_index: u64,
from: Option<&'life2 StreamName>,
to: Option<&'life3 StreamName>,
replace_if_exists: bool,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn rename_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
file_index: u64,
from: Option<&'life2 StreamName>,
to: Option<&'life3 StreamName>,
replace_if_exists: bool,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
path, which has the id
file_index as ShareBackend::remove_stream says: the named
stream from names, or the default stream when from is None,
to the named stream to, or to the default stream when to is
None. Names compare without regard to case, and a renamed stream
takes the spelling of to. from and to never name the same
stream, and a directory, which has no default stream, only renames
a named stream to another. Read more