2020-08-24 08:49:41 -07: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 11:08:54 -07:00
|
|
|
|
|
|
|
size_t advise(const map &, const int &, const size_t &, const opts & = opts_default);
|
2020-09-13 00:24:04 -07:00
|
|
|
size_t prefetch(const map &, const size_t &size, const opts & = opts_default);
|
2020-09-07 11:08:54 -07:00
|
|
|
size_t evict(const map &, const size_t &size, const opts & = opts_default);
|
2022-01-26 11:24:06 -08: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 08:49:41 -07: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-09 22:05:43 -08:00
|
|
|
static const opts default_opts;
|
|
|
|
|
2020-08-24 08:49:41 -07:00
|
|
|
map() = default;
|
2022-06-18 14:31:37 -07:00
|
|
|
explicit map(const fd &, const size_t size, const opts &opts);
|
2021-03-09 22:05:43 -08:00
|
|
|
map(const fd &, const opts &opts = default_opts, const size_t &size = 0UL);
|
2020-08-24 08:49:41 -07: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-23 17:10:20 -08:00
|
|
|
uint alignment {0};
|
2020-08-24 08:49:41 -07:00
|
|
|
bool execute {false};
|
|
|
|
bool shared {false};
|
|
|
|
bool reserve {false};
|
|
|
|
bool populate {false};
|
2021-03-11 13:36:39 -08:00
|
|
|
bool locked {false};
|
2021-03-11 13:37:33 -08:00
|
|
|
bool huge2mb {false};
|
|
|
|
bool huge1gb {false};
|
2020-08-24 08:49:41 -07:00
|
|
|
};
|
|
|
|
|
2022-06-18 14:31:37 -07:00
|
|
|
inline
|
|
|
|
ircd::fs::map::map(const fd &fd,
|
|
|
|
const opts &opts,
|
|
|
|
const size_t &size)
|
|
|
|
:map{fd, size, opts}
|
|
|
|
{}
|
|
|
|
|
2020-08-24 08:49:41 -07:00
|
|
|
inline
|
|
|
|
ircd::fs::map::map(map &&other)
|
|
|
|
noexcept
|
|
|
|
:mutable_buffer{other}
|
|
|
|
{
|
|
|
|
static_cast<mutable_buffer &>(other) = {};
|
|
|
|
}
|