Skip to content

Commit

Permalink
Merge branch 'release/v0.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Galfurian committed Aug 30, 2024
2 parents 540a16e + a3cb623 commit 3add75d
Show file tree
Hide file tree
Showing 35 changed files with 932 additions and 793 deletions.
Empty file removed files/home/user/.bashrc
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions files/home/user/tmp.md
8 changes: 8 additions & 0 deletions files/home/user/welcome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MentOS 0.7.2

Welcome to the MentOS, the Mentoring Operating System.

If you want some help enter the "man" command into the cli.

Bye,
The Ment(OS) Team
Empty file removed files/proc/README
Empty file.
30 changes: 0 additions & 30 deletions libc/inc/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,3 @@
#define O_APPEND 00002000U ///< Set append mode.
#define O_NONBLOCK 00004000U ///< No delay.
#define O_DIRECTORY 00200000U ///< If file exists has no effect. Otherwise, the file is created.

/// @defgroup ModeBitsAccessPermission Mode Bits for Access Permission
/// @brief The file modes.
/// @{

#define S_ISUID 0x0800 ///< Set user id on execution
#define S_ISGID 0x0400 ///< Set group id on execution
#define S_ISVTX 0x0200 ///< Save swapped text even after use (Sticky Bit)
#define S_IRWXU 0x01C0 ///< rwx------ : User can read/write/execute
#define S_IRUSR 0x0100 ///< r-------- : User can read
#define S_IWUSR 0x0080 ///< -w------- : User can write
#define S_IXUSR 0x0040 ///< --x------ : User can execute
#define S_IRWXG 0x0038 ///< ---rwx--- : Group can read/write/execute
#define S_IRGRP 0x0020 ///< ---r----- : Group can read
#define S_IWGRP 0x0010 ///< ----w---- : Group can write
#define S_IXGRP 0x0008 ///< -----x--- : Group can execute
#define S_IRWXO 0x0007 ///< ------rwx : Others can read/write/execute
#define S_IROTH 0x0004 ///< ------r-- : Others can read
#define S_IWOTH 0x0002 ///< -------w- : Others can write
#define S_IXOTH 0x0001 ///< --------x : Others can execute

#define S_ISDIR(m) (((m)&0170000) == 0040000) ///< directory.
#define S_ISCHR(m) (((m)&0170000) == 0020000) ///< char special
#define S_ISBLK(m) (((m)&0170000) == 0060000) ///< block special
#define S_ISREG(m) (((m)&0170000) == 0100000) ///< regular file
#define S_ISFIFO(m) (((m)&0170000) == 0010000) ///< fifo
#define S_ISLNK(m) (((m)&0170000) == 0120000) ///< symbolic link
#define S_ISSOCK(m) (((m)&0170000) == 0140000) ///< socket

/// @}
2 changes: 1 addition & 1 deletion libc/inc/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ char *strtok_r(char *str, const char *delim, char **saveptr);
/// @param buffer the buffer where we save the parsed token.
/// @param buflen the length of the buffer.
/// @return 1 if we still have things to parse, 0 if we finished parsing.
int tokenize(const char *string, char *separators, size_t *offset, char *buffer, ssize_t buflen);
int tokenize(const char *string, const char *separators, size_t *offset, char *buffer, ssize_t buflen);

/// @brief Copies the values of num bytes from the location pointed by source
/// to the memory block pointed by destination.
Expand Down
46 changes: 46 additions & 0 deletions libc/inc/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,52 @@
#include "stddef.h"
#include "time.h"

/// @defgroup FileTypes File Types Macros
/// @brief These constants allow to identify file types.
/// @{
#define S_IFMT 0xF000 ///< Format mask
#define S_IFSOCK 0xC000 ///< Socket
#define S_IFLNK 0xA000 ///< Symbolic link
#define S_IFREG 0x8000 ///< Regular file
#define S_IFBLK 0x6000 ///< Block device
#define S_IFDIR 0x4000 ///< Directory
#define S_IFCHR 0x2000 ///< Character device
#define S_IFIFO 0x1000 ///< Fifo
/// @}

/// @defgroup FileTypeTest File Type Test Macros
/// @brief These macros allows to easily identify file types.
/// @{
#define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
#define S_ISSOCK(mode) (S_ISTYPE(mode, S_IFSOCK)) ///< Check if a socket.
#define S_ISLNK(mode) (S_ISTYPE(mode, S_IFLNK)) ///< Check if a symbolic link.
#define S_ISREG(mode) (S_ISTYPE(mode, S_IFREG)) ///< Check if a regular file.
#define S_ISBLK(mode) (S_ISTYPE(mode, S_IFBLK)) ///< Check if a block special.
#define S_ISDIR(mode) (S_ISTYPE(mode, S_IFDIR)) ///< Check if a directory.
#define S_ISCHR(mode) (S_ISTYPE(mode, S_IFCHR)) ///< Check if a char special.
#define S_ISFIFO(mode) (S_ISTYPE(mode, S_IFIFO)) ///< Check if a fifo.
/// @}

/// @defgroup ModeBitsAccessPermission Mode Bits for Access Permission
/// @brief These constants allow to control access permission for files.
/// @{
#define S_ISUID 0x0800 ///< Set user id on execution
#define S_ISGID 0x0400 ///< Set group id on execution
#define S_ISVTX 0x0200 ///< Save swapped text even after use (Sticky Bit)
#define S_IRWXU 0x01C0 ///< rwx------ : User can read/write/execute
#define S_IRUSR 0x0100 ///< r-------- : User can read
#define S_IWUSR 0x0080 ///< -w------- : User can write
#define S_IXUSR 0x0040 ///< --x------ : User can execute
#define S_IRWXG 0x0038 ///< ---rwx--- : Group can read/write/execute
#define S_IRGRP 0x0020 ///< ---r----- : Group can read
#define S_IWGRP 0x0010 ///< ----w---- : Group can write
#define S_IXGRP 0x0008 ///< -----x--- : Group can execute
#define S_IRWXO 0x0007 ///< ------rwx : Others can read/write/execute
#define S_IROTH 0x0004 ///< ------r-- : Others can read
#define S_IWOTH 0x0002 ///< -------w- : Others can write
#define S_IXOTH 0x0001 ///< --------x : Others can execute
/// @}

/// @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.
Expand Down
29 changes: 18 additions & 11 deletions libc/src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include "string.h"
#include "ctype.h"
#include "fcntl.h"
#include "stdio.h"
#include "stdlib.h"
#include "sys/stat.h"

#ifdef __KERNEL__
#include "mem/kheap.h"
Expand Down Expand Up @@ -218,23 +218,30 @@ char *strpbrk(const char *string, const char *control)
return NULL;
}

int tokenize(const char *string, char *separators, size_t *offset, char *buffer, ssize_t buflen)
int tokenize(const char *string, const char *separators, size_t *offset, char *buffer, ssize_t buflen)
{
// If we reached the end of the parsed string, stop.
if ((*offset >= buflen) || (string[*offset] == 0)) {
return 0;
}
// Skip any leading (multiple) separators.
while (string[*offset] != 0 && strchr(separators, string[*offset])) {
++(*offset);
}
// If we reach the end after skipping, return 0.
if (string[*offset] == 0) {
return 0;
}
// Keep copying character until we either reach 1) the end of the buffer, 2) a
// separator, or 3) the end of the string we are parsing.
do {
for (char *separator = separators; *separator != 0; ++separator) {
if (string[*offset] == *separator) {
// Skip the character.
++(*offset);
// Close the buffer.
*buffer = '\0';
return 1;
}
// Check if the character is a separator.
if (strchr(separators, string[*offset])) {
// Skip the character.
++(*offset);
// Close the buffer.
*buffer = '\0';
return 1;
}
// Save the character.
*buffer = string[*offset];
Expand Down Expand Up @@ -496,7 +503,7 @@ size_t strlen(const char *s)
size_t strnlen(const char *s, size_t count)
{
const char *p = memchr(s, 0, count);
return p ? (size_t)(p-s) : count;
return p ? (size_t)(p - s) : count;
}

int strcmp(const char *s1, const char *s2)
Expand Down
33 changes: 12 additions & 21 deletions mentos/inc/fs/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ extern kmem_cache_t *vfs_file_cache;
/// @brief Forward declaration of task_struct.
struct task_struct;

/// @brief Searches for the mountpoint of the given path.
/// @param absolute_path Path for which we want to search the mountpoint.
/// @return Pointer to the vfs_file of the mountpoint.
super_block_t *vfs_get_superblock(const char *absolute_path);

/// @brief Initialize the Virtual File System (VFS).
void vfs_init(void);

Expand All @@ -37,6 +32,15 @@ int vfs_register_filesystem(file_system_type *fs);
/// @return The outcome of the operation, 0 if fails.
int vfs_unregister_filesystem(file_system_type *fs);

int vfs_register_superblock(const char *name, const char *path, file_system_type *type, vfs_file_t *root);

int vfs_unregister_superblock(super_block_t *sb);

/// @brief Searches for the mountpoint of the given path.
/// @param absolute_path Path for which we want to search the mountpoint.
/// @return Pointer to the vfs_file of the mountpoint.
super_block_t *vfs_get_superblock(const char *absolute_path);

/// @brief Given an absolute path to a file, vfs_open_abspath() returns a file struct, used to access the file.
/// @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.
Expand Down Expand Up @@ -127,11 +131,11 @@ int vfs_rmdir(const char *path);
vfs_file_t *vfs_creat(const char *path, mode_t mode);

/// @brief Read the symbolic link, if present.
/// @param file the file for which we want to read the symbolic link information.
/// @param path the path to the symbolic link.
/// @param buffer the buffer where we will store the symbolic link path.
/// @param bufsize the size of the buffer.
/// @return The number of read characters on success, -1 otherwise and errno is set to indicate the error.
ssize_t vfs_readlink(vfs_file_t *file, char *buffer, size_t bufsize);
ssize_t vfs_readlink(const char *path, char *buffer, size_t bufsize);

/// @brief Creates a symbolic link.
/// @param linkname the name of the link.
Expand All @@ -151,24 +155,12 @@ int vfs_stat(const char *path, stat_t *buf);
/// @return 0 on success, -errno on failure.
int vfs_fstat(vfs_file_t *file, stat_t *buf);

/// @brief Mount a file system to the specified path.
/// @param path Path where we want to map the filesystem.
/// @param fs_root Root node of the filesystem.
/// @return 1 on success, 0 on fail.
/// @details
/// For example, if we have an EXT2 filesystem with a root node
/// of ext2_root and we want to mount it to /, we would run
/// vfs_mount("/", ext2_root); - or, if we have a procfs node,
/// we could mount that to /dev/procfs. Individual files can also
/// be mounted.
int vfs_mount(const char *path, vfs_file_t *fs_root);

/// @brief Mount the path as a filesystem of the given type.
/// @param type The type of filesystem
/// @param path The path to where it should be mounter.
/// @param args The arguments passed to the filesystem mount callback.
/// @return 0 on success, a negative number if fails and errno is set.
int do_mount(const char *type, const char *path, const char *args);
int vfs_mount(const char *type, const char *path, const char *args);

/// @brief Locks the access to the given file.
/// @param file The file to lock.
Expand Down Expand Up @@ -199,7 +191,6 @@ 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.
Expand Down
2 changes: 1 addition & 1 deletion mentos/inc/fs/vfs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef int (*vfs_ioctl_callback)(vfs_file_t *, int, void *);
/// Function for creating symbolic links.
typedef int (*vfs_symlink_callback)(const char *, const char *);
/// Function that reads the symbolic link data associated with a file.
typedef ssize_t (*vfs_readlink_callback)(vfs_file_t *, char *, size_t);
typedef ssize_t (*vfs_readlink_callback)(const char *, char *, size_t);
/// Function used to modify the attributes of an fs entry.
typedef int (*vfs_setattr_callback)(const char *, struct iattr *);
/// Function used to modify the attributes of a file.
Expand Down
2 changes: 1 addition & 1 deletion mentos/inc/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define OS_MINOR_VERSION 7

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

/// Helper to transform the given argument into a string.
#define OS_STR_HELPER(x) #x
Expand Down
37 changes: 27 additions & 10 deletions mentos/src/drivers/ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,25 @@ static int ata_stat(const char *path, stat_t *stat)
}

// == VFS ENTRY GENERATION ====================================================

/// @brief The mount call-back, which prepares everything and calls the actual
/// ATA mount function.
/// @param path the path where the filesystem should be mounted.
/// @param device the device we mount.
/// @return the VFS file of the filesystem.
static vfs_file_t *ata_mount_callback(const char *path, const char *device)
{
pr_err("mount_callback(%s, %s): ATA has no mount callback!\n", path, device);
return NULL;
}

/// Filesystem information.
static file_system_type ata_file_system_type = {
.name = "ata",
.fs_flags = 0,
.mount = ata_mount_callback
};

/// Filesystem general operations.
static vfs_sys_operations_t ata_sys_operations = {
.mkdir_f = NULL,
Expand Down Expand Up @@ -1208,9 +1227,9 @@ static vfs_file_t *ata_device_create(ata_device_t *dev)
}
// Set the device name.
memcpy(file->name, dev->name, NAME_MAX);
file->uid = 0;
file->gid = 0;
file->mask = 0x2000 | 0600;
file->uid = 0;
file->gid = 0;
file->mask = 0x2000 | 0600;
file->atime = sys_time(NULL);
file->mtime = sys_time(NULL);
file->ctime = sys_time(NULL);
Expand Down Expand Up @@ -1259,7 +1278,7 @@ static ata_device_type_t ata_device_detect(ata_device_t *dev)
// Update the filesystem entry with the length of the device.
dev->fs_root->length = ata_max_offset(dev);
// Try to mount the drive.
if (!vfs_mount(dev->path, dev->fs_root)) {
if (!vfs_register_superblock(dev->fs_root->name, dev->path, &ata_file_system_type, dev->fs_root)) {
pr_alert("Failed to mount ata device!\n");
// Free the memory.
kmem_cache_free(dev->fs_root);
Expand All @@ -1273,12 +1292,6 @@ static ata_device_type_t ata_device_detect(ata_device_t *dev)
} else if (type == ata_dev_type_no_device) {
pr_debug("[%s] Found no device...\n", ata_get_device_settings_str(dev));
}
// if (type == ata_dev_type_unknown) {
// pr_debug("[%s] Found unsupported device...\n", ata_get_device_settings_str(dev));
// }
// if ((type != ata_dev_type_no_device) && (type != ata_dev_type_unknown)) {
// pr_warning(" Found %s device connected to %s.\n", ata_get_device_type_str(type), ata_get_device_settings_str(dev));
// }
return type;
}

Expand Down Expand Up @@ -1320,11 +1333,15 @@ static void pci_find_ata(uint32_t device, uint16_t vendorid, uint16_t deviceid,
}

// == INITIALIZE/FINALIZE ATA =================================================

int ata_initialize(void)
{
// Search for ATA devices.
pci_scan(&pci_find_ata, -1, &ata_pci);

// Register the filesystem.
vfs_register_filesystem(&ata_file_system_type);

// Install the IRQ handlers.
irq_install_handler(IRQ_FIRST_HD, ata_irq_handler_master, "IDE Master");
irq_install_handler(IRQ_SECOND_HD, ata_irq_handler_slave, "IDE Slave");
Expand Down
Loading

0 comments on commit 3add75d

Please sign in to comment.