2020-08-24 17:49:41 +02:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_FS_MAP_H
|
|
|
|
|
|
|
|
namespace ircd::fs
|
|
|
|
{
|
|
|
|
struct map;
|
2020-09-07 20:08:54 +02:00
|
|
|
|
|
|
|
size_t advise(const map &, const int &, const size_t &, const opts & = opts_default);
|
2020-09-13 09:24:04 +02:00
|
|
|
size_t prefetch(const map &, const size_t &size, const opts & = opts_default);
|
2020-09-07 20:08:54 +02:00
|
|
|
size_t evict(const map &, const size_t &size, const opts & = opts_default);
|
2022-01-26 20:24:06 +01:00
|
|
|
size_t flush(const map &, const size_t &size, const opts & = opts_default);
|
|
|
|
size_t sync(const map &, const size_t &size, const opts & = opts_default);
|
2020-08-24 17:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Interface to map file into memory.
|
|
|
|
///
|
|
|
|
/// Note that this was created specifically for file maps and not intended to
|
|
|
|
/// be a generic mmap(2) interface, at least for now.
|
|
|
|
struct ircd::fs::map
|
|
|
|
:mutable_buffer
|
|
|
|
{
|
|
|
|
struct opts;
|
|
|
|
|
2021-03-10 07:05:43 +01:00
|
|
|
static const opts default_opts;
|
|
|
|
|
2020-08-24 17:49:41 +02:00
|
|
|
map() = default;
|
2021-03-10 07:05:43 +01:00
|
|
|
map(const fd &, const opts &opts = default_opts, const size_t &size = 0UL);
|
2020-08-24 17:49:41 +02:00
|
|
|
map(map &&) noexcept;
|
|
|
|
map(const map &) = delete;
|
|
|
|
map &operator=(map &&) noexcept;
|
|
|
|
map &operator=(const map &) = delete;
|
|
|
|
~map() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Descriptor options (open options)
|
|
|
|
struct ircd::fs::map::opts
|
|
|
|
:fd::opts
|
|
|
|
{
|
2022-02-24 02:10:20 +01:00
|
|
|
uint alignment {0};
|
2020-08-24 17:49:41 +02:00
|
|
|
bool execute {false};
|
|
|
|
bool shared {false};
|
|
|
|
bool reserve {false};
|
|
|
|
bool populate {false};
|
2021-03-11 22:36:39 +01:00
|
|
|
bool locked {false};
|
2021-03-11 22:37:33 +01:00
|
|
|
bool huge2mb {false};
|
|
|
|
bool huge1gb {false};
|
2020-08-24 17:49:41 +02:00
|
|
|
|
|
|
|
opts(const fd::opts &opts = {std::ios::in})
|
|
|
|
:fd::opts(opts)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::fs::map::map(map &&other)
|
|
|
|
noexcept
|
|
|
|
:mutable_buffer{other}
|
|
|
|
{
|
|
|
|
static_cast<mutable_buffer &>(other) = {};
|
|
|
|
}
|