diff --git a/Drivers/include/fcntl.h b/Drivers/include/fcntl.h
new file mode 100644
index 00000000..587c4fda
--- /dev/null
+++ b/Drivers/include/fcntl.h
@@ -0,0 +1,109 @@
+/*
+ This file is part of Fennix Kernel.
+
+ Fennix Kernel is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of
+ the License, or (at your option) any later version.
+
+ Fennix Kernel is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Fennix Kernel. If not, see .
+*/
+
+#ifndef __FENNIX_API_FCNTL_H__
+#define __FENNIX_API_FCNTL_H__
+
+#ifdef __kernel__
+#include
+#endif
+
+/* cmd */
+#define F_DUPFD 0x1
+#define F_DUPFD_CLOEXEC 0x101
+#define F_DUPFD_CLOFORK 0x201
+#define F_GETFD 0x2
+#define F_SETFD 0x3
+#define F_GETFL 0x4
+#define F_SETFL 0x5
+#define F_GETLK 0x6
+#define F_SETLK 0x7
+#define F_SETLKW 0x8
+#define F_OFD_GETLK 0x9
+#define F_OFD_SETLK 0xA
+#define F_OFD_SETLKW 0xB
+#define F_GETOWN 0xC
+#define F_GETOWN_EX 0xD
+#define F_SETOWN 0xE
+#define F_SETOWN_EX 0xF
+
+#define FD_CLOEXEC 0x1
+#define FD_CLOFORK 0x2
+
+/* l_type */
+#define F_RDLCK 0x1
+#define F_UNLCK 0x2
+#define F_WRLCK 0x3
+
+/* type */
+#define F_OWNER_PID 0
+#define F_OWNER_PGRP 1
+
+/* oflag */
+#define O_CLOEXEC 02000000
+#define O_CLOFORK 04000000
+#define O_CREAT 0x8
+#define O_DIRECTORY 0200000
+#define O_EXCL 0x20
+#define O_NOCTTY 0x40
+#define O_NOFOLLOW 0400000
+#define O_TRUNC 0x400
+#define O_TTY_INIT 0x800
+
+#define O_APPEND 0x4
+#define O_DSYNC 0x10
+#define O_NONBLOCK 0x80
+#define O_RSYNC 0x100
+#define O_SYNC 0x200
+
+#define O_ACCMODE 0x3
+
+#define O_EXEC 0x4
+#define O_RDONLY 0x1
+#define O_RDWR 0x3
+#define O_SEARCH 0x10
+#define O_WRONLY 0x2
+
+#define AT_FDCWD
+#define AT_EACCESS
+#define AT_SYMLINK_NOFOLLOW
+#define AT_SYMLINK_FOLLOW
+#define AT_REMOVEDIR
+
+#define POSIX_FADV_DONTNEED
+#define POSIX_FADV_NOREUSE
+#define POSIX_FADV_NORMAL
+#define POSIX_FADV_RANDOM
+#define POSIX_FADV_SEQUENTIAL
+#define POSIX_FADV_WILLNEED
+
+typedef struct f_owner_ex
+{
+ int type; /* Discriminator for pid. */
+ pid_t pid; /* Process ID or process group ID. */
+} f_owner_ex;
+
+typedef struct flock
+{
+ short l_type; /* Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. */
+ short l_whence; /* Flag for starting offset. */
+ off_t l_start; /* Relative offset in bytes. */
+ off_t l_len; /* Size; if 0 then until EOF. */
+ pid_t l_pid; /* For a process-owned file lock, ignored on input or the process ID of the owning process on output; for an OFD-owned file lock, zero on input or (pid_t)-1 on output. */
+} flock;
+
+#endif // !__FENNIX_API_FCNTL_H__
diff --git a/Drivers/include/fs.h b/Drivers/include/fs.h
index 0a3f1905..3abe9a75 100644
--- a/Drivers/include/fs.h
+++ b/Drivers/include/fs.h
@@ -95,16 +95,6 @@
/** Other: X */
#define S_IXOTH 0001
-#define O_RDONLY 00
-#define O_WRONLY 01
-#define O_RDWR 02
-#define O_CREAT 0100
-#define O_EXCL 0200
-#define O_TRUNC 01000
-#define O_APPEND 02000
-#define O_NOFOLLOW 0400000
-#define O_CLOEXEC 02000000
-
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
diff --git a/Drivers/include/syscalls.h b/Drivers/include/syscalls.h
index df4dcd43..1d75bd71 100644
--- a/Drivers/include/syscalls.h
+++ b/Drivers/include/syscalls.h
@@ -18,6 +18,16 @@
#ifndef __FENNIX_API_SYSTEM_CALLS_LIST_H__
#define __FENNIX_API_SYSTEM_CALLS_LIST_H__
+#if __has_include()
+#include
+#else
+#include
+#endif
+
+#ifndef __fennix__
+#error "__fennix__ not defined"
+#endif
+
#pragma region Syscall Wrappers
#define scarg __UINTPTR_TYPE__
@@ -393,18 +403,18 @@ typedef enum
typedef enum
{
- __SYS_O_RDONLY = 0x1,
- __SYS_O_WRONLY = 0x2,
- __SYS_O_RDWR = 0x3,
- __SYS_O_APPEND = 0x4,
- __SYS_O_CREAT = 0x8,
- __SYS_O_DSYNC = 0x10,
- __SYS_O_EXCL = 0x20,
- __SYS_O_NOCTTY = 0x40,
- __SYS_O_NONBLOCK = 0x80,
- __SYS_O_RSYNC = 0x100,
- __SYS_O_SYNC = 0x200,
- __SYS_O_TRUNC = 0x400
+ __SYS_O_RDONLY = O_RDONLY,
+ __SYS_O_WRONLY = O_WRONLY,
+ __SYS_O_RDWR = O_RDWR,
+ __SYS_O_APPEND = O_APPEND,
+ __SYS_O_CREAT = O_CREAT,
+ __SYS_O_DSYNC = O_DSYNC,
+ __SYS_O_EXCL = O_EXCL,
+ __SYS_O_NOCTTY = O_NOCTTY,
+ __SYS_O_NONBLOCK = O_NONBLOCK,
+ __SYS_O_RSYNC = O_RSYNC,
+ __SYS_O_SYNC = O_SYNC,
+ __SYS_O_TRUNC = O_TRUNC
} syscall_open_flags_t;
typedef enum
@@ -820,6 +830,25 @@ typedef enum
* - #EINVAL if the request is invalid
*/
SYS_IOCTL,
+ /**
+ * @brief Function control
+ *
+ * @code
+ * int fcntl(int fd, int cmd, void *arg);
+ * @endcode
+ *
+ * @details Manipulates the underlying parameters of a device.
+ *
+ * @param fd File descriptor referring to the device
+ * @param cmd Device-specific request code
+ * @param arg Argument for the request
+ *
+ * @return
+ * - #EOK on success
+ * - #EBADF if `fd` is not valid
+ * - #EINVAL if the request is invalid
+ */
+ SYS_FCNTL,
/* File Status */
@@ -1668,6 +1697,9 @@ typedef enum
/** @copydoc SYS_IOCTL */
#define call_ioctl(fd, request, argp) syscall3(SYS_IOCTL, (scarg)fd, (scarg)request, (scarg)argp)
+/** @copydoc SYS_FCNTL */
+#define call_fcntl(fd, cmd, arg) syscall3(SYS_FCNTL, (scarg)fd, (scarg)cmd, (scarg)arg)
+
/* File Status */
/** @copydoc SYS_STAT */
diff --git a/Userspace/libc/abis/fennix/generic/bits/syscalls.h b/Userspace/libc/abis/fennix/generic/bits/syscalls.h
index 3c0fbcc4..1d75bd71 100644
--- a/Userspace/libc/abis/fennix/generic/bits/syscalls.h
+++ b/Userspace/libc/abis/fennix/generic/bits/syscalls.h
@@ -830,6 +830,25 @@ typedef enum
* - #EINVAL if the request is invalid
*/
SYS_IOCTL,
+ /**
+ * @brief Function control
+ *
+ * @code
+ * int fcntl(int fd, int cmd, void *arg);
+ * @endcode
+ *
+ * @details Manipulates the underlying parameters of a device.
+ *
+ * @param fd File descriptor referring to the device
+ * @param cmd Device-specific request code
+ * @param arg Argument for the request
+ *
+ * @return
+ * - #EOK on success
+ * - #EBADF if `fd` is not valid
+ * - #EINVAL if the request is invalid
+ */
+ SYS_FCNTL,
/* File Status */
@@ -1678,6 +1697,9 @@ typedef enum
/** @copydoc SYS_IOCTL */
#define call_ioctl(fd, request, argp) syscall3(SYS_IOCTL, (scarg)fd, (scarg)request, (scarg)argp)
+/** @copydoc SYS_FCNTL */
+#define call_fcntl(fd, cmd, arg) syscall3(SYS_FCNTL, (scarg)fd, (scarg)cmd, (scarg)arg)
+
/* File Status */
/** @copydoc SYS_STAT */