paul@93 | 1 | /* |
paul@93 | 2 | * A resource offering support for creating contexts and opening files. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@10 | 22 | #include "opener_server.h" |
paul@10 | 23 | #include "opener_resource.h" |
paul@10 | 24 | #include "resource_server.h" |
paul@9 | 25 | |
paul@9 | 26 | /* Support for providing access to files. */ |
paul@9 | 27 | |
paul@79 | 28 | OpenerResource::OpenerResource(Pages *pages) |
paul@81 | 29 | : FilePaging(pages) |
paul@9 | 30 | { |
paul@9 | 31 | } |
paul@9 | 32 | |
paul@10 | 33 | int OpenerResource::expected_items() |
paul@9 | 34 | { |
paul@10 | 35 | return Opener_expected_items; |
paul@9 | 36 | } |
paul@9 | 37 | |
paul@10 | 38 | ipc_server_handler_type OpenerResource::handler() |
paul@10 | 39 | { |
paul@10 | 40 | return (ipc_server_handler_type) handle_Opener; |
paul@10 | 41 | } |
paul@10 | 42 | |
paul@10 | 43 | |
paul@10 | 44 | |
paul@48 | 45 | /* Return a pager object for the given path and flags. */ |
paul@10 | 46 | |
paul@136 | 47 | long OpenerResource::open(const char *path, flags_t flags, Pager **pager) |
paul@9 | 48 | { |
paul@9 | 49 | fileid_t fileid = get_fileid(path); |
paul@9 | 50 | |
paul@136 | 51 | /* Handle non-existent files. */ |
paul@136 | 52 | |
paul@9 | 53 | if (fileid == FILEID_INVALID) |
paul@136 | 54 | return -L4_ENOENT; |
paul@9 | 55 | |
paul@136 | 56 | *pager = get_pager(path, fileid, get_flags(flags)); |
paul@136 | 57 | return L4_EOK; |
paul@9 | 58 | } |
paul@9 | 59 | |
paul@10 | 60 | |
paul@10 | 61 | |
paul@10 | 62 | /* Opener interface methods. */ |
paul@10 | 63 | |
paul@10 | 64 | long OpenerResource::context(l4_cap_idx_t *context) |
paul@10 | 65 | { |
paul@10 | 66 | OpenerContextResource *resource = new OpenerContextResource(this); |
paul@10 | 67 | |
paul@62 | 68 | /* Complete the initialisation and start a server in a new thread. |
paul@120 | 69 | If the thread does not start, the resource will be finalised. */ |
paul@10 | 70 | |
paul@120 | 71 | return ResourceServer(resource).start_thread(context); |
paul@10 | 72 | } |
paul@10 | 73 | |
paul@9 | 74 | // vim: tabstop=4 expandtab shiftwidth=4 |