L4Re/departure

Annotated libfsserver/include/fsserver/host_file_opener.h

240:ffd7b371fcfd
2022-02-10 Paul Boddie Removed file paths from various methods, instead relying on file identifiers. Some operations such as file renaming still need to be aware of file paths because they need to know the parent directories of renamed objects.
paul@93 1
/*
paul@93 2
 * An opener for a "host" file provided via the C library.
paul@93 3
 *
paul@236 4
 * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
paul@93 5
 *
paul@93 6
 * This program is free software; you can redistribute it and/or
paul@93 7
 * modify it under the terms of the GNU General Public License as
paul@93 8
 * published by the Free Software Foundation; either version 2 of
paul@93 9
 * the License, or (at your option) any later version.
paul@93 10
 *
paul@93 11
 * This program is distributed in the hope that it will be useful,
paul@93 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@93 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@93 14
 * GNU General Public License for more details.
paul@93 15
 *
paul@93 16
 * You should have received a copy of the GNU General Public License
paul@93 17
 * along with this program; if not, write to the Free Software
paul@93 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@93 19
 * Boston, MA  02110-1301, USA
paul@93 20
 */
paul@93 21
paul@12 22
#pragma once
paul@12 23
paul@12 24
#include <map>
paul@139 25
#include <mutex>
paul@139 26
#include <string>
paul@12 27
paul@94 28
#include <fsserver/opener_resource.h>
paul@12 29
paul@12 30
paul@12 31
paul@139 32
/* Collection data types. */
paul@139 33
paul@139 34
typedef std::map<std::string, fileid_t> HostFileIdentifiers;
paul@240 35
typedef std::map<fileid_t, std::string> HostFilePaths;
paul@139 36
paul@139 37
paul@139 38
paul@12 39
/* Support for providing access to files. */
paul@12 40
paul@12 41
class HostFileOpener : public OpenerResource
paul@12 42
{
paul@12 43
protected:
paul@139 44
    std::mutex _lock;
paul@139 45
paul@139 46
    /* File identifier register. */
paul@139 47
paul@139 48
    HostFileIdentifiers _fileids;
paul@240 49
    HostFilePaths _paths;
paul@12 50
paul@143 51
    virtual fileid_t _get_fileid(const char *path, bool create);
paul@143 52
paul@240 53
    virtual const char *_get_path(fileid_t fileid);
paul@240 54
paul@156 55
    /* Convenience methods determining different object types. */
paul@156 56
paul@240 57
    virtual bool accessing_directory(flags_t flags, fileid_t fileid);
paul@156 58
paul@240 59
    virtual bool accessing_file(flags_t flags, fileid_t fileid);
paul@156 60
paul@144 61
public:
paul@224 62
    explicit HostFileOpener(ResourceRegistry *registry)
paul@209 63
    : OpenerResource(registry)
paul@144 64
    {
paul@144 65
    }
paul@144 66
paul@156 67
    virtual ~HostFileOpener();
paul@156 68
paul@202 69
    /* File opening methods. */
paul@12 70
paul@146 71
    virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid);
paul@12 72
paul@240 73
    virtual long make_accessor(flags_t flags, fileid_t fileid,
paul@202 74
                               Accessor **accessor);
paul@202 75
paul@240 76
    virtual long make_directory_accessor(flags_t flags, fileid_t fileid,
paul@202 77
                                         DirectoryAccessor **accessor);
paul@232 78
paul@240 79
    virtual long remove_object(fileid_t fileid);
paul@232 80
paul@240 81
    virtual long rename_object(const char *source, const char *target);
paul@236 82
paul@240 83
    virtual long unlink_object(fileid_t parent_fileid, fileid_t fileid);
paul@12 84
};
paul@12 85
paul@12 86
// vim: tabstop=4 expandtab shiftwidth=4