The Pedigree Project 0.1
global-sync-syscalls.cc
1/* Copyright (c) 2026, Pedigree Developers. */
2#include "global-sync-syscalls.h"
3#include "pedigree/kernel/process/Process.h"
4#include "pedigree/kernel/process/TerminationDeferral.h"
5#include "pedigree/kernel/process/Thread.h"
6#include "pedigree/kernel/processor/Processor.h"
7#include "pedigree/kernel/processor/ProcessorInformation.h"
8#include "pedigree/kernel/syscallError.h"
9
10#include <fcntl.h>
11
12#include "FileDescriptor.h"
13#include "PosixSubsystem.h"
14#include "modules/system/vfs/File.h"
15#include "modules/system/vfs/VFS.h"
16
17int posix_syncfs(int fd) {
18 int error = 0;
19 {
20 TerminationDeferral lifetime;
21 DescriptorLease descriptor;
22 auto* process = Processor::information().getCurrentThread()->getParent();
23 auto* subsystem = static_cast<PosixSubsystem*>(process->getSubsystem());
24 if (!subsystem || !subsystem->acquireFileDescriptor(fd, descriptor) ||
25 (descriptor->getStatusFlags() & O_PATH)) {
26 error = Error::BadFileDescriptor;
27 } else {
28 File* file = descriptor->getFile();
29 const auto status = file && file->getFilesystem()
30 ? VFS::instance().syncFilesystem(file->getFilesystem())
31 : Filesystem::SyncStatus::Unsupported;
32 switch (status) {
33 case Filesystem::SyncStatus::Success:
34 break;
35 case Filesystem::SyncStatus::Unsupported:
36 error = Error::OperationNotSupported;
37 break;
38 case Filesystem::SyncStatus::NoMemory:
39 error = Error::OutOfMemory;
40 break;
41 case Filesystem::SyncStatus::IoError:
42 error = Error::IoError;
43 break;
44 }
45 }
46 }
47 // Final descriptor release may run backend callbacks; publish the selected
48 // result only after those callbacks and filesystem pin retirement finish.
49 syscallError(error);
50 return error ? -1 : 0;
51}
52
53int posix_sync() {
54 {
55 TerminationDeferral lifetime;
56 // syncAll logs each backend failure and still attempts the remaining mounts.
57 const auto status = VFS::instance().syncAll();
58 (void)status;
59 }
60 syscallError(0);
61 return 0;
62}
int getStatusFlags() const
Get current status flags.
Definition File.h:75
Process * getParent()
Definition Process.h:620
static ProcessorInformation & information()
Filesystem::SyncStatus syncFilesystem(Filesystem *key)
Definition VFS.cc:918
Filesystem::SyncStatus syncAll()
Definition VFS.cc:939
static VFS & instance()
Definition VFS.cc:311