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@31 | 22 | #include <l4/sys/types.h> |
paul@31 | 23 | |
paul@31 | 24 | #include <systypes/base.h> |
paul@31 | 25 | |
paul@31 | 26 | |
paul@31 | 27 | |
paul@33 | 28 | EXTERN_C_BEGIN |
paul@33 | 29 | |
paul@33 | 30 | /* File access abstraction. */ |
paul@33 | 31 | |
paul@31 | 32 | typedef struct |
paul@31 | 33 | { |
paul@33 | 34 | /* File object reference. */ |
paul@33 | 35 | |
paul@31 | 36 | l4_cap_idx_t ref; |
paul@33 | 37 | |
paul@33 | 38 | /* Mapped memory accessing a file region. */ |
paul@33 | 39 | |
paul@31 | 40 | char *memory; |
paul@33 | 41 | |
paul@33 | 42 | /* File region parameters. */ |
paul@33 | 43 | |
paul@35 | 44 | offset_t start_pos, end_pos; /* start and end positions of region */ |
paul@33 | 45 | offset_t data_end; /* amount of data in the region */ |
paul@35 | 46 | |
paul@35 | 47 | /* Total size of file. */ |
paul@35 | 48 | |
paul@35 | 49 | offset_t size; |
paul@33 | 50 | |
paul@31 | 51 | } file_t; |
paul@31 | 52 | |
paul@35 | 53 | |
paul@35 | 54 | |
paul@47 | 55 | /* File operations. */ |
paul@33 | 56 | |
paul@33 | 57 | void file_close(file_t *file); |
paul@47 | 58 | long file_open(file_t *file, const char *filename, l4_cap_idx_t server); |
paul@47 | 59 | |
paul@47 | 60 | /* File lifecycle operations. */ |
paul@47 | 61 | |
paul@33 | 62 | long file_context(file_t *file, l4_cap_idx_t server); |
paul@47 | 63 | long file_context_open(file_t *file, file_t *context); |
paul@31 | 64 | void file_init(file_t *file); |
paul@45 | 65 | |
paul@55 | 66 | /* File and region operations. */ |
paul@45 | 67 | |
paul@33 | 68 | long file_mmap(file_t *file, offset_t position, offset_t length); |
paul@55 | 69 | long file_resize(file_t *file, offset_t size); |
paul@55 | 70 | |
paul@55 | 71 | /* File and region properties. */ |
paul@55 | 72 | |
paul@45 | 73 | offset_t file_populated_span(file_t *file); |
paul@33 | 74 | offset_t file_span(file_t *file); |
paul@33 | 75 | |
paul@46 | 76 | /* Convenience functions. */ |
paul@46 | 77 | |
paul@46 | 78 | char *file_string_get(file_t *file, offset_t offset); |
paul@47 | 79 | int file_string_set(file_t *file, const char *data, offset_t offset, offset_t *written); |
paul@46 | 80 | |
paul@33 | 81 | EXTERN_C_END |
paul@31 | 82 | |
paul@31 | 83 | // vim: tabstop=2 expandtab shiftwidth=2 |