1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2026-01-15 10:10:59 +00:00
serenity/Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/StringVariable.cpp
Liav A 751aae77bc Kernel: Rename /sys/kernel/variables => /sys/kernel/conf
The name "variables" is a bit awkward and what the directory entries are
really about is kernel configuration so let's make it clear with the new
name.
2023-08-27 22:50:22 +02:00

42 lines
1.4 KiB
C++

/*
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/StringVariable.h>
#include <Kernel/Sections.h>
#include <Kernel/Tasks/Process.h>
namespace Kernel {
ErrorOr<void> SysFSSystemStringVariable::try_generate(KBufferBuilder& builder)
{
auto string_value = TRY(value());
return builder.appendff("{}\n", string_value->view());
}
ErrorOr<size_t> SysFSSystemStringVariable::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 = nullptr;
auto new_value = TRY(KString::try_create_uninitialized(count, value));
TRY(buffer.read(value, count));
auto new_value_without_possible_newlines = TRY(KString::try_create(new_value->view().trim("\n"sv)));
// 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);
set_value(move(new_value_without_possible_newlines));
return count;
}
ErrorOr<void> SysFSSystemStringVariable::truncate(u64 size)
{
if (size != 0)
return EPERM;
return {};
}
}