0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 14:38:57 +02:00
construct/ircd/fs_dev.cc
2020-06-07 01:51:19 -07:00

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)
};
}