xref: /aosp_15_r20/external/pigweed/pw_file/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_file:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker=======
4*61c4878aSAndroid Build Coastguard Workerpw_file
5*61c4878aSAndroid Build Coastguard Worker=======
6*61c4878aSAndroid Build Coastguard Worker
7*61c4878aSAndroid Build Coastguard Worker.. attention::
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard Worker  ``pw_file`` is under construction, and may see significant breaking API
10*61c4878aSAndroid Build Coastguard Worker  changes.
11*61c4878aSAndroid Build Coastguard Worker
12*61c4878aSAndroid Build Coastguard WorkerThe ``pw_file`` module defines a service for file system-like interactions
13*61c4878aSAndroid Build Coastguard Workerbetween a client and server. FileSystem services may be backed by true file
14*61c4878aSAndroid Build Coastguard Workersystems, or by virtual file systems that provide a file-system like interface
15*61c4878aSAndroid Build Coastguard Workerwith no true underlying file system.
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard Workerpw_file does not define a protocol for file transfers.
18*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_transfer` provides a generalized mechanism for
19*61c4878aSAndroid Build Coastguard Workerperforming file transfers, and is recommended to be used in tandem with pw_file.
20*61c4878aSAndroid Build Coastguard Worker
21*61c4878aSAndroid Build Coastguard Worker-----------
22*61c4878aSAndroid Build Coastguard WorkerRPC service
23*61c4878aSAndroid Build Coastguard Worker-----------
24*61c4878aSAndroid Build Coastguard WorkerThe FileSystem RPC service is oriented to allow direct interaction, and has no
25*61c4878aSAndroid Build Coastguard Workersequenced protocol. Unlike FTP, all interactions are stateless. This service
26*61c4878aSAndroid Build Coastguard Workeralso does not yet define any authentication mechanism, meaning that all clients
27*61c4878aSAndroid Build Coastguard Workerthat can access a FileSystem service are granted equal permissions.
28*61c4878aSAndroid Build Coastguard Worker
29*61c4878aSAndroid Build Coastguard Worker.. literalinclude:: file.proto
30*61c4878aSAndroid Build Coastguard Worker  :language: protobuf
31*61c4878aSAndroid Build Coastguard Worker  :lines: 14-
32*61c4878aSAndroid Build Coastguard Worker
33*61c4878aSAndroid Build Coastguard Worker------------------------------
34*61c4878aSAndroid Build Coastguard WorkerFlat FileSystem implementation
35*61c4878aSAndroid Build Coastguard Worker------------------------------
36*61c4878aSAndroid Build Coastguard WorkerThis module provides the ``FlatFileSystemService``, an optional implementation
37*61c4878aSAndroid Build Coastguard Workerof the FileSystem RPC service with a virtual interface that allows different
38*61c4878aSAndroid Build Coastguard Workerdata storage implementations to expose logical files. As the name implies, the
39*61c4878aSAndroid Build Coastguard Workerfile system is treated as a flat file system; it does not support any
40*61c4878aSAndroid Build Coastguard Workerdirectory-like interactions.
41*61c4878aSAndroid Build Coastguard Worker
42*61c4878aSAndroid Build Coastguard WorkerThe ``FlatFileSystemService`` implementation requires a static, fixed list of
43*61c4878aSAndroid Build Coastguard Worker``Entry`` pointers. Each ``Entry`` represents a potential
44*61c4878aSAndroid Build Coastguard Workerfile, and acts as an interface boundary that is backed by some kind of storage
45*61c4878aSAndroid Build Coastguard Workermechanism (e.g. ``BlobStore``, ``PersistentBuffer``).
46*61c4878aSAndroid Build Coastguard Worker
47*61c4878aSAndroid Build Coastguard WorkerAll ``Entry`` objects that should be enumerated by a
48*61c4878aSAndroid Build Coastguard Worker``FlatFileSystemService`` MUST be named, and names must be globally unique to
49*61c4878aSAndroid Build Coastguard Workerprevent ambiguity. Unnamed file entries will NOT be enumerated by a
50*61c4878aSAndroid Build Coastguard Worker``FlatFileSystemService``, and are considered empty/deleted files. It is valid
51*61c4878aSAndroid Build Coastguard Workerto have empty files that are enumerated with a name.
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Worker``FlatFileSystemService`` requires two buffers at construction: one buffer for
54*61c4878aSAndroid Build Coastguard Workerreading file names and another for encoding protobuf responses. The recommended
55*61c4878aSAndroid Build Coastguard Workerencoding buffer size for a particular maximum file name length can be calculated
56*61c4878aSAndroid Build Coastguard Workerwith ``EncodingBufferSizeBytes``. For convenience, the
57*61c4878aSAndroid Build Coastguard Worker``FlatFileSystemServiceWithBuffer<kMaxFileNameLength>`` class is provided. That
58*61c4878aSAndroid Build Coastguard Workerclass creates a ``FlatFileSystemService`` with a buffer automatically sized
59*61c4878aSAndroid Build Coastguard Workerbased on the maximum file name length.
60