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@217 | 18 | An overview of the component interactions involved in opening a file or |
paul@217 | 19 | directory is 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@217 | 32 | node [label="Client"]; |
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@217 | 40 | |
paul@188 | 41 | Memory [label="filename",shape=note]; |
paul@183 | 42 | } |
paul@183 | 43 | |
paul@183 | 44 | subgraph { |
paul@217 | 45 | rank=max; |
paul@217 | 46 | |
paul@183 | 47 | Filesystem; |
paul@142 | 48 | |
paul@183 | 49 | subgraph { |
paul@183 | 50 | node [label="Opener\n(user)"]; |
paul@183 | 51 | Opener1; Opener2; |
paul@183 | 52 | } |
paul@183 | 53 | |
paul@183 | 54 | subgraph { |
paul@183 | 55 | node [label="OpenerContext"]; |
paul@188 | 56 | OpenerContext1; OpenerContext2; OpenerContext3; |
paul@183 | 57 | } |
paul@183 | 58 | |
paul@217 | 59 | Object [label="MappedFile\nor\nDirectory"]; |
paul@183 | 60 | } |
paul@183 | 61 | |
paul@381 | 62 | Client1 -> Client2 -> Client3 -> Client4 -> Client5 -> Client6 -> Client7 [dir=none,style=dotted]; |
paul@381 | 63 | Opener1 -> Opener2 [dir=none,style=dotted]; |
paul@381 | 64 | OpenerContext1 -> OpenerContext2 -> OpenerContext3 [dir=none,style=dotted]; |
paul@142 | 65 | |
paul@183 | 66 | Client1 -> Filesystem [label="open_for_user(user)"]; |
paul@183 | 67 | Filesystem -> Opener1; |
paul@188 | 68 | Opener1 -> Client2; |
paul@183 | 69 | |
paul@183 | 70 | Client3 -> Opener2 [label="context()"]; |
paul@183 | 71 | Opener2 -> OpenerContext1; |
paul@188 | 72 | OpenerContext1 -> Client4; |
paul@188 | 73 | |
paul@188 | 74 | Client5 -> Memory -> OpenerContext2; |
paul@183 | 75 | |
paul@188 | 76 | Client6 -> OpenerContext3 [label="open(flags, ...)"]; |
paul@217 | 77 | OpenerContext3 -> Object; |
paul@217 | 78 | Object -> Client7; |
paul@183 | 79 | } |
paul@183 | 80 | }}} |
paul@183 | 81 | |
paul@183 | 82 | ######## |
paul@183 | 83 | |
paul@190 | 84 | In pseudocode, the operations as conducted by the client program are as |
paul@190 | 85 | follows: |
paul@190 | 86 | |
paul@190 | 87 | {{{ |
paul@190 | 88 | opener = filesystem.open_for_user(user) |
paul@190 | 89 | context = opener.context() |
paul@190 | 90 | context.write("filename") # this being a memory access operation |
paul@190 | 91 | file = context.open(flags, ...) |
paul@190 | 92 | }}} |
paul@190 | 93 | |
paul@217 | 94 | Reading from an opened directory is achieved as shown in the following |
paul@217 | 95 | diagram. |
paul@217 | 96 | |
paul@217 | 97 | ######## A graph showing the interactions between components |
paul@217 | 98 | |
paul@217 | 99 | {{{#!graphviz |
paul@217 | 100 | #format svg |
paul@217 | 101 | #transform notugly |
paul@217 | 102 | digraph components { |
paul@217 | 103 | node [fontsize="12.0",fontname="sans-serif",shape=box]; |
paul@217 | 104 | edge [fontsize="12.0",fontname="sans-serif"]; |
paul@217 | 105 | rankdir=LR; |
paul@217 | 106 | |
paul@217 | 107 | subgraph { |
paul@217 | 108 | node [label="Client"]; |
paul@217 | 109 | rank=min; |
paul@217 | 110 | |
paul@217 | 111 | Client1; Client2; Client3; Client4; |
paul@217 | 112 | } |
paul@217 | 113 | |
paul@217 | 114 | subgraph { |
paul@217 | 115 | rank=same; |
paul@217 | 116 | |
paul@217 | 117 | Memory [label="entries",shape=note]; |
paul@217 | 118 | } |
paul@217 | 119 | |
paul@217 | 120 | subgraph { |
paul@217 | 121 | rank=max; |
paul@217 | 122 | |
paul@217 | 123 | Directory; |
paul@217 | 124 | |
paul@217 | 125 | subgraph { |
paul@217 | 126 | node [label="Reader"]; |
paul@217 | 127 | |
paul@217 | 128 | Reader1; Reader2; Reader3; |
paul@217 | 129 | } |
paul@217 | 130 | } |
paul@217 | 131 | |
paul@381 | 132 | Client1 -> Client2 -> Client3 -> Client4 [dir=none,style=dotted]; |
paul@381 | 133 | Reader1 -> Reader2 -> Reader3 [dir=none,style=dotted]; |
paul@217 | 134 | |
paul@217 | 135 | Client1 -> Directory [label="opendir()"]; |
paul@217 | 136 | Directory -> Reader1; |
paul@217 | 137 | Reader1 -> Client2; |
paul@217 | 138 | |
paul@217 | 139 | Client3 -> Reader2 [label="current_region()"]; |
paul@217 | 140 | Reader3 -> Memory -> Client4; |
paul@217 | 141 | } |
paul@217 | 142 | }}} |
paul@217 | 143 | |
paul@217 | 144 | ######## |
paul@217 | 145 | |
paul@217 | 146 | In pseudocode, the operations as conducted by the client program are as |
paul@217 | 147 | follows: |
paul@217 | 148 | |
paul@217 | 149 | {{{ |
paul@217 | 150 | reader = directory.opendir() |
paul@217 | 151 | reader.current_region() |
paul@217 | 152 | entries = reader.read() # this being a memory access operation |
paul@217 | 153 | }}} |
paul@217 | 154 | |
paul@183 | 155 | == Filesystems == |
paul@142 | 156 | |
paul@144 | 157 | Filesystems implement the `Filesystem` interface which provides the |
paul@144 | 158 | `open_for_user` operation: |
paul@144 | 159 | |
paul@144 | 160 | {{{ |
paul@172 | 161 | open_for_user(in user_t user, out cap opener) |
paul@144 | 162 | }}} |
paul@144 | 163 | |
paul@183 | 164 | The operation yields a file opener appropriate for the given [[Users|user]] |
paul@183 | 165 | credentials. |
paul@144 | 166 | |
paul@398 | 167 | == File and Directory Openers == |
paul@144 | 168 | |
paul@398 | 169 | openers implement the `Opener` interface which provides the `context` |
paul@142 | 170 | operation: |
paul@142 | 171 | |
paul@142 | 172 | {{{ |
paul@142 | 173 | context(out cap context) |
paul@142 | 174 | }}} |
paul@142 | 175 | |
paul@142 | 176 | Each client program, task or thread obtains its own context because it will |
paul@142 | 177 | need its own dedicated channel for communication with the filesystem. |
paul@142 | 178 | |
paul@183 | 179 | == Opener Contexts == |
paul@142 | 180 | |
paul@183 | 181 | An opener context acts as a dataspace, meaning that it can be attached to a |
paul@183 | 182 | task using a region manager and provide a buffer via a region of mapped memory |
paul@183 | 183 | that the task can write to. In the case of a context, the task will write a |
paul@183 | 184 | filesystem path indicating the file to be opened. |
paul@142 | 185 | |
paul@142 | 186 | Each context allows a client program to request access to individual files via |
paul@142 | 187 | operations provided by the `OpenerContext` interface, of which the most |
paul@142 | 188 | pertinent is the `open` operation: |
paul@142 | 189 | |
paul@142 | 190 | {{{ |
paul@172 | 191 | open(in flags_t flags, out offset_t size, out cap file, |
paul@172 | 192 | out object_flags_t object_flags) |
paul@142 | 193 | }}} |
paul@142 | 194 | |
paul@142 | 195 | Using the path information written to the context's memory region, the `open` |
paul@172 | 196 | operation will obtain a reference to a file-like object whose characteristics |
paul@172 | 197 | are described by the accompanying `object_flags`, these helping the client to |
paul@172 | 198 | distinguish between files that support arbitrary memory mapping operations and |
paul@172 | 199 | pipes that mandate sequential region-by-region access. |
paul@172 | 200 | |
paul@172 | 201 | Alongside regular files, directories may also be opened. Reading from them |
paul@172 | 202 | yields a listing of directory entries. |
paul@142 | 203 | |
paul@270 | 204 | === Removing === |
paul@270 | 205 | |
paul@270 | 206 | Filesystem objects are removed by invoking the `remove` operation on an opener |
paul@270 | 207 | context: |
paul@270 | 208 | |
paul@270 | 209 | {{{ |
paul@270 | 210 | remove() |
paul@270 | 211 | }}} |
paul@270 | 212 | |
paul@270 | 213 | The path information identifying the object must first be written to the |
paul@270 | 214 | context's memory region. |
paul@270 | 215 | |
paul@270 | 216 | === Renaming === |
paul@270 | 217 | |
paul@270 | 218 | Filesystem objects are renamed by invoking the `rename` operation on an opener |
paul@270 | 219 | context: |
paul@270 | 220 | |
paul@270 | 221 | {{{ |
paul@270 | 222 | rename() |
paul@270 | 223 | }}} |
paul@270 | 224 | |
paul@270 | 225 | The path information of the affected object and the destination of the rename |
paul@270 | 226 | operation must first be written to the context's memory region. The |
paul@270 | 227 | destination path follows immediately after the terminating byte of the |
paul@270 | 228 | affected path. |
paul@270 | 229 | |
paul@270 | 230 | === Statistics/Metadata === |
paul@270 | 231 | |
paul@270 | 232 | Statistics or metadata for a filesystem object can be obtained by invoking the |
paul@270 | 233 | `stat` operation on an opener context: |
paul@270 | 234 | |
paul@270 | 235 | {{{ |
paul@270 | 236 | stat() |
paul@270 | 237 | }}} |
paul@270 | 238 | |
paul@270 | 239 | The path information identifying the object must first be written to the |
paul@270 | 240 | context's memory region. As a result of the invocation, a `stat` data |
paul@270 | 241 | structure will be written to the start of the memory region. |
paul@270 | 242 | |
paul@183 | 243 | == Files == |
paul@142 | 244 | |
paul@142 | 245 | Files themselves act as dataspaces, meaning that they can be attached to a |
paul@142 | 246 | task using a region manager and provide their content via a region of mapped |
paul@142 | 247 | memory. Files implement the `MappedFile` interface. |
paul@142 | 248 | |
paul@142 | 249 | Control over the region of the file provided via mapped memory occurs |
paul@142 | 250 | using the `mmap` operation: |
paul@142 | 251 | |
paul@142 | 252 | {{{ |
paul@142 | 253 | mmap(in offset_t position, in offset_t length, |
paul@359 | 254 | in offset_t start_visible, in offset_t end_visible, |
paul@142 | 255 | out offset_t start_pos, out offset_t end_pos, |
paul@142 | 256 | out offset_t size) |
paul@142 | 257 | }}} |
paul@142 | 258 | |
paul@142 | 259 | Files also implement the more general `File` interface that provides the |
paul@142 | 260 | `resize` operation: |
paul@142 | 261 | |
paul@142 | 262 | {{{ |
paul@142 | 263 | resize(inout offset_t size) |
paul@142 | 264 | }}} |
paul@142 | 265 | |
paul@142 | 266 | This allows the portion of the memory region dedicated to the file's contents |
paul@142 | 267 | to be extended. |
paul@142 | 268 | |
paul@183 | 269 | == Directories == |
paul@172 | 270 | |
paul@217 | 271 | Directories are obtained, like files, using the `open` operation. They |
paul@217 | 272 | implement the `Directory` interface. |
paul@217 | 273 | |
paul@217 | 274 | To read directory listings, the `opendir` operation is used to obtain a |
paul@217 | 275 | directory reader: |
paul@217 | 276 | |
paul@217 | 277 | {{{ |
paul@217 | 278 | opendir(out offset_t size, out cap file, out object_flags_t object_flags) |
paul@217 | 279 | }}} |
paul@217 | 280 | |
paul@217 | 281 | Directory readers are meant to be accessed like files, meaning that it should |
paul@172 | 282 | be possible to attach them to a task using a region manager and access the |
paul@172 | 283 | provided content, this being a listing of directory entries, via the mapped |
paul@172 | 284 | region. |
paul@172 | 285 | |
paul@172 | 286 | However, unlike files which may support arbitrary mapping of their contents, |
paul@172 | 287 | the provided content may be supplied by a pipe endpoint, thereby not |
paul@172 | 288 | supporting precisely the same navigation mechanisms as those supported by |
paul@172 | 289 | files. |
paul@172 | 290 | |
paul@183 | 291 | == Pipe Openers == |
paul@172 | 292 | |
paul@172 | 293 | Distinct from filesystems but potentially used by them, pipe openers provide a |
paul@172 | 294 | means of obtaining pipes, which are channels that support unidirectional |
paul@172 | 295 | communication via shared memory. |
paul@172 | 296 | |
paul@172 | 297 | Pipe openers implement the `PipeOpener` interface and support the following |
paul@172 | 298 | operation: |
paul@172 | 299 | |
paul@172 | 300 | {{{ |
paul@172 | 301 | pipe(in offset_t size, out cap reader, out cap writer) |
paul@172 | 302 | }}} |
paul@172 | 303 | |
paul@172 | 304 | The size is indicated to request pipe regions long enough for the needs of the |
paul@172 | 305 | communicating parties, with both reader and writer endpoint capabilities being |
paul@172 | 306 | returned. Such capabilities may be propagated to the eventual parties, these |
paul@172 | 307 | typically being separate tasks. |
paul@172 | 308 | |
paul@183 | 309 | == Pipes == |
paul@172 | 310 | |
paul@172 | 311 | Although not generally obtained from filesystems, pipes may be involved in |
paul@172 | 312 | providing content from some filesystem objects such as directories. However, |
paul@172 | 313 | they are also obtained directly from an appropriate pipe server providing pipe |
paul@172 | 314 | opening facilities. |
paul@172 | 315 | |
paul@172 | 316 | Pipes expose single regions of shared memory to their endpoints, with the |
paul@172 | 317 | writing endpoint populating one region while the reading endpoint accesses the |
paul@172 | 318 | other. The reading endpoint may advance to the region being written, and this |
paul@172 | 319 | will free up a new region for the writer when it has filled its region. When |
paul@172 | 320 | the writer itself advances, it permits the reader to consume all data in the |
paul@172 | 321 | fully populated region. Naturally, the reader may not advance ahead of the |
paul@172 | 322 | writer. |
paul@172 | 323 | |
paul@172 | 324 | Pipes implement the `Pipe` interface and a number of operations to support |
paul@172 | 325 | this interaction mechanism. |
paul@172 | 326 | |
paul@172 | 327 | The details of an endpoint's current region can be queried using the following |
paul@172 | 328 | operation: |
paul@172 | 329 | |
paul@172 | 330 | {{{ |
paul@172 | 331 | current_region(out offset_t populated_size, out offset_t size) |
paul@172 | 332 | }}} |
paul@172 | 333 | |
paul@172 | 334 | This provides details of the populated size (or amount of written data) in a |
paul@172 | 335 | region along with the size of the region. |
paul@172 | 336 | |
paul@172 | 337 | Navigation to the next available region of the pipe is performed using the |
paul@172 | 338 | following operation: |
paul@172 | 339 | |
paul@172 | 340 | {{{ |
paul@172 | 341 | next_region(inout offset_t populated_size, out offset_t size) |
paul@172 | 342 | }}} |
paul@172 | 343 | |
paul@172 | 344 | Here, the populated size may be specified by the writer so that the reader may |
paul@172 | 345 | query the current region's properties using the appropriate operation. |
paul@172 | 346 | |
paul@172 | 347 | The status of the pipe can be queried using the `closed` operation: |
paul@172 | 348 | |
paul@172 | 349 | {{{ |
paul@172 | 350 | closed(out int closed) |
paul@172 | 351 | }}} |
paul@172 | 352 | |
paul@172 | 353 | This indicates through a boolean-equivalent parameter whether one or both |
paul@172 | 354 | endpoints have been closed. |