Update MentOs code to the latest development version.

This commit is contained in:
Enrico Fraccaroli
2021-10-04 11:44:02 +02:00
parent 6fd063984a
commit b01eccca2e
484 changed files with 42358 additions and 20285 deletions
+41
View File
@@ -0,0 +1,41 @@
/// MentOS, The Mentoring Operating system project
/// @file bitops.h
/// @brief Bitmasks functions.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#define bit_set(V, B) ((V) | (1U << (B))) ///< Sets the given bit.
#define bit_clear(V, B) ((V) & ~(1U << (B))) ///< Clears the given bit.
#define bit_flip(V, B) ((V) ^ (1U << (B))) ///< Flips the given bit.
#define bit_set_assign(V, B) ((V) |= (1U << (B))) ///< Sets the given bit, permanently.
#define bit_clear_assign(V, B) ((V) &= ~(1U << (B))) ///< Clears the given bit, permanently.
#define bit_flip_assign(V, B) ((V) ^= (1U << (B))) ///< Flips the given bit, permanently.
#define bit_check(V, B) ((V) & (1U << (B))) ///< Checks if the given bit is 1.
#define bitmask_set(V, M) ((V) | (M)) ///< Sets the bits identified by the mask.
#define bitmask_clear(V, M) ((V) & ~(M)) ///< Clears the bits identified by the mask.
#define bitmask_flip(V, M) ((V) ^ (M)) ///< Flips the bits identified by the mask.
#define bitmask_set_assign(V, M) ((V) |= (M)) ///< Sets the bits identified by the mask, permanently.
#define bitmask_clear_assign(V, M) ((V) &= ~(M)) ///< Clears the bits identified by the mask, permanently.
#define bitmask_flip_assign(V, M) ((V) ^= (M)) ///< Flips the bits identified by the mask, permanently.
#define bitmask_check(V, M) ((V) & (M)) ///< Checks if the bits identified by the mask are all 1.
/// @brief Finds the first bit at zero, starting from the less significative bit.
static inline int find_first_zero(unsigned long value)
{
for (int i = 0; i < 32; ++i)
if (!bit_check(value, i))
return i;
return 0;
}
/// @brief Finds the first bit not zero, starting from the less significative bit.
static inline int find_first_non_zero(unsigned long value)
{
for (int i = 0; i < 32; ++i)
if (bit_check(value, i))
return i;
return 0;
}
+50
View File
@@ -0,0 +1,50 @@
/// MentOS, The Mentoring Operating system project
/// @file dirent.h
/// @brief Functions used to manage directories.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#include "limits.h"
#include "stddef.h"
/// File types for `d_type'.
enum {
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14
};
static const char dt_char_array[] = {
'?', // DT_UNKNOWN = 0,
'p', //DT_FIFO = 1,
'c', //DT_CHR = 2,
'*',
'd', //DT_DIR = 4,
'*',
'b', //DT_BLK = 6,
'*',
'-', //DT_REG = 8,
'*',
'l', //DT_LNK = 10,
'*',
's', //DT_SOCK = 12,
'*',
'?', //DT_WHT = 14
};
/// Directory entry.
typedef struct dirent_t {
ino_t d_ino; ///< Inode number.
off_t d_off; ///< Offset to next linux_dirent.
unsigned short d_reclen; ///< Length of this linux_dirent.
unsigned short d_type; ///< type of the directory entry.
char d_name[NAME_MAX]; ///< Filename (null-terminated)
} dirent_t;
+138
View File
@@ -0,0 +1,138 @@
/// MentOS, The Mentoring Operating system project
/// @file errno.h
/// @brief System call errors definition.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
extern int *__geterrno();
/// Provide easy access to the error number.
#define errno (*__geterrno())
#define EPERM 1 ///< Operation not permitted.
#define ENOENT 2 ///< No such file or directory.
#define ESRCH 3 ///< No such process.
#define EINTR 4 ///< Interrupted system call.
#define EIO 5 ///< I/O error.
#define ENXIO 6 ///< No such device or address.
#define E2BIG 7 ///< Arg list too long.
#define ENOEXEC 8 ///< Exec format error.
#define EBADF 9 ///< Bad file number.
#define ECHILD 10 ///< No child processes.
#define EAGAIN 11 ///< Try again.
#define ENOMEM 12 ///< Out of memory.
#define EACCES 13 ///< Permission denied.
#define EFAULT 14 ///< Bad address.
#define ENOTBLK 15 ///< Block device required.
#define EBUSY 16 ///< Device or resource busy.
#define EEXIST 17 ///< File exists.
#define EXDEV 18 ///< Cross-device link.
#define ENODEV 19 ///< No such device.
#define ENOTDIR 20 ///< Not a directory.
#define EISDIR 21 ///< Is a directory.
#define EINVAL 22 ///< Invalid argument.
#define ENFILE 23 ///< File table overflow.
#define EMFILE 24 ///< Too many open files.
#define ENOTTY 25 ///< Not a typewriter.
#define ETXTBSY 26 ///< Text file busy.
#define EFBIG 27 ///< File too large.
#define ENOSPC 28 ///< No space left on device.
#define ESPIPE 29 ///< Illegal seek.
#define EROFS 30 ///< Read-only file system.
#define EMLINK 31 ///< Too many links.
#define EPIPE 32 ///< Broken pipe.
#define EDOM 33 ///< Math argument out of domain of func.
#define ERANGE 34 ///< Math result not representable.
#define EDEADLK 35 ///< Resource deadlock would occur.
#define ENAMETOOLONG 36 ///< File name too long.
#define ENOLCK 37 ///< No record locks available.
#define ENOSYS 38 ///< Function not implemented.
#define ENOTEMPTY 39 ///< Directory not empty.
#define ELOOP 40 ///< Too many symbolic links encountered.
#define EWOULDBLOCK EAGAIN ///< Operation would block.
#define ENOMSG 42 ///< No message of desired type.
#define EIDRM 43 ///< Identifier removed.
#define ECHRNG 44 ///< Channel number out of range.
#define EL2NSYNC 45 ///< Level 2 not synchronized.
#define EL3HLT 46 ///< Level 3 halted.
#define EL3RST 47 ///< Level 3 reset.
#define ELNRNG 48 ///< Link number out of range.
#define EUNATCH 49 ///< Protocol driver not attached.
#define ENOCSI 50 ///< No CSI structure available.
#define EL2HLT 51 ///< Level 2 halted.
#define EBADE 52 ///< Invalid exchange.
#define EBADR 53 ///< Invalid request descriptor.
#define EXFULL 54 ///< Exchange full.
#define ENOANO 55 ///< No anode.
#define EBADRQC 56 ///< Invalid request code.
#define EBADSLT 57 ///< Invalid slot.
#define EDEADLOCK EDEADLK ///< Resource deadlock would occur.
#define EBFONT 59 ///< Bad font file format.
#define ENOSTR 60 ///< Device not a stream.
#define ENODATA 61 ///< No data available.
#define ETIME 62 ///< Timer expired.
#define ENOSR 63 ///< Out of streams resources.
#define ENONET 64 ///< Machine is not on the network.
#define ENOPKG 65 ///< Package not installed.
#define EREMOTE 66 ///< Object is remote.
#define ENOLINK 67 ///< Link has been severed.
#define EADV 68 ///< Advertise error.
#define ESRMNT 69 ///< Srmount error.
#define ECOMM 70 ///< Communication error on send.
#define EPROTO 71 ///< Protocol error.
#define EMULTIHOP 72 ///< Multihop attempted.
#define EDOTDOT 73 ///< RFS specific error.
#define EBADMSG 74 ///< Not a data message.
#define EOVERFLOW 75 ///< Value too large for defined data type.
#define ENOTUNIQ 76 ///< Name not unique on network.
#define EBADFD 77 ///< File descriptor in bad state.
#define EREMCHG 78 ///< Remote address changed.
#define ELIBACC 79 ///< Can not access a needed shared library.
#define ELIBBAD 80 ///< Accessing a corrupted shared library.
#define ELIBSCN 81 ///< .lib section in a.out corrupted.
#define ELIBMAX 82 ///< Attempting to link in too many shared libraries.
#define ELIBEXEC 83 ///< Cannot exec a shared library directly.
#define EILSEQ 84 ///< Illegal byte sequence.
#define ERESTART 85 ///< Interrupted system call should be restarted.
#define ESTRPIPE 86 ///< Streams pipe error.
#define EUSERS 87 ///< Too many users.
#define ENOTSOCK 88 ///< Socket operation on non-socket.
#define EDESTADDRREQ 89 ///< Destination address required.
#define EMSGSIZE 90 ///< Message too long.
#define EPROTOTYPE 91 ///< Protocol wrong type for socket.
#define ENOPROTOOPT 92 ///< Protocol not available.
#define EPROTONOSUPPORT 93 ///< Protocol not supported.
#define ESOCKTNOSUPPORT 94 ///< Socket type not supported.
#define EOPNOTSUPP 95 ///< Operation not supported on transport endpoint.
#define EPFNOSUPPORT 96 ///< Protocol family not supported.
#define EAFNOSUPPORT 97 ///< Address family not supported by protocol.
#define EADDRINUSE 98 ///< Address already in use.
#define EADDRNOTAVAIL 99 ///< Cannot assign requested address.
#define ENETDOWN 100 ///< Network is down.
#define ENETUNREACH 101 ///< Network is unreachable.
#define ENETRESET 102 ///< Network dropped connection because of reset.
#define ECONNABORTED 103 ///< Software caused connection abort.
#define ECONNRESET 104 ///< Connection reset by peer.
#define ENOBUFS 105 ///< No buffer space available.
#define EISCONN 106 ///< Transport endpoint is already connected.
#define ENOTCONN 107 ///< Transport endpoint is not connected.
#define ESHUTDOWN 108 ///< Cannot send after transport endpoint shutdown.
#define ETOOMANYREFS 109 ///< Too many references: cannot splice.
#define ETIMEDOUT 110 ///< Connection timed out.
#define ECONNREFUSED 111 ///< Connection refused.
#define EHOSTDOWN 112 ///< Host is down.
#define EHOSTUNREACH 113 ///< No route to host.
#define EALREADY 114 ///< Operation already in progress.
#define EINPROGRESS 115 ///< Operation now in progress.
#define ESTALE 116 ///< Stale NFS file handle.
#define EUCLEAN 117 ///< Structure needs cleaning.
#define ENOTNAM 118 ///< Not a XENIX named type file.
#define ENAVAIL 119 ///< No XENIX semaphores available.
#define EISNAM 120 ///< Is a named type file.
#define EREMOTEIO 121 ///< Remote I/O error.
#define EDQUOT 122 ///< Quota exceeded.
#define ENOMEDIUM 123 ///< No medium found.
#define EMEDIUMTYPE 124 ///< Wrong medium type.
#define ENOTSCHEDULABLE 125 ///< The periodc process cannot be scheduled.
+15
View File
@@ -0,0 +1,15 @@
/// MentOS, The Mentoring Operating system project
/// @file ioctl.h
/// @brief Input/Output ConTroL (IOCTL) functions.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
/// @brief Perform the I/O control operation specified by REQUEST on FD.
/// One argument may follow; its presence and type depend on REQUEST.
/// @param fd Must be an open file descriptor.
/// @param request The device-dependent request code
/// @param data An untyped pointer to memory.
/// @return Return value depends on REQUEST. Usually -1 indicates error.
int ioctl(int fd, unsigned long int request, void *data);
+36
View File
@@ -0,0 +1,36 @@
/// MentOS, The Mentoring Operating system project
/// @file reboot.h
/// @brief Defines the values required to issue a reboot.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
/// Magic values required to use _reboot() system call.
#define LINUX_REBOOT_MAGIC1 0xfee1dead
/// Magic values required to use _reboot() system call.
#define LINUX_REBOOT_MAGIC2 672274793
/// Magic values required to use _reboot() system call.
#define LINUX_REBOOT_MAGIC2A 85072278
/// Magic values required to use _reboot() system call.
#define LINUX_REBOOT_MAGIC2B 369367448
/// Magic values required to use _reboot() system call.
#define LINUX_REBOOT_MAGIC2C 537993216
// Commands accepted by the _reboot() system call.
/// Restart system using default command and mode.
#define LINUX_REBOOT_CMD_RESTART 0x01234567
/// Stop OS and give system control to ROM monitor, if any.
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
/// Ctrl-Alt-Del sequence causes RESTART command.
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
/// Ctrl-Alt-Del sequence sends SIGINT to init task.
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
/// Stop OS and remove all power from system, if possible.
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
/// Restart system using given command string.
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
/// Suspend system using software suspend if compiled in.
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
/// Restart system using a previously loaded Linux kernel
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
+35
View File
@@ -0,0 +1,35 @@
/// MentOS, The Mentoring Operating system project
/// @file stat.h
/// @brief Stat functions.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#define __SYS_STAT_H
#include "bits/stat.h"
#include "stddef.h"
#include "time.h"
/// @brief Retrieves information about the file at the given location.
/// @param path The path to the file that is being inquired.
/// @param buf A structure where data about the file will be stored.
/// @return Returns a negative value on failure.
int stat(const char *path, stat_t *buf);
/// @brief Retrieves information about the file at the given location.
/// @param fd The file descriptor of the file that is being inquired.
/// @param buf A structure where data about the file will be stored.
/// @return Returns a negative value on failure.
int fstat(int fd, stat_t *buf);
/// @brief Creates a new directory at the given path.
/// @param path The path of the new directory.
/// @param mode The permission of the new directory.
/// @return Returns a negative value on failure.
int mkdir(const char *path, mode_t mode);
/// @brief Removes the given directory.
/// @param path The path to the directory to remove.
/// @return Returns a negative value on failure.
int rmdir(const char *path);
+70
View File
@@ -0,0 +1,70 @@
/// MentOS, The Mentoring Operating system project
/// @file types.h
/// @brief Collection of Kernel datatype
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
/// The type of process id.
typedef signed int pid_t;
/// The type of process user variable.
typedef unsigned int user_t;
/// The type of process status.
typedef unsigned int status_t;
/// Type for system keys.
typedef int key_t;
/// Defines the list of flags of a process.
typedef enum eflags_list {
/// Carry flag.
EFLAG_CF = (1 << 0),
/// Parity flag.
EFLAG_PF = (1 << 2),
/// Auxiliary carry flag.
EFLAG_AF = (1 << 4),
/// Zero flag.
EFLAG_ZF = (1 << 6),
/// Sign flag.
EFLAG_SF = (1 << 7),
/// Trap flag.
EFLAG_TF = (1 << 8),
/// Interrupt enable flag.
EFLAG_IF = (1 << 9),
/// Direction flag.
EFLAG_DF = (1 << 10),
/// Overflow flag.
EFLAG_OF = (1 << 11),
/// Nested task flag.
EFLAG_NT = (1 << 14),
/// Resume flag.
EFLAG_RF = (1 << 16),
/// Virtual 8086 mode flag.
EFLAG_VM = (1 << 17),
/// Alignment check flag (486+).
EFLAG_AC = (1 << 18),
/// Virutal interrupt flag.
EFLAG_VIF = (1 << 19),
/// Virtual interrupt pending flag.
EFLAG_VIP = (1 << 20),
/// ID flag.
EFLAG_ID = (1 << 21),
} eflags_list;
+223
View File
@@ -0,0 +1,223 @@
/// MentOS, The Mentoring Operating system project
/// @file unistd.h
/// @brief Functions used to manage files.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#include "sys/types.h"
#include "sys/dirent.h"
#include "stddef.h"
#define STDIN_FILENO 0 ///< Standard input.
#define STDOUT_FILENO 1 ///< Standard output.
#define STDERR_FILENO 2 ///< Standard error output.
/// @brief Read data from a file descriptor.
/// @param fd The file descriptor.
/// @param buf The buffer.
/// @param nbytes The number of bytes to read.
/// @return The number of read characters.
ssize_t read(int fd, void *buf, size_t nbytes);
/// @brief Write data into a file descriptor.
/// @param fd The file descriptor.
/// @param buf The buffer collecting data to written.
/// @param nbytes The number of bytes to write.
/// @return The number of written bytes.
ssize_t write(int fd, void *buf, size_t nbytes);
/// @brief Opens the file specified by pathname.
/// @param pathname A pathname for a file.
/// @param flags Used to set the file status flags and file access modes
/// of the open file description.
/// @param mode Specifies the file mode bits be applied when a new file
/// is created.
/// @return Returns a file descriptor, a small, nonnegative integer for
/// use in subsequent system calls.
int open(const char *pathname, int flags, mode_t mode);
/// @brief Close a file descriptor.
/// @param fd The file descriptor.
/// @return The result of the operation.
int close(int fd);
/// @brief Repositions the file offset inside a file.
/// @param fd The file descriptor of the file.
/// @param offset The offest to use for the operation.
/// @param whence The type of operation.
/// @return Upon successful completion, returns the resulting offset
/// location as measured in bytes from the beginning of the file. On
/// error, the value (off_t) -1 is returned and errno is set to
/// indicate the error.
off_t lseek(int fd, off_t offset, int whence);
/// @brief Delete a name and possibly the file it refers to.
/// @param path The path to the file.
/// @return
int unlink(const char *path);
/// @brief Wrapper for exit system call.
/// @param status The exit status.
extern void exit(int status);
/// @brief Returns the process ID (PID) of the calling process.
/// @return pid_t process identifier.
extern pid_t getpid();
///@brief Return session id of the given process.
/// If pid == 0 return the SID of the calling process
/// If pid != 0 return the SID corresponding to the process having identifier == pid
///@param pid process identifier from wich we want the SID
///@return On success return SID of the session
/// Otherwise return -1 with errno set on: EPERM or ESRCH
extern pid_t getsid(pid_t pid);
///@brief creates a new session if the calling process is not a
/// process group leader. The calling process is the leader of the
/// new session (i.e., its session ID is made the same as its process
/// ID). The calling process also becomes the process group leader
/// of a new process group in the session (i.e., its process group ID
/// is made the same as its process ID).
///@return On success return SID of the session just created
/// Otherwise return -1 with errno : EPERM
extern pid_t setsid();
///@brief returns the group ID of the calling process.
///@return GID of the current process
extern pid_t getgid();
///@brief sets the effective group ID of the calling process.
///@param pid process identifier to
///@return On success, zero is returned.
/// Otherwise returns -1 with errno set to :EINVAL or EPERM
extern int setgid(pid_t pid);
/// @brief Returns the parent process ID (PPID) of the calling process.
/// @return pid_t parent process identifier.
extern pid_t getppid();
/// @brief Clone the calling process, but without copying the whole address space.
/// The calling process is suspended until the new process exits or is
/// replaced by a call to `execve'.
/// @return Return -1 for errors, 0 to the new process, and the process ID of
/// the new process to the old process.
extern pid_t fork();
/// @brief Replaces the current process image with a new process image (argument list).
/// @param path The absolute path to the binary file to execute.
/// @param arg A list of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @param ... The argument list.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execl(const char *path, const char *arg, ...);
/// @brief Replaces the current process image with a new process image (argument list).
/// @param file The name of the binary file to execute, which is searched inside the
/// paths specified inside the PATH environmental variable.
/// @param arg A list of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @param ... The argument list.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execlp(const char *file, const char *arg, ...);
/// @brief Replaces the current process image with a new process image (argument list).
/// @param path The absolute path to the binary file to execute.
/// @param arg A list of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @param ... The argument list which contains as last argument the environment.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execle(const char *path, const char *arg, ...);
/// @brief Replaces the current process image with a new process image (argument list).
/// @param file The name of the binary file to execute, which is searched inside the
/// paths specified inside the PATH environmental variable.
/// @param arg A list of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @param ... The argument list which contains as last argument the environment.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execlpe(const char *file, const char *arg, ...);
/// @brief Replaces the current process image with a new process image (argument vector).
/// @param path The absolute path to the binary file to execute.
/// @param argv A vector of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execv(const char *path, char *const argv[]);
/// @brief Replaces the current process image with a new process image (argument vector).
/// @param file The name of the binary file to execute, which is searched inside the
/// paths specified inside the PATH environmental variable.
/// @param argv A vector of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execvp(const char *file, char *const argv[]);
/// @brief Replaces the current process image with a new process
/// image (argument vector), allows the caller to specify
/// the environment of the executed program via `envp`.
/// @param path The absolute path to the binary file to execute.
/// @param argv A vector of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @param envp A vector of one or more pointers to null-terminated strings that represent
/// the environment list available to the executed program.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execve(const char *path, char *const argv[], char *const envp[]);
/// @brief Replaces the current process image with a new process
/// image (argument vector), allows the caller to specify
/// the environment of the executed program via `envp`.
/// @param file The name of the binary file to execute, which is searched inside the
/// paths specified inside the PATH environmental variable.
/// @param argv A vector of one or more pointers to null-terminated strings that represent
/// the argument list available to the executed program.
/// @param envp A vector of one or more pointers to null-terminated strings that represent
/// the environment list available to the executed program.
/// @return Returns -1 only if an error has occurred, and sets errno.
int execvpe(const char *file, char *const argv[], char *const envp[]);
/// @brief Adds inc to the nice value for the calling thread.
/// @param inc The value to add to the nice.
/// @return On success, the new nice value is returned. On error, -1 is
/// returned, and errno is set appropriately.
int nice(int inc);
/// @brief Reboots the system, or enables/disables the reboot keystroke.
/// @param magic1 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC1.
/// @param magic2 fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC2.
/// @param cmd The command to send to the reboot.
/// @param arg Argument passed with some specific commands.
/// @return For the values of cmd that stop or restart the system, a
/// successful call to reboot() does not return. For the other cmd
/// values, zero is returned on success. In all cases, -1 is
/// returned on failure, and errno is set appropriately.
int reboot(int magic1, int magic2, unsigned int cmd, void *arg);
/// @brief Get current working directory.
/// @param buf The array where the CWD will be copied.
/// @param size The size of the array.
/// @return On success, returns the same pointer to buf.
/// On failure, returnr NULL, and errno is set to indicate the error.
char *getcwd(char *buf, size_t size);
/// @brief Changes the current working directory to the given path.
/// @param path The new current working directory.
int chdir(char const *path);
/// @brief Is identical to chdir(), the only difference is that the
/// directory is given as an open file descriptor.
/// @param fd The file descriptor of the open directory.
int fchdir(int fd);
/// Provide access to the directory entries.
/// @param fd The fd pointing to the opened directory.
/// @param dirp The buffer where de data should be placed.
/// @param count The size of the buffer.
/// @return On success, the number of bytes read is returned. On end of
/// directory, 0 is returned. On error, -1 is returned, and errno is set
/// appropriately.
int getdents(int fd, dirent_t *dirp, unsigned int count);
/// @brief Send signal to calling thread after desired seconds.
int alarm(int seconds);
+30
View File
@@ -0,0 +1,30 @@
/// MentOS, The Mentoring Operating system project
/// @file utsname.h
/// @brief Functions used to provide information about the machine & OS.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
/// Maximum length of the string used by utsname.
#define SYS_LEN 257
/// @brief Holds information concerning the machine and the os.
typedef struct utsname_t {
/// The name of the system.
char sysname[SYS_LEN];
/// The name of the node.
char nodename[SYS_LEN];
/// Operating system release (e.g., "2.6.28").
char release[SYS_LEN];
/// The version of the OS.
char version[SYS_LEN];
/// The name of the machine.
char machine[SYS_LEN];
} utsname_t;
/// @brief Returns system information in the structure pointed to by buf.
/// @param buf Buffer where the info will be placed.
/// @return 0 on success, a negative value on failure.
int uname(utsname_t* buf);
+77
View File
@@ -0,0 +1,77 @@
/// MentOS, The Mentoring Operating system project
/// @file wait.h
/// @brief Event management functions.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
/// @brief Return immediately if no child is there to be waited for.
#define WNOHANG 0x00000001
/// @brief Return for children that are stopped, and whose status has not
/// been reported.
#define WUNTRACED 0x00000002
/// @brief returns true if the child process exited because of a signal that
/// was not caught.
#define WIFSIGNALED(status) (!WIFSTOPPED(status) && !WIFEXITED(status))
/// @brief returns true if the child process that caused the return is
/// currently stopped; this is only possible if the call was done using
/// WUNTRACED().
#define WIFSTOPPED(status) (((status)&0xff) == 0x7f)
/// @brief evaluates to the least significant eight bits of the return code
/// of the child that terminated, which may have been set as the argument
/// to a call to exit() or as the argument for a return statement in the
/// main program. This macro can only be evaluated if WIFEXITED()
/// returned nonzero.
#define WEXITSTATUS(status) (((status)&0xff00) >> 8)
/// @brief returns the number of the signal that caused the child process to
/// terminate. This macro can only be evaluated if WIFSIGNALED() returned
/// nonzero.
#define WTERMSIG(status) ((status)&0x7f)
/// @brief Is nonzero if the child exited normally.
#define WIFEXITED(status) (WTERMSIG(status) == 0)
/// @brief returns the number of the signal that caused the child to stop.
/// This macro can only be evaluated if WIFSTOPPED() returned nonzero.
#define WSTOPSIG(status) (WEXITSTATUS(status))
//==== Task States ============================================================
#define TASK_RUNNING 0x00 ///< The process is either: 1) running on CPU or 2) waiting in a run queue.
#define TASK_INTERRUPTIBLE (1 << 0) ///< The process is sleeping, waiting for some event to occur.
#define TASK_UNINTERRUPTIBLE (1 << 1) ///< Similar to TASK_INTERRUPTIBLE, but it doesn't process signals.
#define TASK_STOPPED (1 << 2) ///< Stopped, it's not running, and not able to run.
#define TASK_TRACED (1 << 3) ///< Is being monitored by other processes such as debuggers.
#define EXIT_ZOMBIE (1 << 4) ///< The process has terminated.
#define EXIT_DEAD (1 << 5) ///< The final state.
//==============================================================================
/// @brief Suspends the execution of the calling thread until ANY child has
/// changed state.
/// @param status Variable where the new status of the child is stored.
/// @return On error, -1 is returned, otherwise it returns the pid of the
/// child that has unlocked the wait.
extern pid_t wait(int *status);
/// @brief Suspends the execution of the calling thread until a child
/// specified by pid argument has changed state.
/// @param pid Se details below for more information.
/// @param status Variable where the new status of the child is stored.
/// @param options Waitpid options.
/// @return On error, -1 is returned, otherwise it returns the pid of the
/// child that has unlocked the wait.
/// @details
/// By default, waitpid() waits only for terminated children, but this
/// behavior is modifiable via the options argument, as described below.
/// The value of pid can be:
/// - 1 meaning wait for any child process.
/// 0 meaning wait for any child process whose process group ID is
/// equal to that of the calling process.
/// > 0 meaning wait for the child whose process ID is equal to the
/// value of pid.
extern pid_t waitpid(pid_t pid, int *status, int options);