The Pedigree Project 0.1
inotify-syscalls.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 */
8
9#ifndef INOTIFY_SYSCALLS_H
10#define INOTIFY_SYSCALLS_H
11
12#include "pedigree/kernel/compiler.h"
13#include "pedigree/kernel/process/Readiness.h"
14#include "pedigree/kernel/processor/types.h"
15
16class File;
17class InotifyState;
18
19namespace LinuxInotify {
20constexpr uint32_t Access = 0x00000001;
21constexpr uint32_t Modify = 0x00000002;
22constexpr uint32_t Attributes = 0x00000004;
23constexpr uint32_t CloseWrite = 0x00000008;
24constexpr uint32_t CloseNoWrite = 0x00000010;
25constexpr uint32_t Open = 0x00000020;
26constexpr uint32_t MovedFrom = 0x00000040;
27constexpr uint32_t MovedTo = 0x00000080;
28constexpr uint32_t Create = 0x00000100;
29constexpr uint32_t Delete = 0x00000200;
30constexpr uint32_t DeleteSelf = 0x00000400;
31constexpr uint32_t MoveSelf = 0x00000800;
32constexpr uint32_t AllEvents = 0x00000FFF;
33constexpr uint32_t Unmount = 0x00002000;
34constexpr uint32_t QueueOverflow = 0x00004000;
35constexpr uint32_t Ignored = 0x00008000;
36constexpr uint32_t OnlyDirectory = 0x01000000;
37constexpr uint32_t DontFollow = 0x02000000;
38constexpr uint32_t ExcludeUnlinked = 0x04000000;
39constexpr uint32_t MaskCreate = 0x10000000;
40constexpr uint32_t MaskAdd = 0x20000000;
41constexpr uint32_t IsDirectory = 0x40000000;
42constexpr uint32_t OneShot = 0x80000000;
43constexpr uint32_t AllBits = AllEvents | Unmount | QueueOverflow | Ignored | OnlyDirectory |
44 DontFollow | ExcludeUnlinked | MaskCreate | MaskAdd | IsDirectory |
45 OneShot;
46
47constexpr int NonBlock = 0x00000800;
48constexpr int CloseOnExec = 0x00080000;
49} // namespace LinuxInotify
50
52 int32_t wd;
53 uint32_t mask;
54 uint32_t cookie;
55 uint32_t len;
56};
57static_assert(sizeof(LinuxInotifyEvent) == 16,
58 "Linux x86-64 inotify_event header must be 16 bytes");
59
61class EXPORTED_PUBLIC InotifyInstance final : public ReadinessSource {
62 public:
64 ~InotifyInstance() override;
65
66 int addWatch(File* target, uint32_t mask);
67 int removeWatch(int wd);
68 int readEvents(uint8_t* buffer, size_t length, bool canBlock);
69 int readEventsToUser(uint8_t* buffer, size_t length, bool canBlock);
70
71 ReadyMask queryReady();
73
75 void eventsQueued();
76 void lastDescriptorClosed();
77
78 private:
79 InotifyInstance(const InotifyInstance&) = delete;
80 InotifyInstance& operator=(const InotifyInstance&) = delete;
81
82 void reapInactiveWatches();
83
84 InotifyState* m_State;
85};
86
87int posix_inotify_init();
88int posix_inotify_init1(int flags);
89int posix_inotify_add_watch(int fd, const char* pathname, uint32_t mask);
90int posix_inotify_rm_watch(int fd, int wd);
91
92#endif
Definition File.h:74
virtual ReadinessGenerations readinessGenerations()
Definition Readiness.cc:177