mirror of
https://github.com/matrix-construct/construct
synced 2024-06-10 05:58:56 +02:00
ircd::fs: Split fs::dev definitions into unit.
This commit is contained in:
parent
9ee4afd560
commit
4d98f8fa8d
|
@ -156,6 +156,7 @@ libircd_la_SOURCES += prof_linux.cc
|
|||
endif
|
||||
libircd_la_SOURCES += fs.cc
|
||||
libircd_la_SOURCES += fs_path.cc
|
||||
libircd_la_SOURCES += fs_dev.cc
|
||||
libircd_la_SOURCES += ios.cc
|
||||
libircd_la_SOURCES += ctx_x86_64.S
|
||||
libircd_la_SOURCES += ctx.cc
|
||||
|
|
68
ircd/fs.cc
68
ircd/fs.cc
|
@ -13,7 +13,6 @@
|
|||
#include <RB_INC_SYS_STATFS_H
|
||||
#include <RB_INC_SYS_STATVFS_H
|
||||
#include <RB_INC_SYS_RESOURCE_H
|
||||
#include <RB_INC_SYS_SYSMACROS_H
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#ifdef IRCD_USE_AIO
|
||||
|
@ -2147,73 +2146,6 @@ ircd::fs::flags(const std::ios::openmode &mode)
|
|||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// fs/device.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)
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// fs/opts.h
|
||||
|
|
73
ircd/fs_dev.cc
Normal file
73
ircd/fs_dev.cc
Normal file
|
@ -0,0 +1,73 @@
|
|||
// 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)
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue