paul@31 | 1 | /* |
paul@31 | 2 | * File access convenience functions and types. |
paul@31 | 3 | * |
paul@236 | 4 | * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@31 | 5 | * |
paul@31 | 6 | * This program is free software; you can redistribute it and/or |
paul@31 | 7 | * modify it under the terms of the GNU General Public License as |
paul@31 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@31 | 9 | * the License, or (at your option) any later version. |
paul@31 | 10 | * |
paul@31 | 11 | * This program is distributed in the hope that it will be useful, |
paul@31 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@31 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@31 | 14 | * GNU General Public License for more details. |
paul@31 | 15 | * |
paul@31 | 16 | * You should have received a copy of the GNU General Public License |
paul@31 | 17 | * along with this program; if not, write to the Free Software |
paul@31 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@31 | 19 | * Boston, MA 02110-1301, USA |
paul@31 | 20 | */ |
paul@31 | 21 | |
paul@98 | 22 | #pragma once |
paul@98 | 23 | |
paul@31 | 24 | #include <l4/sys/types.h> |
paul@31 | 25 | |
paul@31 | 26 | #include <systypes/base.h> |
paul@150 | 27 | #include <systypes/user.h> |
paul@31 | 28 | |
paul@31 | 29 | |
paul@31 | 30 | |
paul@180 | 31 | /* C compatibility types (defined in the implementation). */ |
paul@180 | 32 | |
paul@180 | 33 | struct file_notifier; |
paul@180 | 34 | |
paul@180 | 35 | typedef struct file_notifier file_notifier_t; |
paul@180 | 36 | |
paul@180 | 37 | |
paul@180 | 38 | |
paul@33 | 39 | EXTERN_C_BEGIN |
paul@33 | 40 | |
paul@33 | 41 | /* File access abstraction. */ |
paul@33 | 42 | |
paul@31 | 43 | typedef struct |
paul@31 | 44 | { |
paul@33 | 45 | /* File object reference. */ |
paul@33 | 46 | |
paul@31 | 47 | l4_cap_idx_t ref; |
paul@33 | 48 | |
paul@33 | 49 | /* Mapped memory accessing a file region. */ |
paul@33 | 50 | |
paul@31 | 51 | char *memory; |
paul@33 | 52 | |
paul@33 | 53 | /* File region parameters. */ |
paul@33 | 54 | |
paul@35 | 55 | offset_t start_pos, end_pos; /* start and end positions of region */ |
paul@90 | 56 | offset_t data_end; /* amount/extent of data in the region */ |
paul@90 | 57 | offset_t data_current; /* client access offset */ |
paul@35 | 58 | |
paul@35 | 59 | /* Total size of file. */ |
paul@35 | 60 | |
paul@35 | 61 | offset_t size; |
paul@33 | 62 | |
paul@171 | 63 | /* Support for arbitrary memory mapping and explicit object size. */ |
paul@90 | 64 | |
paul@171 | 65 | object_flags_t object_flags; |
paul@108 | 66 | |
paul@117 | 67 | /* Blocking accesses. */ |
paul@117 | 68 | |
paul@122 | 69 | notify_flags_t can_block; |
paul@117 | 70 | |
paul@124 | 71 | /* Saved notifications. */ |
paul@124 | 72 | |
paul@124 | 73 | notify_flags_t notifications; |
paul@124 | 74 | |
paul@31 | 75 | } file_t; |
paul@31 | 76 | |
paul@35 | 77 | |
paul@35 | 78 | |
paul@144 | 79 | /* Filesystem operations. */ |
paul@144 | 80 | |
paul@150 | 81 | long file_open_for_user(user_t user, l4_cap_idx_t server, l4_cap_idx_t *opener); |
paul@144 | 82 | |
paul@47 | 83 | /* File operations. */ |
paul@33 | 84 | |
paul@33 | 85 | void file_close(file_t *file); |
paul@85 | 86 | long file_open(file_t *file, const char *filename, flags_t flags, l4_cap_idx_t server); |
paul@232 | 87 | long file_remove(const char *filename, l4_cap_idx_t server); |
paul@236 | 88 | long file_rename(const char *source, const char *target, l4_cap_idx_t server); |
paul@47 | 89 | |
paul@47 | 90 | /* File lifecycle operations. */ |
paul@47 | 91 | |
paul@33 | 92 | long file_context(file_t *file, l4_cap_idx_t server); |
paul@85 | 93 | long file_context_open(file_t *file, flags_t flags, file_t *context); |
paul@232 | 94 | long file_context_remove(file_t *context); |
paul@236 | 95 | long file_context_rename(file_t *context); |
paul@31 | 96 | void file_init(file_t *file); |
paul@45 | 97 | |
paul@55 | 98 | /* File and region operations. */ |
paul@45 | 99 | |
paul@90 | 100 | long file_flush(file_t *file); |
paul@33 | 101 | long file_mmap(file_t *file, offset_t position, offset_t length); |
paul@55 | 102 | long file_resize(file_t *file, offset_t size); |
paul@55 | 103 | |
paul@55 | 104 | /* File and region properties. */ |
paul@55 | 105 | |
paul@45 | 106 | offset_t file_populated_span(file_t *file); |
paul@33 | 107 | offset_t file_span(file_t *file); |
paul@33 | 108 | |
paul@46 | 109 | /* Convenience functions. */ |
paul@46 | 110 | |
paul@46 | 111 | char *file_string_get(file_t *file, offset_t offset); |
paul@47 | 112 | int file_string_set(file_t *file, const char *data, offset_t offset, offset_t *written); |
paul@46 | 113 | |
paul@90 | 114 | /* Client data functions. */ |
paul@90 | 115 | |
paul@90 | 116 | offset_t file_data_available(file_t *file); |
paul@90 | 117 | char *file_data_current(file_t *file); |
paul@90 | 118 | offset_t file_data_current_position(file_t *file); |
paul@90 | 119 | offset_t file_data_end_position(file_t *file); |
paul@90 | 120 | offset_t file_data_space(file_t *file); |
paul@90 | 121 | |
paul@90 | 122 | /* Client data transfer functions. */ |
paul@90 | 123 | |
paul@98 | 124 | void file_data_read(file_t *file, char *buf, offset_t to_transfer); |
paul@98 | 125 | void file_data_write(file_t *file, char *buf, offset_t to_transfer); |
paul@90 | 126 | |
paul@117 | 127 | /* Notification functions. */ |
paul@117 | 128 | |
paul@180 | 129 | void file_notify_close(file_notifier_t *notifier); |
paul@180 | 130 | file_notifier_t *file_notify_local(void); |
paul@180 | 131 | file_notifier_t *file_notify_task(void); |
paul@180 | 132 | |
paul@180 | 133 | long file_notify_subscribe(file_t *file, notify_flags_t flags, file_notifier_t *notifier); |
paul@180 | 134 | long file_notify_unsubscribe(file_t *file, file_notifier_t *notifier); |
paul@180 | 135 | long file_notify_wait_file(file_t *file, file_notifier_t *notifier); |
paul@180 | 136 | long file_notify_wait_files(file_t **file, file_notifier_t *notifier); |
paul@117 | 137 | |
paul@65 | 138 | |
paul@65 | 139 | |
paul@65 | 140 | /* Pipe operations. */ |
paul@65 | 141 | |
paul@66 | 142 | long pipe_open(offset_t size, file_t *reader, file_t *writer, l4_cap_idx_t server); |
paul@65 | 143 | |
paul@65 | 144 | /* Pipe region operations. */ |
paul@65 | 145 | |
paul@65 | 146 | long pipe_current(file_t *pipe); |
paul@65 | 147 | long pipe_next(file_t *pipe); |
paul@65 | 148 | long pipe_written(file_t *pipe, offset_t size); |
paul@65 | 149 | |
paul@117 | 150 | |
paul@117 | 151 | |
paul@202 | 152 | /* Directory operations. */ |
paul@202 | 153 | |
paul@202 | 154 | long directory_opendir(file_t *file, file_t *reader); |
paul@202 | 155 | |
paul@202 | 156 | |
paul@202 | 157 | |
paul@33 | 158 | EXTERN_C_END |
paul@31 | 159 | |
paul@31 | 160 | // vim: tabstop=2 expandtab shiftwidth=2 |