2018-02-03 18:22:01 -08:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
2018-01-10 21:30:31 -08:00
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2018-02-03 18:22:01 -08:00
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
2018-01-10 21:30:31 -08:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
2018-02-03 18:22:01 -08:00
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2018-01-10 21:30:31 -08:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_FS_READ_H
|
|
|
|
|
|
|
|
namespace ircd::fs
|
|
|
|
{
|
|
|
|
struct read_opts extern const read_opts_default;
|
|
|
|
|
2018-11-28 17:26:25 -08:00
|
|
|
// Yields ircd::ctx for read into buffers; returns bytes read
|
|
|
|
size_t read(const fd &, const mutable_buffers &, const read_opts & = read_opts_default);
|
|
|
|
size_t read(const string_view &path, const mutable_buffers &, const read_opts & = read_opts_default);
|
|
|
|
|
2018-01-10 21:30:31 -08:00
|
|
|
// Yields ircd::ctx for read into buffer; returns view of read portion.
|
2018-05-30 02:13:06 -07:00
|
|
|
const_buffer read(const fd &, const mutable_buffer &, const read_opts & = read_opts_default);
|
2018-04-24 18:34:46 -07:00
|
|
|
const_buffer read(const string_view &path, const mutable_buffer &, const read_opts & = read_opts_default);
|
2018-01-10 21:30:31 -08:00
|
|
|
|
|
|
|
// Yields ircd::ctx for read into allocated string; returns that string
|
2018-05-30 02:13:06 -07:00
|
|
|
std::string read(const fd &, const read_opts & = read_opts_default);
|
2018-01-10 21:30:31 -08:00
|
|
|
std::string read(const string_view &path, const read_opts & = read_opts_default);
|
2018-06-02 11:44:53 -07:00
|
|
|
|
2019-04-20 16:59:08 -07:00
|
|
|
// Test whether bytes in the specified range are cached and should not block
|
2019-04-21 03:57:12 -07:00
|
|
|
bool fincore(const fd &, const size_t &, const read_opts & = read_opts_default);
|
2019-04-20 16:59:08 -07:00
|
|
|
|
2019-05-03 03:33:45 -07:00
|
|
|
// Prefetch data for subsequent read(); offset given in opts (WILLNEED).
|
2019-03-15 21:25:07 -07:00
|
|
|
size_t prefetch(const fd &, const size_t &, const read_opts & = read_opts_default);
|
2019-05-03 04:34:16 -07:00
|
|
|
|
|
|
|
// Evict data which won't be read anymore (DONTNEED).
|
|
|
|
size_t evict(const fd &, const size_t &, const read_opts & = read_opts_default);
|
2018-01-10 21:30:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Options for a read operation
|
|
|
|
struct ircd::fs::read_opts
|
2018-12-29 20:02:22 -08:00
|
|
|
:opts
|
2018-01-10 21:30:31 -08:00
|
|
|
{
|
2018-12-18 13:41:45 -08:00
|
|
|
/// Yields the ircd::ctx until the buffers are full or EOF. This performs
|
|
|
|
/// the unix incremental read loop internally. When this option is true,
|
|
|
|
/// any return value from a function in the read suite will not be a
|
|
|
|
/// partial value requiring another invocation of read.
|
|
|
|
bool all {true};
|
2018-12-18 14:17:38 -08:00
|
|
|
|
|
|
|
/// Whether to propagate an EINTR; otherwise we reinvoke the syscall. For a
|
|
|
|
/// read(2) family call this can only happen before any data was read;
|
|
|
|
/// an exception will be thrown. We default to true because we have faith
|
|
|
|
/// in the useful propagation of an exception for this event.
|
|
|
|
bool interruptible {true};
|
2018-12-26 15:41:12 -08:00
|
|
|
|
2019-04-06 12:13:16 -07:00
|
|
|
read_opts(const off_t & = 0);
|
2018-01-10 21:30:31 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::fs::read_opts::read_opts(const off_t &offset)
|
2019-04-06 12:13:16 -07:00
|
|
|
:opts{offset, op::READ}
|
2018-01-10 21:30:31 -08:00
|
|
|
{}
|