1.1 --- a/conf/dstest_ext2.cfg Sun Jul 18 00:47:14 2021 +0200 1.2 +++ b/conf/dstest_ext2.cfg Sat Jul 24 18:55:21 2021 +0200 1.3 @@ -31,4 +31,5 @@ 1.4 }, 1.5 log = { "client", "g" }, 1.6 }, 1.7 - "rom/dstest_block_client_simple", "home/paulb/LICENCE.txt", "1"); 1.8 + -- program, file to read, user identifier, repetition 1.9 + "rom/dstest_block_client_simple", "home/paulb/LICENCE.txt", "1000", "1");
2.1 --- a/docs/wiki/Files Sun Jul 18 00:47:14 2021 +0200 2.2 +++ b/docs/wiki/Files Sat Jul 24 18:55:21 2021 +0200 2.3 @@ -13,7 +13,19 @@ 2.4 2.5 === Filesystems === 2.6 2.7 -Filesystems implement the `Opener` interface which provides the `context` 2.8 +Filesystems implement the `Filesystem` interface which provides the 2.9 +`open_for_user` operation: 2.10 + 2.11 +{{{ 2.12 +open_for_user(in sys_uid_t uid, in sys_gid_t gid, in sys_mode_t umask, 2.13 + out cap opener) 2.14 +}}} 2.15 + 2.16 +The operation yields a file opener appropriate for the given user credentials. 2.17 + 2.18 +=== File Openers === 2.19 + 2.20 +File openers implement the `Opener` interface which provides the `context` 2.21 operation: 2.22 2.23 {{{
3.1 --- a/libext2fs_blockserver/lib/src/blockserver_io.c Sun Jul 18 00:47:14 2021 +0200 3.2 +++ b/libext2fs_blockserver/lib/src/blockserver_io.c Sat Jul 24 18:55:21 2021 +0200 3.3 @@ -19,6 +19,8 @@ 3.4 * 02110-1301 USA 3.5 */ 3.6 3.7 +#include <l4/re/env.h> 3.8 + 3.9 #include <stdio.h> 3.10 #include <stdlib.h> 3.11 3.12 @@ -122,9 +124,11 @@ 3.13 3.14 static errcode_t blockserver_open(const char *name, int flags, io_channel *channel) 3.15 { 3.16 + l4_cap_idx_t server = l4re_env_get_cap(blockserver_default_cap); 3.17 + 3.18 /* Open a device via the named capability. */ 3.19 3.20 - file_t *file = client_open_using(name, flags, blockserver_default_cap); 3.21 + file_t *file = client_open_using(name, flags, server); 3.22 3.23 /* NOTE: May want a more appropriate error code. */ 3.24
4.1 --- a/libfsclient/include/fsclient/client.h Sun Jul 18 00:47:14 2021 +0200 4.2 +++ b/libfsclient/include/fsclient/client.h Sat Jul 24 18:55:21 2021 +0200 4.3 @@ -27,13 +27,19 @@ 4.4 4.5 EXTERN_C_BEGIN 4.6 4.7 +/* Filesystem access operations. */ 4.8 + 4.9 +l4_cap_idx_t client_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask); 4.10 +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); 4.11 + 4.12 /* Opening and closing operations. */ 4.13 4.14 void client_close(file_t *file); 4.15 file_t *client_open(const char *name, flags_t flags); 4.16 -file_t *client_open_using(const char *name, flags_t flags, const char *cap); 4.17 +file_t *client_open_using(const char *name, flags_t flags, l4_cap_idx_t server); 4.18 + 4.19 long client_pipe(file_t **reader, file_t **writer); 4.20 -long client_pipe_using(file_t **reader, file_t **writer, const char *cap); 4.21 +long client_pipe_using(file_t **reader, file_t **writer, l4_cap_idx_t server); 4.22 4.23 /* File and region operations. */ 4.24
5.1 --- a/libfsclient/include/fsclient/file.h Sun Jul 18 00:47:14 2021 +0200 5.2 +++ b/libfsclient/include/fsclient/file.h Sat Jul 24 18:55:21 2021 +0200 5.3 @@ -75,6 +75,11 @@ 5.4 5.5 5.6 5.7 +/* Filesystem operations. */ 5.8 + 5.9 +long file_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, 5.10 + l4_cap_idx_t server, l4_cap_idx_t *opener); 5.11 + 5.12 /* File operations. */ 5.13 5.14 void file_close(file_t *file);
6.1 --- a/libfsclient/lib/src/Makefile Sun Jul 18 00:47:14 2021 +0200 6.2 +++ b/libfsclient/lib/src/Makefile Sat Jul 24 18:55:21 2021 +0200 6.3 @@ -15,7 +15,7 @@ 6.4 6.5 # Individual interfaces. 6.6 6.7 -CLIENT_INTERFACES_CC = dataspace file flush mapped_file notification opener opener_context pipe pipe_opener 6.8 +CLIENT_INTERFACES_CC = dataspace file filesystem flush mapped_file notification opener opener_context pipe pipe_opener 6.9 6.10 # Generated and plain source files. 6.11
7.1 --- a/libfsclient/lib/src/client.cc Sun Jul 18 00:47:14 2021 +0200 7.2 +++ b/libfsclient/lib/src/client.cc Sat Jul 24 18:55:21 2021 +0200 7.3 @@ -20,7 +20,6 @@ 7.4 */ 7.5 7.6 #include <l4/re/env.h> 7.7 -#include <ipc/irq.h> 7.8 7.9 #include <stdio.h> 7.10 #include <stdlib.h> 7.11 @@ -143,6 +142,33 @@ 7.12 7.13 7.14 7.15 +/* Open a file opening object. */ 7.16 + 7.17 +l4_cap_idx_t client_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask) 7.18 +{ 7.19 + l4_cap_idx_t server = l4re_env_get_cap("server"); 7.20 + 7.21 + return client_open_for_user_using(uid, gid, umask, server); 7.22 +} 7.23 + 7.24 +/* Open a file opening object via a named capability. */ 7.25 + 7.26 +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) 7.27 +{ 7.28 + if (l4_is_invalid_cap(server)) 7.29 + return L4_INVALID_CAP; 7.30 + 7.31 + l4_cap_idx_t opener; 7.32 + long err = file_open_for_user(uid, gid, umask, server, &opener); 7.33 + 7.34 + if (err) 7.35 + return L4_INVALID_CAP; 7.36 + 7.37 + return opener; 7.38 +} 7.39 + 7.40 + 7.41 + 7.42 /* Close a filesystem object. */ 7.43 7.44 void client_close(file_t *file) 7.45 @@ -160,20 +186,23 @@ 7.46 7.47 file_t *client_open(const char *name, flags_t flags) 7.48 { 7.49 - return client_open_using(name, flags, "server"); 7.50 + l4_cap_idx_t server = l4re_env_get_cap("server"); 7.51 + 7.52 + return client_open_using(name, flags, server); 7.53 } 7.54 7.55 /* Open a filesystem object via a named capability. */ 7.56 7.57 -file_t *client_open_using(const char *name, flags_t flags, const char *cap) 7.58 +file_t *client_open_using(const char *name, flags_t flags, l4_cap_idx_t server) 7.59 { 7.60 + if (l4_is_invalid_cap(server)) 7.61 + return NULL; 7.62 + 7.63 file_t *file = (file_t *) malloc(sizeof(file_t)); 7.64 7.65 if (file == NULL) 7.66 return NULL; 7.67 7.68 - l4_cap_idx_t server = l4re_env_get_cap(cap); 7.69 - 7.70 if (file_open(file, name, flags, server)) 7.71 { 7.72 free(file); 7.73 @@ -189,11 +218,16 @@ 7.74 7.75 long client_pipe(file_t **reader, file_t **writer) 7.76 { 7.77 - return client_pipe_using(reader, writer, "pipes"); 7.78 + l4_cap_idx_t server = l4re_env_get_cap("pipes"); 7.79 + 7.80 + return client_pipe_using(reader, writer, server); 7.81 } 7.82 7.83 -long client_pipe_using(file_t **reader, file_t **writer, const char *cap) 7.84 +long client_pipe_using(file_t **reader, file_t **writer, l4_cap_idx_t server) 7.85 { 7.86 + if (l4_is_invalid_cap(server)) 7.87 + return -L4_EINVAL; 7.88 + 7.89 *reader = (file_t *) malloc(sizeof(file_t)); 7.90 7.91 if (*reader == NULL) 7.92 @@ -207,8 +241,6 @@ 7.93 return -L4_ENOMEM; 7.94 } 7.95 7.96 - l4_cap_idx_t server = l4re_env_get_cap(cap); 7.97 - 7.98 long err = pipe_open(DEFAULT_PIPE_SIZE, *reader, *writer, server); 7.99 7.100 if (err)
8.1 --- a/libfsclient/lib/src/file.cc Sun Jul 18 00:47:14 2021 +0200 8.2 +++ b/libfsclient/lib/src/file.cc Sat Jul 24 18:55:21 2021 +0200 8.3 @@ -26,6 +26,7 @@ 8.4 8.5 #include "dataspace_client.h" 8.6 #include "file_client.h" 8.7 +#include "filesystem_client.h" 8.8 #include "flush_client.h" 8.9 #include "opener_client.h" 8.10 #include "opener_context_client.h" 8.11 @@ -61,6 +62,18 @@ 8.12 8.13 8.14 8.15 +/* Obtain a reference to a file opener for the given user. */ 8.16 + 8.17 +long file_open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, 8.18 + l4_cap_idx_t server, l4_cap_idx_t *opener) 8.19 +{ 8.20 + client_Filesystem filesystem(server); 8.21 + 8.22 + return filesystem.open_for_user(uid, gid, umask, opener); 8.23 +} 8.24 + 8.25 + 8.26 + 8.27 /* Initialise the given file structure. */ 8.28 8.29 void file_init(file_t *file)
9.1 --- a/libfsserver/include/fsserver/block_file_opener.h Sun Jul 18 00:47:14 2021 +0200 9.2 +++ b/libfsserver/include/fsserver/block_file_opener.h Sat Jul 24 18:55:21 2021 +0200 9.3 @@ -29,18 +29,17 @@ 9.4 9.5 class BlockFileOpener : public HostFileOpener 9.6 { 9.7 -protected: 9.8 +public: 9.9 + explicit BlockFileOpener(FilePaging *paging) 9.10 + : HostFileOpener(paging) 9.11 + { 9.12 + } 9.13 + 9.14 /* Configurable methods. */ 9.15 9.16 virtual fileid_t get_fileid(const char *path, flags_t flags); 9.17 9.18 virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); 9.19 - 9.20 -public: 9.21 - explicit BlockFileOpener(Pages *pages) 9.22 - : HostFileOpener(pages) 9.23 - { 9.24 - } 9.25 }; 9.26 9.27 // vim: tabstop=4 expandtab shiftwidth=4
10.1 --- a/libfsserver/include/fsserver/ext2_file_opener.h Sun Jul 18 00:47:14 2021 +0200 10.2 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Sat Jul 24 18:55:21 2021 +0200 10.3 @@ -24,6 +24,7 @@ 10.4 #include <ext2fs/ext2fs.h> 10.5 10.6 #include <fsserver/opener_resource.h> 10.7 +#include <systypes/user.h> 10.8 10.9 10.10 10.11 @@ -33,18 +34,22 @@ 10.12 { 10.13 protected: 10.14 ext2_filsys _fs; 10.15 + sys_uid_t _uid; 10.16 + sys_gid_t _gid; 10.17 + sys_mode_t _umask; 10.18 + 10.19 +public: 10.20 + explicit Ext2FileOpener(FilePaging *paging, ext2_filsys fs, sys_uid_t uid, 10.21 + sys_gid_t gid, sys_mode_t umask) 10.22 + : OpenerResource(paging), _fs(fs), _uid(uid), _gid(gid), _umask(umask) 10.23 + { 10.24 + } 10.25 10.26 /* Configurable methods. */ 10.27 10.28 virtual fileid_t get_fileid(const char *path, flags_t flags); 10.29 10.30 virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); 10.31 - 10.32 -public: 10.33 - explicit Ext2FileOpener(ext2_filsys fs, Pages *pages) 10.34 - : OpenerResource(pages), _fs(fs) 10.35 - { 10.36 - } 10.37 }; 10.38 10.39 // vim: tabstop=4 expandtab shiftwidth=4
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/libfsserver/include/fsserver/ext2_filesystem.h Sat Jul 24 18:55:21 2021 +0200 11.3 @@ -0,0 +1,50 @@ 11.4 +/* 11.5 + * A resource supporting the creation of user-specific ext2 filesystem opener 11.6 + * resources. 11.7 + * 11.8 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 11.9 + * 11.10 + * This program is free software; you can redistribute it and/or 11.11 + * modify it under the terms of the GNU General Public License as 11.12 + * published by the Free Software Foundation; either version 2 of 11.13 + * the License, or (at your option) any later version. 11.14 + * 11.15 + * This program is distributed in the hope that it will be useful, 11.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11.18 + * GNU General Public License for more details. 11.19 + * 11.20 + * You should have received a copy of the GNU General Public License 11.21 + * along with this program; if not, write to the Free Software 11.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 11.23 + * Boston, MA 02110-1301, USA 11.24 + */ 11.25 + 11.26 +#pragma once 11.27 + 11.28 +#include <ext2fs/ext2fs.h> 11.29 + 11.30 +#include <fsserver/filesystem_resource.h> 11.31 + 11.32 + 11.33 + 11.34 +/* Support for providing access to user-specific filesystems. */ 11.35 + 11.36 +class Ext2Filesystem : public FilesystemResource 11.37 +{ 11.38 +protected: 11.39 + ext2_filsys _fs; 11.40 + 11.41 +public: 11.42 + explicit Ext2Filesystem(Pages *pages, ext2_filsys fs) 11.43 + : FilesystemResource(pages), _fs(fs) 11.44 + { 11.45 + } 11.46 + 11.47 + /* Filesystem interface methods. */ 11.48 + 11.49 + virtual long open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, 11.50 + l4_cap_idx_t *opener); 11.51 +}; 11.52 + 11.53 +// vim: tabstop=4 expandtab shiftwidth=4
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/libfsserver/include/fsserver/file_opening.h Sat Jul 24 18:55:21 2021 +0200 12.3 @@ -0,0 +1,38 @@ 12.4 +/* 12.5 + * Generic support for opening files. 12.6 + * 12.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 12.8 + * 12.9 + * This program is free software; you can redistribute it and/or 12.10 + * modify it under the terms of the GNU General Public License as 12.11 + * published by the Free Software Foundation; either version 2 of 12.12 + * the License, or (at your option) any later version. 12.13 + * 12.14 + * This program is distributed in the hope that it will be useful, 12.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12.17 + * GNU General Public License for more details. 12.18 + * 12.19 + * You should have received a copy of the GNU General Public License 12.20 + * along with this program; if not, write to the Free Software 12.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 12.22 + * Boston, MA 02110-1301, USA 12.23 + */ 12.24 + 12.25 +#pragma once 12.26 + 12.27 +#include <fsserver/accessor.h> 12.28 + 12.29 + 12.30 + 12.31 +/* An interface offering file opening support. */ 12.32 + 12.33 +class FileOpening 12.34 +{ 12.35 +public: 12.36 + virtual fileid_t get_fileid(const char *path, flags_t flags) = 0; 12.37 + 12.38 + virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor) = 0; 12.39 +}; 12.40 + 12.41 +// vim: tabstop=4 expandtab shiftwidth=4
13.1 --- a/libfsserver/include/fsserver/file_paging.h Sun Jul 18 00:47:14 2021 +0200 13.2 +++ b/libfsserver/include/fsserver/file_paging.h Sat Jul 24 18:55:21 2021 +0200 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * General functionality supporting file paging. 13.6 + * A registry of objects supporting paging for files. 13.7 * 13.8 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 13.9 * 13.10 @@ -24,10 +24,11 @@ 13.11 #include <map> 13.12 #include <mutex> 13.13 13.14 -#include <fsserver/accessor.h> 13.15 +#include <fsserver/file_opening.h> 13.16 #include <fsserver/notification.h> 13.17 +#include <fsserver/page_mapper.h> 13.18 #include <fsserver/pager.h> 13.19 -#include <fsserver/page_mapper.h> 13.20 +#include <fsserver/pages.h> 13.21 13.22 13.23 13.24 @@ -44,26 +45,9 @@ 13.25 { 13.26 protected: 13.27 Pages *_pages; 13.28 - 13.29 FileMapping _mappers; 13.30 std::mutex _lock; 13.31 13.32 - /* Pager initialisation methods. */ 13.33 - 13.34 - long get_mapper(const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 13.35 - 13.36 - long get_pager(const char *path, flags_t flags, Pager **pager); 13.37 - 13.38 - /* Configurable methods. */ 13.39 - 13.40 - virtual map_flags_t get_flags(flags_t flags); 13.41 - 13.42 - /* Configurable methods requiring implementation. */ 13.43 - 13.44 - virtual fileid_t get_fileid(const char *path, flags_t flags) = 0; 13.45 - 13.46 - virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor) = 0; 13.47 - 13.48 /* Mapper registry access. */ 13.49 13.50 PageMapper *get(fileid_t fileid); 13.51 @@ -72,9 +56,19 @@ 13.52 13.53 void set(fileid_t fileid, PageMapper *mapper); 13.54 13.55 + /* Pager initialisation methods. */ 13.56 + 13.57 + map_flags_t get_flags(flags_t flags); 13.58 + 13.59 public: 13.60 explicit FilePaging(Pages *pages); 13.61 13.62 + /* Pager initialisation methods. */ 13.63 + 13.64 + long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 13.65 + 13.66 + long get_pager(FileOpening *opening, const char *path, flags_t flags, Pager **pager); 13.67 + 13.68 /* Methods for the pager. */ 13.69 13.70 void detach_pager(fileid_t fileid, PageMapper *mapper);
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/libfsserver/include/fsserver/filesystem_resource.h Sat Jul 24 18:55:21 2021 +0200 14.3 @@ -0,0 +1,52 @@ 14.4 +/* 14.5 + * A resource supporting the creation of user-specific opener resources. 14.6 + * 14.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 14.8 + * 14.9 + * This program is free software; you can redistribute it and/or 14.10 + * modify it under the terms of the GNU General Public License as 14.11 + * published by the Free Software Foundation; either version 2 of 14.12 + * the License, or (at your option) any later version. 14.13 + * 14.14 + * This program is distributed in the hope that it will be useful, 14.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14.17 + * GNU General Public License for more details. 14.18 + * 14.19 + * You should have received a copy of the GNU General Public License 14.20 + * along with this program; if not, write to the Free Software 14.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 14.22 + * Boston, MA 02110-1301, USA 14.23 + */ 14.24 + 14.25 +#pragma once 14.26 + 14.27 +#include <fsserver/file_paging.h> 14.28 +#include <fsserver/filesystem_interface.h> 14.29 +#include <fsserver/resource.h> 14.30 + 14.31 + 14.32 + 14.33 +/* Support for providing access to user-specific filesystems. */ 14.34 + 14.35 +class FilesystemResource : public Resource, public FilePaging, public Filesystem 14.36 +{ 14.37 +public: 14.38 + explicit FilesystemResource(Pages *pages); 14.39 + 14.40 + /* Server details. */ 14.41 + 14.42 + int expected_items(); 14.43 + 14.44 + ipc_server_handler_type handler(); 14.45 + 14.46 + void *interface() 14.47 + { return static_cast<Filesystem *>(this); } 14.48 + 14.49 + /* Filesystem interface methods. */ 14.50 + 14.51 + virtual long open_for_user(sys_uid_t uid, sys_gid_t gid, sys_mode_t umask, 14.52 + l4_cap_idx_t *opener) = 0; 14.53 +}; 14.54 + 14.55 +// vim: tabstop=4 expandtab shiftwidth=4
15.1 --- a/libfsserver/include/fsserver/host_file_opener.h Sun Jul 18 00:47:14 2021 +0200 15.2 +++ b/libfsserver/include/fsserver/host_file_opener.h Sat Jul 24 18:55:21 2021 +0200 15.3 @@ -48,17 +48,17 @@ 15.4 15.5 virtual fileid_t _get_fileid(const char *path, bool create); 15.6 15.7 +public: 15.8 + explicit HostFileOpener(FilePaging *paging) 15.9 + : OpenerResource(paging) 15.10 + { 15.11 + } 15.12 + 15.13 /* Configurable methods. */ 15.14 15.15 virtual fileid_t get_fileid(const char *path, flags_t flags); 15.16 15.17 virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); 15.18 - 15.19 -public: 15.20 - explicit HostFileOpener(Pages *pages) 15.21 - : OpenerResource(pages) 15.22 - { 15.23 - } 15.24 }; 15.25 15.26 // vim: tabstop=4 expandtab shiftwidth=4
16.1 --- a/libfsserver/include/fsserver/opener_resource.h Sun Jul 18 00:47:14 2021 +0200 16.2 +++ b/libfsserver/include/fsserver/opener_resource.h Sat Jul 24 18:55:21 2021 +0200 16.3 @@ -21,22 +21,23 @@ 16.4 16.5 #pragma once 16.6 16.7 -#include <l4/sys/ipc.h> 16.8 - 16.9 +#include <fsserver/file_opening.h> 16.10 #include <fsserver/file_paging.h> 16.11 #include <fsserver/opener_context_resource.h> 16.12 #include <fsserver/opener_interface.h> 16.13 -#include <fsserver/pages.h> 16.14 #include <fsserver/resource.h> 16.15 16.16 16.17 16.18 /* Support for providing access to files. */ 16.19 16.20 -class OpenerResource : public Resource, public FilePaging, public Opener 16.21 +class OpenerResource : public Resource, public FileOpening, public Opener 16.22 { 16.23 +protected: 16.24 + FilePaging *_paging; 16.25 + 16.26 public: 16.27 - explicit OpenerResource(Pages *pages); 16.28 + explicit OpenerResource(FilePaging *paging); 16.29 16.30 /* Server details. */ 16.31
17.1 --- a/libfsserver/include/fsserver/test_file_opener.h Sun Jul 18 00:47:14 2021 +0200 17.2 +++ b/libfsserver/include/fsserver/test_file_opener.h Sat Jul 24 18:55:21 2021 +0200 17.3 @@ -32,14 +32,14 @@ 17.4 protected: 17.5 offset_t _file_size; 17.6 17.7 +public: 17.8 + explicit TestFileOpener(FilePaging *paging, offset_t file_size=0); 17.9 + 17.10 /* Configurable methods. */ 17.11 17.12 virtual fileid_t get_fileid(const char *path, flags_t flags); 17.13 17.14 virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); 17.15 - 17.16 -public: 17.17 - explicit TestFileOpener(Pages *pages, offset_t file_size=0); 17.18 }; 17.19 17.20 // vim: tabstop=4 expandtab shiftwidth=4
18.1 --- a/libfsserver/lib/Makefile Sun Jul 18 00:47:14 2021 +0200 18.2 +++ b/libfsserver/lib/Makefile Sat Jul 24 18:55:21 2021 +0200 18.3 @@ -30,7 +30,7 @@ 18.4 18.5 CLIENT_INTERFACES_CC = notifier 18.6 18.7 -SERVER_INTERFACES_CC = opener pipe_opener $(call common_interfaces,$(COMP_INTERFACES_CC)) 18.8 +SERVER_INTERFACES_CC = filesystem opener pipe_opener $(call common_interfaces,$(COMP_INTERFACES_CC)) 18.9 18.10 # Generated and plain source files. 18.11 18.12 @@ -43,8 +43,10 @@ 18.13 files/block_file_opener.cc \ 18.14 files/ext2_file_accessor.cc \ 18.15 files/ext2_file_opener.cc \ 18.16 + files/ext2_filesystem.cc \ 18.17 files/file_pager.cc \ 18.18 files/file_paging.cc \ 18.19 + files/filesystem_resource.cc \ 18.20 files/host_file_accessor.cc \ 18.21 files/host_file_opener.cc \ 18.22 files/opener_context_resource.cc \
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/libfsserver/lib/files/ext2_filesystem.cc Sat Jul 24 18:55:21 2021 +0200 19.3 @@ -0,0 +1,40 @@ 19.4 +/* 19.5 + * A resource supporting the creation of user-specific ext2 filesystem opener 19.6 + * resources. 19.7 + * 19.8 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 19.9 + * 19.10 + * This program is free software; you can redistribute it and/or 19.11 + * modify it under the terms of the GNU General Public License as 19.12 + * published by the Free Software Foundation; either version 2 of 19.13 + * the License, or (at your option) any later version. 19.14 + * 19.15 + * This program is distributed in the hope that it will be useful, 19.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 19.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19.18 + * GNU General Public License for more details. 19.19 + * 19.20 + * You should have received a copy of the GNU General Public License 19.21 + * along with this program; if not, write to the Free Software 19.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19.23 + * Boston, MA 02110-1301, USA 19.24 + */ 19.25 + 19.26 +#include "ext2_file_opener.h" 19.27 +#include "ext2_filesystem.h" 19.28 +#include "resource_server.h" 19.29 + 19.30 +/* Return a file opener object for the given user. */ 19.31 + 19.32 +long Ext2Filesystem::open_for_user(sys_uid_t uid, sys_gid_t gid, 19.33 + sys_mode_t umask, l4_cap_idx_t *ref) 19.34 +{ 19.35 + Resource *resource = new Ext2FileOpener(this, _fs, uid, gid, umask); 19.36 + 19.37 + /* Complete the initialisation and start a server in a new thread. 19.38 + If the thread does not start, the resource will be finalised. */ 19.39 + 19.40 + return ResourceServer(resource).start_thread(ref); 19.41 +} 19.42 + 19.43 +// vim: tabstop=4 expandtab shiftwidth=4
20.1 --- a/libfsserver/lib/files/file_paging.cc Sun Jul 18 00:47:14 2021 +0200 20.2 +++ b/libfsserver/lib/files/file_paging.cc Sat Jul 24 18:55:21 2021 +0200 20.3 @@ -82,7 +82,7 @@ 20.4 /* Obtain a page mapper for the 'fileid' or register a new one in the 20.5 paging object. */ 20.6 20.7 -long FilePaging::get_mapper(const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper) 20.8 +long FilePaging::get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper) 20.9 { 20.10 /* Obtain any registered page mapper. */ 20.11 20.12 @@ -94,7 +94,7 @@ 20.13 /* Make an accessor and page mapper, registering the mapper. */ 20.14 20.15 Accessor *accessor; 20.16 - long err = make_accessor(path, flags, fileid, &accessor); 20.17 + long err = opening->make_accessor(path, flags, fileid, &accessor); 20.18 20.19 if (err) 20.20 return err; 20.21 @@ -110,13 +110,13 @@ 20.22 20.23 /* Return a pager initialised with a page mapper. */ 20.24 20.25 -long FilePaging::get_pager(const char *path, flags_t flags, Pager **pager) 20.26 +long FilePaging::get_pager(FileOpening *opening, const char *path, flags_t flags, Pager **pager) 20.27 { 20.28 std::lock_guard<std::mutex> guard(_lock); 20.29 20.30 /* Obtain an identifier for the file, even for new files. */ 20.31 20.32 - fileid_t fileid = get_fileid(path, flags); 20.33 + fileid_t fileid = opening->get_fileid(path, flags); 20.34 20.35 if (fileid == FILEID_INVALID) 20.36 return -L4_ENOENT; 20.37 @@ -125,7 +125,7 @@ 20.38 page mapper. */ 20.39 20.40 PageMapper *mapper; 20.41 - long err = get_mapper(path, flags, fileid, &mapper); 20.42 + long err = get_mapper(opening, path, flags, fileid, &mapper); 20.43 20.44 if (err) 20.45 return err;
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/libfsserver/lib/files/filesystem_resource.cc Sat Jul 24 18:55:21 2021 +0200 21.3 @@ -0,0 +1,42 @@ 21.4 +/* 21.5 + * A resource supporting the creation of user-specific opener resources. 21.6 + * 21.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 21.8 + * 21.9 + * This program is free software; you can redistribute it and/or 21.10 + * modify it under the terms of the GNU General Public License as 21.11 + * published by the Free Software Foundation; either version 2 of 21.12 + * the License, or (at your option) any later version. 21.13 + * 21.14 + * This program is distributed in the hope that it will be useful, 21.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 21.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21.17 + * GNU General Public License for more details. 21.18 + * 21.19 + * You should have received a copy of the GNU General Public License 21.20 + * along with this program; if not, write to the Free Software 21.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 21.22 + * Boston, MA 02110-1301, USA 21.23 + */ 21.24 + 21.25 +#include "filesystem_server.h" 21.26 +#include "filesystem_resource.h" 21.27 + 21.28 +/* Support for providing access to user-specific filesystems. */ 21.29 + 21.30 +FilesystemResource::FilesystemResource(Pages *pages) 21.31 +: FilePaging(pages) 21.32 +{ 21.33 +} 21.34 + 21.35 +int FilesystemResource::expected_items() 21.36 +{ 21.37 + return Filesystem_expected_items; 21.38 +} 21.39 + 21.40 +ipc_server_handler_type FilesystemResource::handler() 21.41 +{ 21.42 + return (ipc_server_handler_type) handle_Filesystem; 21.43 +} 21.44 + 21.45 +// vim: tabstop=4 expandtab shiftwidth=4
22.1 --- a/libfsserver/lib/files/opener_resource.cc Sun Jul 18 00:47:14 2021 +0200 22.2 +++ b/libfsserver/lib/files/opener_resource.cc Sat Jul 24 18:55:21 2021 +0200 22.3 @@ -25,8 +25,8 @@ 22.4 22.5 /* Support for providing access to files. */ 22.6 22.7 -OpenerResource::OpenerResource(Pages *pages) 22.8 -: FilePaging(pages) 22.9 +OpenerResource::OpenerResource(FilePaging *paging) 22.10 +: _paging(paging) 22.11 { 22.12 } 22.13 22.14 @@ -46,7 +46,7 @@ 22.15 22.16 long OpenerResource::open(const char *path, flags_t flags, Pager **pager) 22.17 { 22.18 - return get_pager(path, flags, pager); 22.19 + return _paging->get_pager(this, path, flags, pager); 22.20 } 22.21 22.22
23.1 --- a/libfsserver/lib/files/test_file_opener.cc Sun Jul 18 00:47:14 2021 +0200 23.2 +++ b/libfsserver/lib/files/test_file_opener.cc Sat Jul 24 18:55:21 2021 +0200 23.3 @@ -26,8 +26,8 @@ 23.4 23.5 /* Support for providing access to files. */ 23.6 23.7 -TestFileOpener::TestFileOpener(Pages *pages, offset_t file_size) 23.8 -: OpenerResource(pages), _file_size(file_size) 23.9 +TestFileOpener::TestFileOpener(FilePaging *paging, offset_t file_size) 23.10 +: OpenerResource(paging), _file_size(file_size) 23.11 { 23.12 } 23.13
24.1 --- a/servers/block_file_server.cc Sun Jul 18 00:47:14 2021 +0200 24.2 +++ b/servers/block_file_server.cc Sat Jul 24 18:55:21 2021 +0200 24.3 @@ -66,7 +66,8 @@ 24.4 MemoryIncremental mem(memory_pages); 24.5 PageQueueShared queue; 24.6 Pages pages(&mem, &queue); 24.7 - BlockFileOpener opener(&pages); 24.8 + FilePaging paging(&pages); 24.9 + BlockFileOpener opener(&paging); 24.10 24.11 /* Register a server associating it with the given object. */ 24.12
25.1 --- a/servers/client_file_server.cc Sun Jul 18 00:47:14 2021 +0200 25.2 +++ b/servers/client_file_server.cc Sat Jul 24 18:55:21 2021 +0200 25.3 @@ -67,7 +67,8 @@ 25.4 MemoryIncremental mem(memory_pages); 25.5 PageQueueShared queue; 25.6 Pages pages(&mem, &queue); 25.7 - ClientFileOpener opener(&pages); 25.8 + FilePaging paging(&pages); 25.9 + ClientFileOpener opener(&paging); 25.10 25.11 /* Register a server associating it with the given object. */ 25.12
26.1 --- a/servers/ext2_file_server.cc Sun Jul 18 00:47:14 2021 +0200 26.2 +++ b/servers/ext2_file_server.cc Sat Jul 24 18:55:21 2021 +0200 26.3 @@ -30,7 +30,7 @@ 26.4 #include <fsserver/page_queue_shared.h> 26.5 #include <fsserver/pages.h> 26.6 #include <fsserver/resource_server.h> 26.7 -#include <fsserver/ext2_file_opener.h> 26.8 +#include <fsserver/ext2_filesystem.h> 26.9 #include <mem/memory_incremental.h> 26.10 26.11 26.12 @@ -94,11 +94,11 @@ 26.13 MemoryIncremental mem(memory_pages); 26.14 PageQueueShared queue; 26.15 Pages pages(&mem, &queue); 26.16 - Ext2FileOpener opener(fs, &pages); 26.17 + Ext2Filesystem filesystem(&pages, fs); 26.18 26.19 /* Register a server associating it with the given object. */ 26.20 26.21 - ResourceServer server(&opener); 26.22 + ResourceServer server(&filesystem); 26.23 err = server.bind(server_name); 26.24 26.25 if (err)
27.1 --- a/servers/host_file_server.cc Sun Jul 18 00:47:14 2021 +0200 27.2 +++ b/servers/host_file_server.cc Sat Jul 24 18:55:21 2021 +0200 27.3 @@ -66,7 +66,8 @@ 27.4 MemoryIncremental mem(memory_pages); 27.5 PageQueueShared queue; 27.6 Pages pages(&mem, &queue); 27.7 - HostFileOpener opener(&pages); 27.8 + FilePaging paging(&pages); 27.9 + HostFileOpener opener(&paging); 27.10 27.11 /* Register a server associating it with the given object. */ 27.12
28.1 --- a/servers/test_file_server.cc Sun Jul 18 00:47:14 2021 +0200 28.2 +++ b/servers/test_file_server.cc Sat Jul 24 18:55:21 2021 +0200 28.3 @@ -65,7 +65,8 @@ 28.4 MemoryIncremental mem(memory_pages, page(REGION_PAGES)); 28.5 PageQueueShared queue; 28.6 Pages pages(&mem, &queue); 28.7 - TestFileOpener opener(&pages, page(FILE_PAGES)); 28.8 + FilePaging paging(&pages); 28.9 + TestFileOpener opener(&paging, page(FILE_PAGES)); 28.10 28.11 /* Register a server associating it with the given object. */ 28.12
29.1 --- a/tests/dstest_block_client_simple.cc Sun Jul 18 00:47:14 2021 +0200 29.2 +++ b/tests/dstest_block_client_simple.cc Sat Jul 24 18:55:21 2021 +0200 29.3 @@ -32,18 +32,35 @@ 29.4 { 29.5 if (argc < 2) 29.6 { 29.7 - printf("Need a filename and optional repetition.\n"); 29.8 + printf("Need a filename, optional user identifier, and optional repetition.\n"); 29.9 return 1; 29.10 } 29.11 29.12 /* Obtain filename and access parameters. */ 29.13 29.14 char *filename = argv[1]; 29.15 - int repetition = argc > 2 ? atoi(argv[2]) : 10; 29.16 + sys_uid_t uid = argc > 2 ? atoi(argv[2]) : 0; 29.17 + int repetition = argc > 3 ? atoi(argv[3]) : 10; 29.18 + file_t *file; 29.19 + 29.20 + /* With a user, open a user-specific file opener. */ 29.21 + 29.22 + if (uid) 29.23 + { 29.24 + l4_cap_idx_t opener = client_open_for_user(uid, uid, 0022); 29.25 29.26 - /* Invoke the open method to receive the file reference. */ 29.27 + if (l4_is_invalid_cap(opener)) 29.28 + { 29.29 + printf("Could not obtain opener for file.\n"); 29.30 + return 1; 29.31 + } 29.32 29.33 - file_t *file = client_open(filename, O_RDWR); 29.34 + /* Invoke the open method to receive the file reference. */ 29.35 + 29.36 + file = client_open_using(filename, O_RDWR, opener); 29.37 + } 29.38 + else 29.39 + file = client_open(filename, O_RDWR); 29.40 29.41 if (file == NULL) 29.42 {