paul@102 | 1 | /* |
paul@106 | 2 | * An opener for a file provided by an Ext2-compatible filesystem. |
paul@102 | 3 | * |
paul@102 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@102 | 5 | * |
paul@102 | 6 | * This program is free software; you can redistribute it and/or |
paul@102 | 7 | * modify it under the terms of the GNU General Public License as |
paul@102 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@102 | 9 | * the License, or (at your option) any later version. |
paul@102 | 10 | * |
paul@102 | 11 | * This program is distributed in the hope that it will be useful, |
paul@102 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@102 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@102 | 14 | * GNU General Public License for more details. |
paul@102 | 15 | * |
paul@102 | 16 | * You should have received a copy of the GNU General Public License |
paul@102 | 17 | * along with this program; if not, write to the Free Software |
paul@102 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@102 | 19 | * Boston, MA 02110-1301, USA |
paul@102 | 20 | */ |
paul@102 | 21 | |
paul@102 | 22 | #pragma once |
paul@102 | 23 | |
paul@106 | 24 | #include <ext2fs/ext2fs.h> |
paul@106 | 25 | |
paul@168 | 26 | #include <fsclient/file.h> |
paul@148 | 27 | #include <fsserver/ext2_file_operations.h> |
paul@106 | 28 | #include <fsserver/opener_resource.h> |
paul@144 | 29 | #include <systypes/user.h> |
paul@102 | 30 | |
paul@102 | 31 | |
paul@102 | 32 | |
paul@168 | 33 | /* Forward declarations. */ |
paul@168 | 34 | |
paul@168 | 35 | struct Ext2FileOpenerDir; |
paul@168 | 36 | |
paul@168 | 37 | |
paul@168 | 38 | |
paul@102 | 39 | /* Support for providing access to files. */ |
paul@102 | 40 | |
paul@106 | 41 | class Ext2FileOpener : public OpenerResource |
paul@102 | 42 | { |
paul@102 | 43 | protected: |
paul@148 | 44 | Ext2FileOperations *_ops; |
paul@145 | 45 | user_t _user; |
paul@144 | 46 | |
paul@156 | 47 | /* Convenience methods determining different object types. */ |
paul@156 | 48 | |
paul@156 | 49 | virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid); |
paul@156 | 50 | |
paul@156 | 51 | virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); |
paul@156 | 52 | |
paul@168 | 53 | /* Convenience methods obtaining different pager types. */ |
paul@168 | 54 | |
paul@168 | 55 | virtual long get_directory(const char *path, flags_t flags, fileid_t fileid, offset_t *size, l4_cap_idx_t *cap); |
paul@168 | 56 | |
paul@144 | 57 | public: |
paul@148 | 58 | explicit Ext2FileOpener(FilePaging *paging, Ext2FileOperations *ops, user_t user) |
paul@148 | 59 | : OpenerResource(paging), _ops(ops), _user(user) |
paul@144 | 60 | { |
paul@144 | 61 | } |
paul@102 | 62 | |
paul@156 | 63 | virtual ~Ext2FileOpener(); |
paul@156 | 64 | |
paul@102 | 65 | /* Configurable methods. */ |
paul@102 | 66 | |
paul@146 | 67 | virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid); |
paul@102 | 68 | |
paul@143 | 69 | virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid, Accessor **accessor); |
paul@168 | 70 | |
paul@168 | 71 | /* Helper methods. */ |
paul@168 | 72 | |
paul@168 | 73 | void read_directory(fileid_t fileid, file_t *writer); |
paul@168 | 74 | |
paul@168 | 75 | int write_directory_entry(struct Ext2FileOpenerDir *dir); |
paul@168 | 76 | }; |
paul@168 | 77 | |
paul@168 | 78 | |
paul@168 | 79 | |
paul@168 | 80 | /* Helper structures. */ |
paul@168 | 81 | |
paul@168 | 82 | struct Ext2FileOpenerDir |
paul@168 | 83 | { |
paul@168 | 84 | Ext2FileOpener *opener; |
paul@168 | 85 | file_t *writer; |
paul@168 | 86 | struct ext2_dir_entry *entry; |
paul@168 | 87 | long offset; |
paul@102 | 88 | }; |
paul@102 | 89 | |
paul@102 | 90 | // vim: tabstop=4 expandtab shiftwidth=4 |