L4Re/departure

Annotated libfsserver/lib/files/test_file_opener.cc

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 test file containing generated content.
paul@93 3
 *
paul@240 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@9 22
#include "test_file_accessor.h"
paul@9 23
#include "test_file_opener.h"
paul@9 24
paul@9 25
#include <stdlib.h>
paul@9 26
paul@9 27
/* Support for providing access to files. */
paul@9 28
paul@224 29
TestFileOpener::TestFileOpener(ResourceRegistry *registry, offset_t file_size)
paul@209 30
: OpenerResource(registry), _file_size(file_size)
paul@9 31
{
paul@9 32
}
paul@9 33
paul@156 34
TestFileOpener::~TestFileOpener()
paul@156 35
{
paul@156 36
}
paul@156 37
paul@240 38
bool TestFileOpener::accessing_directory(flags_t flags, fileid_t fileid)
paul@156 39
{
paul@240 40
    (void) flags; (void) fileid;
paul@156 41
    return false;
paul@156 42
}
paul@156 43
paul@240 44
bool TestFileOpener::accessing_file(flags_t flags, fileid_t fileid)
paul@156 45
{
paul@240 46
    (void) flags; (void) fileid;
paul@156 47
    return true;
paul@156 48
}
paul@156 49
paul@9 50
/* Return a file identifier for the given 'path'. */
paul@9 51
paul@146 52
long TestFileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)
paul@9 53
{
paul@143 54
    (void) flags;
paul@143 55
paul@9 56
    /* NOTE: Just convert the path to a number. */
paul@9 57
paul@146 58
    *fileid = atol(path);
paul@146 59
    return L4_EOK;
paul@9 60
}
paul@9 61
paul@9 62
/* Return a new accessor for 'fileid'. */
paul@9 63
paul@240 64
long TestFileOpener::make_accessor(flags_t flags, fileid_t fileid,
paul@240 65
                                   Accessor **accessor)
paul@9 66
{
paul@240 67
    (void) flags;
paul@143 68
    *accessor = new TestFileAccessor(fileid, _file_size);
paul@143 69
    return L4_EOK;
paul@9 70
}
paul@9 71
paul@202 72
/* Return a new directory accessor for 'fileid'. */
paul@202 73
paul@240 74
long TestFileOpener::make_directory_accessor(flags_t flags, fileid_t fileid,
paul@202 75
                                             DirectoryAccessor **accessor)
paul@202 76
{
paul@240 77
    (void) flags; (void) fileid; (void) accessor;
paul@202 78
    return -L4_EIO;
paul@202 79
}
paul@202 80
paul@232 81
/* Remove a filesystem object. */
paul@232 82
paul@240 83
long TestFileOpener::remove_object(fileid_t fileid)
paul@232 84
{
paul@240 85
    (void) fileid;
paul@232 86
    return L4_EOK;
paul@232 87
}
paul@232 88
paul@236 89
/* Rename a filesystem object, placing source inside the parent of target. */
paul@236 90
paul@240 91
long TestFileOpener::rename_object(const char *source, const char *target)
paul@236 92
{
paul@240 93
    (void) source; (void) target;
paul@236 94
    return -L4_EIO;
paul@236 95
}
paul@236 96
paul@232 97
/* Unlink a filesystem object. */
paul@232 98
paul@240 99
long TestFileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid)
paul@232 100
{
paul@240 101
    (void) parent_fileid; (void) fileid;
paul@232 102
    return -L4_EIO;
paul@232 103
}
paul@232 104
paul@9 105
// vim: tabstop=4 expandtab shiftwidth=4