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