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 /* Return an object for the given path and flags. */ 82 83 long OpenerResource::open(const char *path, flags_t flags, offset_t *size, 84 l4_cap_idx_t *cap, object_flags_t *object_flags) 85 { 86 Resource *resource; 87 long err = _registry->get_resource(this, path, flags, size, object_flags, &resource); 88 89 if (err) 90 return err; 91 92 /* Notify listeners subscribed to the parent of the opened object. */ 93 94 notify_parent(path); 95 96 /* Start a server for the resource. */ 97 98 return ResourceServer(resource).start_thread(cap); 99 } 100 101 /* Request the removal of the named filesystem object. */ 102 103 long OpenerResource::remove(const char *path) 104 { 105 return _registry->remove_provider(this, path); 106 } 107 108 /* Request the renaming of the named filesystem object. */ 109 110 long OpenerResource::rename(const char *source, const char *target) 111 { 112 return _registry->rename_provider(this, source, target); 113 } 114 115 116 117 /* Opener interface methods. */ 118 119 long OpenerResource::context(l4_cap_idx_t *context) 120 { 121 OpenerContextResource *resource = new OpenerContextResource(this); 122 123 /* Complete the initialisation and start a server in a new thread. 124 If the thread does not start, the resource will be finalised. */ 125 126 return ResourceServer(resource).start_thread(context); 127 } 128 129 // vim: tabstop=4 expandtab shiftwidth=4