1 /* 2 * A filesystem directory listing accessor. 3 * 4 * Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 26 /* Instead of <stdint.h> for SIZE_MAX and <cstdint>... */ 27 28 #ifndef SIZE_MAX 29 #define SIZE_MAX __SIZE_MAX__ 30 #endif 31 32 #include <stdio.h> 33 34 #include <ext2fs/ext2fs.h> 35 36 #include <fsserver/accessor.h> 37 #include "fs_directory_listing.h" 38 39 40 41 /* Filesystem directory listing accessor. */ 42 43 class Fs_directory_listing_accessor : public Accessor 44 { 45 private: 46 ext2_filsys _fs; 47 ext2_ino_t _dir; 48 int _flags; 49 Fs_directory_listing *_listing = 0; 50 51 public: 52 /* NOTE: The actual size of a directory listing is not readily determined. */ 53 54 explicit Fs_directory_listing_accessor(ext2_filsys fs, ext2_ino_t dir, 55 int flags, 56 Pages *pages, size_t size=SIZE_MAX) 57 : Accessor(pages, size), _fs(fs), _dir(dir), _flags(flags) 58 { 59 } 60 61 /* Accessor methods. */ 62 63 unsigned long get_fileid() { return _dir; } 64 65 void detach(l4_cap_idx_t irq); 66 67 long flush(); 68 69 size_t fstat(char *buffer, size_t length); 70 71 size_t read(size_t start, char *buffer, size_t length); 72 73 size_t write(size_t start, char *buffer, size_t length); 74 };