2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2020-03-08 14:33:14 +03:00
|
|
|
#include <AK/Memory.h>
|
2021-07-11 22:02:15 +03:00
|
|
|
#include <Kernel/Devices/FullDevice.h>
|
2021-06-22 18:40:16 +03:00
|
|
|
#include <Kernel/Sections.h>
|
2019-06-07 12:43:58 +03:00
|
|
|
#include <LibC/errno_numbers.h>
|
2018-10-14 14:16:09 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-18 11:37:26 +03:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<FullDevice> FullDevice::must_create()
|
|
|
|
{
|
2021-06-28 16:19:25 +03:00
|
|
|
return adopt_ref(*new FullDevice);
|
2021-06-18 11:37:26 +03:00
|
|
|
}
|
|
|
|
|
2021-02-19 20:41:50 +03:00
|
|
|
UNMAP_AFTER_INIT FullDevice::FullDevice()
|
2018-10-30 15:59:29 +03:00
|
|
|
: CharacterDevice(1, 7)
|
2018-10-14 14:16:09 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-19 20:41:50 +03:00
|
|
|
UNMAP_AFTER_INIT FullDevice::~FullDevice()
|
2018-10-14 14:16:09 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-10 12:44:42 +03:00
|
|
|
bool FullDevice::can_read(const FileDescription&, size_t) const
|
2018-10-25 14:07:59 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:18:51 +03:00
|
|
|
KResultOr<size_t> FullDevice::read(FileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
|
2018-10-14 14:16:09 +03:00
|
|
|
{
|
2021-05-27 10:13:49 +03:00
|
|
|
if (!buffer.memset(0, size))
|
2021-01-21 01:11:17 +03:00
|
|
|
return EFAULT;
|
2021-05-27 10:13:49 +03:00
|
|
|
return size;
|
2018-10-14 14:16:09 +03:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:18:51 +03:00
|
|
|
KResultOr<size_t> FullDevice::write(FileDescription&, u64, const UserOrKernelBuffer&, size_t size)
|
2018-10-14 14:16:09 +03:00
|
|
|
{
|
2019-02-25 23:19:57 +03:00
|
|
|
if (size == 0)
|
2018-10-14 14:16:09 +03:00
|
|
|
return 0;
|
2021-01-21 01:11:17 +03:00
|
|
|
return ENOSPC;
|
2018-10-14 14:16:09 +03:00
|
|
|
}
|
2020-02-16 03:27:42 +03:00
|
|
|
}
|