2#include "pedigree/kernel/process/TerminationDeferral.h"
3#include "pedigree/kernel/syscallError.h"
7#include "DevFs-block.h"
8#include "file-handle-syscalls.h"
10#include "swap-syscalls.h"
13int operate(
const char* path,
unsigned flags,
bool enable) {
15 if (!posix_effective_root()) {
16 SYSCALL_ERROR(NotEnoughPermissions);
19 if (flags & ~0x7ffffU) {
20 SYSCALL_ERROR(InvalidArgument);
24 SYSCALL_ERROR(OperationNotSupported);
30 if (!target.resolve(AT_FDCWD, path,
true,
false))
32 if (!target.file->isBlockDevice()) {
33 SYSCALL_ERROR(NotABlockDevice);
36 const uint64_t number = target.file->deviceNumber();
37 if (!PosixBlock::valid(number, PosixBlock::PhysicalMajor)) {
38 if (PosixBlock::valid(number, PosixBlock::MountedMajor))
39 SYSCALL_ERROR(DeviceBusy);
41 SYSCALL_ERROR(OperationNotSupported);
44 const uint32_t endpoint = PosixBlock::minor(number);
46 status = enable ? manager.activateSwap(endpoint) : manager.deactivateSwap(endpoint);
49 case SwapStatus::Success:
52 case SwapStatus::Unsupported:
53 SYSCALL_ERROR(OperationNotSupported);
55 case SwapStatus::Busy:
56 SYSCALL_ERROR(DeviceBusy);
58 case SwapStatus::NoMemory:
59 SYSCALL_ERROR(OutOfMemory);
61 case SwapStatus::IoError:
62 SYSCALL_ERROR(IoError);
65 SYSCALL_ERROR(InvalidArgument);
71int posix_swapon(
const char* path,
int flags) {
72 return operate(path,
static_cast<unsigned>(flags),
true);
74int posix_swapoff(
const char* path) {
75 return operate(path, 0,
false);
Memory-mapped file interface.
static MemoryMapManager & instance()