From f0af695b6c3289a041e8fce8926721063796c596 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 22 Nov 2023 21:06:33 +0100 Subject: Meta: Use dirent as a general include file This include file is shared by the kernel and libc --- include/dirent.h | 33 +++++++++++++++++++++++++++++++++ kernel/Makefile | 2 +- kernel/fs/vfs.h | 6 +----- userland/libc/include/dirent.h | 31 ------------------------------- 4 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 include/dirent.h delete mode 100644 userland/libc/include/dirent.h diff --git a/include/dirent.h b/include/dirent.h new file mode 100644 index 0000000..153d36a --- /dev/null +++ b/include/dirent.h @@ -0,0 +1,33 @@ +#ifndef DIRENT_H +#define DIRENT_H +#include +#include +#include +#include +#include +#ifndef KERNEL +#include +#endif + +#define S_ISREG(_m) (_m & (STAT_REG)) +#define S_ISDIR(_m) (_m & (STAT_DIR)) + +struct dirent { + ino_t d_ino; // File serial number. + char d_name[PATH_MAX]; // Filename string of entry. +}; + +typedef struct { + int fd; + struct dirent internal_direntry; + int dir_num; +} DIR; + +DIR *opendir(const char *dirname); +struct dirent *readdir(DIR *dir); +int closedir(DIR *dirp); +int alphasort(const struct dirent **d1, const struct dirent **d2); +int scandir(const char *dir, struct dirent ***namelist, + int (*sel)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)); +#endif diff --git a/kernel/Makefile b/kernel/Makefile index e2c3db2..0542b49 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,7 +1,7 @@ CC="i686-sb-gcc" AS="i686-sb-as" OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o cpu/int_syscall.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o -CFLAGS = -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign +CFLAGS = -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL INCLUDE=-I./includes/ -I../include/ -I./libc/include/ all: myos.iso diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h index 76c0a0c..d042acf 100644 --- a/kernel/fs/vfs.h +++ b/kernel/fs/vfs.h @@ -10,6 +10,7 @@ typedef struct vfs_mounts vfs_mounts_t; #include #include #include +#include // FIXME: Is there some standard value for this? #define O_NONBLOCK (1 << 0) @@ -38,11 +39,6 @@ struct vfs_mounts { vfs_inode_t *local_root; }; -struct dirent { - unsigned int d_ino; // File serial number. - char d_name[PATH_MAX]; // Filename string of entry. -}; - struct vfs_fd { size_t offset; int flags; diff --git a/userland/libc/include/dirent.h b/userland/libc/include/dirent.h deleted file mode 100644 index 9f25cbf..0000000 --- a/userland/libc/include/dirent.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef DIRENT_H -#define DIRENT_H -#include -#include -#include -#include -#include -#include - -#define S_ISREG(_m) (_m & (STAT_REG)) -#define S_ISDIR(_m) (_m & (STAT_DIR)) - -struct dirent { - ino_t d_ino; // File serial number. - char d_name[PATH_MAX]; // Filename string of entry. -}; - -typedef struct { - int fd; - struct dirent internal_direntry; - int dir_num; -} DIR; - -DIR *opendir(const char *dirname); -struct dirent *readdir(DIR *dir); -int closedir(DIR *dirp); -int alphasort(const struct dirent **d1, const struct dirent **d2); -int scandir(const char *dir, struct dirent ***namelist, - int (*sel)(const struct dirent *), - int (*compar)(const struct dirent **, const struct dirent **)); -#endif -- cgit v1.2.3