1.1 --- a/conf/dstest_client.cfg Thu Apr 22 00:12:16 2021 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,34 +0,0 @@ 1.4 --- vim:set ft=lua: 1.5 - 1.6 -local L4 = require("L4"); 1.7 - 1.8 -local l = L4.default_loader; 1.9 - 1.10 -local blocksvr = l:new_channel(); 1.11 - 1.12 -l:startv({ 1.13 - caps = { 1.14 - server = blocksvr:svr(), 1.15 - }, 1.16 - log = { "blocksvr", "r" }, 1.17 - }, 1.18 - "rom/dstest_block_server", "10"); 1.19 - 1.20 -local clientsvr = l:new_channel(); 1.21 - 1.22 -l:startv({ 1.23 - caps = { 1.24 - server = blocksvr, 1.25 - clientsvr = clientsvr:svr(), 1.26 - }, 1.27 - log = { "clientsvr", "r" }, 1.28 - }, 1.29 - "rom/dstest_client_server", "10", "clientsvr"); 1.30 - 1.31 -l:startv({ 1.32 - caps = { 1.33 - server = clientsvr, 1.34 - }, 1.35 - log = { "client", "g" }, 1.36 - }, 1.37 - "rom/dstest_block_client_simple", "rom/dstest_client.cfg");
2.1 --- a/conf/dstest_client.list Thu Apr 22 00:12:16 2021 +0200 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,26 +0,0 @@ 2.4 -entry dstest_client 2.5 -roottask moe rom/dstest_client.cfg 2.6 -module dstest_client.cfg 2.7 -module l4re 2.8 -module ned 2.9 -module dstest_block_client_simple 2.10 -module dstest_block_server 2.11 -module dstest_client_server 2.12 -module lib4re-c.so 2.13 -module lib4re-c-util.so 2.14 -module lib4re.so 2.15 -module lib4re-util.so 2.16 -module libc_be_l4refile.so 2.17 -module libc_be_l4re.so 2.18 -module libc_be_socket_noop.so 2.19 -module libc_support_misc.so 2.20 -module libdl.so 2.21 -module libipc.so 2.22 -module libl4sys-direct.so 2.23 -module libl4sys.so 2.24 -module libl4util.so 2.25 -module libld-l4.so 2.26 -module libpthread.so 2.27 -module libstdc++.so 2.28 -module libsupc++.so 2.29 -module libuc_c.so
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/conf/dstest_ext2.cfg Sat Apr 24 23:15:21 2021 +0200 3.3 @@ -0,0 +1,34 @@ 3.4 +-- vim:set ft=lua: 3.5 + 3.6 +local L4 = require("L4"); 3.7 + 3.8 +local l = L4.default_loader; 3.9 + 3.10 +local blocksvr = l:new_channel(); 3.11 + 3.12 +l:startv({ 3.13 + caps = { 3.14 + server = blocksvr:svr(), 3.15 + }, 3.16 + log = { "blocksvr", "r" }, 3.17 + }, 3.18 + "rom/dstest_block_server", "10"); 3.19 + 3.20 +local ext2svr = l:new_channel(); 3.21 + 3.22 +l:startv({ 3.23 + caps = { 3.24 + blocksvr = blocksvr, 3.25 + ext2svr = ext2svr:svr(), 3.26 + }, 3.27 + log = { "ext2svr", "y" }, 3.28 + }, 3.29 + "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr"); 3.30 + 3.31 +l:startv({ 3.32 + caps = { 3.33 + server = ext2svr, 3.34 + }, 3.35 + log = { "client", "g" }, 3.36 + }, 3.37 + "rom/dstest_block_client_simple", "home/paulb/LICENCE.txt", "1");
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/conf/dstest_ext2.list Sat Apr 24 23:15:21 2021 +0200 4.3 @@ -0,0 +1,27 @@ 4.4 +entry dstest_ext2 4.5 +roottask moe rom/dstest_ext2.cfg 4.6 +module dstest_ext2.cfg 4.7 +module e2test.fs 4.8 +module l4re 4.9 +module ned 4.10 +module dstest_block_client_simple 4.11 +module dstest_block_server 4.12 +module dstest_ext2_server 4.13 +module lib4re-c.so 4.14 +module lib4re-c-util.so 4.15 +module lib4re.so 4.16 +module lib4re-util.so 4.17 +module libc_be_l4refile.so 4.18 +module libc_be_l4re.so 4.19 +module libc_be_socket_noop.so 4.20 +module libc_support_misc.so 4.21 +module libdl.so 4.22 +module libipc.so 4.23 +module libl4sys-direct.so 4.24 +module libl4sys.so 4.25 +module libl4util.so 4.26 +module libld-l4.so 4.27 +module libpthread.so 4.28 +module libstdc++.so 4.29 +module libsupc++.so 4.30 +module libuc_c.so
5.1 --- a/libfsserver/Control Thu Apr 22 00:12:16 2021 +0200 5.2 +++ b/libfsserver/Control Sat Apr 24 23:15:21 2021 +0200 5.3 @@ -1,3 +1,3 @@ 5.4 -requires: libstdc++ libc libipc libmem libfsclient 5.5 +requires: libstdc++ libc libipc libmem libfsclient libext2fs libext2fs_blockserver libe2access libe2access_blockserver 5.6 provides: libfsserver 5.7 maintainer: paul@boddie.org.uk
6.1 --- a/libfsserver/include/fsserver/accessor.h Thu Apr 22 00:12:16 2021 +0200 6.2 +++ b/libfsserver/include/fsserver/accessor.h Sat Apr 24 23:15:21 2021 +0200 6.3 @@ -51,8 +51,6 @@ 6.4 6.5 virtual void close(); 6.6 6.7 - virtual void open(); 6.8 - 6.9 /* Data transfer methods. */ 6.10 6.11 virtual void fill(Flexpage *flexpage);
7.1 --- a/libfsserver/include/fsserver/block_file_accessor.h Thu Apr 22 00:12:16 2021 +0200 7.2 +++ b/libfsserver/include/fsserver/block_file_accessor.h Sat Apr 24 23:15:21 2021 +0200 7.3 @@ -21,6 +21,8 @@ 7.4 7.5 #pragma once 7.6 7.7 +#include <stdio.h> 7.8 + 7.9 #include <fsserver/accessor.h> 7.10 7.11 7.12 @@ -32,6 +34,7 @@ 7.13 { 7.14 protected: 7.15 offset_t _size; 7.16 + FILE *_fp; 7.17 char *_data; 7.18 7.19 /* Data transfer helper methods. */ 7.20 @@ -41,7 +44,7 @@ 7.21 virtual void flush_populated(Flexpage *flexpage); 7.22 7.23 public: 7.24 - explicit BlockFileAccessor(const char *path, fileid_t fileid); 7.25 + explicit BlockFileAccessor(FILE *fp, fileid_t fileid); 7.26 7.27 virtual offset_t get_size(); 7.28
8.1 --- a/libfsserver/include/fsserver/block_file_opener.h Thu Apr 22 00:12:16 2021 +0200 8.2 +++ b/libfsserver/include/fsserver/block_file_opener.h Sat Apr 24 23:15:21 2021 +0200 8.3 @@ -32,7 +32,7 @@ 8.4 protected: 8.5 /* Configurable methods. */ 8.6 8.7 - virtual Accessor *make_accessor(fileid_t fileid); 8.8 + virtual Accessor *make_accessor(const char *path, fileid_t fileid); 8.9 8.10 public: 8.11 explicit BlockFileOpener(Pages *pages)
9.1 --- a/libfsserver/include/fsserver/client_file_accessor.h Thu Apr 22 00:12:16 2021 +0200 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,58 +0,0 @@ 9.4 -/* 9.5 - * A file accessor employing a file provided via the filesystem client 9.6 - * interface. 9.7 - * 9.8 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 9.9 - * 9.10 - * This program is free software; you can redistribute it and/or 9.11 - * modify it under the terms of the GNU General Public License as 9.12 - * published by the Free Software Foundation; either version 2 of 9.13 - * the License, or (at your option) any later version. 9.14 - * 9.15 - * This program is distributed in the hope that it will be useful, 9.16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 9.17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9.18 - * GNU General Public License for more details. 9.19 - * 9.20 - * You should have received a copy of the GNU General Public License 9.21 - * along with this program; if not, write to the Free Software 9.22 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 9.23 - * Boston, MA 02110-1301, USA 9.24 - */ 9.25 - 9.26 -#pragma once 9.27 - 9.28 -#include <fsserver/accessor.h> 9.29 - 9.30 -#include <fsclient/file.h> 9.31 - 9.32 - 9.33 - 9.34 -/* A filesystem client file accessor, providing flexpages corresponding to file 9.35 - regions. */ 9.36 - 9.37 -class ClientFileAccessor : public Accessor 9.38 -{ 9.39 -protected: 9.40 - const char *_path; 9.41 - file_t *_file; 9.42 - 9.43 - /* Data transfer helper methods. */ 9.44 - 9.45 - virtual void fill_populated(Flexpage *flexpage); 9.46 - 9.47 - virtual void flush_populated(Flexpage *flexpage); 9.48 - 9.49 -public: 9.50 - explicit ClientFileAccessor(const char *path, fileid_t fileid); 9.51 - 9.52 - virtual void close(); 9.53 - 9.54 - virtual void open(); 9.55 - 9.56 - virtual offset_t get_size(); 9.57 - 9.58 - virtual void set_size(offset_t size); 9.59 -}; 9.60 - 9.61 -// vim: tabstop=4 expandtab shiftwidth=4
10.1 --- a/libfsserver/include/fsserver/client_file_opener.h Thu Apr 22 00:12:16 2021 +0200 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,49 +0,0 @@ 10.4 -/* 10.5 - * An opener for a file provided via the filesystem client interface. 10.6 - * 10.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 10.8 - * 10.9 - * This program is free software; you can redistribute it and/or 10.10 - * modify it under the terms of the GNU General Public License as 10.11 - * published by the Free Software Foundation; either version 2 of 10.12 - * the License, or (at your option) any later version. 10.13 - * 10.14 - * This program is distributed in the hope that it will be useful, 10.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10.17 - * GNU General Public License for more details. 10.18 - * 10.19 - * You should have received a copy of the GNU General Public License 10.20 - * along with this program; if not, write to the Free Software 10.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 10.22 - * Boston, MA 02110-1301, USA 10.23 - */ 10.24 - 10.25 -#pragma once 10.26 - 10.27 -#include <fsserver/host_file_opener.h> 10.28 - 10.29 - 10.30 - 10.31 -/* Support for providing access to files. */ 10.32 - 10.33 -class ClientFileOpener : public HostFileOpener 10.34 -{ 10.35 -protected: 10.36 - //const char *_filename; 10.37 - fileid_t _counter = 1; // NOTE: Temporary measure. 10.38 - 10.39 - /* Configurable methods. */ 10.40 - 10.41 - virtual fileid_t get_fileid(const char *path); 10.42 - 10.43 - virtual Accessor *make_accessor(fileid_t fileid); 10.44 - 10.45 -public: 10.46 - explicit ClientFileOpener(Pages *pages) 10.47 - : HostFileOpener(pages) 10.48 - { 10.49 - } 10.50 -}; 10.51 - 10.52 -// 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_file_accessor.h Sat Apr 24 23:15:21 2021 +0200 11.3 @@ -0,0 +1,53 @@ 11.4 +/* 11.5 + * A file accessor employing a file provided by an Ext2-compatible filesystem. 11.6 + * 11.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 11.8 + * 11.9 + * This program is free software; you can redistribute it and/or 11.10 + * modify it under the terms of the GNU General Public License as 11.11 + * published by the Free Software Foundation; either version 2 of 11.12 + * the License, or (at your option) any later version. 11.13 + * 11.14 + * This program is distributed in the hope that it will be useful, 11.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11.17 + * GNU General Public License for more details. 11.18 + * 11.19 + * You should have received a copy of the GNU General Public License 11.20 + * along with this program; if not, write to the Free Software 11.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 11.22 + * Boston, MA 02110-1301, USA 11.23 + */ 11.24 + 11.25 +#pragma once 11.26 + 11.27 +#include <ext2fs/ext2fs.h> 11.28 + 11.29 +#include <fsserver/accessor.h> 11.30 + 11.31 + 11.32 + 11.33 +/* An Ext2 file accessor, providing flexpages corresponding to file regions. */ 11.34 + 11.35 +class Ext2FileAccessor : public Accessor 11.36 +{ 11.37 +protected: 11.38 + ext2_file_t _file; 11.39 + 11.40 + /* Data transfer helper methods. */ 11.41 + 11.42 + virtual void fill_populated(Flexpage *flexpage); 11.43 + 11.44 + virtual void flush_populated(Flexpage *flexpage); 11.45 + 11.46 +public: 11.47 + explicit Ext2FileAccessor(ext2_file_t file, fileid_t fileid); 11.48 + 11.49 + virtual void close(); 11.50 + 11.51 + virtual offset_t get_size(); 11.52 + 11.53 + virtual void set_size(offset_t size); 11.54 +}; 11.55 + 11.56 +// vim: tabstop=4 expandtab shiftwidth=4
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Sat Apr 24 23:15:21 2021 +0200 12.3 @@ -0,0 +1,50 @@ 12.4 +/* 12.5 + * An opener for a file provided by an Ext2-compatible filesystem. 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 <ext2fs/ext2fs.h> 12.28 + 12.29 +#include <fsserver/opener_resource.h> 12.30 + 12.31 + 12.32 + 12.33 +/* Support for providing access to files. */ 12.34 + 12.35 +class Ext2FileOpener : public OpenerResource 12.36 +{ 12.37 +protected: 12.38 + ext2_filsys _fs; 12.39 + 12.40 + /* Configurable methods. */ 12.41 + 12.42 + virtual fileid_t get_fileid(const char *path); 12.43 + 12.44 + virtual Accessor *make_accessor(const char *path, fileid_t fileid); 12.45 + 12.46 +public: 12.47 + explicit Ext2FileOpener(ext2_filsys fs, Pages *pages) 12.48 + : OpenerResource(pages), _fs(fs) 12.49 + { 12.50 + } 12.51 +}; 12.52 + 12.53 +// vim: tabstop=4 expandtab shiftwidth=4
13.1 --- a/libfsserver/include/fsserver/file_paging.h Thu Apr 22 00:12:16 2021 +0200 13.2 +++ b/libfsserver/include/fsserver/file_paging.h Sat Apr 24 23:15:21 2021 +0200 13.3 @@ -49,9 +49,9 @@ 13.4 13.5 /* Pager initialisation methods. */ 13.6 13.7 - PageMapper *get_mapper(fileid_t fileid); 13.8 + PageMapper *get_mapper(const char *path, fileid_t fileid); 13.9 13.10 - Pager *get_pager(fileid_t fileid, flags_t flags); 13.11 + Pager *get_pager(const char *path, fileid_t fileid, flags_t flags); 13.12 13.13 /* Configurable methods. */ 13.14 13.15 @@ -59,12 +59,14 @@ 13.16 13.17 virtual flags_t get_flags(flags_t flags); 13.18 13.19 - virtual Accessor *make_accessor(fileid_t fileid) = 0; 13.20 + virtual Accessor *make_accessor(const char *path, fileid_t fileid) = 0; 13.21 13.22 /* Mapper registry access. */ 13.23 13.24 PageMapper *get(fileid_t fileid); 13.25 13.26 + void remove(fileid_t fileid, PageMapper *mapper); 13.27 + 13.28 void set(fileid_t fileid, PageMapper *mapper); 13.29 13.30 public:
14.1 --- a/libfsserver/include/fsserver/host_file_accessor.h Thu Apr 22 00:12:16 2021 +0200 14.2 +++ b/libfsserver/include/fsserver/host_file_accessor.h Sat Apr 24 23:15:21 2021 +0200 14.3 @@ -34,7 +34,6 @@ 14.4 { 14.5 protected: 14.6 offset_t _size; 14.7 - const char *_path; 14.8 FILE *_fp; 14.9 14.10 /* Data transfer helper methods. */ 14.11 @@ -44,15 +43,13 @@ 14.12 virtual void flush_populated(Flexpage *flexpage); 14.13 14.14 public: 14.15 - explicit HostFileAccessor(const char *path, fileid_t fileid); 14.16 + explicit HostFileAccessor(FILE *fp, fileid_t fileid); 14.17 14.18 virtual offset_t get_size(); 14.19 14.20 virtual void set_size(offset_t size); 14.21 14.22 virtual void close(); 14.23 - 14.24 - virtual void open(); 14.25 }; 14.26 14.27 // vim: tabstop=4 expandtab shiftwidth=4
15.1 --- a/libfsserver/include/fsserver/host_file_opener.h Thu Apr 22 00:12:16 2021 +0200 15.2 +++ b/libfsserver/include/fsserver/host_file_opener.h Sat Apr 24 23:15:21 2021 +0200 15.3 @@ -27,25 +27,17 @@ 15.4 15.5 15.6 15.7 -/* Collection types. */ 15.8 - 15.9 -typedef std::map<fileid_t, const char *> FilePaths; 15.10 -typedef std::pair<fileid_t, const char *> FilePathEntry; 15.11 - 15.12 - 15.13 - 15.14 /* Support for providing access to files. */ 15.15 15.16 class HostFileOpener : public OpenerResource 15.17 { 15.18 protected: 15.19 - FilePaths _paths; 15.20 15.21 /* Configurable methods. */ 15.22 15.23 virtual fileid_t get_fileid(const char *path); 15.24 15.25 - virtual Accessor *make_accessor(fileid_t fileid); 15.26 + virtual Accessor *make_accessor(const char *path, fileid_t fileid); 15.27 15.28 public: 15.29 explicit HostFileOpener(Pages *pages)
16.1 --- a/libfsserver/include/fsserver/test_file_opener.h Thu Apr 22 00:12:16 2021 +0200 16.2 +++ b/libfsserver/include/fsserver/test_file_opener.h Sat Apr 24 23:15:21 2021 +0200 16.3 @@ -36,7 +36,7 @@ 16.4 16.5 virtual fileid_t get_fileid(const char *path); 16.6 16.7 - virtual Accessor *make_accessor(fileid_t fileid); 16.8 + virtual Accessor *make_accessor(const char *path, fileid_t fileid); 16.9 16.10 public: 16.11 explicit TestFileOpener(Pages *pages, offset_t file_size=0);
17.1 --- a/libfsserver/lib/Makefile Thu Apr 22 00:12:16 2021 +0200 17.2 +++ b/libfsserver/lib/Makefile Sat Apr 24 23:15:21 2021 +0200 17.3 @@ -37,8 +37,8 @@ 17.4 PLAIN_SRC_CC = \ 17.5 files/block_file_accessor.cc \ 17.6 files/block_file_opener.cc \ 17.7 - files/client_file_accessor.cc \ 17.8 - files/client_file_opener.cc \ 17.9 + files/ext2_file_accessor.cc \ 17.10 + files/ext2_file_opener.cc \ 17.11 files/file_pager.cc \ 17.12 files/file_paging.cc \ 17.13 files/host_file_accessor.cc \ 17.14 @@ -69,7 +69,9 @@ 17.15 $(SERVER_INTERFACES_SRC_CC) \ 17.16 $(PLAIN_SRC_CC) 17.17 17.18 -REQUIRES_LIBS = l4re_c-util libmem libipc libstdc++ libsystypes libfsclient 17.19 +REQUIRES_LIBS = \ 17.20 + l4re_c-util libmem libipc libstdc++ libsystypes libfsclient \ 17.21 + libext2fs libext2fs_blockserver libe2access libe2access_blockserver 17.22 17.23 PRIVATE_INCDIR = $(PKGDIR)/include $(PKGDIR)/include/fsserver \ 17.24 $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
18.1 --- a/libfsserver/lib/files/block_file_accessor.cc Thu Apr 22 00:12:16 2021 +0200 18.2 +++ b/libfsserver/lib/files/block_file_accessor.cc Sat Apr 24 23:15:21 2021 +0200 18.3 @@ -30,14 +30,14 @@ 18.4 18.5 18.6 18.7 -BlockFileAccessor::BlockFileAccessor(const char *path, fileid_t fileid) 18.8 -: Accessor(fileid) 18.9 +BlockFileAccessor::BlockFileAccessor(FILE *fp, fileid_t fileid) 18.10 +: Accessor(fileid), _fp(fp) 18.11 { 18.12 /* Obtain the size of the file. */ 18.13 18.14 struct stat buf; 18.15 18.16 - if (stat(path, &buf)) 18.17 + if (fstat(fileno(fp), &buf)) 18.18 { 18.19 _size = 0; 18.20 return; 18.21 @@ -53,17 +53,7 @@ 18.22 18.23 /* Load the file into memory and initialise the size. */ 18.24 18.25 - FILE *fp = fopen(path, "r"); 18.26 - 18.27 - if (fp == NULL) 18.28 - { 18.29 - free(_data); 18.30 - return; 18.31 - } 18.32 - 18.33 _size = fread(_data, sizeof(char), _size, fp); 18.34 - 18.35 - fclose(fp); 18.36 } 18.37 18.38 /* Return the size of the file. */
19.1 --- a/libfsserver/lib/files/block_file_opener.cc Thu Apr 22 00:12:16 2021 +0200 19.2 +++ b/libfsserver/lib/files/block_file_opener.cc Sat Apr 24 23:15:21 2021 +0200 19.3 @@ -24,14 +24,14 @@ 19.4 19.5 /* Return a new accessor for 'fileid'. */ 19.6 19.7 -Accessor *BlockFileOpener::make_accessor(fileid_t fileid) 19.8 +Accessor *BlockFileOpener::make_accessor(const char *path, fileid_t fileid) 19.9 { 19.10 - FilePaths::iterator found = _paths.find(fileid); 19.11 + FILE *fp = fopen(path, "r"); 19.12 19.13 - if (found != _paths.end()) 19.14 - return new BlockFileAccessor(found->second, fileid); 19.15 - else 19.16 + if (fp == NULL) 19.17 return NULL; 19.18 + 19.19 + return new BlockFileAccessor(fp, fileid); 19.20 } 19.21 19.22 // vim: tabstop=4 expandtab shiftwidth=4
20.1 --- a/libfsserver/lib/files/client_file_accessor.cc Thu Apr 22 00:12:16 2021 +0200 20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 20.3 @@ -1,108 +0,0 @@ 20.4 -/* 20.5 - * A file accessor using the filesystem client interface. 20.6 - * 20.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 20.8 - * 20.9 - * This program is free software; you can redistribute it and/or 20.10 - * modify it under the terms of the GNU General Public License as 20.11 - * published by the Free Software Foundation; either version 2 of 20.12 - * the License, or (at your option) any later version. 20.13 - * 20.14 - * This program is distributed in the hope that it will be useful, 20.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 20.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20.17 - * GNU General Public License for more details. 20.18 - * 20.19 - * You should have received a copy of the GNU General Public License 20.20 - * along with this program; if not, write to the Free Software 20.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20.22 - * Boston, MA 02110-1301, USA 20.23 - */ 20.24 - 20.25 -#include <stdio.h> 20.26 -#include <string.h> 20.27 - 20.28 -#include <algorithm> 20.29 - 20.30 -#include <fsclient/client.h> 20.31 -#include <systypes/fcntl.h> 20.32 - 20.33 -#include "client_file_accessor.h" 20.34 - 20.35 - 20.36 - 20.37 -ClientFileAccessor::ClientFileAccessor(const char *path, fileid_t fileid) 20.38 -: Accessor(fileid), _path(path) 20.39 -{ 20.40 -} 20.41 - 20.42 -/* Return the size of the file. */ 20.43 - 20.44 -offset_t ClientFileAccessor::get_size() 20.45 -{ 20.46 - return _file->size; 20.47 -} 20.48 - 20.49 -/* Update the size of the file. */ 20.50 - 20.51 -void ClientFileAccessor::set_size(offset_t size) 20.52 -{ 20.53 - file_resize(_file, size); 20.54 -} 20.55 - 20.56 -/* Perform any closing operation on the file. */ 20.57 - 20.58 -void ClientFileAccessor::close() 20.59 -{ 20.60 - client_close(_file); 20.61 -} 20.62 - 20.63 -/* Perform any opening operation on the file. */ 20.64 - 20.65 -void ClientFileAccessor::open() 20.66 -{ 20.67 - _file = client_open(_path, O_RDWR); 20.68 -} 20.69 - 20.70 -/* Data transfer helper methods. */ 20.71 - 20.72 -/* Fill the populated portion of a flexpage. */ 20.73 - 20.74 -void ClientFileAccessor::fill_populated(Flexpage *flexpage) 20.75 -{ 20.76 - offset_t filepos = flexpage->base_offset; 20.77 - offset_t addr = flexpage->base_addr; 20.78 - 20.79 - /* Tag the region with file state. */ 20.80 - 20.81 - flexpage->region->fill(fileid, filepos); 20.82 - 20.83 - /* Fill the region with file content. */ 20.84 - 20.85 - client_seek(_file, filepos, SEEK_SET); 20.86 - offset_t nread = client_read(_file, (char *) addr, flexpage->size); 20.87 - 20.88 - /* Pad the flexpage with zero. */ 20.89 - 20.90 - memset((void *) (addr + nread), 0, flexpage->size - nread); 20.91 -} 20.92 - 20.93 -/* Flush the populated portion of a flexpage. */ 20.94 - 20.95 -void ClientFileAccessor::flush_populated(Flexpage *flexpage) 20.96 -{ 20.97 - offset_t filepos = flexpage->base_offset; 20.98 - offset_t addr = flexpage->base_addr; 20.99 - offset_t populated_size = std::min(flexpage->size, get_size() - filepos); 20.100 - 20.101 - /* Remove the file state tag from the region. */ 20.102 - 20.103 - flexpage->region->flush(); 20.104 - 20.105 - /* Copy the populated region to the file. */ 20.106 - 20.107 - client_seek(_file, filepos, SEEK_SET); 20.108 - client_write(_file, (char *) addr, populated_size); 20.109 -} 20.110 - 20.111 -// vim: tabstop=4 expandtab shiftwidth=4
21.1 --- a/libfsserver/lib/files/client_file_opener.cc Thu Apr 22 00:12:16 2021 +0200 21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 21.3 @@ -1,46 +0,0 @@ 21.4 -/* 21.5 - * An opener for a file provided via the filesystem client interface. 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 "client_file_accessor.h" 21.26 -#include "client_file_opener.h" 21.27 - 21.28 -/* Return a file identifier for the given 'path'. */ 21.29 - 21.30 -fileid_t ClientFileOpener::get_fileid(const char *path) 21.31 -{ 21.32 - _paths.insert(FilePathEntry(_counter, path)); 21.33 - 21.34 - return _counter++; 21.35 -} 21.36 - 21.37 -/* Return a new accessor for 'fileid'. */ 21.38 - 21.39 -Accessor *ClientFileOpener::make_accessor(fileid_t fileid) 21.40 -{ 21.41 - FilePaths::iterator found = _paths.find(fileid); 21.42 - 21.43 - if (found != _paths.end()) 21.44 - return new ClientFileAccessor(found->second, fileid); 21.45 - else 21.46 - return NULL; 21.47 -} 21.48 - 21.49 -// vim: tabstop=4 expandtab shiftwidth=4
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/libfsserver/lib/files/ext2_file_accessor.cc Sat Apr 24 23:15:21 2021 +0200 22.3 @@ -0,0 +1,105 @@ 22.4 +/* 22.5 + * A file accessor employing a file provided by an Ext2-compatible filesystem. 22.6 + * 22.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 22.8 + * 22.9 + * This program is free software; you can redistribute it and/or 22.10 + * modify it under the terms of the GNU General Public License as 22.11 + * published by the Free Software Foundation; either version 2 of 22.12 + * the License, or (at your option) any later version. 22.13 + * 22.14 + * This program is distributed in the hope that it will be useful, 22.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 22.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22.17 + * GNU General Public License for more details. 22.18 + * 22.19 + * You should have received a copy of the GNU General Public License 22.20 + * along with this program; if not, write to the Free Software 22.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 22.22 + * Boston, MA 02110-1301, USA 22.23 + */ 22.24 + 22.25 +#include <stdio.h> 22.26 +#include <string.h> 22.27 +#include <sys/stat.h> 22.28 +#include <sys/types.h> 22.29 + 22.30 +#include <algorithm> 22.31 + 22.32 +#include <systypes/fcntl.h> 22.33 + 22.34 +#include "ext2_file_accessor.h" 22.35 + 22.36 + 22.37 + 22.38 +Ext2FileAccessor::Ext2FileAccessor(ext2_file_t file, fileid_t fileid) 22.39 +: Accessor(fileid), _file(file) 22.40 +{ 22.41 +} 22.42 + 22.43 +/* Return the size of the file. */ 22.44 + 22.45 +offset_t Ext2FileAccessor::get_size() 22.46 +{ 22.47 + return ext2fs_file_get_size(_file); 22.48 +} 22.49 + 22.50 +/* Update the size of the file. */ 22.51 + 22.52 +void Ext2FileAccessor::set_size(offset_t size) 22.53 +{ 22.54 + ext2fs_file_set_size(_file, size); 22.55 +} 22.56 + 22.57 +/* Perform any closing operation on the file. */ 22.58 + 22.59 +void Ext2FileAccessor::close() 22.60 +{ 22.61 + ext2fs_file_flush(_file); 22.62 + ext2fs_file_close(_file); 22.63 +} 22.64 + 22.65 +/* Data transfer helper methods. */ 22.66 + 22.67 +/* Fill the populated portion of a flexpage. */ 22.68 + 22.69 +void Ext2FileAccessor::fill_populated(Flexpage *flexpage) 22.70 +{ 22.71 + offset_t filepos = flexpage->base_offset; 22.72 + offset_t addr = flexpage->base_addr; 22.73 + 22.74 + /* Tag the region with file state. */ 22.75 + 22.76 + flexpage->region->fill(fileid, filepos); 22.77 + 22.78 + /* Fill the region with file content. */ 22.79 + 22.80 + ext2fs_file_llseek(_file, filepos, SEEK_SET, NULL); 22.81 + 22.82 + unsigned int nread; 22.83 + ext2fs_file_read(_file, (void *) addr, flexpage->size, &nread); 22.84 + 22.85 + /* Pad the flexpage with zero. */ 22.86 + 22.87 + memset((void *) (addr + nread), 0, flexpage->size - nread); 22.88 +} 22.89 + 22.90 +/* Flush the populated portion of a flexpage. */ 22.91 + 22.92 +void Ext2FileAccessor::flush_populated(Flexpage *flexpage) 22.93 +{ 22.94 + offset_t filepos = flexpage->base_offset; 22.95 + offset_t addr = flexpage->base_addr; 22.96 + offset_t populated_size = std::min(flexpage->size, get_size() - filepos); 22.97 + 22.98 + /* Remove the file state tag from the region. */ 22.99 + 22.100 + flexpage->region->flush(); 22.101 + 22.102 + /* Copy the populated region to the file. */ 22.103 + 22.104 + ext2fs_file_llseek(_file, filepos, SEEK_SET, NULL); 22.105 + ext2fs_file_write(_file, (const void *) addr, populated_size, NULL); 22.106 +} 22.107 + 22.108 +// vim: tabstop=4 expandtab shiftwidth=4
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/libfsserver/lib/files/ext2_file_opener.cc Sat Apr 24 23:15:21 2021 +0200 23.3 @@ -0,0 +1,57 @@ 23.4 +/* 23.5 + * An opener for a file provided by an Ext2-compatible filesystem. 23.6 + * 23.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 23.8 + * 23.9 + * This program is free software; you can redistribute it and/or 23.10 + * modify it under the terms of the GNU General Public License as 23.11 + * published by the Free Software Foundation; either version 2 of 23.12 + * the License, or (at your option) any later version. 23.13 + * 23.14 + * This program is distributed in the hope that it will be useful, 23.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 23.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23.17 + * GNU General Public License for more details. 23.18 + * 23.19 + * You should have received a copy of the GNU General Public License 23.20 + * along with this program; if not, write to the Free Software 23.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 23.22 + * Boston, MA 02110-1301, USA 23.23 + */ 23.24 + 23.25 +#include <e2access/image.h> 23.26 + 23.27 +#include "ext2_file_accessor.h" 23.28 +#include "ext2_file_opener.h" 23.29 + 23.30 +/* Return a file identifier for the given 'path'. */ 23.31 + 23.32 +fileid_t Ext2FileOpener::get_fileid(const char *path) 23.33 +{ 23.34 + /* Obtain the inode number. */ 23.35 + 23.36 + ext2_ino_t ino; 23.37 + errcode_t retval = image_find_path(_fs, &path, &ino); 23.38 + 23.39 + if (retval) 23.40 + return FILEID_INVALID; 23.41 + 23.42 + return (fileid_t) ino; 23.43 +} 23.44 + 23.45 +/* Return a new accessor for 'fileid'. */ 23.46 + 23.47 +Accessor *Ext2FileOpener::make_accessor(const char *path, fileid_t fileid) 23.48 +{ 23.49 + (void) path; 23.50 + 23.51 + ext2_file_t file; 23.52 + errcode_t retval = ext2fs_file_open(_fs, (ext2_ino_t) fileid, EXT2_FILE_WRITE, &file); 23.53 + 23.54 + if (retval) 23.55 + return NULL; 23.56 + 23.57 + return new Ext2FileAccessor(file, fileid); 23.58 +} 23.59 + 23.60 +// vim: tabstop=4 expandtab shiftwidth=4
24.1 --- a/libfsserver/lib/files/file_paging.cc Thu Apr 22 00:12:16 2021 +0200 24.2 +++ b/libfsserver/lib/files/file_paging.cc Sat Apr 24 23:15:21 2021 +0200 24.3 @@ -53,6 +53,15 @@ 24.4 return mapper; 24.5 } 24.6 24.7 +/* Remove a page mapper and its resources for the given 'fileid'. */ 24.8 + 24.9 +void FilePaging::remove(fileid_t fileid, PageMapper *mapper) 24.10 +{ 24.11 + _mappers.erase(fileid); 24.12 + delete mapper->accessor(); 24.13 + delete mapper; 24.14 +} 24.15 + 24.16 /* Register a page 'mapper' for the given 'fileid'. */ 24.17 24.18 void FilePaging::set(fileid_t fileid, PageMapper *mapper) 24.19 @@ -77,7 +86,7 @@ 24.20 /* Obtain a page mapper for the 'fileid' or register a new one in the 24.21 paging object. */ 24.22 24.23 -PageMapper *FilePaging::get_mapper(fileid_t fileid) 24.24 +PageMapper *FilePaging::get_mapper(const char *path, fileid_t fileid) 24.25 { 24.26 /* Obtain any registered page mapper. */ 24.27 24.28 @@ -88,7 +97,11 @@ 24.29 24.30 /* Make an accessor and page mapper, registering the mapper. */ 24.31 24.32 - Accessor *accessor = make_accessor(fileid); 24.33 + Accessor *accessor = make_accessor(path, fileid); 24.34 + 24.35 + if (accessor == NULL) 24.36 + return NULL; 24.37 + 24.38 mapper = new PageMapper(accessor, _pages); 24.39 24.40 set(fileid, mapper); 24.41 @@ -100,14 +113,18 @@ 24.42 24.43 /* Return a pager initialised with a page mapper. */ 24.44 24.45 -Pager *FilePaging::get_pager(fileid_t fileid, flags_t flags) 24.46 +Pager *FilePaging::get_pager(const char *path, fileid_t fileid, flags_t flags) 24.47 { 24.48 std::lock_guard<std::mutex> guard(_lock); 24.49 24.50 /* Initialise the pager with the mapper and a reference to this object for 24.51 closing the mapper and accessor. */ 24.52 24.53 - PageMapper *mapper = get_mapper(fileid); 24.54 + PageMapper *mapper = get_mapper(path, fileid); 24.55 + 24.56 + if (mapper == NULL) 24.57 + return NULL; 24.58 + 24.59 return new FilePager(fileid, mapper, flags, this); 24.60 } 24.61 24.62 @@ -118,11 +135,7 @@ 24.63 std::lock_guard<std::mutex> guard(_lock); 24.64 24.65 if (!mapper->detach()) 24.66 - { 24.67 - _mappers.erase(fileid); 24.68 - delete mapper->accessor(); 24.69 - delete mapper; 24.70 - } 24.71 + remove(fileid, mapper); 24.72 } 24.73 24.74 // vim: tabstop=4 expandtab shiftwidth=4
25.1 --- a/libfsserver/lib/files/host_file_accessor.cc Thu Apr 22 00:12:16 2021 +0200 25.2 +++ b/libfsserver/lib/files/host_file_accessor.cc Sat Apr 24 23:15:21 2021 +0200 25.3 @@ -26,14 +26,14 @@ 25.4 25.5 #include "host_file_accessor.h" 25.6 25.7 -HostFileAccessor::HostFileAccessor(const char *path, fileid_t fileid) 25.8 -: Accessor(fileid), _path(path) 25.9 +HostFileAccessor::HostFileAccessor(FILE *fp, fileid_t fileid) 25.10 +: Accessor(fileid), _fp(fp) 25.11 { 25.12 /* Initialise the size of the file. */ 25.13 25.14 struct stat buf; 25.15 25.16 - if (!stat(_path, &buf)) 25.17 + if (!fstat(fileno(fp), &buf)) 25.18 _size = buf.st_size; 25.19 else 25.20 _size = 0; 25.21 @@ -60,13 +60,6 @@ 25.22 fclose(_fp); 25.23 } 25.24 25.25 -/* Perform any opening operation on the file. */ 25.26 - 25.27 -void HostFileAccessor::open() 25.28 -{ 25.29 - _fp = fopen(_path, "r"); 25.30 -} 25.31 - 25.32 /* Data transfer helper methods. */ 25.33 25.34 void HostFileAccessor::fill_populated(Flexpage *flexpage)
26.1 --- a/libfsserver/lib/files/host_file_opener.cc Thu Apr 22 00:12:16 2021 +0200 26.2 +++ b/libfsserver/lib/files/host_file_opener.cc Sat Apr 24 23:15:21 2021 +0200 26.3 @@ -35,21 +35,19 @@ 26.4 26.5 stat(path, &statbuf); 26.6 26.7 - _paths.insert(FilePathEntry(statbuf.st_ino, path)); 26.8 - 26.9 return statbuf.st_ino; 26.10 } 26.11 26.12 /* Return a new accessor for 'fileid'. */ 26.13 26.14 -Accessor *HostFileOpener::make_accessor(fileid_t fileid) 26.15 +Accessor *HostFileOpener::make_accessor(const char *path, fileid_t fileid) 26.16 { 26.17 - FilePaths::iterator found = _paths.find(fileid); 26.18 + FILE *fp = fopen(path, "r"); 26.19 26.20 - if (found != _paths.end()) 26.21 - return new HostFileAccessor(found->second, fileid); 26.22 - else 26.23 + if (fp == NULL) 26.24 return NULL; 26.25 + 26.26 + return new HostFileAccessor(fp, fileid); 26.27 } 26.28 26.29 // vim: tabstop=4 expandtab shiftwidth=4
27.1 --- a/libfsserver/lib/files/opener_resource.cc Thu Apr 22 00:12:16 2021 +0200 27.2 +++ b/libfsserver/lib/files/opener_resource.cc Sat Apr 24 23:15:21 2021 +0200 27.3 @@ -51,7 +51,7 @@ 27.4 if (fileid == FILEID_INVALID) 27.5 return NULL; 27.6 27.7 - return get_pager(fileid, get_flags(flags)); 27.8 + return get_pager(path, fileid, get_flags(flags)); 27.9 } 27.10 27.11
28.1 --- a/libfsserver/lib/files/test_file_opener.cc Thu Apr 22 00:12:16 2021 +0200 28.2 +++ b/libfsserver/lib/files/test_file_opener.cc Sat Apr 24 23:15:21 2021 +0200 28.3 @@ -42,8 +42,9 @@ 28.4 28.5 /* Return a new accessor for 'fileid'. */ 28.6 28.7 -Accessor *TestFileOpener::make_accessor(fileid_t fileid) 28.8 +Accessor *TestFileOpener::make_accessor(const char *path, fileid_t fileid) 28.9 { 28.10 + (void) path; 28.11 return new TestFileAccessor(fileid, _file_size); 28.12 } 28.13
29.1 --- a/libfsserver/lib/generic/accessor.cc Thu Apr 22 00:12:16 2021 +0200 29.2 +++ b/libfsserver/lib/generic/accessor.cc Sat Apr 24 23:15:21 2021 +0200 29.3 @@ -40,12 +40,6 @@ 29.4 { 29.5 } 29.6 29.7 -/* Perform any opening operation on the file. */ 29.8 - 29.9 -void Accessor::open() 29.10 -{ 29.11 -} 29.12 - 29.13 /* Data transfer methods. */ 29.14 29.15 void Accessor::fill(Flexpage *flexpage)
30.1 --- a/libfsserver/lib/mapping/page_mapper.cc Thu Apr 22 00:12:16 2021 +0200 30.2 +++ b/libfsserver/lib/mapping/page_mapper.cc Sat Apr 24 23:15:21 2021 +0200 30.3 @@ -37,9 +37,6 @@ 30.4 { 30.5 std::lock_guard<std::mutex> guard(_lock); 30.6 30.7 - if (!_attached) 30.8 - _accessor->open(); 30.9 - 30.10 _attached += 1; 30.11 } 30.12
31.1 --- a/servers/Control Thu Apr 22 00:12:16 2021 +0200 31.2 +++ b/servers/Control Sat Apr 24 23:15:21 2021 +0200 31.3 @@ -1,3 +1,3 @@ 31.4 -requires: libstdc++ libc libipc libfsserver libmem 31.5 +requires: libstdc++ libc libipc libfsserver libmem libe2access_blockserver 31.6 provides: fsservers 31.7 maintainer: paul@boddie.org.uk
32.1 --- a/servers/Makefile Thu Apr 22 00:12:16 2021 +0200 32.2 +++ b/servers/Makefile Sat Apr 24 23:15:21 2021 +0200 32.3 @@ -3,7 +3,7 @@ 32.4 32.5 TARGET = \ 32.6 dstest_block_server \ 32.7 - dstest_client_server \ 32.8 + dstest_ext2_server \ 32.9 dstest_host_server \ 32.10 dstest_pipe_server \ 32.11 dstest_test_server 32.12 @@ -12,7 +12,7 @@ 32.13 32.14 SRC_CC_dstest_block_server = block_file_server.cc 32.15 32.16 -SRC_CC_dstest_client_server = client_file_server.cc 32.17 +SRC_CC_dstest_ext2_server = ext2_file_server.cc 32.18 32.19 SRC_CC_dstest_host_server = host_file_server.cc 32.20 32.21 @@ -20,6 +20,6 @@ 32.22 32.23 SRC_CC_dstest_test_server = test_file_server.cc 32.24 32.25 -REQUIRES_LIBS = l4re_c-util libmem libfsserver libipc libstdc++ libsystypes 32.26 +REQUIRES_LIBS = l4re_c-util libmem libfsserver libipc libstdc++ libsystypes libe2access_blockserver 32.27 32.28 include $(L4DIR)/mk/prog.mk
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/servers/ext2_file_server.cc Sat Apr 24 23:15:21 2021 +0200 33.3 @@ -0,0 +1,113 @@ 33.4 +/* 33.5 + * A dataspace server exposing file contents from an Ext2-based filesystem. 33.6 + * 33.7 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk> 33.8 + * 33.9 + * This program is free software; you can redistribute it and/or 33.10 + * modify it under the terms of the GNU General Public License as 33.11 + * published by the Free Software Foundation; either version 2 of 33.12 + * the License, or (at your option) any later version. 33.13 + * 33.14 + * This program is distributed in the hope that it will be useful, 33.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 33.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33.17 + * GNU General Public License for more details. 33.18 + * 33.19 + * You should have received a copy of the GNU General Public License 33.20 + * along with this program; if not, write to the Free Software 33.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 33.22 + * Boston, MA 02110-1301, USA 33.23 + */ 33.24 + 33.25 +#include <l4/sys/err.h> 33.26 + 33.27 +#include <ipc/thread.h> 33.28 + 33.29 +#include <stdio.h> 33.30 +#include <stdlib.h> 33.31 + 33.32 +#include <e2access/fs.h> 33.33 +#include <fsserver/page_queue_shared.h> 33.34 +#include <fsserver/pages.h> 33.35 +#include <fsserver/resource_server.h> 33.36 +#include <fsserver/ext2_file_opener.h> 33.37 +#include <mem/memory_incremental.h> 33.38 + 33.39 + 33.40 + 33.41 +/* Default number of pages for files. */ 33.42 + 33.43 +const unsigned int MEMORY_PAGES = 20; 33.44 + 33.45 + 33.46 + 33.47 +/* Server program. */ 33.48 + 33.49 +int main(int argc, char *argv[]) 33.50 +{ 33.51 + /* Require filesystem object details. */ 33.52 + 33.53 + if (argc < 3) 33.54 + { 33.55 + printf("Need a filesystem capability name and filename.\n"); 33.56 + return 1; 33.57 + } 33.58 + 33.59 + const char *fs_cap = argv[1]; 33.60 + const char *fs_filename = argv[2]; 33.61 + long err; 33.62 + 33.63 + /* Introduce concurrency control. */ 33.64 + 33.65 + err = ipc_thread_init(); 33.66 + 33.67 + if (err) 33.68 + { 33.69 + printf("Initialisation error: %s\n", l4sys_errtostr(err)); 33.70 + return 1; 33.71 + } 33.72 + 33.73 + unsigned int memory_pages = MEMORY_PAGES; 33.74 + 33.75 + if (argc > 3) 33.76 + memory_pages = atoi(argv[3]); 33.77 + 33.78 + const char *server_name = (argc > 4) ? argv[4] : "server"; 33.79 + 33.80 + /* Set the capability used to access the filesystem. */ 33.81 + 33.82 + e2access_init(fs_cap); 33.83 + 33.84 + /* Attempt to open the filesystem. */ 33.85 + 33.86 + ext2_filsys fs; 33.87 + errcode_t retval = e2access_open(fs_filename, EXT2_FLAG_RW, &fs); // EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS 33.88 + 33.89 + if (retval) 33.90 + { 33.91 + printf("Could not obtain filesystem: %ld.\n", retval); 33.92 + return 1; 33.93 + } 33.94 + 33.95 + /* Some memory plus infrastructure. */ 33.96 + 33.97 + MemoryIncremental mem(memory_pages); 33.98 + PageQueueShared queue; 33.99 + Pages pages(&mem, &queue); 33.100 + Ext2FileOpener opener(fs, &pages); 33.101 + 33.102 + /* Register a server associating it with the given object. */ 33.103 + 33.104 + ResourceServer server(&opener); 33.105 + err = server.bind(server_name); 33.106 + 33.107 + if (err) 33.108 + { 33.109 + printf("Could not bind server: %s\n", l4sys_errtostr(err)); 33.110 + return 1; 33.111 + } 33.112 + 33.113 + printf("Starting server using %d pages...\n", memory_pages); 33.114 + server.start(); 33.115 + return 0; 33.116 +}
34.1 --- a/tests/dstest_block_client_simple.cc Thu Apr 22 00:12:16 2021 +0200 34.2 +++ b/tests/dstest_block_client_simple.cc Sat Apr 24 23:15:21 2021 +0200 34.3 @@ -22,6 +22,7 @@ 34.4 #include <systypes/fcntl.h> 34.5 34.6 #include <stdio.h> 34.7 +#include <stdlib.h> 34.8 34.9 #include <fsclient/client.h> 34.10 34.11 @@ -31,13 +32,14 @@ 34.12 { 34.13 if (argc < 2) 34.14 { 34.15 - printf("Need a filename.\n"); 34.16 + printf("Need a filename and optional repetition.\n"); 34.17 return 1; 34.18 } 34.19 34.20 /* Obtain filename and access parameters. */ 34.21 34.22 char *filename = argv[1]; 34.23 + int repetition = argc > 2 ? atoi(argv[2]) : 10; 34.24 34.25 /* Invoke the open method to receive the file reference. */ 34.26 34.27 @@ -67,7 +69,7 @@ 34.28 34.29 printf("Copy %ld bytes to end...\n", nread); 34.30 34.31 - for (int times = 0; times < 10; times++) 34.32 + for (int times = 0; times < repetition; times++) 34.33 { 34.34 printf("Copy #%d...\n", times); 34.35