# HG changeset patch # User Paul Boddie # Date 1627145721 -7200 # Node ID 9c62ddc654a714aedb54a626971a02d3750dc0e6 # Parent 5dd13dfc437b71b5e9982dba4c9da192c9cb218f Introduced filesystem objects, separated file paging functionality from openers, and made the ext2 file opener configurable for specific users, each opener being created via the ext2 filesystem object. Changed the file opening mechanism so that openers are called from the file paging functionality where new file accessors and mappers need to be created. A file opening interface has been defined to establish the functionality provided by each opener to implement its part of the mechanism. Introduced filesystem-related functions to the client and file libraries, also changing functions with overridable capability details to accept the actual capability index instead of the name of the capability in the environment. Changed the libext2fs interfacing to work with the updated client library. diff -r 5dd13dfc437b -r 9c62ddc654a7 conf/dstest_ext2.cfg --- a/conf/dstest_ext2.cfg Sun Jul 18 00:47:14 2021 +0200 +++ b/conf/dstest_ext2.cfg Sat Jul 24 18:55:21 2021 +0200 @@ -31,4 +31,5 @@ }, log = { "client", "g" }, }, - "rom/dstest_block_client_simple", "home/paulb/LICENCE.txt", "1"); + -- program, file to read, user identifier, repetition + "rom/dstest_block_client_simple", "home/paulb/LICENCE.txt", "1000", "1"); diff -r 5dd13dfc437b -r 9c62ddc654a7 docs/wiki/Files --- a/docs/wiki/Files Sun Jul 18 00:47:14 2021 +0200 +++ b/docs/wiki/Files Sat Jul 24 18:55:21 2021 +0200 @@ -13,7 +13,19 @@ === Filesystems === -Filesystems implement the `Opener` interface which provides the `context` +Filesystems implement the `Filesystem` interface which provides the +`open_for_user` operation: + +{{{ +open_for_user(in sys_uid_t uid, in sys_gid_t gid, in sys_mode_t umask, + out cap opener) +}}} + +The operation yields a file opener appropriate for the given user credentials. + +=== File Openers === + +File openers implement the `Opener` interface which provides the `context` operation: {{{ diff -r 5dd13dfc437b -r 9c62ddc654a7 libext2fs_blockserver/lib/src/blockserver_io.c --- a/libext2fs_blockserver/lib/src/blockserver_io.c Sun Jul 18 00:47:14 2021 +0200 +++ b/libext2fs_blockserver/lib/src/blockserver_io.c Sat Jul 24 18:55:21 2021 +0200 @@ -19,6 +19,8 @@ * 02110-1301 USA */ +#include + #include #include @@ -122,9 +124,11 @@ static errcode_t blockserver_open(const char *name, int flags, io_channel *channel) { + l4_cap_idx_t server = l4re_env_get_cap(blockserver_default_cap); + /* Open a device via the named capability. */ - file_t *file = client_open_using(name, flags, blockserver_default_cap); + file_t *file = client_open_using(name, flags, server); /* NOTE: May want a more appropriate error code. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsclient/include/fsclient/client.h --- a/libfsclient/include/fsclient/client.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsclient/include/fsclient/client.h Sat Jul 24 18:55:21 2021 +0200 @@ -27,13 +27,19 @@ EXTERN_C_BEGIN +/* Filesystem access operations. */ + +l4_cap_idx_t client_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask); +l4_cap_idx_t client_open_for_user_using(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, l4_cap_idx_t server); + /* Opening and closing operations. */ void client_close(file_t *file); file_t *client_open(const char *name, flags_t flags); -file_t *client_open_using(const char *name, flags_t flags, const char *cap); +file_t *client_open_using(const char *name, flags_t flags, l4_cap_idx_t server); + long client_pipe(file_t **reader, file_t **writer); -long client_pipe_using(file_t **reader, file_t **writer, const char *cap); +long client_pipe_using(file_t **reader, file_t **writer, l4_cap_idx_t server); /* File and region operations. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsclient/include/fsclient/file.h --- a/libfsclient/include/fsclient/file.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsclient/include/fsclient/file.h Sat Jul 24 18:55:21 2021 +0200 @@ -75,6 +75,11 @@ +/* Filesystem operations. */ + +long file_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, + l4_cap_idx_t server, l4_cap_idx_t *opener); + /* File operations. */ void file_close(file_t *file); diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsclient/lib/src/Makefile --- a/libfsclient/lib/src/Makefile Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsclient/lib/src/Makefile Sat Jul 24 18:55:21 2021 +0200 @@ -15,7 +15,7 @@ # Individual interfaces. -CLIENT_INTERFACES_CC = dataspace file flush mapped_file notification opener opener_context pipe pipe_opener +CLIENT_INTERFACES_CC = dataspace file filesystem flush mapped_file notification opener opener_context pipe pipe_opener # Generated and plain source files. diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsclient/lib/src/client.cc Sat Jul 24 18:55:21 2021 +0200 @@ -20,7 +20,6 @@ */ #include -#include #include #include @@ -143,6 +142,33 @@ +/* Open a file opening object. */ + +l4_cap_idx_t client_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask) +{ + l4_cap_idx_t server = l4re_env_get_cap("server"); + + return client_open_for_user_using(uid, gid, umask, server); +} + +/* Open a file opening object via a named capability. */ + +l4_cap_idx_t client_open_for_user_using(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, l4_cap_idx_t server) +{ + if (l4_is_invalid_cap(server)) + return L4_INVALID_CAP; + + l4_cap_idx_t opener; + long err = file_open_for_user(uid, gid, umask, server, &opener); + + if (err) + return L4_INVALID_CAP; + + return opener; +} + + + /* Close a filesystem object. */ void client_close(file_t *file) @@ -160,20 +186,23 @@ file_t *client_open(const char *name, flags_t flags) { - return client_open_using(name, flags, "server"); + l4_cap_idx_t server = l4re_env_get_cap("server"); + + return client_open_using(name, flags, server); } /* Open a filesystem object via a named capability. */ -file_t *client_open_using(const char *name, flags_t flags, const char *cap) +file_t *client_open_using(const char *name, flags_t flags, l4_cap_idx_t server) { + if (l4_is_invalid_cap(server)) + return NULL; + file_t *file = (file_t *) malloc(sizeof(file_t)); if (file == NULL) return NULL; - l4_cap_idx_t server = l4re_env_get_cap(cap); - if (file_open(file, name, flags, server)) { free(file); @@ -189,11 +218,16 @@ long client_pipe(file_t **reader, file_t **writer) { - return client_pipe_using(reader, writer, "pipes"); + l4_cap_idx_t server = l4re_env_get_cap("pipes"); + + return client_pipe_using(reader, writer, server); } -long client_pipe_using(file_t **reader, file_t **writer, const char *cap) +long client_pipe_using(file_t **reader, file_t **writer, l4_cap_idx_t server) { + if (l4_is_invalid_cap(server)) + return -L4_EINVAL; + *reader = (file_t *) malloc(sizeof(file_t)); if (*reader == NULL) @@ -207,8 +241,6 @@ return -L4_ENOMEM; } - l4_cap_idx_t server = l4re_env_get_cap(cap); - long err = pipe_open(DEFAULT_PIPE_SIZE, *reader, *writer, server); if (err) diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsclient/lib/src/file.cc --- a/libfsclient/lib/src/file.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsclient/lib/src/file.cc Sat Jul 24 18:55:21 2021 +0200 @@ -26,6 +26,7 @@ #include "dataspace_client.h" #include "file_client.h" +#include "filesystem_client.h" #include "flush_client.h" #include "opener_client.h" #include "opener_context_client.h" @@ -61,6 +62,18 @@ +/* Obtain a reference to a file opener for the given user. */ + +long file_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, + l4_cap_idx_t server, l4_cap_idx_t *opener) +{ + client_Filesystem filesystem(server); + + return filesystem.open_for_user(uid, gid, umask, opener); +} + + + /* Initialise the given file structure. */ void file_init(file_t *file) diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/block_file_opener.h --- a/libfsserver/include/fsserver/block_file_opener.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/include/fsserver/block_file_opener.h Sat Jul 24 18:55:21 2021 +0200 @@ -29,18 +29,17 @@ class BlockFileOpener : public HostFileOpener { -protected: +public: + explicit BlockFileOpener(FilePaging *paging) + : HostFileOpener(paging) + { + } + /* Configurable methods. */ virtual fileid_t get_fileid(const char *path, flags_t flags); virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); - -public: - explicit BlockFileOpener(Pages *pages) - : HostFileOpener(pages) - { - } }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/ext2_file_opener.h --- a/libfsserver/include/fsserver/ext2_file_opener.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Sat Jul 24 18:55:21 2021 +0200 @@ -24,6 +24,7 @@ #include #include +#include @@ -33,18 +34,22 @@ { protected: ext2_filsys _fs; + sys_uid_t _uid; + sys_gid_t _gid; + sys_mode_t _umask; + +public: + explicit Ext2FileOpener(FilePaging *paging, ext2_filsys fs, sys_uid_t uid, + sys_gid_t gid, sys_mode_t umask) + : OpenerResource(paging), _fs(fs), _uid(uid), _gid(gid), _umask(umask) + { + } /* Configurable methods. */ virtual fileid_t get_fileid(const char *path, flags_t flags); virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); - -public: - explicit Ext2FileOpener(ext2_filsys fs, Pages *pages) - : OpenerResource(pages), _fs(fs) - { - } }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/ext2_filesystem.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/ext2_filesystem.h Sat Jul 24 18:55:21 2021 +0200 @@ -0,0 +1,50 @@ +/* + * A resource supporting the creation of user-specific ext2 filesystem opener + * resources. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + +#include + + + +/* Support for providing access to user-specific filesystems. */ + +class Ext2Filesystem : public FilesystemResource +{ +protected: + ext2_filsys _fs; + +public: + explicit Ext2Filesystem(Pages *pages, ext2_filsys fs) + : FilesystemResource(pages), _fs(fs) + { + } + + /* Filesystem interface methods. */ + + virtual long open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, + l4_cap_idx_t *opener); +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/file_opening.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/file_opening.h Sat Jul 24 18:55:21 2021 +0200 @@ -0,0 +1,38 @@ +/* + * Generic support for opening files. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + + + +/* An interface offering file opening support. */ + +class FileOpening +{ +public: + virtual fileid_t get_fileid(const char *path, flags_t flags) = 0; + + virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor) = 0; +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/file_paging.h --- a/libfsserver/include/fsserver/file_paging.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/include/fsserver/file_paging.h Sat Jul 24 18:55:21 2021 +0200 @@ -1,5 +1,5 @@ /* - * General functionality supporting file paging. + * A registry of objects supporting paging for files. * * Copyright (C) 2021 Paul Boddie * @@ -24,10 +24,11 @@ #include #include -#include +#include #include +#include #include -#include +#include @@ -44,26 +45,9 @@ { protected: Pages *_pages; - FileMapping _mappers; std::mutex _lock; - /* Pager initialisation methods. */ - - long get_mapper(const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); - - long get_pager(const char *path, flags_t flags, Pager **pager); - - /* Configurable methods. */ - - virtual map_flags_t get_flags(flags_t flags); - - /* Configurable methods requiring implementation. */ - - virtual fileid_t get_fileid(const char *path, flags_t flags) = 0; - - virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor) = 0; - /* Mapper registry access. */ PageMapper *get(fileid_t fileid); @@ -72,9 +56,19 @@ void set(fileid_t fileid, PageMapper *mapper); + /* Pager initialisation methods. */ + + map_flags_t get_flags(flags_t flags); + public: explicit FilePaging(Pages *pages); + /* Pager initialisation methods. */ + + long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); + + long get_pager(FileOpening *opening, const char *path, flags_t flags, Pager **pager); + /* Methods for the pager. */ void detach_pager(fileid_t fileid, PageMapper *mapper); diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/filesystem_resource.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/filesystem_resource.h Sat Jul 24 18:55:21 2021 +0200 @@ -0,0 +1,52 @@ +/* + * A resource supporting the creation of user-specific opener resources. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include +#include +#include + + + +/* Support for providing access to user-specific filesystems. */ + +class FilesystemResource : public Resource, public FilePaging, public Filesystem +{ +public: + explicit FilesystemResource(Pages *pages); + + /* Server details. */ + + int expected_items(); + + ipc_server_handler_type handler(); + + void *interface() + { return static_cast(this); } + + /* Filesystem interface methods. */ + + virtual long open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, + l4_cap_idx_t *opener) = 0; +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/host_file_opener.h --- a/libfsserver/include/fsserver/host_file_opener.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/include/fsserver/host_file_opener.h Sat Jul 24 18:55:21 2021 +0200 @@ -48,17 +48,17 @@ virtual fileid_t _get_fileid(const char *path, bool create); +public: + explicit HostFileOpener(FilePaging *paging) + : OpenerResource(paging) + { + } + /* Configurable methods. */ virtual fileid_t get_fileid(const char *path, flags_t flags); virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); - -public: - explicit HostFileOpener(Pages *pages) - : OpenerResource(pages) - { - } }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/opener_resource.h --- a/libfsserver/include/fsserver/opener_resource.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/include/fsserver/opener_resource.h Sat Jul 24 18:55:21 2021 +0200 @@ -21,22 +21,23 @@ #pragma once -#include - +#include #include #include #include -#include #include /* Support for providing access to files. */ -class OpenerResource : public Resource, public FilePaging, public Opener +class OpenerResource : public Resource, public FileOpening, public Opener { +protected: + FilePaging *_paging; + public: - explicit OpenerResource(Pages *pages); + explicit OpenerResource(FilePaging *paging); /* Server details. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/include/fsserver/test_file_opener.h --- a/libfsserver/include/fsserver/test_file_opener.h Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/include/fsserver/test_file_opener.h Sat Jul 24 18:55:21 2021 +0200 @@ -32,14 +32,14 @@ protected: offset_t _file_size; +public: + explicit TestFileOpener(FilePaging *paging, offset_t file_size=0); + /* Configurable methods. */ virtual fileid_t get_fileid(const char *path, flags_t flags); virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); - -public: - explicit TestFileOpener(Pages *pages, offset_t file_size=0); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/lib/Makefile --- a/libfsserver/lib/Makefile Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/lib/Makefile Sat Jul 24 18:55:21 2021 +0200 @@ -30,7 +30,7 @@ CLIENT_INTERFACES_CC = notifier -SERVER_INTERFACES_CC = opener pipe_opener $(call common_interfaces,$(COMP_INTERFACES_CC)) +SERVER_INTERFACES_CC = filesystem opener pipe_opener $(call common_interfaces,$(COMP_INTERFACES_CC)) # Generated and plain source files. @@ -43,8 +43,10 @@ files/block_file_opener.cc \ files/ext2_file_accessor.cc \ files/ext2_file_opener.cc \ + files/ext2_filesystem.cc \ files/file_pager.cc \ files/file_paging.cc \ + files/filesystem_resource.cc \ files/host_file_accessor.cc \ files/host_file_opener.cc \ files/opener_context_resource.cc \ diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/lib/files/ext2_filesystem.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/files/ext2_filesystem.cc Sat Jul 24 18:55:21 2021 +0200 @@ -0,0 +1,40 @@ +/* + * A resource supporting the creation of user-specific ext2 filesystem opener + * resources. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include "ext2_file_opener.h" +#include "ext2_filesystem.h" +#include "resource_server.h" + +/* Return a file opener object for the given user. */ + +long Ext2Filesystem::open_for_user(sys_uid_t uid, sys_gid_t gid, + sys_mode_t umask, l4_cap_idx_t *ref) +{ + Resource *resource = new Ext2FileOpener(this, _fs, uid, gid, umask); + + /* Complete the initialisation and start a server in a new thread. + If the thread does not start, the resource will be finalised. */ + + return ResourceServer(resource).start_thread(ref); +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/lib/files/file_paging.cc --- a/libfsserver/lib/files/file_paging.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/lib/files/file_paging.cc Sat Jul 24 18:55:21 2021 +0200 @@ -82,7 +82,7 @@ /* Obtain a page mapper for the 'fileid' or register a new one in the paging object. */ -long FilePaging::get_mapper(const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper) +long FilePaging::get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper) { /* Obtain any registered page mapper. */ @@ -94,7 +94,7 @@ /* Make an accessor and page mapper, registering the mapper. */ Accessor *accessor; - long err = make_accessor(path, flags, fileid, &accessor); + long err = opening->make_accessor(path, flags, fileid, &accessor); if (err) return err; @@ -110,13 +110,13 @@ /* Return a pager initialised with a page mapper. */ -long FilePaging::get_pager(const char *path, flags_t flags, Pager **pager) +long FilePaging::get_pager(FileOpening *opening, const char *path, flags_t flags, Pager **pager) { std::lock_guard guard(_lock); /* Obtain an identifier for the file, even for new files. */ - fileid_t fileid = get_fileid(path, flags); + fileid_t fileid = opening->get_fileid(path, flags); if (fileid == FILEID_INVALID) return -L4_ENOENT; @@ -125,7 +125,7 @@ page mapper. */ PageMapper *mapper; - long err = get_mapper(path, flags, fileid, &mapper); + long err = get_mapper(opening, path, flags, fileid, &mapper); if (err) return err; diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/lib/files/filesystem_resource.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/files/filesystem_resource.cc Sat Jul 24 18:55:21 2021 +0200 @@ -0,0 +1,42 @@ +/* + * A resource supporting the creation of user-specific opener resources. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include "filesystem_server.h" +#include "filesystem_resource.h" + +/* Support for providing access to user-specific filesystems. */ + +FilesystemResource::FilesystemResource(Pages *pages) +: FilePaging(pages) +{ +} + +int FilesystemResource::expected_items() +{ + return Filesystem_expected_items; +} + +ipc_server_handler_type FilesystemResource::handler() +{ + return (ipc_server_handler_type) handle_Filesystem; +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/lib/files/opener_resource.cc --- a/libfsserver/lib/files/opener_resource.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/lib/files/opener_resource.cc Sat Jul 24 18:55:21 2021 +0200 @@ -25,8 +25,8 @@ /* Support for providing access to files. */ -OpenerResource::OpenerResource(Pages *pages) -: FilePaging(pages) +OpenerResource::OpenerResource(FilePaging *paging) +: _paging(paging) { } @@ -46,7 +46,7 @@ long OpenerResource::open(const char *path, flags_t flags, Pager **pager) { - return get_pager(path, flags, pager); + return _paging->get_pager(this, path, flags, pager); } diff -r 5dd13dfc437b -r 9c62ddc654a7 libfsserver/lib/files/test_file_opener.cc --- a/libfsserver/lib/files/test_file_opener.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/libfsserver/lib/files/test_file_opener.cc Sat Jul 24 18:55:21 2021 +0200 @@ -26,8 +26,8 @@ /* Support for providing access to files. */ -TestFileOpener::TestFileOpener(Pages *pages, offset_t file_size) -: OpenerResource(pages), _file_size(file_size) +TestFileOpener::TestFileOpener(FilePaging *paging, offset_t file_size) +: OpenerResource(paging), _file_size(file_size) { } diff -r 5dd13dfc437b -r 9c62ddc654a7 servers/block_file_server.cc --- a/servers/block_file_server.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/servers/block_file_server.cc Sat Jul 24 18:55:21 2021 +0200 @@ -66,7 +66,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - BlockFileOpener opener(&pages); + FilePaging paging(&pages); + BlockFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 servers/client_file_server.cc --- a/servers/client_file_server.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/servers/client_file_server.cc Sat Jul 24 18:55:21 2021 +0200 @@ -67,7 +67,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - ClientFileOpener opener(&pages); + FilePaging paging(&pages); + ClientFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 servers/ext2_file_server.cc --- a/servers/ext2_file_server.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/servers/ext2_file_server.cc Sat Jul 24 18:55:21 2021 +0200 @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include @@ -94,11 +94,11 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - Ext2FileOpener opener(fs, &pages); + Ext2Filesystem filesystem(&pages, fs); /* Register a server associating it with the given object. */ - ResourceServer server(&opener); + ResourceServer server(&filesystem); err = server.bind(server_name); if (err) diff -r 5dd13dfc437b -r 9c62ddc654a7 servers/host_file_server.cc --- a/servers/host_file_server.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/servers/host_file_server.cc Sat Jul 24 18:55:21 2021 +0200 @@ -66,7 +66,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - HostFileOpener opener(&pages); + FilePaging paging(&pages); + HostFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 servers/test_file_server.cc --- a/servers/test_file_server.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/servers/test_file_server.cc Sat Jul 24 18:55:21 2021 +0200 @@ -65,7 +65,8 @@ MemoryIncremental mem(memory_pages, page(REGION_PAGES)); PageQueueShared queue; Pages pages(&mem, &queue); - TestFileOpener opener(&pages, page(FILE_PAGES)); + FilePaging paging(&pages); + TestFileOpener opener(&paging, page(FILE_PAGES)); /* Register a server associating it with the given object. */ diff -r 5dd13dfc437b -r 9c62ddc654a7 tests/dstest_block_client_simple.cc --- a/tests/dstest_block_client_simple.cc Sun Jul 18 00:47:14 2021 +0200 +++ b/tests/dstest_block_client_simple.cc Sat Jul 24 18:55:21 2021 +0200 @@ -32,18 +32,35 @@ { if (argc < 2) { - printf("Need a filename and optional repetition.\n"); + printf("Need a filename, optional user identifier, and optional repetition.\n"); return 1; } /* Obtain filename and access parameters. */ char *filename = argv[1]; - int repetition = argc > 2 ? atoi(argv[2]) : 10; + sys_uid_t uid = argc > 2 ? atoi(argv[2]) : 0; + int repetition = argc > 3 ? atoi(argv[3]) : 10; + file_t *file; + + /* With a user, open a user-specific file opener. */ + + if (uid) + { + l4_cap_idx_t opener = client_open_for_user(uid, uid, 0022); - /* Invoke the open method to receive the file reference. */ + if (l4_is_invalid_cap(opener)) + { + printf("Could not obtain opener for file.\n"); + return 1; + } - file_t *file = client_open(filename, O_RDWR); + /* Invoke the open method to receive the file reference. */ + + file = client_open_using(filename, O_RDWR, opener); + } + else + file = client_open(filename, O_RDWR); if (file == NULL) {