1 = Mechanisms = 2 3 Within the filesystem server library, a number of different abstractions and 4 mechanisms are employed to provide access to filesystem objects. 5 6 <<TableOfContents(2,3)>> 7 8 The abstractions or components used in the library are organised as follows. 9 10 ######## A graph showing the relationships between library components 11 12 {{{#!graphviz 13 #format svg 14 #transform notugly 15 digraph components { 16 node [fontsize="12.0",fontname="sans-serif",shape=box]; 17 edge [fontsize="12.0",fontname="sans-serif"]; 18 rankdir=LR; 19 20 subgraph { 21 rank=same; 22 23 Resource -> DirectoryResource -> FilePager 24 [dir=none,style=dotted]; 25 } 26 27 subgraph { 28 rank=same; 29 30 Provider -> DirectoryProvider -> FileProvider 31 [dir=none,style=dotted]; 32 } 33 34 subgraph { 35 rank=same; 36 37 Accessor -> Ext2FileAccessor 38 [dir=none,style=dotted]; 39 } 40 41 subgraph { 42 rank=same; 43 44 DirectoryAccessor -> Ext2DirectoryAccessor 45 [dir=none,style=dotted]; 46 } 47 48 subgraph { 49 node [shape=ellipse]; 50 rank=same; 51 52 Directory [label="dir"]; 53 File [label="dir/file"]; 54 } 55 56 DirectoryResource -> DirectoryProvider -> Ext2DirectoryAccessor -> Directory; 57 FilePager -> FileProvider -> Ext2FileAccessor -> File; 58 } 59 }}} 60 61 ######## 62 63 == Accountable == 64 65 This interface provides the following operations: 66 67 {{{ 68 attach() 69 detach(out unsigned int count) 70 }}} 71 72 Its purpose is to provide reference counting for components, with the `attach` 73 operation incrementing the number of users of a component, and with the 74 `detach` operation decrementing the number of users. When components no longer 75 have any attached users, they may perform operations to tidy up after 76 themselves and permit their deallocation. 77 78 == Accessors == 79 80 Accessors provide the means of accessing filesystem object data and metadata. 81 Conceptually, files and directories are both exposed by accessors, although 82 the interfaces and mechanisms may differ between these types of objects. 83 84 === Directory Accessors === 85 86 Currently, directory accessors provide support for traversing directory 87 listings, obtaining the relevant filesystem metadata using the underlying 88 filesystem access library. 89 90 === File Accessors === 91 92 File content is accessed through an interface with the following operations: 93 94 {{{ 95 close() 96 fill(inout Flexpage flexpage) 97 flush(inout Flexpage flexpage) 98 get_size(out offset_t size) 99 set_size(in offset_t size) 100 }}} 101 102 The operations need to be supported with actual filesystem operations. For 103 example, ext2-based filesystems employ a specific abstraction which invokes 104 library functions provided by the `libext2fs` package. 105 106 == Providers == 107 108 Providers encapsulate the essential functionality for accessing filesystem 109 objects. Implementing the `Accountable` interface, they are shared by 110 resources and discarded when no resources are using them. 111 112 The following operations are supported by providers: 113 114 {{{ 115 registry(out ProviderRegistry *registry) 116 make_resource(out offset_t size, out object_flags_t object_flags, out Resource *resource) 117 }}} 118 119 Providers are associated with filesystem objects in a registry which can be 120 obtained from each provider. 121 122 Providers also support the creation of resources through which each user of a 123 provider exercises its use of that provider. 124 125 == Resources == 126 127 Resources allow each user of a filesystem object to access that object 128 independently. They effectively provide a session in which accesses may occur. 129 130 The base interface of a resource is as follows: 131 132 {{{ 133 activate() 134 close() 135 }}} 136 137 Activation of a resource is an optional operation that performs any 138 initialisation before a resource is made available to its user. 139 140 In practice, other operations are required to make resources useful. 141 142 === Directory Resources === 143 144 Directory resources primarily expose the contents of directories in the 145 filesystem. They employ directory accessors which concern themselves with the 146 actual filesystem content. 147 148 [[Components#Directories|Directory components]] are provided using directory 149 resources. 150 151 === Pagers === 152 153 Pagers are resources that support dataspace access operations, thus allowing 154 the resources to expose filesystem content in mapped memory regions. 155 156 [[Components#Files|File components]] and [[Components#Pipes|pipe components]] 157 are provided using pagers. 158 159 == Registries == 160 161 The basic mechanism for obtaining a resource involves a registry, as 162 illustrated by the following diagram. 163 164 ######## A graph showing the use of a registry in obtaining resources 165 166 {{{#!graphviz 167 #format svg 168 #transform notugly 169 digraph registry { 170 node [fontsize="12.0",fontname="sans-serif",shape=box]; 171 edge [fontsize="12.0",fontname="sans-serif"]; 172 rankdir=LR; 173 174 subgraph { 175 node [label="OpenerContextResource"]; 176 rank=same; 177 178 OpenerContextResource1 -> OpenerContextResource2 [dir=none,style=dotted]; 179 } 180 181 subgraph { 182 node [label="OpenerResource"]; 183 rank=same; 184 185 OpenerResource1 -> OpenerResource2 [dir=none,style=dotted]; 186 } 187 188 subgraph { 189 rank=same; 190 191 ResourceRegistry -> Resource; 192 } 193 194 subgraph { 195 rank=same; 196 197 ProviderRegistry -> Provider; 198 } 199 200 OpenerContextResource1 -> OpenerResource1 [label="open"]; 201 OpenerResource1 -> ResourceRegistry [label="get_resource"]; 202 ResourceRegistry -> ProviderRegistry [label="get/set"]; 203 204 Provider -> Resource -> OpenerResource2 -> OpenerContextResource2; 205 } 206 }}} 207 208 ########