mirror of
https://github.com/matrix-construct/construct
synced 2024-11-19 00:10:59 +01:00
74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
|
// 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.
|
||
|
|
||
|
#include <RB_INC_SYS_SYSMACROS_H
|
||
|
|
||
|
#ifdef __linux__
|
||
|
ircd::string_view
|
||
|
ircd::fs::dev::sysfs(const mutable_buffer &out,
|
||
|
const ulong &id,
|
||
|
const string_view &relpath)
|
||
|
{
|
||
|
const string_view path{fmt::sprintf
|
||
|
{
|
||
|
path_scratch, "/sys/dev/block/%s/%s",
|
||
|
sysfs_id(name_scratch, id),
|
||
|
relpath
|
||
|
}};
|
||
|
|
||
|
fs::read_opts opts;
|
||
|
opts.aio = false;
|
||
|
return fs::read(path, out, opts);
|
||
|
}
|
||
|
#else
|
||
|
ircd::string_view
|
||
|
ircd::fs::dev::sysfs(const mutable_buffer &out,
|
||
|
const ulong &id,
|
||
|
const string_view &relpath)
|
||
|
{
|
||
|
throw panic
|
||
|
{
|
||
|
"sysfs(5) is not available."
|
||
|
};
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
ircd::string_view
|
||
|
ircd::fs::dev::sysfs_id(const mutable_buffer &out,
|
||
|
const ulong &id)
|
||
|
{
|
||
|
return sysfs_id(out, dev::id(id));
|
||
|
}
|
||
|
|
||
|
ircd::string_view
|
||
|
ircd::fs::dev::sysfs_id(const mutable_buffer &out,
|
||
|
const major_minor &id)
|
||
|
{
|
||
|
return fmt::sprintf
|
||
|
{
|
||
|
out, "%lu:%lu", id.first, id.second
|
||
|
};
|
||
|
}
|
||
|
|
||
|
ulong
|
||
|
ircd::fs::dev::id(const major_minor &id)
|
||
|
{
|
||
|
return makedev(id.first, id.second);
|
||
|
}
|
||
|
|
||
|
ircd::fs::dev::major_minor
|
||
|
ircd::fs::dev::id(const ulong &id)
|
||
|
{
|
||
|
return
|
||
|
{
|
||
|
major(id), minor(id)
|
||
|
};
|
||
|
}
|