class Vnode
Defined at line 81 of file ../../src/storage/lib/vfs/cpp/vnode.h
The VFS interface declares a default abstract Vnode class with common operations that may be
overridden.
The ops are used for dispatch and the lifecycle of Vnodes are owned by RefPtrs.
All names passed to the Vnode class are valid according to "IsValidName".
Memory management
-----------------
The Vnode uses the fbl::Recyclable system to allow caching. This kicks in when the reference
count of the node goes to zero.
fbl::RefPtr uses fbl::internal::has_fbl_recycle_v which checks whether there is an fbl_recycle()
implementation on the class being pointed to. This does not catch base class implementations!
Each derived class must inherit from fbl::Recyclable
<class
_name> and implement an fbl_recycle()
function. These implementations should call the protected virtual function RecycleNode().
Derived classes should override RecycleNode() to implement the desired caching behavior.
Protected Members
shared_mutex mutex_
Public Methods
void ~Vnode ()
Defined at line 53 of file ../../src/storage/lib/vfs/cpp/vnode.cc
fuchsia_io::NodeProtocolKinds GetProtocols ()
Returns the set of all protocols supported by the vnode.
void fbl_recycle ()
See class comment above about memory management.
Defined at line 94 of file ../../src/storage/lib/vfs/cpp/vnode.h
bool Supports (fuchsia_io::NodeProtocolKinds protocols)
Returns true if the vnode supports at least one protocol specified in |protocols|.
Defined at line 111 of file ../../src/storage/lib/vfs/cpp/vnode.h
fuchsia_io::Abilities GetAbilities ()
Returns the set of operations the vnode supports. The default implementation assumes files are
readable/writable, and directories are mutable.
Defined at line 214 of file ../../src/storage/lib/vfs/cpp/vnode.cc
bool ValidateRights (fuchsia_io::Rights rights)
To be overridden by implementations to check that it is valid to access the vnode with the
given |rights|. The default implementation always returns true. The vnode will only be opened
for a particular request if the validation passes.
Defined at line 123 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx::result<> DeprecatedValidateOptions (DeprecatedOptions options)
Ensures that it is valid to access the vnode with given io1 connection options.
Defined at line 125 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Open (fbl::RefPtr<Vnode> * out_redirect)
Opens the vnode. This is a callback to signal that a new connection is about to be created and
I/O operations will follow. In addition, it provides an opportunity to redirect subsequent I/O.
If the open fails, the file will be deemed to be not opened and Close() will not be called.
Vnode implementations should override OpenNode() which this function calls after some
bookkeeping.
Open will never be invoked when a node reference connection is created. This corresponds
to Posix open()'s O_PATH flag which will create a thing representing the path to the file
without giving the ability to do most operations like read or write. In the future, we may want
the ability to track these connections, in which case we should add a Connect()/Disconnect()
pair that would surround the Open()/Close() for the normal case, but would be called regardless
of the flags to cover the node-reference case.
If the implementation of |Open()| sets |out_redirect| to a non-null value, all following I/O
operations on the opened object will be redirected to the indicated vnode instead of being
handled by this instance. This is useful when implementing lazy files/pseudo files, where a
different vnode may be used for each new connection to a file. Note that the |out_redirect|
vnode is not |Open()|ed further for the purpose of creating this connection. Furthermore, the
redirected vnode must support the same set of protocols as the original vnode.
Defined at line 141 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t ConnectService (zx::channel channel)
Serves a custom FIDL protocol over the specified |channel|, when the node protocol is
|VnodeProtocol::kService|.
The default implementation returns |ZX_ERR_NOT_SUPPORTED|.
Subclasses may override this behavior to serve custom protocols over the channel.
Defined at line 66 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t WatchDir (FuchsiaVfs * vfs, fuchsia_io::wire::WatchMask mask, uint32_t options, fidl::ServerEnd<fuchsia_io::DirectoryWatcher> watcher)
Defined at line 68 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx::result<zx::stream> CreateStream (uint32_t stream_options)
Create a |zx::stream| for reading and writing to this vnode.
On success, all |Read|, |Write|, and |Append| operations will be directed to the returned
stream rather than to the |Read|, |Write|, and |Append| methods on the vnode.
The |zx::stream| will be duplicated and transported to a remote process to improve performance.
The |zx::vmo| backing the |zx::stream| will itself need to be |zx::pager| backed in order to
detect writes made to the |zx::stream|.
Implementations should pass the given |stream_options| as the options to |zx::stream::create|.
These options ensure that the created |zx::stream| object has the appropriate rights for the
given connection.
If the vnode does not support reading and writing using a |zx::stream|, return
ZX_ERR_NOT_SUPPORTED, which will cause |Read|, |Write|, and |Append| operations to be called as
methods on the vnode. Other errors are considered fatal and will terminate the connection.
Defined at line 62 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t GetVmo (fuchsia_io::wire::VmoFlags flags, zx::vmo * out_vmo)
Acquire a vmo from a vnode.
At the moment, mmap can only map files from read-only filesystems, since (without paging) there
is no mechanism to update either
1) The file by writing to the mapping, or
2) The mapping by writing to the underlying file.
Defined at line 73 of file ../../src/storage/lib/vfs/cpp/vnode.cc
void DeprecatedOpenRemote (fuchsia_io::OpenFlags , fuchsia_io::ModeType , fidl::StringView , fidl::ServerEnd<fuchsia_io::Node> )
If |IsRemote()| returns true, requests to open this Vnode using
fuchsia.io/Directory.DeprecatedOpen will be forwarded to this function.
TODO(https://fxbug.dev/324080864): This should be removed when we drop support for the
fuchsia.io/Directory.DeprecatedOpen method.
Defined at line 77 of file ../../src/storage/lib/vfs/cpp/vnode.cc
void OpenRemote (fuchsia_io::wire::DirectoryOpenRequest request)
If |IsRemote()| returns true, requests to open this Vnode via fuchsia.io/Directory.Open will
be forwarded to this function.
Defined at line 82 of file ../../src/storage/lib/vfs/cpp/vnode.cc
std::shared_ptr<file_lock::FileLock> GetVnodeFileLock ()
Instead of adding a |file_lock::FileLock| member variable to |Vnode|,
maintain a map from |this| to the lock objects. This is done, because
file locking only applies to regular files, so we want to avoid the
memory overhead for all other |Vnode| types.
Defined at line 86 of file ../../src/storage/lib/vfs/cpp/vnode.cc
bool DeleteFileLock (zx_koid_t owner)
Defined at line 100 of file ../../src/storage/lib/vfs/cpp/vnode.cc
bool DeleteFileLockInTeardown (zx_koid_t owner)
There is no guard here, as the connection is in teardown.
Defined at line 114 of file ../../src/storage/lib/vfs/cpp/vnode.cc
void Notify (std::string_view name, fuchsia_io::wire::WatchEvent event)
Invoked by the VFS layer whenever files are added or removed.
Defined at line 153 of file ../../src/storage/lib/vfs/cpp/vnode.h
zx_status_t Close ()
Closes the vnode. Will be called once for each successful Open().
Vnode implementations should override CloseNode() which this function calls after some
bookkeeping.
Defined at line 156 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Read (void * data, size_t len, size_t off, size_t * out_actual)
Read data from the vnode at offset.
If successful, returns the number of bytes read in |out_actual|. This must be less than or
equal to |len|.
See |CreateStream| for a mechanism to offload |Read| to a |zx::stream| object.
Defined at line 164 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Write (const void * data, size_t len, size_t offset, size_t * out_actual)
Write |len| bytes of |data| to the file, starting at |offset|.
If successful, returns the number of bytes written in |out_actual|. This must be less than or
equal to |len|.
See |CreateStream| for a mechanism to offload |Write| to a |zx::stream| object.
Defined at line 168 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Append (const void * data, size_t len, size_t * out_end, size_t * out_actual)
Write |len| bytes of |data| to the end of the file.
If successful, returns the number of bytes written in |out_actual|, and
returns the new end of file offset in |out_end|.
See |CreateStream| for a mechanism to offload |Append| to a |zx::stream| object.
Defined at line 172 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Truncate (size_t len)
Change the size of the vnode.
Defined at line 199 of file ../../src/storage/lib/vfs/cpp/vnode.cc
void Sync (SyncCallback closure)
Defined at line 210 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Readdir (VdirCookie * cookie, void * dirents, size_t len, size_t * out_actual)
Read directory entries of vn, error if not a directory. FS-specific Cookie must be a buffer of
VdirCookie size or smaller. Cookie must be zero'd before first call and will be used by the
readdir implementation to maintain state across calls. To "rewind" and start from the
beginning, cookie may be zero'd.
Defined at line 189 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Lookup (std::string_view name, fbl::RefPtr<Vnode> * out)
Attempt to find child of vn, child returned on success.
Defined at line 176 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx::result<fs::VnodeAttributes> GetAttributes ()
Get attributes of the vnode.
Defined at line 180 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx::result<> UpdateAttributes (const VnodeAttributesUpdate & attributes)
Update attributes of the vnode. Only those attributes specified by
|SupportedMutableAttributes()| will be specified in |attributes|.
Defined at line 185 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx::result<fbl::RefPtr<Vnode>> Create (std::string_view name, CreationType type)
Create a new object with specified |name| and |type| under this Vnode. On success, the newly
created Vnode must already be opened (i.e. |Open()| will not be called on the result).
Defined at line 193 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Unlink (std::string_view name, bool must_be_dir)
Removes name from directory vn
Defined at line 197 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Rename (fbl::RefPtr<Vnode> newdir, std::string_view oldname, std::string_view newname, bool src_must_be_dir, bool dst_must_be_dir)
Renames the path at oldname in olddir to the path at newname in newdir. Called on the "olddir"
vnode.
Unlinks any prior newname if it already exists.
Defined at line 201 of file ../../src/storage/lib/vfs/cpp/vnode.cc
zx_status_t Link (std::string_view name, fbl::RefPtr<Vnode> target)
Creates a hard link to the 'target' vnode with a provided name in vndir
Defined at line 206 of file ../../src/storage/lib/vfs/cpp/vnode.cc
bool IsRemote ()
Returns true if this is a remote filesystem mount point. This is only relevant on Fuchsia
builds (the remote handling below is all Fuchsia-only) but this can exist and just return false
on host builds to simplify platform handling.
Defined at line 212 of file ../../src/storage/lib/vfs/cpp/vnode.cc
VnodeAttributesQuery SupportedMutableAttributes ()
Returns the set of attributes this vnode supports. Requests to update attributes which the
vnode does not support will be rejected.
Defined at line 274 of file ../../src/storage/lib/vfs/cpp/vnode.h
Protected Methods
void Vnode (const Vnode & )
Defined at line 303 of file ../../src/storage/lib/vfs/cpp/vnode.h
void Vnode (Vnode && )
Defined at line 303 of file ../../src/storage/lib/vfs/cpp/vnode.h
Vnode & operator= (const Vnode & )
Defined at line 303 of file ../../src/storage/lib/vfs/cpp/vnode.h
Vnode & operator= (Vnode && )
Defined at line 303 of file ../../src/storage/lib/vfs/cpp/vnode.h
void RecycleNode ()
Implementation of fbl_recycle(). Normal fbl_recycle() use is non-virtual and requires different
inheritance paths to fbl::Recyclable. This virtual implementation allows there to be one
implementation.
This function is called when the object reference count drops to 0. This default implementation
just deletes the object to get "normal" reference counting. Derived classes can override to
implement caching if desired.
See the class comment above on recycling, this is subtle.
Defined at line 314 of file ../../src/storage/lib/vfs/cpp/vnode.h
zx_status_t OpenNode (fbl::RefPtr<Vnode> * out_redirect)
Opens/Closes the vnode. These are the callbacks that the Vnode implementation overrides to do
the open and close work. They are called by the public Open() and Close() functions which
handles bookkeeping for the base class.
The open_count() will be updated BEFORE each call. If OpenNode fails, the open count will be
rolled back.
See Open() above for documentation.
Defined at line 324 of file ../../src/storage/lib/vfs/cpp/vnode.h
zx_status_t CloseNode ()
Defined at line 327 of file ../../src/storage/lib/vfs/cpp/vnode.h
void Vnode ()
Defined at line 329 of file ../../src/storage/lib/vfs/cpp/vnode.h
size_t open_count ()
Returns the number of open connections, not counting node_reference connections. See Open().
Defined at line 336 of file ../../src/storage/lib/vfs/cpp/vnode.h