Skip to content

Commit

Permalink
Merge branch 'release/v0.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Galfurian committed Aug 22, 2024
2 parents 4bc52fb + 4dd80ed commit 540a16e
Show file tree
Hide file tree
Showing 64 changed files with 1,999 additions and 1,042 deletions.
710 changes: 357 additions & 353 deletions .clang-format

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion files/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MentOS 0.6.0
MentOS 0.7.2

Welcome to the MentOS, the Mentoring Operating System.

Expand Down
2 changes: 1 addition & 1 deletion files/etc/group
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
root:x:0:user,root,marco
user:x:1000:banana,marco
user:x:1000:banana,marco
8 changes: 7 additions & 1 deletion files/usr/share/man/hier.man
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ DESCRIPTION
Contains the source code used to build the system.

/usr/share
Contains the source code used to build the system.
Contains subdirectories with specific application data, that can be shared
among different architectures of the same OS.

/usr/share/man
Manual pages go here.

/var Contains files which may change in size.

/var/lib
Variable state information for programs.
28 changes: 28 additions & 0 deletions files/usr/share/man/passwd.man
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
NAME
passwd - the password file

DESCRIPTION
/etc/passwd contains one line for each user account, with seven fields
delimited by colons (":").

These fields are:
* login name
* optional encrypted password
* numerical user ID
* numerical group ID
* user name or comment field
* user home directory
* optional user command interpreter

If the password field is a lower-case "x", then the encrypted password is
actually stored in the shadow file instead; there must be a corresponding
line in the /etc/shadow file, or else the user account is invalid.

The home directory field provides the name of the initial working directory.
The login program uses this information to set the value of the $HOME
environmental variable.

The command interpreter field provides the name of the user's command
language interpreter, or the name of the initial program to execute.
The login program uses this information to set the value of the $SHELL
environmental variable.
22 changes: 22 additions & 0 deletions files/usr/share/man/shadow.man
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
NAME
shadow - shadowed password file

DESCRIPTION
shadow is a file which contains the password information for the
system's accounts.

This file must not be readable by regular users if password security is to
be maintained.

Each line of this file contains 9 fields, separated by colons (“:”), in the
following order:

* login name
* encrypted password
* date of last password change
* minimum password age
* maximum password age
* password warning period
* password inactivity period
* account expiration date
* reserved field
15 changes: 13 additions & 2 deletions libc/inc/sys/list_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include "stddef.h"
#include "assert.h"

/// @brief Structure used to implement the list_head data structure.
typedef struct list_head {
Expand Down Expand Up @@ -73,6 +74,7 @@ static inline void list_head_init(list_head *head)
/// @return 1 if empty, 0 otherwise.
static inline int list_head_empty(const list_head *head)
{
assert(head && "Variable head is NULL.");
return head->next == head;
}

Expand All @@ -93,6 +95,8 @@ static inline unsigned list_head_size(const list_head *head)
/// @param location the element after which we insert.
static inline void list_head_insert_after(list_head *new_entry, list_head *location)
{
assert(new_entry && "Variable new_entry is NULL.");
assert(location && "Variable location is NULL.");
// We store the old `next` element.
list_head *old_next = location->next;
// We insert our element.
Expand All @@ -110,6 +114,8 @@ static inline void list_head_insert_after(list_head *new_entry, list_head *locat
/// @param location the element after which we insert.
static inline void list_head_insert_before(list_head *new_entry, list_head *location)
{
assert(new_entry && "Variable new_entry is NULL.");
assert(location && "Variable location is NULL.");
// We store the old `previous` element.
list_head *old_prev = location->prev;
// We link the old `previous` element to our new entry.
Expand All @@ -128,6 +134,8 @@ static inline void list_head_remove(list_head *entry)
{
// Check if the element is actually in a list.
if (!list_head_empty(entry)) {
assert(entry->prev && "Attribute entry->prev is NULL.");
assert(entry->next && "Attribute entry->next is NULL.");
// We link the `previous` element to the `next` one.
entry->prev->next = entry->next;
// We link the `next` element to the `previous` one.
Expand Down Expand Up @@ -162,16 +170,17 @@ static inline void list_head_append(list_head *main, list_head *secondary)
{
// Check that both lists are actually filled with entries.
if (!list_head_empty(main) && !list_head_empty(secondary)) {
assert(main->prev && "Attribute main->prev is NULL.");
assert(secondary->next && "Attribute secondary->next is NULL.");
assert(secondary->prev && "Attribute secondary->prev is NULL.");
// Connect the last element of the main list to the first one of the secondary list.
main->prev->next = secondary->next;
// Connect the first element of the secondary list to the last one of the main list.
secondary->next->prev = main->prev;

// Connect the last element of the secondary list to our main.
secondary->prev->next = main;
// Connect our main to the last element of the secondary list.
main->prev = secondary->prev;

// Re-initialize the secondary list.
list_head_init(secondary);
}
Expand All @@ -184,6 +193,8 @@ static inline void list_head_replace(list_head *entry1, list_head *entry2)
{
// First we need to remove the second entry.
list_head_remove(entry2);
assert(entry2->next && "Attribute entry2->next is NULL.");
assert(entry2->prev && "Attribute entry2->prev is NULL.");
// Then, we can place second entry where the first entry is.
entry2->next = entry1->next;
entry2->next->prev = entry2;
Expand Down
24 changes: 24 additions & 0 deletions libc/inc/sys/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,38 @@

#ifndef __KERNEL__

/// @brief creates a new mapping in the virtual address space of the calling process.
/// @param addr the starting address for the new mapping.
/// @param length specifies the length of the mapping (which must be greater than 0).
/// @param prot describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).
/// @param flags determines whether updates to the mapping are visible to other processes mapping the same region.
/// @param fd in case of file mapping, the file descriptor to use.
/// @param offset offset in the file, which must be a multiple of the page size PAGE_SIZE.
/// @return returns a pointer to the mapped area, -1 and errno is set.
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

/// @brief deletes the mappings for the specified address range.
/// @param addr the starting address.
/// @param length the length of the mapped area.
/// @return 0 on success, -1 on falure and errno is set.
int munmap(void *addr, size_t length);

#else

/// @brief creates a new mapping in the virtual address space of the calling process.
/// @param addr the starting address for the new mapping.
/// @param length specifies the length of the mapping (which must be greater than 0).
/// @param prot describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).
/// @param flags determines whether updates to the mapping are visible to other processes mapping the same region.
/// @param fd in case of file mapping, the file descriptor to use.
/// @param offset offset in the file, which must be a multiple of the page size PAGE_SIZE.
/// @return returns a pointer to the mapped area, -1 and errno is set.
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

/// @brief deletes the mappings for the specified address range.
/// @param addr the starting address.
/// @param length the length of the mapped area.
/// @return 0 on success, -1 on falure and errno is set.
int sys_munmap(void *addr, size_t length);

#endif
8 changes: 4 additions & 4 deletions libc/inc/sys/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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
/// @return 0 on success, -errno on failure.
int unlink(const char *path);

/// @brief Creates a symbolic link.
Expand Down Expand Up @@ -306,23 +306,23 @@ int fchmod(int fd, mode_t mode);
/// @brief Change the owner and group of a file.
/// @param pathname The pathname of the file to change.
/// @param owner The new owner to set.
/// @param owner The new group to set.
/// @param group The new group to set.
/// @return On success, 0 is returned.
/// On error, -1 is returned, and errno is set appropriately.
int chown(const char *pathname, uid_t owner, gid_t group);

/// @brief Change the owner and group of a file.
/// @param fd The fd pointing to the opened file.
/// @param owner The new owner to set.
/// @param owner The new group to set.
/// @param group The new group to set.
/// @return On success, 0 is returned.
/// On error, -1 is returned, and errno is set appropriately.
int fchown(int fd, uid_t owner, gid_t group);

/// @brief Change the owner and group of a file.
/// @param pathname The pathname of the file to change.
/// @param owner The new owner to set.
/// @param owner The new group to set.
/// @param group The new group to set.
/// @return On success, 0 is returned.
/// On error, -1 is returned, and errno is set appropriately.
int lchown(const char *pathname, uid_t owner, gid_t group);
2 changes: 1 addition & 1 deletion libc/src/grp.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static inline int __search_entry(int fd, char *buf, size_t buflen, const char *n
buf[pos] = 0;
// Check the entry.
if (name) {
if (strncmp(buf, name, strlen(name)) == 0) {
if (strncmp(buf, name, strlen(name)) == 0 && buf[strlen(name)] == ':') {
return 1;
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion libc/src/pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static inline char *__search_entry(int fd, char *buffer, int buflen, const char
char *name_end = strchr(buffer, ':');
if (name_end) {
*name_end = '\0';
if (strncmp(buffer, name, strlen(name)) == 0) {
if (strlen(name) == strlen(buffer) &&
strncmp(buffer, name, strlen(name)) == 0) {
*name_end = ':';
return buffer;
}
Expand Down
10 changes: 5 additions & 5 deletions mentos/inc/fs/namei.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "stddef.h"

#define REMOVE_TRAILING_SLASH 1 << 0
#define FOLLOW_LINKS 1 << 1
#define CREAT_LAST_COMPONENT 1 << 2
#define FOLLOW_LINKS 1 << 1
#define CREAT_LAST_COMPONENT 1 << 2

/// @brief Resolve the path by following all symbolic links.
/// @param path The path to resolve.
/// @param resolved_path The buffer where the resolved path is stored.
/// @param size The size of the provided resolved_path buffer.
/// @param buffer The buffer where the resolved path is stored.
/// @param buflen The size of the provided resolved_path buffer.
/// @param flags The flags controlling how the path is resolved.
/// @return -errno on fail, 1 on success.
int resolve_path(const char *path, char *resolved_path, size_t size, int flags);
int resolve_path(const char *path, char *buffer, size_t buflen, int flags);
6 changes: 6 additions & 0 deletions mentos/inc/fs/procfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ proc_dir_entry_t *proc_create_entry(const char *name, proc_dir_entry_t *parent);
/// @return 0 if succeed, or -errno in case of error.
int proc_destroy_entry(const char *name, proc_dir_entry_t *parent);

/// @brief Sets the mask of a given procfs entry.
/// @param entry Pointer to the entry.
/// @param mask The mask to set.
/// @return 0 if succeed, or -errno in case of error.
int proc_entry_set_mask(proc_dir_entry_t *entry, mode_t mask);

/// @brief Create the entire procfs entry tree for the give process.
/// @param entry Pointer to the task_struct of the process.
/// @return 0 if succeed, or -errno in case of error.
Expand Down
22 changes: 12 additions & 10 deletions mentos/inc/fs/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ int vfs_register_filesystem(file_system_type *fs);
int vfs_unregister_filesystem(file_system_type *fs);

/// @brief Given an absolute path to a file, vfs_open_abspath() returns a file struct, used to access the file.
/// @param abspath An absolute path to 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.
/// @param absolute_path An absolute path to 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 struct, or NULL.
vfs_file_t *vfs_open_abspath(const char *pathname, int flags, mode_t mode);
vfs_file_t *vfs_open_abspath(const char *absolute_path, int flags, mode_t mode);

/// @brief Given a pathname for a file, vfs_open() returns a file struct, used to access the file.
/// @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.
/// @param path 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 struct, or NULL.
vfs_file_t *vfs_open(const char *pathname, int flags, mode_t mode);
vfs_file_t *vfs_open(const char *path, int flags, mode_t mode);

/// @brief Decreases the number of references to a given file, if the
/// references number reaches 0, close the file.
Expand Down Expand Up @@ -199,13 +199,15 @@ int vfs_destroy_task(struct task_struct *task);
/// @return -errno on fail, fd on success.
int get_unused_fd(void);


/// @brief Return new smallest available file desriptor.
/// @param fd the descriptor of the file we want to duplicate.
/// @return -errno on fail, fd on success.
int sys_dup(int fd);

/// @brief Check if the requested open flags against the file mask
/// @brief Check if the requested open flags against the file mask.
/// @param flags The requested open flags.
/// @param mode The permissions of the file.
/// @param mask The permissions of the file.
/// @param uid The owner of the task opening the file.
/// @param gid The group of the task opening the file.
/// @return 0 on fail, 1 on success.
Expand Down
43 changes: 28 additions & 15 deletions mentos/inc/fs/vfs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,40 @@ typedef struct vfs_file_descriptor_t {

/// @brief Data structure containing attributes of a file.
struct iattr {
/// Validity check on iattr struct.
unsigned int ia_valid;
/// Access mode.
mode_t ia_mode;
/// Owner uid.
uid_t ia_uid;
/// Owner gid.
gid_t ia_gid;
/// Time of last access.
uint32_t ia_atime;
/// Time of last data modification.
uint32_t ia_mtime;
/// Time of last status change.
uint32_t ia_ctime;
};

#define ATTR_MODE (1 << 0)
#define ATTR_UID (1 << 1)
#define ATTR_GID (1 << 2)
#define ATTR_ATIME (1 << 3)
#define ATTR_MTIME (1 << 4)
#define ATTR_CTIME (1 << 5)

#define IATTR_CHOWN(user, group) \
{ .ia_valid = ATTR_UID | ATTR_GID, \
.ia_uid = user, \
.ia_gid = group }

#define IATTR_CHMOD(mode) \
{ .ia_valid = ATTR_MODE, \
.ia_mode = mode }
#define ATTR_MODE (1 << 0) ///< Flag set to specify the validity of MODE.
#define ATTR_UID (1 << 1) ///< Flag set to specify the validity of UID.
#define ATTR_GID (1 << 2) ///< Flag set to specify the validity of GID.
#define ATTR_ATIME (1 << 3) ///< Flag set to specify the validity of ATIME.
#define ATTR_MTIME (1 << 4) ///< Flag set to specify the validity of MTIME.
#define ATTR_CTIME (1 << 5) ///< Flag set to specify the validity of CTIME.

/// Used to initialize an iattr inside the chown function.
#define IATTR_CHOWN(user, group) \
{ \
.ia_valid = ATTR_UID | ATTR_GID, \
.ia_uid = (user), \
.ia_gid = (group) \
}

/// Used to initialize an iattr inside the chmod function.
#define IATTR_CHMOD(mode) \
{ \
.ia_valid = ATTR_MODE, \
.ia_mode = (mode) \
}
2 changes: 1 addition & 1 deletion mentos/inc/process/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct wait_queue_entry_t {

/// @brief Allocates the memory for a wait_queue_entry.
/// @return a pointer to the allocated wait_queue_entry.
wait_queue_entry_t * wait_queue_entry_alloc();
wait_queue_entry_t * wait_queue_entry_alloc(void);

/// @brief Frees the memory of a wait_queue_entry.
/// @param wait_queue_entry pointer to the wait_queue_entry.
Expand Down
4 changes: 2 additions & 2 deletions mentos/inc/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#define OS_MAJOR_VERSION 0

/// Minor version of the operating system.
#define OS_MINOR_VERSION 6
#define OS_MINOR_VERSION 7

/// Micro version of the operating system.
#define OS_MICRO_VERSION 0
#define OS_MICRO_VERSION 2

/// Helper to transform the given argument into a string.
#define OS_STR_HELPER(x) #x
Expand Down
Loading

0 comments on commit 540a16e

Please sign in to comment.