2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-14 00:59:22 +00:00
|
|
|
#include "NullDevice.h"
|
2020-08-25 01:35:19 +00:00
|
|
|
#include <AK/Singleton.h>
|
2018-12-03 23:27:16 +00:00
|
|
|
#include <AK/StdLibExtras.h>
|
2018-10-14 00:59:22 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-08-25 01:35:19 +00:00
|
|
|
static AK::Singleton<NullDevice> s_the;
|
|
|
|
|
2021-02-19 23:00:19 +00:00
|
|
|
UNMAP_AFTER_INIT void NullDevice::initialize()
|
2020-08-25 01:35:19 +00:00
|
|
|
{
|
|
|
|
s_the.ensure_instance();
|
|
|
|
}
|
2019-02-12 10:25:25 +00:00
|
|
|
|
|
|
|
NullDevice& NullDevice::the()
|
|
|
|
{
|
|
|
|
return *s_the;
|
|
|
|
}
|
|
|
|
|
2021-02-19 17:41:50 +00:00
|
|
|
UNMAP_AFTER_INIT NullDevice::NullDevice()
|
2018-10-30 12:59:29 +00:00
|
|
|
: CharacterDevice(1, 3)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-19 17:41:50 +00:00
|
|
|
UNMAP_AFTER_INIT NullDevice::~NullDevice()
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-10 09:44:42 +00:00
|
|
|
bool NullDevice::can_read(const FileDescription&, size_t) const
|
2018-10-25 11:07:59 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-17 12:18:51 +00:00
|
|
|
KResultOr<size_t> NullDevice::read(FileDescription&, u64, UserOrKernelBuffer&, size_t)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-17 12:18:51 +00:00
|
|
|
KResultOr<size_t> NullDevice::write(FileDescription&, u64, const UserOrKernelBuffer&, size_t buffer_size)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
2020-08-04 16:02:23 +00:00
|
|
|
return min(static_cast<size_t>(PAGE_SIZE), buffer_size);
|
2018-10-14 00:59:22 +00:00
|
|
|
}
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|