paul@31 | 1 | /* |
paul@31 | 2 | * File access convenience functions and types. |
paul@31 | 3 | * |
paul@634 | 4 | * Copyright (C) 2021, 2022, 2023, 2024 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@266 | 24 | #include <sys/stat.h> |
paul@266 | 25 | |
paul@330 | 26 | #include <l4/re/c/rm.h> |
paul@31 | 27 | #include <l4/sys/types.h> |
paul@31 | 28 | |
paul@31 | 29 | #include <systypes/base.h> |
paul@150 | 30 | #include <systypes/user.h> |
paul@31 | 31 | |
paul@575 | 32 | #include <fsclient/notify.h> |
paul@180 | 33 | |
paul@180 | 34 | |
paul@180 | 35 | |
paul@33 | 36 | EXTERN_C_BEGIN |
paul@33 | 37 | |
paul@658 | 38 | struct file_t; |
paul@658 | 39 | |
paul@479 | 40 | /* File access abstraction compatible with notifiable_base_t. */ |
paul@33 | 41 | |
paul@658 | 42 | typedef struct file_t |
paul@31 | 43 | { |
paul@33 | 44 | /* File object reference. */ |
paul@33 | 45 | |
paul@31 | 46 | l4_cap_idx_t ref; |
paul@33 | 47 | |
paul@575 | 48 | /* Notification structure. */ |
paul@575 | 49 | |
paul@575 | 50 | notifiable_t notifiable; |
paul@575 | 51 | |
paul@33 | 52 | /* Mapped memory accessing a file region. */ |
paul@33 | 53 | |
paul@31 | 54 | char *memory; |
paul@33 | 55 | |
paul@33 | 56 | /* File region parameters. */ |
paul@33 | 57 | |
paul@35 | 58 | offset_t start_pos, end_pos; /* start and end positions of region */ |
paul@90 | 59 | offset_t data_end; /* amount/extent of data in the region */ |
paul@90 | 60 | offset_t data_current; /* client access offset */ |
paul@35 | 61 | |
paul@35 | 62 | /* Total size of file. */ |
paul@35 | 63 | |
paul@35 | 64 | offset_t size; |
paul@33 | 65 | |
paul@171 | 66 | /* Support for arbitrary memory mapping and explicit object size. */ |
paul@90 | 67 | |
paul@171 | 68 | object_flags_t object_flags; |
paul@108 | 69 | |
paul@117 | 70 | /* Blocking accesses. */ |
paul@117 | 71 | |
paul@122 | 72 | notify_flags_t can_block; |
paul@117 | 73 | |
paul@330 | 74 | /* Flags indicated when opening the file. */ |
paul@330 | 75 | |
paul@330 | 76 | flags_t flags; |
paul@330 | 77 | |
paul@402 | 78 | /* Any failure or error condition on the file. */ |
paul@402 | 79 | |
paul@402 | 80 | long error; |
paul@402 | 81 | |
paul@658 | 82 | /* Metadata file object reference. */ |
paul@658 | 83 | |
paul@658 | 84 | struct file_t *metadata; |
paul@658 | 85 | |
paul@31 | 86 | } file_t; |
paul@31 | 87 | |
paul@35 | 88 | |
paul@35 | 89 | |
paul@144 | 90 | /* Filesystem operations. */ |
paul@144 | 91 | |
paul@150 | 92 | long file_open_for_user(user_t user, l4_cap_idx_t server, l4_cap_idx_t *opener); |
paul@144 | 93 | |
paul@47 | 94 | /* File operations. */ |
paul@33 | 95 | |
paul@33 | 96 | void file_close(file_t *file); |
paul@271 | 97 | long file_mkdir(const char *filename, mode_t mode, l4_cap_idx_t server); |
paul@85 | 98 | long file_open(file_t *file, const char *filename, flags_t flags, l4_cap_idx_t server); |
paul@232 | 99 | long file_remove(const char *filename, l4_cap_idx_t server); |
paul@475 | 100 | long file_reopen(file_t *file, file_t *new_file, flags_t flags); |
paul@236 | 101 | long file_rename(const char *source, const char *target, l4_cap_idx_t server); |
paul@266 | 102 | long file_stat(const char *filename, struct stat *st, l4_cap_idx_t server); |
paul@47 | 103 | |
paul@47 | 104 | /* File lifecycle operations. */ |
paul@47 | 105 | |
paul@33 | 106 | long file_context(file_t *file, l4_cap_idx_t server); |
paul@271 | 107 | long file_context_mkdir(mode_t mode, file_t *context); |
paul@85 | 108 | long file_context_open(file_t *file, flags_t flags, file_t *context); |
paul@232 | 109 | long file_context_remove(file_t *context); |
paul@236 | 110 | long file_context_rename(file_t *context); |
paul@266 | 111 | long file_context_stat(struct stat *st, file_t *context); |
paul@31 | 112 | void file_init(file_t *file); |
paul@45 | 113 | |
paul@55 | 114 | /* File and region operations. */ |
paul@45 | 115 | |
paul@90 | 116 | long file_flush(file_t *file); |
paul@339 | 117 | long file_mmap(file_t *file, offset_t position, offset_t length, |
paul@339 | 118 | offset_t start_visible, offset_t end_visible, |
paul@634 | 119 | rm_flags_t region_flags); |
paul@357 | 120 | long file_mmap_only(file_t *file, offset_t position, offset_t length, |
paul@357 | 121 | offset_t start_visible, offset_t end_visible); |
paul@634 | 122 | flags_t file_opening_flags(rm_flags_t rm_flags); |
paul@634 | 123 | rm_flags_t file_region_flags(flags_t flags); |
paul@55 | 124 | long file_resize(file_t *file, offset_t size); |
paul@55 | 125 | |
paul@55 | 126 | /* File and region properties. */ |
paul@55 | 127 | |
paul@45 | 128 | offset_t file_populated_span(file_t *file); |
paul@33 | 129 | offset_t file_span(file_t *file); |
paul@33 | 130 | |
paul@46 | 131 | /* Convenience functions. */ |
paul@46 | 132 | |
paul@46 | 133 | char *file_string_get(file_t *file, offset_t offset); |
paul@47 | 134 | int file_string_set(file_t *file, const char *data, offset_t offset, offset_t *written); |
paul@46 | 135 | |
paul@90 | 136 | /* Client data functions. */ |
paul@90 | 137 | |
paul@90 | 138 | offset_t file_data_available(file_t *file); |
paul@90 | 139 | char *file_data_current(file_t *file); |
paul@90 | 140 | offset_t file_data_current_position(file_t *file); |
paul@90 | 141 | offset_t file_data_end_position(file_t *file); |
paul@90 | 142 | offset_t file_data_space(file_t *file); |
paul@90 | 143 | |
paul@90 | 144 | /* Client data transfer functions. */ |
paul@90 | 145 | |
paul@98 | 146 | void file_data_read(file_t *file, char *buf, offset_t to_transfer); |
paul@98 | 147 | void file_data_write(file_t *file, char *buf, offset_t to_transfer); |
paul@90 | 148 | |
paul@117 | 149 | /* Notification functions. */ |
paul@117 | 150 | |
paul@479 | 151 | notifiable_t *file_notifiable(file_t *file); |
paul@479 | 152 | notify_flags_t file_notifications(file_t *file); |
paul@479 | 153 | |
paul@575 | 154 | long file_notify_wait_file(file_t *file, notifier_t *notifier); |
paul@575 | 155 | long file_notify_wait_files(file_t **file, notifier_t *notifier); |
paul@117 | 156 | |
paul@65 | 157 | |
paul@65 | 158 | |
paul@65 | 159 | /* Pipe operations. */ |
paul@65 | 160 | |
paul@66 | 161 | long pipe_open(offset_t size, file_t *reader, file_t *writer, l4_cap_idx_t server); |
paul@65 | 162 | |
paul@65 | 163 | /* Pipe region operations. */ |
paul@65 | 164 | |
paul@665 | 165 | long pipe_current(file_t *pipe, int sync); |
paul@65 | 166 | long pipe_next(file_t *pipe); |
paul@65 | 167 | long pipe_written(file_t *pipe, offset_t size); |
paul@65 | 168 | |
paul@117 | 169 | |
paul@117 | 170 | |
paul@202 | 171 | /* Directory operations. */ |
paul@202 | 172 | |
paul@202 | 173 | long directory_opendir(file_t *file, file_t *reader); |
paul@202 | 174 | |
paul@202 | 175 | |
paul@202 | 176 | |
paul@33 | 177 | EXTERN_C_END |
paul@31 | 178 | |
paul@31 | 179 | // vim: tabstop=2 expandtab shiftwidth=2 |