1 /* 2 * A resource offering support for creating contexts and opening files. 3 * 4 * Copyright (C) 2021, 2022 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 "opener_server.h" 23 #include "opener_resource.h" 24 #include "resource_server.h" 25 26 /* Support for providing access to files. */ 27 28 OpenerResource::OpenerResource(ResourceRegistry *registry) 29 : _registry(registry) 30 { 31 } 32 33 OpenerResource::~OpenerResource() 34 { 35 } 36 37 int OpenerResource::expected_items() 38 { 39 return Opener_expected_items; 40 } 41 42 ipc_server_handler_type OpenerResource::handler() 43 { 44 return (ipc_server_handler_type) handle_Opener; 45 } 46 47 48 49 /* Obtain any active parent directory for a path, notifying its subscribers of 50 the file opening event. 51 NOTE: This might need to happen in the registry due to concurrency issues. */ 52 53 long OpenerResource::notify_parent(const char *path) 54 { 55 Provider *provider; 56 fileid_t fileid; 57 long err; 58 59 err = get_parent(path, &fileid); 60 61 if (err) 62 return err; 63 64 /* Obtain the provider of the parent directory. */ 65 66 err = _registry->find_provider(fileid, &provider); 67 68 if (err) 69 return err; 70 71 /* With any active provider, send a notification. 72 NOTE: This should also communicate which file was involved, probably 73 NOTE: using the file identifier of the opened file. */ 74 75 provider->notify_all(NOTIFY_FILE_OPENED); 76 return L4_EOK; 77 } 78 79 80 81 /* Make a directory. */ 82 83 long OpenerResource::mkdir(const char *path, sys_mode_t mode) 84 { 85 return make_directory_object(path, mode); 86 } 87 88 /* Return an object for the given path and flags. */ 89 90 long OpenerResource::open(const char *path, flags_t flags, offset_t *size, 91 l4_cap_idx_t *cap, object_flags_t *object_flags) 92 { 93 Resource *resource; 94 long err = _registry->get_resource(this, path, flags, size, object_flags, &resource); 95 96 if (err) 97 return err; 98 99 /* Notify listeners subscribed to the parent of the opened object. */ 100 101 notify_parent(path); 102 103 /* Start a server for the resource. */ 104 105 return ResourceServer(resource).start_thread(cap); 106 } 107 108 /* Request the removal of the named filesystem object. */ 109 110 long OpenerResource::remove(const char *path) 111 { 112 return _registry->remove_provider(this, path); 113 } 114 115 /* Request the renaming of the named filesystem object. */ 116 117 long OpenerResource::rename(const char *source, const char *target) 118 { 119 return _registry->rename_provider(this, source, target); 120 } 121 122 /* Obtain statistics metadata for the named filesystem object. */ 123 124 long OpenerResource::stat(const char *path, void *base, offset_t size) 125 { 126 return stat_object(path, base, size); 127 } 128 129 130 131 /* Opener interface methods. */ 132 133 long OpenerResource::context(l4_cap_idx_t *context) 134 { 135 OpenerContextResource *resource = new OpenerContextResource(this); 136 137 /* Complete the initialisation and start a server in a new thread. 138 If the thread does not start, the resource will be finalised. */ 139 140 return ResourceServer(resource).start_thread(context); 141 } 142 143 // vim: tabstop=4 expandtab shiftwidth=4