1.1 --- a/libfsserver/include/fsserver/block_file_opener.h Sun Oct 17 22:14:40 2021 +0200 1.2 +++ b/libfsserver/include/fsserver/block_file_opener.h Mon Oct 18 22:59:22 2021 +0200 1.3 @@ -30,7 +30,7 @@ 1.4 class BlockFileOpener : public HostFileOpener 1.5 { 1.6 public: 1.7 - explicit BlockFileOpener(FileObjectRegistry *registry) 1.8 + explicit BlockFileOpener(ResourceRegistry *registry) 1.9 : HostFileOpener(registry) 1.10 { 1.11 }
2.1 --- a/libfsserver/include/fsserver/directory_provider.h Sun Oct 17 22:14:40 2021 +0200 2.2 +++ b/libfsserver/include/fsserver/directory_provider.h Mon Oct 18 22:59:22 2021 +0200 2.3 @@ -34,7 +34,7 @@ 2.4 DirectoryAccessor *_accessor; 2.5 2.6 public: 2.7 - explicit DirectoryProvider(fileid_t fileid, FileRegistry *registry, 2.8 + explicit DirectoryProvider(fileid_t fileid, ProviderRegistry *registry, 2.9 DirectoryAccessor *accessor); 2.10 2.11 virtual ~DirectoryProvider();
3.1 --- a/libfsserver/include/fsserver/ext2_file_opener.h Sun Oct 17 22:14:40 2021 +0200 3.2 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Mon Oct 18 22:59:22 2021 +0200 3.3 @@ -45,7 +45,7 @@ 3.4 virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); 3.5 3.6 public: 3.7 - explicit Ext2FileOpener(FileObjectRegistry *registry, Ext2FileOperations *ops, user_t user) 3.8 + explicit Ext2FileOpener(ResourceRegistry *registry, Ext2FileOperations *ops, user_t user) 3.9 : OpenerResource(registry), _ops(ops), _user(user) 3.10 { 3.11 }
4.1 --- a/libfsserver/include/fsserver/file_object_registry.h Sun Oct 17 22:14:40 2021 +0200 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,70 +0,0 @@ 4.4 -/* 4.5 - * A registry of filesystem objects. 4.6 - * 4.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 4.8 - * 4.9 - * This program is free software; you can redistribute it and/or 4.10 - * modify it under the terms of the GNU General Public License as 4.11 - * published by the Free Software Foundation; either version 2 of 4.12 - * the License, or (at your option) any later version. 4.13 - * 4.14 - * This program is distributed in the hope that it will be useful, 4.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 4.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4.17 - * GNU General Public License for more details. 4.18 - * 4.19 - * You should have received a copy of the GNU General Public License 4.20 - * along with this program; if not, write to the Free Software 4.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 4.22 - * Boston, MA 02110-1301, USA 4.23 - */ 4.24 - 4.25 -#pragma once 4.26 - 4.27 -#include <fsserver/directory_provider.h> 4.28 -#include <fsserver/file_opening.h> 4.29 -#include <fsserver/file_provider.h> 4.30 -#include <fsserver/file_registry.h> 4.31 -#include <fsserver/pager.h> 4.32 -#include <fsserver/pages.h> 4.33 - 4.34 - 4.35 - 4.36 -/* A registry of filesystem objects. */ 4.37 - 4.38 -class FileObjectRegistry : public FileRegistry 4.39 -{ 4.40 -protected: 4.41 - Pages *_pages; 4.42 - 4.43 - map_flags_t get_flags(flags_t flags); 4.44 - 4.45 - /* Provider initialisation methods. */ 4.46 - 4.47 - long make_directory_provider(FileOpening *opening, const char *path, 4.48 - flags_t flags, fileid_t fileid, 4.49 - Provider **provider); 4.50 - 4.51 - long make_file_provider(FileOpening *opening, const char *path, 4.52 - flags_t flags, fileid_t fileid, 4.53 - Provider **provider); 4.54 - 4.55 - long make_provider(FileOpening *opening, const char *path, 4.56 - flags_t flags, fileid_t fileid, 4.57 - Provider **provider); 4.58 - 4.59 -public: 4.60 - explicit FileObjectRegistry(Pages *pages); 4.61 - 4.62 - /* Resource discovery methods. */ 4.63 - 4.64 - long find_provider(fileid_t fileid, Provider **provider); 4.65 - 4.66 - /* Resource initialisation methods. */ 4.67 - 4.68 - long get_resource(FileOpening *opening, const char *path, flags_t flags, 4.69 - offset_t *size, object_flags_t *object_flags, 4.70 - Resource **resource); 4.71 -}; 4.72 - 4.73 -// vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/libfsserver/include/fsserver/file_provider.h Sun Oct 17 22:14:40 2021 +0200 5.2 +++ b/libfsserver/include/fsserver/file_provider.h Mon Oct 18 22:59:22 2021 +0200 5.3 @@ -36,7 +36,7 @@ 5.4 5.5 public: 5.6 explicit FileProvider(fileid_t fileid, map_flags_t flags, 5.7 - FileRegistry *registry, PageMapper *mapper); 5.8 + ProviderRegistry *registry, PageMapper *mapper); 5.9 5.10 virtual ~FileProvider(); 5.11
6.1 --- a/libfsserver/include/fsserver/file_registry.h Sun Oct 17 22:14:40 2021 +0200 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,61 +0,0 @@ 6.4 -/* 6.5 - * A registry of filesystem objects. 6.6 - * 6.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 6.8 - * 6.9 - * This program is free software; you can redistribute it and/or 6.10 - * modify it under the terms of the GNU General Public License as 6.11 - * published by the Free Software Foundation; either version 2 of 6.12 - * the License, or (at your option) any later version. 6.13 - * 6.14 - * This program is distributed in the hope that it will be useful, 6.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 6.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6.17 - * GNU General Public License for more details. 6.18 - * 6.19 - * You should have received a copy of the GNU General Public License 6.20 - * along with this program; if not, write to the Free Software 6.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 6.22 - * Boston, MA 02110-1301, USA 6.23 - */ 6.24 - 6.25 -#pragma once 6.26 - 6.27 -#include <map> 6.28 -#include <mutex> 6.29 - 6.30 -#include <mem/types.h> 6.31 -#include <fsserver/accountable.h> 6.32 - 6.33 - 6.34 - 6.35 -/* Mapping type from file identifiers to page mappers. */ 6.36 - 6.37 -typedef std::map<fileid_t, Accountable *> FileMapping; 6.38 -typedef std::pair<fileid_t, Accountable *> FileMappingEntry; 6.39 - 6.40 - 6.41 - 6.42 -/* A registry of filesystem objects. */ 6.43 - 6.44 -class FileRegistry 6.45 -{ 6.46 -protected: 6.47 - FileMapping _providers; 6.48 - std::mutex _lock; 6.49 - 6.50 - /* Filesystem object access. */ 6.51 - 6.52 - Accountable *get(fileid_t fileid); 6.53 - 6.54 - void remove(fileid_t fileid, Accountable *obj); 6.55 - 6.56 - void set(fileid_t fileid, Accountable *obj); 6.57 - 6.58 -public: 6.59 - /* Methods for resources. */ 6.60 - 6.61 - void detach(fileid_t fileid, Accountable *mapper); 6.62 -}; 6.63 - 6.64 -// vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/libfsserver/include/fsserver/filesystem_resource.h Sun Oct 17 22:14:40 2021 +0200 7.2 +++ b/libfsserver/include/fsserver/filesystem_resource.h Mon Oct 18 22:59:22 2021 +0200 7.3 @@ -21,15 +21,15 @@ 7.4 7.5 #pragma once 7.6 7.7 -#include <fsserver/file_object_registry.h> 7.8 #include <fsserver/filesystem_object_interface.h> 7.9 #include <fsserver/resource.h> 7.10 +#include <fsserver/resource_registry.h> 7.11 7.12 7.13 7.14 /* Support for providing access to user-specific filesystems. */ 7.15 7.16 -class FilesystemResource : public Resource, public FileObjectRegistry, 7.17 +class FilesystemResource : public Resource, public ResourceRegistry, 7.18 public FilesystemObject 7.19 { 7.20 public:
8.1 --- a/libfsserver/include/fsserver/host_file_opener.h Sun Oct 17 22:14:40 2021 +0200 8.2 +++ b/libfsserver/include/fsserver/host_file_opener.h Mon Oct 18 22:59:22 2021 +0200 8.3 @@ -55,7 +55,7 @@ 8.4 virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); 8.5 8.6 public: 8.7 - explicit HostFileOpener(FileObjectRegistry *registry) 8.8 + explicit HostFileOpener(ResourceRegistry *registry) 8.9 : OpenerResource(registry) 8.10 { 8.11 }
9.1 --- a/libfsserver/include/fsserver/opener_resource.h Sun Oct 17 22:14:40 2021 +0200 9.2 +++ b/libfsserver/include/fsserver/opener_resource.h Mon Oct 18 22:59:22 2021 +0200 9.3 @@ -21,11 +21,11 @@ 9.4 9.5 #pragma once 9.6 9.7 -#include <fsserver/file_object_registry.h> 9.8 #include <fsserver/file_opening.h> 9.9 #include <fsserver/opener_context_resource.h> 9.10 #include <fsserver/opener_interface.h> 9.11 #include <fsserver/resource.h> 9.12 +#include <fsserver/resource_registry.h> 9.13 9.14 9.15 9.16 @@ -34,7 +34,7 @@ 9.17 class OpenerResource : public Resource, public FileOpening, public Opener 9.18 { 9.19 protected: 9.20 - FileObjectRegistry *_registry; 9.21 + ResourceRegistry *_registry; 9.22 9.23 /* Retrieval methods. */ 9.24 9.25 @@ -45,7 +45,7 @@ 9.26 virtual long notify_parent(const char *path); 9.27 9.28 public: 9.29 - explicit OpenerResource(FileObjectRegistry *registry); 9.30 + explicit OpenerResource(ResourceRegistry *registry); 9.31 9.32 virtual ~OpenerResource(); 9.33
10.1 --- a/libfsserver/include/fsserver/provider.h Sun Oct 17 22:14:40 2021 +0200 10.2 +++ b/libfsserver/include/fsserver/provider.h Mon Oct 18 22:59:22 2021 +0200 10.3 @@ -22,8 +22,8 @@ 10.4 #pragma once 10.5 10.6 #include <fsserver/accountable.h> 10.7 -#include <fsserver/file_registry.h> 10.8 #include <fsserver/notification.h> 10.9 +#include <fsserver/provider_registry.h> 10.10 #include <fsserver/resource.h> 10.11 10.12 10.13 @@ -34,14 +34,14 @@ 10.14 { 10.15 protected: 10.16 fileid_t _fileid; 10.17 - FileRegistry *_registry; 10.18 + ProviderRegistry *_registry; 10.19 10.20 public: 10.21 - explicit Provider(fileid_t fileid, FileRegistry *registry); 10.22 + explicit Provider(fileid_t fileid, ProviderRegistry *registry); 10.23 10.24 virtual ~Provider(); 10.25 10.26 - virtual FileRegistry *registry(); 10.27 + virtual ProviderRegistry *registry(); 10.28 10.29 virtual long make_resource(offset_t *size, object_flags_t *object_flags, 10.30 Resource **resource) = 0;
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/libfsserver/include/fsserver/provider_registry.h Mon Oct 18 22:59:22 2021 +0200 11.3 @@ -0,0 +1,61 @@ 11.4 +/* 11.5 + * A registry of filesystem object providers. 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 <map> 11.28 +#include <mutex> 11.29 + 11.30 +#include <mem/types.h> 11.31 +#include <fsserver/accountable.h> 11.32 + 11.33 + 11.34 + 11.35 +/* Mapping type from file identifiers to page mappers. */ 11.36 + 11.37 +typedef std::map<fileid_t, Accountable *> FileMapping; 11.38 +typedef std::pair<fileid_t, Accountable *> FileMappingEntry; 11.39 + 11.40 + 11.41 + 11.42 +/* A registry of filesystem object providers. */ 11.43 + 11.44 +class ProviderRegistry 11.45 +{ 11.46 +protected: 11.47 + FileMapping _providers; 11.48 + std::mutex _lock; 11.49 + 11.50 + /* Filesystem object access. */ 11.51 + 11.52 + Accountable *get(fileid_t fileid); 11.53 + 11.54 + void remove(fileid_t fileid, Accountable *obj); 11.55 + 11.56 + void set(fileid_t fileid, Accountable *obj); 11.57 + 11.58 +public: 11.59 + /* Methods for resources. */ 11.60 + 11.61 + void detach(fileid_t fileid, Accountable *mapper); 11.62 +}; 11.63 + 11.64 +// vim: tabstop=4 expandtab shiftwidth=4
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/libfsserver/include/fsserver/resource_registry.h Mon Oct 18 22:59:22 2021 +0200 12.3 @@ -0,0 +1,70 @@ 12.4 +/* 12.5 + * A registry of filesystem object resources. 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/directory_provider.h> 12.28 +#include <fsserver/file_opening.h> 12.29 +#include <fsserver/file_provider.h> 12.30 +#include <fsserver/pager.h> 12.31 +#include <fsserver/pages.h> 12.32 +#include <fsserver/provider_registry.h> 12.33 + 12.34 + 12.35 + 12.36 +/* A registry of filesystem object resources. */ 12.37 + 12.38 +class ResourceRegistry : public ProviderRegistry 12.39 +{ 12.40 +protected: 12.41 + Pages *_pages; 12.42 + 12.43 + map_flags_t get_flags(flags_t flags); 12.44 + 12.45 + /* Provider initialisation methods. */ 12.46 + 12.47 + long make_directory_provider(FileOpening *opening, const char *path, 12.48 + flags_t flags, fileid_t fileid, 12.49 + Provider **provider); 12.50 + 12.51 + long make_file_provider(FileOpening *opening, const char *path, 12.52 + flags_t flags, fileid_t fileid, 12.53 + Provider **provider); 12.54 + 12.55 + long make_provider(FileOpening *opening, const char *path, 12.56 + flags_t flags, fileid_t fileid, 12.57 + Provider **provider); 12.58 + 12.59 +public: 12.60 + explicit ResourceRegistry(Pages *pages); 12.61 + 12.62 + /* Resource discovery methods. */ 12.63 + 12.64 + long find_provider(fileid_t fileid, Provider **provider); 12.65 + 12.66 + /* Resource initialisation methods. */ 12.67 + 12.68 + long get_resource(FileOpening *opening, const char *path, flags_t flags, 12.69 + offset_t *size, object_flags_t *object_flags, 12.70 + Resource **resource); 12.71 +}; 12.72 + 12.73 +// vim: tabstop=4 expandtab shiftwidth=4
13.1 --- a/libfsserver/include/fsserver/test_file_opener.h Sun Oct 17 22:14:40 2021 +0200 13.2 +++ b/libfsserver/include/fsserver/test_file_opener.h Mon Oct 18 22:59:22 2021 +0200 13.3 @@ -39,7 +39,7 @@ 13.4 virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); 13.5 13.6 public: 13.7 - explicit TestFileOpener(FileObjectRegistry *registry, offset_t file_size=0); 13.8 + explicit TestFileOpener(ResourceRegistry *registry, offset_t file_size=0); 13.9 13.10 virtual ~TestFileOpener(); 13.11
14.1 --- a/libfsserver/lib/Makefile Sun Oct 17 22:14:40 2021 +0200 14.2 +++ b/libfsserver/lib/Makefile Mon Oct 18 22:59:22 2021 +0200 14.3 @@ -56,10 +56,8 @@ 14.4 files/ext2_file_opener.cc \ 14.5 files/ext2_file_operations.cc \ 14.6 files/ext2_filesystem.cc \ 14.7 - files/file_object_registry.cc \ 14.8 files/file_pager.cc \ 14.9 files/file_provider.cc \ 14.10 - files/file_registry.cc \ 14.11 files/filesystem_resource.cc \ 14.12 files/host_file_accessor.cc \ 14.13 files/host_file_opener.cc \ 14.14 @@ -69,6 +67,8 @@ 14.15 files/test_file_opener.cc \ 14.16 generic/accessor.cc \ 14.17 generic/accountable.cc \ 14.18 + generic/provider_registry.cc \ 14.19 + generic/resource_registry.cc \ 14.20 generic/notification.cc \ 14.21 generic/pager.cc \ 14.22 generic/provider.cc \
15.1 --- a/libfsserver/lib/directories/directory_provider.cc Sun Oct 17 22:14:40 2021 +0200 15.2 +++ b/libfsserver/lib/directories/directory_provider.cc Mon Oct 18 22:59:22 2021 +0200 15.3 @@ -26,7 +26,8 @@ 15.4 15.5 /* Initialise the provider. */ 15.6 15.7 -DirectoryProvider::DirectoryProvider(fileid_t fileid, FileRegistry *registry, 15.8 +DirectoryProvider::DirectoryProvider(fileid_t fileid, 15.9 + ProviderRegistry *registry, 15.10 DirectoryAccessor *accessor) 15.11 : Provider(fileid, registry), _accessor(accessor) 15.12 {
16.1 --- a/libfsserver/lib/files/file_object_registry.cc Sun Oct 17 22:14:40 2021 +0200 16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 16.3 @@ -1,172 +0,0 @@ 16.4 -/* 16.5 - * File registry and opening functionality. 16.6 - * 16.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 16.8 - * 16.9 - * This program is free software; you can redistribute it and/or 16.10 - * modify it under the terms of the GNU General Public License as 16.11 - * published by the Free Software Foundation; either version 2 of 16.12 - * the License, or (at your option) any later version. 16.13 - * 16.14 - * This program is distributed in the hope that it will be useful, 16.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16.17 - * GNU General Public License for more details. 16.18 - * 16.19 - * You should have received a copy of the GNU General Public License 16.20 - * along with this program; if not, write to the Free Software 16.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 16.22 - * Boston, MA 02110-1301, USA 16.23 - */ 16.24 - 16.25 -#include "directory_resource.h" 16.26 -#include "file_object_registry.h" 16.27 -#include "file_pager.h" 16.28 - 16.29 -#include <systypes/fcntl.h> 16.30 - 16.31 - 16.32 - 16.33 -/* The file object registry provides a memory page collection to the page 16.34 - mappers it creates. */ 16.35 - 16.36 -FileObjectRegistry::FileObjectRegistry(Pages *pages) 16.37 -: _pages(pages) 16.38 -{ 16.39 -} 16.40 - 16.41 - 16.42 - 16.43 -/* Convert opening flags to map-compatible paging flags. */ 16.44 - 16.45 -map_flags_t FileObjectRegistry::get_flags(flags_t flags) 16.46 -{ 16.47 - return flags & (O_WRONLY | O_RDWR) ? L4RE_DS_MAP_FLAG_RW : L4RE_DS_MAP_FLAG_RO; 16.48 -} 16.49 - 16.50 - 16.51 - 16.52 -/* Make a directory provider. */ 16.53 - 16.54 -long FileObjectRegistry::make_directory_provider(FileOpening *opening, 16.55 - const char *path, flags_t flags, 16.56 - fileid_t fileid, 16.57 - Provider **provider) 16.58 -{ 16.59 - /* Make an accessor and a provider to encapsulate it. */ 16.60 - 16.61 - DirectoryAccessor *accessor; 16.62 - long err = opening->make_directory_accessor(path, flags, fileid, &accessor); 16.63 - 16.64 - if (err) 16.65 - return err; 16.66 - 16.67 - *provider = new DirectoryProvider(fileid, this, accessor); 16.68 - return L4_EOK; 16.69 -} 16.70 - 16.71 -/* Make a file provider. */ 16.72 - 16.73 -long FileObjectRegistry::make_file_provider(FileOpening *opening, 16.74 - const char *path, flags_t flags, 16.75 - fileid_t fileid, 16.76 - Provider **provider) 16.77 -{ 16.78 - /* Make an accessor, page mapper, and a provider to encapsulate them. */ 16.79 - 16.80 - Accessor *accessor; 16.81 - long err = opening->make_accessor(path, flags, fileid, &accessor); 16.82 - 16.83 - if (err) 16.84 - return err; 16.85 - 16.86 - PageMapper *mapper = new PageMapper(accessor, _pages); 16.87 - *provider = new FileProvider(fileid, get_flags(flags), this, mapper); 16.88 - return L4_EOK; 16.89 -} 16.90 - 16.91 -/* Make a provider of the appropriate type. */ 16.92 - 16.93 -long FileObjectRegistry::make_provider(FileOpening *opening, 16.94 - const char *path, flags_t flags, 16.95 - fileid_t fileid, 16.96 - Provider **provider) 16.97 -{ 16.98 - long err = -L4_EIO; 16.99 - 16.100 - if (opening->accessing_directory(path, flags, fileid)) 16.101 - err = make_directory_provider(opening, path, flags, fileid, provider); 16.102 - else if (opening->accessing_file(path, flags, fileid)) 16.103 - err = make_file_provider(opening, path, flags, fileid, provider); 16.104 - 16.105 - if (err) 16.106 - return err; 16.107 - 16.108 - /* Register the provider. */ 16.109 - 16.110 - set(fileid, *provider); 16.111 - return L4_EOK; 16.112 -} 16.113 - 16.114 - 16.115 - 16.116 -/* Return a resource for a filesystem object. */ 16.117 - 16.118 -long FileObjectRegistry::get_resource(FileOpening *opening, const char *path, 16.119 - flags_t flags, offset_t *size, 16.120 - object_flags_t *object_flags, 16.121 - Resource **resource) 16.122 -{ 16.123 - std::lock_guard<std::mutex> guard(_lock); 16.124 - 16.125 - /* Obtain an identifier for the object, even for new files (subject to use 16.126 - of the appropriate flag). */ 16.127 - 16.128 - fileid_t fileid; 16.129 - long err = opening->get_fileid(path, flags, &fileid); 16.130 - 16.131 - if (err) 16.132 - return err; 16.133 - 16.134 - /* Obtain a provider for the object. */ 16.135 - 16.136 - Provider *provider; 16.137 - err = find_provider(fileid, &provider); 16.138 - 16.139 - /* Make a new provider if necessary. */ 16.140 - 16.141 - if (err == -L4_ENOENT) 16.142 - err = make_provider(opening, path, flags, fileid, &provider); 16.143 - 16.144 - if (err) 16.145 - return err; 16.146 - 16.147 - /* Make a resource for the provider. */ 16.148 - 16.149 - return provider->make_resource(size, object_flags, resource); 16.150 -} 16.151 - 16.152 - 16.153 - 16.154 -/* Obtain any active provider for the given 'fileid'. */ 16.155 - 16.156 -long FileObjectRegistry::find_provider(fileid_t fileid, Provider **provider) 16.157 -{ 16.158 - /* Obtain any registered provider. */ 16.159 - 16.160 - Accountable *accountable = get(fileid); 16.161 - 16.162 - if (accountable != NULL) 16.163 - { 16.164 - *provider = dynamic_cast<Provider *>(accountable); 16.165 - 16.166 - if ((*provider) != NULL) 16.167 - return L4_EOK; 16.168 - else 16.169 - return -L4_EIO; 16.170 - } 16.171 - 16.172 - return -L4_ENOENT; 16.173 -} 16.174 - 16.175 -// vim: tabstop=4 expandtab shiftwidth=4
17.1 --- a/libfsserver/lib/files/file_provider.cc Sun Oct 17 22:14:40 2021 +0200 17.2 +++ b/libfsserver/lib/files/file_provider.cc Mon Oct 18 22:59:22 2021 +0200 17.3 @@ -27,7 +27,7 @@ 17.4 /* Initialise the provider with a page 'mapper' for the file's contents. */ 17.5 17.6 FileProvider::FileProvider(fileid_t fileid, map_flags_t flags, 17.7 - FileRegistry *registry, PageMapper *mapper) 17.8 + ProviderRegistry *registry, PageMapper *mapper) 17.9 : Provider(fileid, registry), _flags(flags), _mapper(mapper) 17.10 { 17.11 }
18.1 --- a/libfsserver/lib/files/file_registry.cc Sun Oct 17 22:14:40 2021 +0200 18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 18.3 @@ -1,76 +0,0 @@ 18.4 -/* 18.5 - * File registry functionality. 18.6 - * 18.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 18.8 - * 18.9 - * This program is free software; you can redistribute it and/or 18.10 - * modify it under the terms of the GNU General Public License as 18.11 - * published by the Free Software Foundation; either version 2 of 18.12 - * the License, or (at your option) any later version. 18.13 - * 18.14 - * This program is distributed in the hope that it will be useful, 18.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 18.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18.17 - * GNU General Public License for more details. 18.18 - * 18.19 - * You should have received a copy of the GNU General Public License 18.20 - * along with this program; if not, write to the Free Software 18.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 18.22 - * Boston, MA 02110-1301, USA 18.23 - */ 18.24 - 18.25 -#include "file_registry.h" 18.26 - 18.27 - 18.28 - 18.29 -/* Methods for use with the lock already acquired. */ 18.30 - 18.31 -/* Return any registered provider for the given 'fileid' or NULL if no such 18.32 - provider is registered. */ 18.33 - 18.34 -Accountable *FileRegistry::get(fileid_t fileid) 18.35 -{ 18.36 - FileMapping::iterator entry = _providers.find(fileid); 18.37 - Accountable *provider; 18.38 - 18.39 - if (entry == _providers.end()) 18.40 - provider = NULL; 18.41 - else 18.42 - provider = entry->second; 18.43 - 18.44 - return provider; 18.45 -} 18.46 - 18.47 -/* Remove a provider and its resources for the given 'fileid'. */ 18.48 - 18.49 -void FileRegistry::remove(fileid_t fileid, Accountable *provider) 18.50 -{ 18.51 - _providers.erase(fileid); 18.52 - delete provider; 18.53 -} 18.54 - 18.55 -/* Register a 'provider' for the given 'fileid'. */ 18.56 - 18.57 -void FileRegistry::set(fileid_t fileid, Accountable *provider) 18.58 -{ 18.59 - FileMapping::iterator entry = _providers.find(fileid); 18.60 - 18.61 - if (entry != _providers.end()) 18.62 - return; 18.63 - 18.64 - _providers[fileid] = provider; 18.65 -} 18.66 - 18.67 - 18.68 - 18.69 -/* Detach from a provider, potentially removing it from the registry. */ 18.70 - 18.71 -void FileRegistry::detach(fileid_t fileid, Accountable *provider) 18.72 -{ 18.73 - std::lock_guard<std::mutex> guard(_lock); 18.74 - 18.75 - if (!provider->detach()) 18.76 - remove(fileid, provider); 18.77 -} 18.78 - 18.79 -// vim: tabstop=4 expandtab shiftwidth=4
19.1 --- a/libfsserver/lib/files/filesystem_resource.cc Sun Oct 17 22:14:40 2021 +0200 19.2 +++ b/libfsserver/lib/files/filesystem_resource.cc Mon Oct 18 22:59:22 2021 +0200 19.3 @@ -25,7 +25,7 @@ 19.4 /* Support for providing access to user-specific filesystems. */ 19.5 19.6 FilesystemResource::FilesystemResource(Pages *pages) 19.7 -: FileObjectRegistry(pages) 19.8 +: ResourceRegistry(pages) 19.9 { 19.10 } 19.11
20.1 --- a/libfsserver/lib/files/opener_resource.cc Sun Oct 17 22:14:40 2021 +0200 20.2 +++ b/libfsserver/lib/files/opener_resource.cc Mon Oct 18 22:59:22 2021 +0200 20.3 @@ -27,7 +27,7 @@ 20.4 20.5 /* Support for providing access to files. */ 20.6 20.7 -OpenerResource::OpenerResource(FileObjectRegistry *registry) 20.8 +OpenerResource::OpenerResource(ResourceRegistry *registry) 20.9 : _registry(registry) 20.10 { 20.11 }
21.1 --- a/libfsserver/lib/files/test_file_opener.cc Sun Oct 17 22:14:40 2021 +0200 21.2 +++ b/libfsserver/lib/files/test_file_opener.cc Mon Oct 18 22:59:22 2021 +0200 21.3 @@ -26,7 +26,7 @@ 21.4 21.5 /* Support for providing access to files. */ 21.6 21.7 -TestFileOpener::TestFileOpener(FileObjectRegistry *registry, offset_t file_size) 21.8 +TestFileOpener::TestFileOpener(ResourceRegistry *registry, offset_t file_size) 21.9 : OpenerResource(registry), _file_size(file_size) 21.10 { 21.11 }
22.1 --- a/libfsserver/lib/generic/provider.cc Sun Oct 17 22:14:40 2021 +0200 22.2 +++ b/libfsserver/lib/generic/provider.cc Mon Oct 18 22:59:22 2021 +0200 22.3 @@ -23,7 +23,7 @@ 22.4 22.5 22.6 22.7 -Provider::Provider(fileid_t fileid, FileRegistry *registry) 22.8 +Provider::Provider(fileid_t fileid, ProviderRegistry *registry) 22.9 : NotificationSupport(), _fileid(fileid), _registry(registry) 22.10 { 22.11 } 22.12 @@ -32,7 +32,7 @@ 22.13 { 22.14 } 22.15 22.16 -FileRegistry *Provider::registry() 22.17 +ProviderRegistry *Provider::registry() 22.18 { 22.19 return _registry; 22.20 }
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/libfsserver/lib/generic/provider_registry.cc Mon Oct 18 22:59:22 2021 +0200 23.3 @@ -0,0 +1,76 @@ 23.4 +/* 23.5 + * Filesystem provider registry. 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 "provider_registry.h" 23.26 + 23.27 + 23.28 + 23.29 +/* Methods for use with the lock already acquired. */ 23.30 + 23.31 +/* Return any registered provider for the given 'fileid' or NULL if no such 23.32 + provider is registered. */ 23.33 + 23.34 +Accountable *ProviderRegistry::get(fileid_t fileid) 23.35 +{ 23.36 + FileMapping::iterator entry = _providers.find(fileid); 23.37 + Accountable *provider; 23.38 + 23.39 + if (entry == _providers.end()) 23.40 + provider = NULL; 23.41 + else 23.42 + provider = entry->second; 23.43 + 23.44 + return provider; 23.45 +} 23.46 + 23.47 +/* Remove a provider and its resources for the given 'fileid'. */ 23.48 + 23.49 +void ProviderRegistry::remove(fileid_t fileid, Accountable *provider) 23.50 +{ 23.51 + _providers.erase(fileid); 23.52 + delete provider; 23.53 +} 23.54 + 23.55 +/* Register a 'provider' for the given 'fileid'. */ 23.56 + 23.57 +void ProviderRegistry::set(fileid_t fileid, Accountable *provider) 23.58 +{ 23.59 + FileMapping::iterator entry = _providers.find(fileid); 23.60 + 23.61 + if (entry != _providers.end()) 23.62 + return; 23.63 + 23.64 + _providers[fileid] = provider; 23.65 +} 23.66 + 23.67 + 23.68 + 23.69 +/* Detach from a provider, potentially removing it from the registry. */ 23.70 + 23.71 +void ProviderRegistry::detach(fileid_t fileid, Accountable *provider) 23.72 +{ 23.73 + std::lock_guard<std::mutex> guard(_lock); 23.74 + 23.75 + if (!provider->detach()) 23.76 + remove(fileid, provider); 23.77 +} 23.78 + 23.79 +// vim: tabstop=4 expandtab shiftwidth=4
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/libfsserver/lib/generic/resource_registry.cc Mon Oct 18 22:59:22 2021 +0200 24.3 @@ -0,0 +1,172 @@ 24.4 +/* 24.5 + * Filesystem resource registry incorporating opening functionality. 24.6 + * 24.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 24.8 + * 24.9 + * This program is free software; you can redistribute it and/or 24.10 + * modify it under the terms of the GNU General Public License as 24.11 + * published by the Free Software Foundation; either version 2 of 24.12 + * the License, or (at your option) any later version. 24.13 + * 24.14 + * This program is distributed in the hope that it will be useful, 24.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 24.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24.17 + * GNU General Public License for more details. 24.18 + * 24.19 + * You should have received a copy of the GNU General Public License 24.20 + * along with this program; if not, write to the Free Software 24.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 24.22 + * Boston, MA 02110-1301, USA 24.23 + */ 24.24 + 24.25 +#include "directory_resource.h" 24.26 +#include "file_pager.h" 24.27 +#include "resource_registry.h" 24.28 + 24.29 +#include <systypes/fcntl.h> 24.30 + 24.31 + 24.32 + 24.33 +/* The file object registry provides a memory page collection to the page 24.34 + mappers it creates. */ 24.35 + 24.36 +ResourceRegistry::ResourceRegistry(Pages *pages) 24.37 +: _pages(pages) 24.38 +{ 24.39 +} 24.40 + 24.41 + 24.42 + 24.43 +/* Convert opening flags to map-compatible paging flags. */ 24.44 + 24.45 +map_flags_t ResourceRegistry::get_flags(flags_t flags) 24.46 +{ 24.47 + return flags & (O_WRONLY | O_RDWR) ? L4RE_DS_MAP_FLAG_RW : L4RE_DS_MAP_FLAG_RO; 24.48 +} 24.49 + 24.50 + 24.51 + 24.52 +/* Make a directory provider. */ 24.53 + 24.54 +long ResourceRegistry::make_directory_provider(FileOpening *opening, 24.55 + const char *path, flags_t flags, 24.56 + fileid_t fileid, 24.57 + Provider **provider) 24.58 +{ 24.59 + /* Make an accessor and a provider to encapsulate it. */ 24.60 + 24.61 + DirectoryAccessor *accessor; 24.62 + long err = opening->make_directory_accessor(path, flags, fileid, &accessor); 24.63 + 24.64 + if (err) 24.65 + return err; 24.66 + 24.67 + *provider = new DirectoryProvider(fileid, this, accessor); 24.68 + return L4_EOK; 24.69 +} 24.70 + 24.71 +/* Make a file provider. */ 24.72 + 24.73 +long ResourceRegistry::make_file_provider(FileOpening *opening, 24.74 + const char *path, flags_t flags, 24.75 + fileid_t fileid, 24.76 + Provider **provider) 24.77 +{ 24.78 + /* Make an accessor, page mapper, and a provider to encapsulate them. */ 24.79 + 24.80 + Accessor *accessor; 24.81 + long err = opening->make_accessor(path, flags, fileid, &accessor); 24.82 + 24.83 + if (err) 24.84 + return err; 24.85 + 24.86 + PageMapper *mapper = new PageMapper(accessor, _pages); 24.87 + *provider = new FileProvider(fileid, get_flags(flags), this, mapper); 24.88 + return L4_EOK; 24.89 +} 24.90 + 24.91 +/* Make a provider of the appropriate type. */ 24.92 + 24.93 +long ResourceRegistry::make_provider(FileOpening *opening, 24.94 + const char *path, flags_t flags, 24.95 + fileid_t fileid, 24.96 + Provider **provider) 24.97 +{ 24.98 + long err = -L4_EIO; 24.99 + 24.100 + if (opening->accessing_directory(path, flags, fileid)) 24.101 + err = make_directory_provider(opening, path, flags, fileid, provider); 24.102 + else if (opening->accessing_file(path, flags, fileid)) 24.103 + err = make_file_provider(opening, path, flags, fileid, provider); 24.104 + 24.105 + if (err) 24.106 + return err; 24.107 + 24.108 + /* Register the provider. */ 24.109 + 24.110 + set(fileid, *provider); 24.111 + return L4_EOK; 24.112 +} 24.113 + 24.114 + 24.115 + 24.116 +/* Obtain any active provider for the given 'fileid'. */ 24.117 + 24.118 +long ResourceRegistry::find_provider(fileid_t fileid, Provider **provider) 24.119 +{ 24.120 + /* Obtain any registered provider. */ 24.121 + 24.122 + Accountable *accountable = get(fileid); 24.123 + 24.124 + if (accountable != NULL) 24.125 + { 24.126 + *provider = dynamic_cast<Provider *>(accountable); 24.127 + 24.128 + if ((*provider) != NULL) 24.129 + return L4_EOK; 24.130 + else 24.131 + return -L4_EIO; 24.132 + } 24.133 + 24.134 + return -L4_ENOENT; 24.135 +} 24.136 + 24.137 + 24.138 + 24.139 +/* Return a resource for a filesystem object. */ 24.140 + 24.141 +long ResourceRegistry::get_resource(FileOpening *opening, const char *path, 24.142 + flags_t flags, offset_t *size, 24.143 + object_flags_t *object_flags, 24.144 + Resource **resource) 24.145 +{ 24.146 + std::lock_guard<std::mutex> guard(_lock); 24.147 + 24.148 + /* Obtain an identifier for the object, even for new files (subject to use 24.149 + of the appropriate flag). */ 24.150 + 24.151 + fileid_t fileid; 24.152 + long err = opening->get_fileid(path, flags, &fileid); 24.153 + 24.154 + if (err) 24.155 + return err; 24.156 + 24.157 + /* Obtain a provider for the object. */ 24.158 + 24.159 + Provider *provider; 24.160 + err = find_provider(fileid, &provider); 24.161 + 24.162 + /* Make a new provider if necessary. */ 24.163 + 24.164 + if (err == -L4_ENOENT) 24.165 + err = make_provider(opening, path, flags, fileid, &provider); 24.166 + 24.167 + if (err) 24.168 + return err; 24.169 + 24.170 + /* Make a resource for the provider. */ 24.171 + 24.172 + return provider->make_resource(size, object_flags, resource); 24.173 +} 24.174 + 24.175 +// vim: tabstop=4 expandtab shiftwidth=4
25.1 --- a/servers/block_file_server.cc Sun Oct 17 22:14:40 2021 +0200 25.2 +++ b/servers/block_file_server.cc Mon Oct 18 22:59:22 2021 +0200 25.3 @@ -66,7 +66,7 @@ 25.4 MemoryIncremental mem(memory_pages); 25.5 PageQueueShared queue; 25.6 Pages pages(&mem, &queue); 25.7 - FileObjectRegistry registry(&pages); 25.8 + ResourceRegistry registry(&pages); 25.9 BlockFileOpener opener(®istry); 25.10 25.11 /* Register a server associating it with the given object. */
26.1 --- a/servers/client_file_server.cc Sun Oct 17 22:14:40 2021 +0200 26.2 +++ b/servers/client_file_server.cc Mon Oct 18 22:59:22 2021 +0200 26.3 @@ -67,7 +67,7 @@ 26.4 MemoryIncremental mem(memory_pages); 26.5 PageQueueShared queue; 26.6 Pages pages(&mem, &queue); 26.7 - FileObjectRegistry registry(&pages); 26.8 + ResourceRegistry registry(&pages); 26.9 ClientFileOpener opener(®istry); 26.10 26.11 /* Register a server associating it with the given object. */
27.1 --- a/servers/host_file_server.cc Sun Oct 17 22:14:40 2021 +0200 27.2 +++ b/servers/host_file_server.cc Mon Oct 18 22:59:22 2021 +0200 27.3 @@ -66,7 +66,7 @@ 27.4 MemoryIncremental mem(memory_pages); 27.5 PageQueueShared queue; 27.6 Pages pages(&mem, &queue); 27.7 - FileObjectRegistry registry(&pages); 27.8 + ResourceRegistry registry(&pages); 27.9 HostFileOpener opener(®istry); 27.10 27.11 /* Register a server associating it with the given object. */
28.1 --- a/servers/test_file_server.cc Sun Oct 17 22:14:40 2021 +0200 28.2 +++ b/servers/test_file_server.cc Mon Oct 18 22:59:22 2021 +0200 28.3 @@ -65,7 +65,7 @@ 28.4 MemoryIncremental mem(memory_pages, page(REGION_PAGES)); 28.5 PageQueueShared queue; 28.6 Pages pages(&mem, &queue); 28.7 - FileObjectRegistry registry(&pages); 28.8 + ResourceRegistry registry(&pages); 28.9 TestFileOpener opener(®istry, page(FILE_PAGES)); 28.10 28.11 /* Register a server associating it with the given object. */