L4Re/departure

Annotated libfsserver/include/fsserver/host_file_opener.h

232:9cfd2fb90c33
2022-01-04 Paul Boddie Added initial support for file removal.
paul@93 1
/*
paul@93 2
 * An opener for a "host" file provided via the C library.
paul@93 3
 *
paul@93 4
 * Copyright (C) 2021 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@139 35
paul@139 36
paul@139 37
paul@12 38
/* Support for providing access to files. */
paul@12 39
paul@12 40
class HostFileOpener : public OpenerResource
paul@12 41
{
paul@12 42
protected:
paul@139 43
    std::mutex _lock;
paul@139 44
paul@139 45
    /* File identifier register. */
paul@139 46
paul@139 47
    HostFileIdentifiers _fileids;
paul@12 48
paul@143 49
    virtual fileid_t _get_fileid(const char *path, bool create);
paul@143 50
paul@156 51
    /* Convenience methods determining different object types. */
paul@156 52
paul@156 53
    virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid);
paul@156 54
paul@156 55
    virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid);
paul@156 56
paul@144 57
public:
paul@224 58
    explicit HostFileOpener(ResourceRegistry *registry)
paul@209 59
    : OpenerResource(registry)
paul@144 60
    {
paul@144 61
    }
paul@144 62
paul@156 63
    virtual ~HostFileOpener();
paul@156 64
paul@202 65
    /* File opening methods. */
paul@12 66
paul@146 67
    virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid);
paul@12 68
paul@202 69
    virtual long make_accessor(const char *path, flags_t flags, fileid_t fileid,
paul@202 70
                               Accessor **accessor);
paul@202 71
paul@202 72
    virtual long make_directory_accessor(const char *path, flags_t flags,
paul@202 73
                                         fileid_t fileid,
paul@202 74
                                         DirectoryAccessor **accessor);
paul@232 75
paul@232 76
    virtual long remove_object(const char *path, fileid_t fileid);
paul@232 77
paul@232 78
    virtual long unlink_object(const char *path, fileid_t fileid);
paul@12 79
};
paul@12 80
paul@12 81
// vim: tabstop=4 expandtab shiftwidth=4