1.1 --- a/server/src/Makefile Mon Jul 22 17:36:37 2019 +0200
1.2 +++ b/server/src/Makefile Sun Dec 01 19:09:59 2019 +0100
1.3 @@ -6,6 +6,6 @@
1.4
1.5 SRC_CC = main.cc fspath.cc
1.6
1.7 -REQUIRES_LIBS = libstdc++ l4re_c l4re_c-util libipc libfsclient libfsserver
1.8 +REQUIRES_LIBS = libstdc++ l4re_c libipc libfsclient libfsserver
1.9
1.10 include $(L4DIR)/mk/prog.mk
2.1 --- a/server/src/main.cc Mon Jul 22 17:36:37 2019 +0200
2.2 +++ b/server/src/main.cc Sun Dec 01 19:09:59 2019 +0100
2.3 @@ -19,12 +19,8 @@
2.4 * Boston, MA 02110-1301, USA
2.5 */
2.6
2.7 -#include <l4/util/util.h>
2.8 -
2.9 -#include <l4/re/c/dataspace.h>
2.10 #include <l4/re/env.h>
2.11 #include <l4/sys/err.h>
2.12 -#include <l4/sys/types.h>
2.13
2.14 #include <stdlib.h>
2.15 #include <stdio.h>
2.16 @@ -34,11 +30,17 @@
2.17 #include <map>
2.18
2.19 #include <fsclient/fsdesc.h>
2.20 -#include <fsclient/fs_ipc.h>
2.21 -#include <fsclient/ops.h>
2.22 -#include <fsserver/server.h>
2.23 +#include <fsclient/fsdesc_client.h>
2.24 #include "fspath.h"
2.25
2.26 +/* Exposure of the resource. */
2.27 +
2.28 +#include <fsserver/file_resource_server.h>
2.29 +
2.30 +/* Implemented interfaces. */
2.31 +
2.32 +#include <fsserver/user_filesystem_resource.h>
2.33 +
2.34
2.35
2.36 /* Mountpoint-to-server mapping. */
2.37 @@ -49,165 +51,161 @@
2.38
2.39
2.40
2.41 -/* Virtual filesystem server. */
2.42 +/* Virtual filesystem resource. */
2.43
2.44 -class Vfs_server : public OpeningServer
2.45 +class Vfs_resource : public UserFilesystemResource
2.46 {
2.47 private:
2.48 MountTable _servers;
2.49
2.50 public:
2.51 - explicit Vfs_server()
2.52 - : OpeningServer()
2.53 + explicit Vfs_resource()
2.54 + : UserFilesystemResource()
2.55 {
2.56 }
2.57
2.58 - void dispatch(ipc_message_t *msg)
2.59 +
2.60 +
2.61 + /* Obtain an object as a filesystem reference. */
2.62 +
2.63 + long getfs_object(fs_object_t *fsobj, l4_cap_idx_t *fs)
2.64 {
2.65 - switch (l4_msgtag_label(msg->tag))
2.66 - {
2.67 - case Fs_op_mount:
2.68 - mount(msg);
2.69 - break;
2.70 + file_descriptor_t desc;
2.71 + long err;
2.72 +
2.73 + /* Obtain a suitable descriptor. */
2.74 +
2.75 + err = init_desc(&desc, fsobj);
2.76 +
2.77 + if (err)
2.78 + return err;
2.79 +
2.80 + /* Return a reference to any directly-accessed object. */
2.81 +
2.82 + char *path = fsdesc_get_name(fsobj);
2.83
2.84 - case Fs_op_open:
2.85 - open(msg);
2.86 - break;
2.87 + if ((path != NULL) && !strlen(path))
2.88 + {
2.89 + *fs = desc.server;
2.90 + return L4_EOK;
2.91 + }
2.92 +
2.93 + /* Find the path within the selected filesystem. */
2.94 +
2.95 + /* Propagate the message to the identified filesystem.
2.96 + The L4_MSGTAG_PROPAGATE flag is not supported by Fiasco.OC, so this
2.97 + object has to act as intermediary. */
2.98
2.99 - case Fs_op_getfs:
2.100 - getfs(msg);
2.101 - break;
2.102 + err = fs_getfs(&desc);
2.103 +
2.104 + if (err)
2.105 + return err;
2.106 +
2.107 + /* Free the capabilities and buffer from this task. */
2.108
2.109 - default:
2.110 - ipc_message_send_error(msg, -L4_EBADPROTO);
2.111 - break;
2.112 - }
2.113 + fsdesc_deallocate_object(fsobj);
2.114 +
2.115 + /* Export and eventually free the server reference from this task. */
2.116 +
2.117 + *fs = discard_cap(desc.ref);
2.118 +
2.119 + return L4_EOK;
2.120 }
2.121
2.122 - void getfs(ipc_message_t *msg)
2.123 + /* Mount a filesystem at a particular location. */
2.124 +
2.125 + long mount_object(fs_object_t *fsobj, l4_cap_idx_t fs)
2.126 {
2.127 - _open(Fs_op_getfs, msg);
2.128 + /* Obtain the object's path. */
2.129 +
2.130 + char *path = fsdesc_get_name(fsobj);
2.131 +
2.132 + if (path == NULL)
2.133 + return -L4_EINVAL;
2.134 +
2.135 + /* Mount the supplied capability. */
2.136 +
2.137 + mount_at_path(fs, path);
2.138 +
2.139 + /* Free the capability and buffer from this task. */
2.140 +
2.141 + fsdesc_deallocate_buffer(fsobj);
2.142 +
2.143 + return L4_EOK;
2.144 }
2.145
2.146 - void open(ipc_message_t *msg)
2.147 - {
2.148 - _open(Fs_op_open, msg);
2.149 - }
2.150 + /* Open a filesystem object. */
2.151
2.152 - void _open(int op, ipc_message_t *msg)
2.153 + long open_object(fs_object_t *fsobj, int flags, size_t *size, l4_cap_idx_t *file)
2.154 {
2.155 file_descriptor_t desc;
2.156 - int flags;
2.157 long err;
2.158
2.159 - /* Obtain the flags. */
2.160 + /* Obtain a suitable descriptor. */
2.161 +
2.162 + err = init_desc(&desc, fsobj);
2.163 +
2.164 + if (err)
2.165 + return err;
2.166 +
2.167 + /* Find the path within the selected filesystem. */
2.168
2.169 - flags = ipc_message_get_word(msg, 0);
2.170 + /* Propagate the message to the identified filesystem.
2.171 + The L4_MSGTAG_PROPAGATE flag is not supported by Fiasco.OC, so this
2.172 + object has to act as intermediary. */
2.173
2.174 - /* Obtain the dataspace and IRQ object. */
2.175 + err = fs_open(&desc, flags);
2.176 +
2.177 + if (err)
2.178 + return err;
2.179 +
2.180 + /* Free the capabilities and buffer from this task. */
2.181
2.182 - err = fsdesc_import_object(msg, 0, &desc.obj);
2.183 - if (err)
2.184 - {
2.185 - ipc_message_send_error(msg, -L4_EIO);
2.186 - return;
2.187 - }
2.188 + fsdesc_deallocate_object(fsobj);
2.189 +
2.190 + /* Export and eventually free the server reference from this task. */
2.191 +
2.192 + *size = desc.obj.size;
2.193 + *file = discard_cap(desc.ref);
2.194 +
2.195 + return L4_EOK;
2.196 + }
2.197 +
2.198 +
2.199 +
2.200 + /* Non-exported methods. */
2.201 +
2.202 + /* Initialise a descriptor for accessing a mounted filesystem. */
2.203 +
2.204 + long init_desc(file_descriptor_t *desc, fs_object_t *obj)
2.205 + {
2.206 + /* Copy the object details into the descriptor. */
2.207 +
2.208 + desc->obj = *obj;
2.209
2.210 /* Match the path to a mountpoint. */
2.211
2.212 - char *path = fsdesc_get_name(&desc.obj);
2.213 + char *path = fsdesc_get_name(&desc->obj);
2.214
2.215 if (path == NULL)
2.216 - {
2.217 - ipc_message_send_error(msg, -L4_EINVAL);
2.218 - return;
2.219 - }
2.220 + return -L4_EINVAL;
2.221
2.222 MountTableIterator entry = find_mountpoint(path);
2.223
2.224 if (entry == _servers.end())
2.225 - {
2.226 - ipc_message_send_error(msg, -L4_ENOENT);
2.227 - return;
2.228 - }
2.229 + return -L4_ENOENT;
2.230
2.231 /* Rewrite the path for the selected filesystem. */
2.232
2.233 rewrite_path(path, entry->first);
2.234
2.235 - /* Find the path within the selected filesystem. */
2.236 -
2.237 - /* Propagate the message to the identified filesystem.
2.238 - NOTE: The L4_MSGTAG_PROPAGATE flag is not supported by Fiasco.OC, so this
2.239 - NOTE: object has to act as intermediary. */
2.240 -
2.241 - desc.server = entry->second;
2.242 -
2.243 - err = fs_ipc_open(&desc, flags, op);
2.244 - if (err)
2.245 - {
2.246 - ipc_message_send_error(msg, -L4_EIO);
2.247 - return;
2.248 - }
2.249 -
2.250 - /* Free the capabilities and buffer from this task. */
2.251 -
2.252 - fsdesc_deallocate_object(&desc.obj);
2.253 -
2.254 - /* Return the file size. */
2.255 -
2.256 - ipc_message_add_word(msg, desc.obj.size);
2.257 -
2.258 - /* Export and eventually free the server reference from this task. */
2.259 -
2.260 - ipc_message_propagate_item(msg, desc.ref);
2.261 - }
2.262 -
2.263 - void mount(ipc_message_t *msg)
2.264 - {
2.265 - fs_object_t fsobj;
2.266 - l4_cap_idx_t server;
2.267 - long err;
2.268 -
2.269 - /* Obtain the filesystem capability. */
2.270 + /* Use the filesystem as the target of any query. */
2.271
2.272 - err = ipc_message_import_capability(msg, 0, &server);
2.273 - if (err)
2.274 - {
2.275 - ipc_message_send_error(msg, -L4_EIO);
2.276 - return;
2.277 - }
2.278 -
2.279 - /* Obtain the dataspace. */
2.280 -
2.281 - err = fsdesc_import_dataspace(msg, 1, &fsobj);
2.282 - if (err)
2.283 - {
2.284 - ipc_message_send_error(msg, -L4_EIO);
2.285 - return;
2.286 - }
2.287 -
2.288 - /* Obtain the object's path. */
2.289 + desc->server = entry->second;
2.290
2.291 - char *path = fsdesc_get_name(&fsobj);
2.292 -
2.293 - if (path == NULL)
2.294 - {
2.295 - ipc_message_send_error(msg, -L4_EINVAL);
2.296 - return;
2.297 - }
2.298 -
2.299 - /* Mount the supplied capability. */
2.300 -
2.301 - mount_at_path(server, path);
2.302 -
2.303 - /* Free the capability and buffer from this task. */
2.304 -
2.305 - fsdesc_deallocate_buffer(&fsobj);
2.306 + return L4_EOK;
2.307 }
2.308
2.309 - /* Non-exported methods. */
2.310 -
2.311 void mount_at_path(l4_cap_idx_t server, const char *path)
2.312 {
2.313 /* NOTE: Should terminate with path separator if absent.
2.314 @@ -278,9 +276,10 @@
2.315
2.316 /* Initialise and register a new server object. */
2.317
2.318 - Vfs_server server_obj;
2.319 + Vfs_resource resource;
2.320 + UserFilesystemServer server(&resource);
2.321
2.322 - if (server_obj.bind("export"))
2.323 + if (server.bind("export"))
2.324 {
2.325 printf("Could not bind thread.\n");
2.326 return 1;
2.327 @@ -318,13 +317,14 @@
2.328 /* Terminate the path and register the mountpoint. */
2.329
2.330 *sep = '\0';
2.331 - server_obj.mount_at_path(fscap, buffer);
2.332 + resource.mount_at_path(fscap, buffer);
2.333 }
2.334
2.335 fclose(fp);
2.336
2.337 /* Enter the IPC server loop. */
2.338
2.339 - server_obj.loop();
2.340 + printf("Starting vfs resource...\n");
2.341 + server.start();
2.342 return 0;
2.343 }