paul@183 | 1 | = Components = |
paul@142 | 2 | |
paul@142 | 3 | Access to files is provided by a number of programs acting as components. For |
paul@183 | 4 | convenience, the component-level operations are wrapped up in a |
paul@183 | 5 | [[ClientLibrary|client library]] that aims to provide simpler, more familiar |
paul@183 | 6 | mechanisms for opening, reading, writing, and closing files, together with |
paul@183 | 7 | various other operations. |
paul@142 | 8 | |
paul@142 | 9 | <<TableOfContents(2,3)>> |
paul@142 | 10 | |
paul@183 | 11 | Components are accessed via interfaces defined using the interface description |
paul@183 | 12 | language supported by the ``idl4re`` tool. Interface operations in this |
paul@183 | 13 | document are described using excerpts from the appropriate interface |
paul@183 | 14 | descriptions. |
paul@183 | 15 | |
paul@190 | 16 | == Overview == |
paul@190 | 17 | |
paul@190 | 18 | An overview of the component interactions involved in opening a file is |
paul@190 | 19 | provided by the diagram below. |
paul@190 | 20 | |
paul@183 | 21 | ######## A graph showing the interactions between components |
paul@183 | 22 | |
paul@183 | 23 | {{{#!graphviz |
paul@183 | 24 | #format svg |
paul@183 | 25 | #transform notugly |
paul@183 | 26 | digraph components { |
paul@183 | 27 | node [fontsize="12.0",fontname="sans-serif",shape=box]; |
paul@183 | 28 | edge [fontsize="12.0",fontname="sans-serif"]; |
paul@183 | 29 | rankdir=LR; |
paul@183 | 30 | |
paul@183 | 31 | subgraph { |
paul@183 | 32 | node [label="Client",style=solid,color="#000000",fontcolor="#000000"]; |
paul@183 | 33 | rank=min; |
paul@183 | 34 | |
paul@188 | 35 | Client1; Client2; Client3; Client4; Client5; Client6; Client7; |
paul@188 | 36 | } |
paul@183 | 37 | |
paul@188 | 38 | subgraph { |
paul@188 | 39 | rank=same; |
paul@188 | 40 | Memory [label="filename",shape=note]; |
paul@183 | 41 | } |
paul@183 | 42 | |
paul@183 | 43 | subgraph { |
paul@183 | 44 | rank=same; |
paul@183 | 45 | Filesystem; |
paul@142 | 46 | |
paul@183 | 47 | subgraph { |
paul@183 | 48 | node [label="Opener\n(user)"]; |
paul@183 | 49 | Opener1; Opener2; |
paul@183 | 50 | } |
paul@183 | 51 | |
paul@183 | 52 | subgraph { |
paul@183 | 53 | node [label="OpenerContext"]; |
paul@188 | 54 | OpenerContext1; OpenerContext2; OpenerContext3; |
paul@183 | 55 | } |
paul@183 | 56 | |
paul@183 | 57 | MappedFile; |
paul@183 | 58 | } |
paul@183 | 59 | |
paul@189 | 60 | Client1 -> Client2 -> Client3 -> Client4 -> Client5 -> Client6 -> Client7 [arrowhead=none,style=dotted]; |
paul@188 | 61 | Opener1 -> Opener2 [arrowhead=none,style=dotted]; |
paul@188 | 62 | OpenerContext1 -> OpenerContext2 -> OpenerContext3 [arrowhead=none,style=dotted]; |
paul@142 | 63 | |
paul@183 | 64 | Client1 -> Filesystem [label="open_for_user(user)"]; |
paul@183 | 65 | Filesystem -> Opener1; |
paul@188 | 66 | Opener1 -> Client2; |
paul@183 | 67 | |
paul@183 | 68 | Client3 -> Opener2 [label="context()"]; |
paul@183 | 69 | Opener2 -> OpenerContext1; |
paul@188 | 70 | OpenerContext1 -> Client4; |
paul@188 | 71 | |
paul@188 | 72 | Client5 -> Memory -> OpenerContext2; |
paul@183 | 73 | |
paul@188 | 74 | Client6 -> OpenerContext3 [label="open(flags, ...)"]; |
paul@188 | 75 | OpenerContext3 -> MappedFile; |
paul@188 | 76 | MappedFile -> Client7; |
paul@183 | 77 | } |
paul@183 | 78 | }}} |
paul@183 | 79 | |
paul@183 | 80 | ######## |
paul@183 | 81 | |
paul@190 | 82 | In pseudocode, the operations as conducted by the client program are as |
paul@190 | 83 | follows: |
paul@190 | 84 | |
paul@190 | 85 | {{{ |
paul@190 | 86 | opener = filesystem.open_for_user(user) |
paul@190 | 87 | context = opener.context() |
paul@190 | 88 | context.write("filename") # this being a memory access operation |
paul@190 | 89 | file = context.open(flags, ...) |
paul@190 | 90 | }}} |
paul@190 | 91 | |
paul@183 | 92 | == Filesystems == |
paul@142 | 93 | |
paul@144 | 94 | Filesystems implement the `Filesystem` interface which provides the |
paul@144 | 95 | `open_for_user` operation: |
paul@144 | 96 | |
paul@144 | 97 | {{{ |
paul@172 | 98 | open_for_user(in user_t user, out cap opener) |
paul@144 | 99 | }}} |
paul@144 | 100 | |
paul@183 | 101 | The operation yields a file opener appropriate for the given [[Users|user]] |
paul@183 | 102 | credentials. |
paul@144 | 103 | |
paul@183 | 104 | == File Openers == |
paul@144 | 105 | |
paul@144 | 106 | File openers implement the `Opener` interface which provides the `context` |
paul@142 | 107 | operation: |
paul@142 | 108 | |
paul@142 | 109 | {{{ |
paul@142 | 110 | context(out cap context) |
paul@142 | 111 | }}} |
paul@142 | 112 | |
paul@142 | 113 | Each client program, task or thread obtains its own context because it will |
paul@142 | 114 | need its own dedicated channel for communication with the filesystem. |
paul@142 | 115 | |
paul@183 | 116 | == Opener Contexts == |
paul@142 | 117 | |
paul@183 | 118 | An opener context acts as a dataspace, meaning that it can be attached to a |
paul@183 | 119 | task using a region manager and provide a buffer via a region of mapped memory |
paul@183 | 120 | that the task can write to. In the case of a context, the task will write a |
paul@183 | 121 | filesystem path indicating the file to be opened. |
paul@142 | 122 | |
paul@142 | 123 | Each context allows a client program to request access to individual files via |
paul@142 | 124 | operations provided by the `OpenerContext` interface, of which the most |
paul@142 | 125 | pertinent is the `open` operation: |
paul@142 | 126 | |
paul@142 | 127 | {{{ |
paul@172 | 128 | open(in flags_t flags, out offset_t size, out cap file, |
paul@172 | 129 | out object_flags_t object_flags) |
paul@142 | 130 | }}} |
paul@142 | 131 | |
paul@142 | 132 | Using the path information written to the context's memory region, the `open` |
paul@172 | 133 | operation will obtain a reference to a file-like object whose characteristics |
paul@172 | 134 | are described by the accompanying `object_flags`, these helping the client to |
paul@172 | 135 | distinguish between files that support arbitrary memory mapping operations and |
paul@172 | 136 | pipes that mandate sequential region-by-region access. |
paul@172 | 137 | |
paul@172 | 138 | Alongside regular files, directories may also be opened. Reading from them |
paul@172 | 139 | yields a listing of directory entries. |
paul@142 | 140 | |
paul@183 | 141 | == Files == |
paul@142 | 142 | |
paul@142 | 143 | Files themselves act as dataspaces, meaning that they can be attached to a |
paul@142 | 144 | task using a region manager and provide their content via a region of mapped |
paul@142 | 145 | memory. Files implement the `MappedFile` interface. |
paul@142 | 146 | |
paul@142 | 147 | Control over the region of the file provided via mapped memory occurs |
paul@142 | 148 | using the `mmap` operation: |
paul@142 | 149 | |
paul@142 | 150 | {{{ |
paul@142 | 151 | mmap(in offset_t position, in offset_t length, |
paul@142 | 152 | out offset_t start_pos, out offset_t end_pos, |
paul@142 | 153 | out offset_t size) |
paul@142 | 154 | }}} |
paul@142 | 155 | |
paul@142 | 156 | Files also implement the more general `File` interface that provides the |
paul@142 | 157 | `resize` operation: |
paul@142 | 158 | |
paul@142 | 159 | {{{ |
paul@142 | 160 | resize(inout offset_t size) |
paul@142 | 161 | }}} |
paul@142 | 162 | |
paul@142 | 163 | This allows the portion of the memory region dedicated to the file's contents |
paul@142 | 164 | to be extended. |
paul@142 | 165 | |
paul@183 | 166 | == Directories == |
paul@172 | 167 | |
paul@172 | 168 | Directories are also meant to be accessed like files, meaning that it should |
paul@172 | 169 | be possible to attach them to a task using a region manager and access the |
paul@172 | 170 | provided content, this being a listing of directory entries, via the mapped |
paul@172 | 171 | region. |
paul@172 | 172 | |
paul@172 | 173 | However, unlike files which may support arbitrary mapping of their contents, |
paul@172 | 174 | the provided content may be supplied by a pipe endpoint, thereby not |
paul@172 | 175 | supporting precisely the same navigation mechanisms as those supported by |
paul@172 | 176 | files. |
paul@172 | 177 | |
paul@183 | 178 | '''Note''' that directories may well be redefined to support multiple |
paul@183 | 179 | operations, one of which supporting the file-like access described above. |
paul@183 | 180 | |
paul@183 | 181 | == Pipe Openers == |
paul@172 | 182 | |
paul@172 | 183 | Distinct from filesystems but potentially used by them, pipe openers provide a |
paul@172 | 184 | means of obtaining pipes, which are channels that support unidirectional |
paul@172 | 185 | communication via shared memory. |
paul@172 | 186 | |
paul@172 | 187 | Pipe openers implement the `PipeOpener` interface and support the following |
paul@172 | 188 | operation: |
paul@172 | 189 | |
paul@172 | 190 | {{{ |
paul@172 | 191 | pipe(in offset_t size, out cap reader, out cap writer) |
paul@172 | 192 | }}} |
paul@172 | 193 | |
paul@172 | 194 | The size is indicated to request pipe regions long enough for the needs of the |
paul@172 | 195 | communicating parties, with both reader and writer endpoint capabilities being |
paul@172 | 196 | returned. Such capabilities may be propagated to the eventual parties, these |
paul@172 | 197 | typically being separate tasks. |
paul@172 | 198 | |
paul@183 | 199 | == Pipes == |
paul@172 | 200 | |
paul@172 | 201 | Although not generally obtained from filesystems, pipes may be involved in |
paul@172 | 202 | providing content from some filesystem objects such as directories. However, |
paul@172 | 203 | they are also obtained directly from an appropriate pipe server providing pipe |
paul@172 | 204 | opening facilities. |
paul@172 | 205 | |
paul@172 | 206 | Pipes expose single regions of shared memory to their endpoints, with the |
paul@172 | 207 | writing endpoint populating one region while the reading endpoint accesses the |
paul@172 | 208 | other. The reading endpoint may advance to the region being written, and this |
paul@172 | 209 | will free up a new region for the writer when it has filled its region. When |
paul@172 | 210 | the writer itself advances, it permits the reader to consume all data in the |
paul@172 | 211 | fully populated region. Naturally, the reader may not advance ahead of the |
paul@172 | 212 | writer. |
paul@172 | 213 | |
paul@172 | 214 | Pipes implement the `Pipe` interface and a number of operations to support |
paul@172 | 215 | this interaction mechanism. |
paul@172 | 216 | |
paul@172 | 217 | The details of an endpoint's current region can be queried using the following |
paul@172 | 218 | operation: |
paul@172 | 219 | |
paul@172 | 220 | {{{ |
paul@172 | 221 | current_region(out offset_t populated_size, out offset_t size) |
paul@172 | 222 | }}} |
paul@172 | 223 | |
paul@172 | 224 | This provides details of the populated size (or amount of written data) in a |
paul@172 | 225 | region along with the size of the region. |
paul@172 | 226 | |
paul@172 | 227 | Navigation to the next available region of the pipe is performed using the |
paul@172 | 228 | following operation: |
paul@172 | 229 | |
paul@172 | 230 | {{{ |
paul@172 | 231 | next_region(inout offset_t populated_size, out offset_t size) |
paul@172 | 232 | }}} |
paul@172 | 233 | |
paul@172 | 234 | Here, the populated size may be specified by the writer so that the reader may |
paul@172 | 235 | query the current region's properties using the appropriate operation. |
paul@172 | 236 | |
paul@172 | 237 | The status of the pipe can be queried using the `closed` operation: |
paul@172 | 238 | |
paul@172 | 239 | {{{ |
paul@172 | 240 | closed(out int closed) |
paul@172 | 241 | }}} |
paul@172 | 242 | |
paul@172 | 243 | This indicates through a boolean-equivalent parameter whether one or both |
paul@172 | 244 | endpoints have been closed. |