1 /* 2 * A resource offering support for creating contexts and opening files. 3 * 4 * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <resource/resource_server.h> 23 24 #include "opener_server.h" 25 #include "opener_resource.h" 26 27 /* Support for providing access to files. */ 28 29 OpenerResource::OpenerResource(ResourceRegistry *registry) 30 : _registry(registry) 31 { 32 } 33 34 OpenerResource::~OpenerResource() 35 { 36 } 37 38 ipc_server_default_config_type OpenerResource::config() 39 { 40 return config_Opener; 41 } 42 43 44 45 /* Obtain any active parent directory for a path, notifying its subscribers of 46 the file opening event. 47 NOTE: This might need to happen in the registry due to concurrency issues. */ 48 49 long OpenerResource::notify_parent(const char *path) 50 { 51 Provider *provider; 52 fileid_t fileid; 53 long err; 54 55 err = get_parent(path, &fileid); 56 57 if (err) 58 return err; 59 60 /* Obtain the provider of the parent directory. */ 61 62 err = _registry->find_provider(fileid, &provider); 63 64 if (err) 65 return err; 66 67 /* With any active provider, send a notification. 68 NOTE: This should also communicate which file was involved, probably 69 NOTE: using the file identifier of the opened file. */ 70 71 provider->notify_all(NOTIFY_FILE_OPENED, NOTIFY_VALUES_NULL); 72 return L4_EOK; 73 } 74 75 76 77 /* Make a directory. */ 78 79 long OpenerResource::mkdir(const char *path, sys_mode_t mode) 80 { 81 return make_directory_object(path, mode); 82 } 83 84 /* Return an object for the given path and flags. */ 85 86 long OpenerResource::open(const char *path, flags_t flags, offset_t *size, 87 l4_cap_idx_t *file, object_flags_t *object_flags) 88 { 89 Resource *resource; 90 long err = _registry->get_resource(this, path, flags, size, object_flags, &resource); 91 92 if (err) 93 return err; 94 95 /* Notify listeners subscribed to the parent of the opened object. */ 96 97 notify_parent(path); 98 99 /* Start a server for the resource. */ 100 101 return ResourceServer(resource).start_thread(file); 102 } 103 104 /* Request the removal of the named filesystem object. */ 105 106 long OpenerResource::remove(const char *path) 107 { 108 return _registry->remove_provider(this, path); 109 } 110 111 /* Request the renaming of the named filesystem object. */ 112 113 long OpenerResource::rename(const char *source, const char *target) 114 { 115 return _registry->rename_provider(this, source, target); 116 } 117 118 /* Obtain statistics metadata for the named filesystem object. */ 119 120 long OpenerResource::stat(const char *path, void *base, offset_t size) 121 { 122 return stat_object(path, base, size); 123 } 124 125 126 127 /* Opener interface methods. */ 128 129 long OpenerResource::context(l4_cap_idx_t *context) 130 { 131 OpenerContextResource *resource = new OpenerContextResource(this); 132 133 /* Complete the initialisation and start a server in a new thread. 134 If the thread does not start, the resource will be finalised. */ 135 136 return ResourceServer(resource).start_thread(context); 137 } 138 139 // vim: tabstop=4 expandtab shiftwidth=4