paul@31 | 1 | /* |
paul@31 | 2 | * File access convenience functions and types. |
paul@31 | 3 | * |
paul@31 | 4 | * Copyright (C) 2021 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@33 | 31 | EXTERN_C_BEGIN |
paul@33 | 32 | |
paul@33 | 33 | /* File access abstraction. */ |
paul@33 | 34 | |
paul@31 | 35 | typedef struct |
paul@31 | 36 | { |
paul@33 | 37 | /* File object reference. */ |
paul@33 | 38 | |
paul@31 | 39 | l4_cap_idx_t ref; |
paul@33 | 40 | |
paul@124 | 41 | /* Notification endpoint reference. */ |
paul@117 | 42 | |
paul@124 | 43 | l4_cap_idx_t notifier; |
paul@117 | 44 | |
paul@33 | 45 | /* Mapped memory accessing a file region. */ |
paul@33 | 46 | |
paul@31 | 47 | char *memory; |
paul@33 | 48 | |
paul@33 | 49 | /* File region parameters. */ |
paul@33 | 50 | |
paul@35 | 51 | offset_t start_pos, end_pos; /* start and end positions of region */ |
paul@90 | 52 | offset_t data_end; /* amount/extent of data in the region */ |
paul@90 | 53 | offset_t data_current; /* client access offset */ |
paul@35 | 54 | |
paul@35 | 55 | /* Total size of file. */ |
paul@35 | 56 | |
paul@35 | 57 | offset_t size; |
paul@33 | 58 | |
paul@171 | 59 | /* Support for arbitrary memory mapping and explicit object size. */ |
paul@90 | 60 | |
paul@171 | 61 | object_flags_t object_flags; |
paul@108 | 62 | |
paul@117 | 63 | /* Blocking accesses. */ |
paul@117 | 64 | |
paul@122 | 65 | notify_flags_t can_block; |
paul@117 | 66 | |
paul@124 | 67 | /* Saved notifications. */ |
paul@124 | 68 | |
paul@124 | 69 | notify_flags_t notifications; |
paul@124 | 70 | |
paul@31 | 71 | } file_t; |
paul@31 | 72 | |
paul@35 | 73 | |
paul@35 | 74 | |
paul@144 | 75 | /* Filesystem operations. */ |
paul@144 | 76 | |
paul@150 | 77 | long file_open_for_user(user_t user, l4_cap_idx_t server, l4_cap_idx_t *opener); |
paul@144 | 78 | |
paul@47 | 79 | /* File operations. */ |
paul@33 | 80 | |
paul@33 | 81 | void file_close(file_t *file); |
paul@85 | 82 | long file_open(file_t *file, const char *filename, flags_t flags, l4_cap_idx_t server); |
paul@47 | 83 | |
paul@47 | 84 | /* File lifecycle operations. */ |
paul@47 | 85 | |
paul@33 | 86 | long file_context(file_t *file, l4_cap_idx_t server); |
paul@85 | 87 | long file_context_open(file_t *file, flags_t flags, file_t *context); |
paul@31 | 88 | void file_init(file_t *file); |
paul@45 | 89 | |
paul@55 | 90 | /* File and region operations. */ |
paul@45 | 91 | |
paul@90 | 92 | long file_flush(file_t *file); |
paul@33 | 93 | long file_mmap(file_t *file, offset_t position, offset_t length); |
paul@55 | 94 | long file_resize(file_t *file, offset_t size); |
paul@55 | 95 | |
paul@55 | 96 | /* File and region properties. */ |
paul@55 | 97 | |
paul@45 | 98 | offset_t file_populated_span(file_t *file); |
paul@33 | 99 | offset_t file_span(file_t *file); |
paul@33 | 100 | |
paul@46 | 101 | /* Convenience functions. */ |
paul@46 | 102 | |
paul@46 | 103 | char *file_string_get(file_t *file, offset_t offset); |
paul@47 | 104 | int file_string_set(file_t *file, const char *data, offset_t offset, offset_t *written); |
paul@46 | 105 | |
paul@90 | 106 | /* Client data functions. */ |
paul@90 | 107 | |
paul@90 | 108 | offset_t file_data_available(file_t *file); |
paul@90 | 109 | char *file_data_current(file_t *file); |
paul@90 | 110 | offset_t file_data_current_position(file_t *file); |
paul@90 | 111 | offset_t file_data_end_position(file_t *file); |
paul@90 | 112 | offset_t file_data_space(file_t *file); |
paul@90 | 113 | |
paul@90 | 114 | /* Client data transfer functions. */ |
paul@90 | 115 | |
paul@98 | 116 | void file_data_read(file_t *file, char *buf, offset_t to_transfer); |
paul@98 | 117 | void file_data_write(file_t *file, char *buf, offset_t to_transfer); |
paul@90 | 118 | |
paul@117 | 119 | /* Notification functions. */ |
paul@117 | 120 | |
paul@121 | 121 | long file_notify_subscribe(file_t *file, notify_flags_t flags); |
paul@117 | 122 | long file_notify_unsubscribe(file_t *file); |
paul@123 | 123 | long file_notify_wait_file(file_t *file); |
paul@123 | 124 | long file_notify_wait_files(file_t **file); |
paul@117 | 125 | |
paul@65 | 126 | |
paul@65 | 127 | |
paul@65 | 128 | /* Pipe operations. */ |
paul@65 | 129 | |
paul@66 | 130 | long pipe_open(offset_t size, file_t *reader, file_t *writer, l4_cap_idx_t server); |
paul@65 | 131 | |
paul@65 | 132 | /* Pipe region operations. */ |
paul@65 | 133 | |
paul@65 | 134 | long pipe_current(file_t *pipe); |
paul@65 | 135 | long pipe_next(file_t *pipe); |
paul@65 | 136 | long pipe_written(file_t *pipe, offset_t size); |
paul@65 | 137 | |
paul@117 | 138 | |
paul@117 | 139 | |
paul@33 | 140 | EXTERN_C_END |
paul@31 | 141 | |
paul@31 | 142 | // vim: tabstop=2 expandtab shiftwidth=2 |