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
|
|
|
*/
|
|
|
|
|
2020-08-25 01:35:19 +00:00
|
|
|
#include <AK/Singleton.h>
|
2021-09-11 06:19:20 +00:00
|
|
|
#include <Kernel/Devices/DeviceManagement.h>
|
2021-06-22 15:40:16 +00:00
|
|
|
#include <Kernel/Devices/NullDevice.h>
|
|
|
|
#include <Kernel/Sections.h>
|
2018-10-14 00:59:22 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-09-11 06:19:20 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<NullDevice> NullDevice::must_initialize()
|
2019-02-12 10:25:25 +00:00
|
|
|
{
|
2021-09-11 06:19:20 +00:00
|
|
|
auto null_device_or_error = DeviceManagement::try_create_device<NullDevice>();
|
|
|
|
// FIXME: Find a way to propagate errors
|
|
|
|
VERIFY(!null_device_or_error.is_error());
|
|
|
|
return null_device_or_error.release_value();
|
2019-02-12 10:25:25 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:39:11 +00:00
|
|
|
bool NullDevice::can_read(const OpenFileDescription&, size_t) const
|
2018-10-25 11:07:59 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<size_t> NullDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<size_t> NullDevice::write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t buffer_size)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
2021-05-27 07:13:49 +00:00
|
|
|
return buffer_size;
|
2018-10-14 00:59:22 +00:00
|
|
|
}
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|