feat: Vfs and Ext2 support. Code style/attribute improvements

Added VFS and Ext2 support.
Optimized attributes of methods to improve code highlighting.
Printf attribute, malloc attribute, etc.
This commit is contained in:
2021-10-06 21:45:15 +02:00
parent 073051c99e
commit 03f0ec6f88
24 changed files with 1322 additions and 90 deletions

70
include/myke/vfs/vfs.h Normal file
View File

@@ -0,0 +1,70 @@
//
// Created by rick on 19-09-21.
//
#ifndef NEW_KERNEL_VFS_H
#define NEW_KERNEL_VFS_H
#include <stdbool.h>
#include <sys/stat.h>
#define VFS_MOUNT_OK 0
#define VFS_MOUNT_ERROR 1
#define VFS_OPEN_ERROR 1
#define VFS_OPEN_OK 0
#define VFS_CLOSE_OK 1
#define VFS_READ_ERROR (-1)
#define VFS_DGETENTS_ERR 1
struct vfs_mount;
typedef struct vfs_mount {
struct {
} flags;
const char *prefix;
const char *device;
void *driver; // vfs_mount_driver_t
void *global_driver_data;
struct vfs_mount *next;
} vfs_mount_t;
typedef struct vfs_fd {
struct {
} flags;
vfs_mount_t *mount;
void *driver_data;
} vfs_fd_t;
#define VFS_DIRENT_BASE_SIZE (4 + 4 + 2 + 1)
#define VFS_DIRENT_SIZE(name_length) ((VFS_DIRENT_BASE_SIZE + (name_length) + 1 + 15) & (~0xF))
#define VFS_DIRENT_MAX_SIZE (VFS_DIRENT_BASE_SIZE + 256 + 1)
typedef struct vfs_dirent {
uint32_t inode;
uint32_t offset_next;
uint16_t reclen;
uint8_t type;
char name[];
} vfs_dirent_t;
int vfs_mount(const char *path, const char *device, const char *driver);
// https://man7.org/linux/man-pages/man2/open.2.html
vfs_fd_t *vfs_open(const char *path, int flags, int mode);
void vfs_close(vfs_fd_t *fd);
// https://man7.org/linux/man-pages/man2/stat.2.html
int vfs_fstat(vfs_fd_t *fd, stat_t *target, int flags);
// https://man7.org/linux/man-pages/man2/read.2.html
int vfs_read(vfs_fd_t *fd, void *target, size_t size);
// inspiration https://man7.org/linux/man-pages/man2/getdents.2.html
int vfs_getdents(vfs_fd_t *fd, void *target, int count);
#endif //NEW_KERNEL_VFS_H