1 /* 2 * An opener for a file provided by an Ext2-compatible filesystem. 3 * 4 * Copyright (C) 2021, 2022 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 <ext2fs/ext2fs.h> 25 26 #include <fsclient/file.h> 27 #include <fsserver/ext2_file_operations.h> 28 #include <fsserver/opener_resource.h> 29 #include <systypes/user.h> 30 31 32 33 /* Support for providing access to files. */ 34 35 class Ext2FileOpener : public OpenerResource 36 { 37 protected: 38 Ext2FileOperations *_ops; 39 user_t _user; 40 41 /* Convenience methods determining different object types. */ 42 43 virtual bool accessing_directory(flags_t flags, fileid_t fileid); 44 45 virtual bool accessing_file(flags_t flags, fileid_t fileid); 46 47 virtual bool directory_is_empty(fileid_t fileid); 48 49 public: 50 explicit Ext2FileOpener(ResourceRegistry *registry, Ext2FileOperations *ops, user_t user) 51 : OpenerResource(registry), _ops(ops), _user(user) 52 { 53 } 54 55 virtual ~Ext2FileOpener(); 56 57 /* File opening methods. */ 58 59 virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid); 60 61 virtual long make_accessor(flags_t flags, fileid_t fileid, 62 Accessor **accessor); 63 64 virtual long make_directory_accessor(flags_t flags, fileid_t fileid, 65 DirectoryAccessor **accessor); 66 67 /* Filesystem object access and manipulation methods. */ 68 69 virtual long make_directory_object(const char *path, sys_mode_t mode); 70 71 virtual long remove_object(fileid_t fileid); 72 73 virtual long rename_object(const char *source, const char *target); 74 75 virtual long stat_object(const char *path, void *base, offset_t size); 76 77 virtual long unlink_object(fileid_t parent_fileid, fileid_t fileid); 78 }; 79 80 // vim: tabstop=4 expandtab shiftwidth=4