blob: 67f52e93abca84b56424541c6a23a5a8c3ef54f0 (
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
|
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
#include <Kernel/Process.h>
#include <Kernel/Sections.h>
namespace Kernel {
ErrorOr<void> SysFSSystemBooleanVariable::try_generate(KBufferBuilder& builder)
{
return builder.appendff("{}\n", static_cast<int>(value()));
}
ErrorOr<size_t> SysFSSystemBooleanVariable::write_bytes(off_t, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*)
{
MutexLocker locker(m_refresh_lock);
// Note: We do all of this code before taking the spinlock because then we disable
// interrupts so page faults will not work.
char value = 0;
TRY(buffer.read(&value, 1));
// NOTE: If we are in a jail, don't let the current process to change the variable.
if (Process::current().is_currently_in_jail())
return Error::from_errno(EPERM);
if (count != 1)
return Error::from_errno(EINVAL);
if (value == '0') {
set_value(false);
return 1;
} else if (value == '1') {
set_value(true);
return 1;
}
return Error::from_errno(EINVAL);
}
ErrorOr<void> SysFSSystemBooleanVariable::truncate(u64 size)
{
if (size != 0)
return EPERM;
return {};
}
}
|