2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
2018-01-11 06:30:31 +01:00
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2018-02-04 03:22:01 +01:00
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
2018-01-11 06:30:31 +01: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-04 03:22:01 +01: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-11 06:30:31 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_FS_READ_H
|
|
|
|
|
|
|
|
namespace ircd::fs
|
|
|
|
{
|
|
|
|
struct read_opts extern const read_opts_default;
|
|
|
|
|
|
|
|
// Yields ircd::ctx for read into buffer; returns view of read portion.
|
2018-05-30 11:13:06 +02:00
|
|
|
const_buffer read(const fd &, const mutable_buffer &, const read_opts & = read_opts_default);
|
2018-04-25 03:34:46 +02:00
|
|
|
const_buffer read(const string_view &path, const mutable_buffer &, const read_opts & = read_opts_default);
|
2018-01-11 06:30:31 +01:00
|
|
|
|
|
|
|
// Yields ircd::ctx for read into allocated string; returns that string
|
2018-05-30 11:13:06 +02:00
|
|
|
std::string read(const fd &, const read_opts & = read_opts_default);
|
2018-01-11 06:30:31 +01:00
|
|
|
std::string read(const string_view &path, const read_opts & = read_opts_default);
|
2018-06-02 20:44:53 +02:00
|
|
|
|
|
|
|
// Prefetch bytes for subsequent read(); offset is given in opts.
|
|
|
|
void prefetch(const fd &, const size_t &, const read_opts & = read_opts_default);
|
2018-01-11 06:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Options for a read operation
|
|
|
|
struct ircd::fs::read_opts
|
|
|
|
{
|
|
|
|
read_opts() = default;
|
|
|
|
read_opts(const off_t &);
|
|
|
|
|
|
|
|
/// Offset in the file to start the read from.
|
|
|
|
off_t offset {0};
|
|
|
|
|
|
|
|
/// Request priority (this option may be improved, avoid for now)
|
|
|
|
int16_t priority {0};
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::fs::read_opts::read_opts(const off_t &offset)
|
|
|
|
:offset{offset}
|
|
|
|
{}
|