blob: a01552c7e25ef1bbf93b9ab24dfcb051a1312301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/Devices/SelfTTYDevice.h>
#include <Kernel/Sections.h>
#include <Kernel/TTY/TTY.h>
namespace Kernel {
UNMAP_AFTER_INIT NonnullLockRefPtr<SelfTTYDevice> SelfTTYDevice::must_create()
{
auto self_tty_device_or_error = DeviceManagement::try_create_device<SelfTTYDevice>();
// FIXME: Find a way to propagate errors
VERIFY(!self_tty_device_or_error.is_error());
return self_tty_device_or_error.release_value();
}
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
{
// Note: If for some odd reason we try to open this device (early on boot?)
// while there's no current Process assigned, don't fail and return an error.
if (!Process::has_current())
return Error::from_errno(ESRCH);
auto& current_process = Process::current();
LockRefPtr<TTY> tty = current_process.tty();
if (!tty)
return Error::from_errno(ENXIO);
auto description = TRY(OpenFileDescription::try_create(*tty));
description->set_rw_mode(options);
description->set_file_flags(options);
return description;
}
bool SelfTTYDevice::can_read(OpenFileDescription const&, u64) const
{
VERIFY_NOT_REACHED();
}
bool SelfTTYDevice::can_write(OpenFileDescription const&, u64) const
{
VERIFY_NOT_REACHED();
}
ErrorOr<size_t> SelfTTYDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
{
VERIFY_NOT_REACHED();
}
ErrorOr<size_t> SelfTTYDevice::write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t)
{
VERIFY_NOT_REACHED();
}
UNMAP_AFTER_INIT SelfTTYDevice::SelfTTYDevice()
: CharacterDevice(5, 0)
{
}
UNMAP_AFTER_INIT SelfTTYDevice::~SelfTTYDevice()
{
}
}
|