-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add high level filesystem documention
From nextcloud/server#26982 Adds some documentation for the filesystem layer, both a high level overview of how the various pieces interact and a high level guide for apps interacting with the filesystem. Hopefully this will be useful to anyone trying to either use the filesystem or work on the filesystem. Signed-off-by: Louis Chemineau <louis@chmn.me>
- Loading branch information
Showing
2 changed files
with
235 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
============ | ||
Nextcloud filesystem API | ||
============ | ||
|
||
High level overview | ||
------------------- | ||
|
||
The Nextcloud filesystem is roughly based on the unix filesystem, consisting of multiple storages | ||
mounted at various locations. | ||
|
||
.. code-block:: txt | ||
ββββββββββββββββββββββββββββββββββββ | ||
βCode wanting to use the filesystemβ | ||
βββββββββββ¬ββββββββββββββββββββββ¬βββ | ||
β β | ||
β β | ||
ββββββββββββββββββββββββββββββββββββββββββββββββ | ||
βFilesystem β β β | ||
βlayer βnew βlegacy β | ||
β β β β | ||
β βΌ βΌ β | ||
β ββββββββββ Partly build on βββ΄βββββββ β | ||
β βNode APIβββββββββββββββββββΊβView APIβ β | ||
β βββββββββ¬β βββ¬βββββββ β | ||
β β β β | ||
ββββββββββββββββββββββββββββββββββββββββββββββββ | ||
β β | ||
ββββββββββββββββββββββββββββββββββββββββββββββββ | ||
βStorage layer β β β | ||
β βββββββββββββββββββββββ€ β | ||
β β β β | ||
β βΌ βΌ β | ||
β βββββββββ βββββββββ ββββββββ β | ||
β βStorageββββ>βScannerββββ>βCache β β | ||
β βββββββββ βββββββββ ββββββββ β | ||
β β | ||
β β | ||
ββββββββββββββββββββββββββββββββββββββββββββββββ | ||
Filesystem layer | ||
^^^^^^^^^^^^^^^^ | ||
|
||
Any code that wants to use the filesystem has two API options to use, the new ``Node`` api and the old ``View`` api. | ||
New code should preferably use the ``Node`` api as it allows building systems with less overhead than the old api. | ||
|
||
Besides the filesystem apis, this layer also manages the available mounts, containing the logic to allow apps | ||
to setup their mounts and translating filesystem paths into a mountpoint + "internal" path. | ||
|
||
### Storage layer | ||
|
||
The storage implementation handles the details of communicating with the filesystem or remote storage api | ||
and provide a uniform api for Nextcloud to use the storage. | ||
|
||
For each storage a metadata cache/index is maintained to allow reading metadata of the storage without having | ||
to talk to the (potentially) slow storage backend. The scanner is responsible for updating the cache with | ||
information from the storage backend. | ||
|
||
## Storage/Cache wrappers | ||
|
||
To allow apps to customize the behavior of a storage without requiring the app to implement this for every | ||
possible storage backend, a ``Wrapper`` system is used. | ||
|
||
A ``Wrapper`` encapsulates an inner storage and allows overwriting any method to customize its behavior, with | ||
all other methods being passed through to the inner storage. | ||
|
||
Generally search storage wrapper has an equivalent cache wrapper encapsulating the cache of the inner storage | ||
to provide the same behavior modifications when reading metadata from the cache. | ||
|
||
Wrappers can be layered to stack the behavior of the wrappers, for example the ``groupfolders`` app works by | ||
stacking a wrapper to provide access to a single folder on the root storage with a wrapper to limit the permissions | ||
of the storage. | ||
|
||
.. code-block:: txt | ||
βββββββββββββββββ ββββββββββββββββββββββ | ||
βPermissionsMaskβββββββΊβCachePermissionsMaskβ PermissionsMask applies a mask to the permissions of a storage | ||
βββββββββ¬ββββββββ βββββββββββ¬βββββββββββ to provide less-privilaged access to a storage | ||
β β | ||
βΌ βΌ | ||
βββββββββββββββββ ββββββββββββββββββββββ | ||
βJail βββββββΊβCacheJail β Jail restricts access to a file or folder of a storage providing | ||
βββββββββ¬ββββββββ βββββββββββ¬βββββββββββ a limited view into the storage (think unix chroot or bind mount) | ||
β β | ||
βΌ βΌ | ||
βββββββββββββββββ ββββββββββββββββββββββ | ||
βBase Storage βββββββΊβBase Cache β | ||
βββββββββββββββββ ββββββββββββββββββββββ | ||
Code Map | ||
-------- | ||
|
||
Approximate overview of the significant filesystem code | ||
|
||
AppData | ||
~~~~~~~ | ||
|
||
High level api for accessing "appdata" folders, based on the ``Node`` API | ||
|
||
Cache | ||
~~~~~ | ||
|
||
- ``Cache`` implementation | ||
- Cache wrappers | ||
- Scanner and cache update logic | ||
- Search infrastructure | ||
|
||
Mount | ||
~~~~~ | ||
|
||
Mountpoint management and setup | ||
|
||
Node | ||
~~~~ | ||
|
||
``Node`` filesystem api implementation | ||
|
||
ObjectStorage | ||
~~~~~~~~~~~~~ | ||
|
||
Implementation of the various supported object store storage backends | ||
|
||
SimpleFS | ||
~~~~~~~~ | ||
|
||
Simplified version of the Node api, for providing a more limited api for some filesystem bits | ||
|
||
Storage | ||
~~~~~~~ | ||
|
||
Implementation of various storage backends and wrappers | ||
|
||
Streams | ||
~~~~~~~ | ||
|
||
Various low-level php stream wrapper used in storage implementations | ||
|
||
Type | ||
~~~~ | ||
|
||
Mimetype management and detection | ||
|
||
View.php | ||
~~~~~~~~ | ||
|
||
Legacy View api |