paul@93 | 1 | /* |
paul@93 | 2 | * A context resource offering support for opening files. |
paul@93 | 3 | * |
paul@490 | 4 | * Copyright (C) 2021, 2022, 2023 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@170 | 22 | #include <ipc/cap_alloc.h> |
paul@170 | 23 | |
paul@10 | 24 | #include "opener_context_resource.h" |
paul@10 | 25 | #include "opener_context_object_server.h" |
paul@10 | 26 | #include "opener_resource.h" |
paul@9 | 27 | |
paul@32 | 28 | #include <string.h> |
paul@32 | 29 | |
paul@32 | 30 | |
paul@32 | 31 | |
paul@9 | 32 | /* Support for providing access to files. */ |
paul@9 | 33 | |
paul@10 | 34 | OpenerContextResource::OpenerContextResource(OpenerResource *opener, Memory *memory) |
paul@9 | 35 | : SimplePager(memory), _opener(opener) |
paul@9 | 36 | { |
paul@9 | 37 | } |
paul@9 | 38 | |
paul@459 | 39 | ipc_server_default_config_type OpenerContextResource::config() |
paul@9 | 40 | { |
paul@459 | 41 | return config_OpenerContextObject; |
paul@10 | 42 | } |
paul@10 | 43 | |
paul@10 | 44 | |
paul@10 | 45 | |
paul@10 | 46 | /* Opener context interface methods. */ |
paul@10 | 47 | |
paul@271 | 48 | long OpenerContextResource::mkdir(sys_mode_t mode) |
paul@271 | 49 | { |
paul@490 | 50 | char *path = get_string(); |
paul@271 | 51 | |
paul@271 | 52 | if (path == NULL) |
paul@271 | 53 | return -L4_EINVAL; |
paul@271 | 54 | |
paul@271 | 55 | return _opener->mkdir(path, mode); |
paul@271 | 56 | } |
paul@271 | 57 | |
paul@171 | 58 | long OpenerContextResource::open(flags_t flags, offset_t *size, |
paul@171 | 59 | l4_cap_idx_t *file, object_flags_t *object_flags) |
paul@10 | 60 | { |
paul@490 | 61 | char *path = get_string(); |
paul@32 | 62 | |
paul@32 | 63 | if (path == NULL) |
paul@32 | 64 | return -L4_EINVAL; |
paul@32 | 65 | |
paul@202 | 66 | return _opener->open(path, flags, size, file, object_flags); |
paul@10 | 67 | } |
paul@10 | 68 | |
paul@232 | 69 | long OpenerContextResource::remove() |
paul@232 | 70 | { |
paul@490 | 71 | char *path = get_string(); |
paul@232 | 72 | |
paul@232 | 73 | if (path == NULL) |
paul@232 | 74 | return -L4_EINVAL; |
paul@232 | 75 | |
paul@232 | 76 | return _opener->remove(path); |
paul@232 | 77 | } |
paul@232 | 78 | |
paul@236 | 79 | long OpenerContextResource::rename() |
paul@236 | 80 | { |
paul@236 | 81 | char *source, *target; |
paul@236 | 82 | |
paul@490 | 83 | source = get_string(); |
paul@236 | 84 | |
paul@236 | 85 | if (source == NULL) |
paul@236 | 86 | return -L4_EINVAL; |
paul@236 | 87 | |
paul@490 | 88 | target = get_string(strlen(source) + 1); |
paul@236 | 89 | |
paul@236 | 90 | if (target == NULL) |
paul@236 | 91 | return -L4_EINVAL; |
paul@236 | 92 | |
paul@236 | 93 | return _opener->rename(source, target); |
paul@236 | 94 | } |
paul@236 | 95 | |
paul@266 | 96 | long OpenerContextResource::stat() |
paul@266 | 97 | { |
paul@490 | 98 | char *path = get_string(); |
paul@266 | 99 | |
paul@266 | 100 | if (path == NULL) |
paul@266 | 101 | return -L4_EINVAL; |
paul@266 | 102 | |
paul@266 | 103 | return _opener->stat(path, (void *) _region->start, _region->size()); |
paul@266 | 104 | } |
paul@266 | 105 | |
paul@9 | 106 | // vim: tabstop=4 expandtab shiftwidth=4 |