paul@196 | 1 | /* |
paul@196 | 2 | * An object for a directory provided by an Ext2-compatible filesystem. |
paul@196 | 3 | * |
paul@196 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@196 | 5 | * |
paul@196 | 6 | * This program is free software; you can redistribute it and/or |
paul@196 | 7 | * modify it under the terms of the GNU General Public License as |
paul@196 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@196 | 9 | * the License, or (at your option) any later version. |
paul@196 | 10 | * |
paul@196 | 11 | * This program is distributed in the hope that it will be useful, |
paul@196 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@196 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@196 | 14 | * GNU General Public License for more details. |
paul@196 | 15 | * |
paul@196 | 16 | * You should have received a copy of the GNU General Public License |
paul@196 | 17 | * along with this program; if not, write to the Free Software |
paul@196 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@196 | 19 | * Boston, MA 02110-1301, USA |
paul@196 | 20 | */ |
paul@196 | 21 | |
paul@196 | 22 | #pragma once |
paul@196 | 23 | |
paul@196 | 24 | #include <ext2fs/ext2fs.h> |
paul@196 | 25 | |
paul@196 | 26 | #include <fsclient/file.h> |
paul@196 | 27 | #include <fsserver/ext2_file_operations.h> |
paul@196 | 28 | #include <fsserver/directory_resource.h> |
paul@196 | 29 | |
paul@196 | 30 | |
paul@196 | 31 | |
paul@196 | 32 | /* Forward declarations. */ |
paul@196 | 33 | |
paul@196 | 34 | struct Ext2DirectoryState; |
paul@196 | 35 | |
paul@196 | 36 | |
paul@196 | 37 | |
paul@196 | 38 | /* Support for providing access to files. */ |
paul@196 | 39 | |
paul@196 | 40 | class Ext2Directory : public DirectoryResource |
paul@196 | 41 | { |
paul@196 | 42 | protected: |
paul@196 | 43 | Ext2FileOperations *_ops; |
paul@196 | 44 | fileid_t _fileid; |
paul@196 | 45 | |
paul@196 | 46 | virtual long _opendir(flags_t flags, offset_t *size, l4_cap_idx_t *cap, |
paul@196 | 47 | object_flags_t *object_flags); |
paul@196 | 48 | |
paul@196 | 49 | public: |
paul@196 | 50 | explicit Ext2Directory(Ext2FileOperations *ops, fileid_t fileid) |
paul@196 | 51 | : _ops(ops), _fileid(fileid) |
paul@196 | 52 | { |
paul@196 | 53 | } |
paul@196 | 54 | |
paul@196 | 55 | virtual ~Ext2Directory(); |
paul@196 | 56 | |
paul@196 | 57 | /* Helper methods. */ |
paul@196 | 58 | |
paul@196 | 59 | void read_directory(fileid_t fileid, file_t *writer); |
paul@196 | 60 | |
paul@196 | 61 | int write_directory_entry(struct Ext2DirectoryState *dir); |
paul@196 | 62 | }; |
paul@196 | 63 | |
paul@196 | 64 | |
paul@196 | 65 | |
paul@196 | 66 | /* Helper structures. */ |
paul@196 | 67 | |
paul@196 | 68 | struct Ext2DirectoryState |
paul@196 | 69 | { |
paul@196 | 70 | Ext2Directory *directory; |
paul@196 | 71 | file_t *writer; |
paul@196 | 72 | struct ext2_dir_entry *entry; |
paul@196 | 73 | long offset; |
paul@196 | 74 | }; |
paul@196 | 75 | |
paul@196 | 76 | // vim: tabstop=4 expandtab shiftwidth=4 |