diff options
author | Anton Kling <anton@kling.gg> | 2024-04-17 17:06:16 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-04-17 17:06:16 +0200 |
commit | 620d37f41747e943648544d1fd1567d386c91e04 (patch) | |
tree | bd6d616aca8a853f3b90cfd176bba4d37575e42a /userland | |
parent | d0cca44913356f8ce15e15216b0e26c2e74b4d06 (diff) |
Kernel/LibC: Add fstat() and remove stat() syscall
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libc/Makefile | 2 | ||||
-rw-r--r-- | userland/libc/include/syscall.h | 7 | ||||
-rw-r--r-- | userland/libc/sys/stat.h | 30 | ||||
-rw-r--r-- | userland/libc/sys/stat/fstat.c | 9 | ||||
-rw-r--r-- | userland/libc/sys/stat/stat.c | 13 |
5 files changed, 19 insertions, 42 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index af5fa59..b7e14a7 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -3,7 +3,7 @@ AR="i686-sb-ar" AS="i686-sb-as" #CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type CFLAGS = -ggdb -ffreestanding -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o all: libc.a %.o: %.c diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h index 1e8c86c..245b482 100644 --- a/userland/libc/include/syscall.h +++ b/userland/libc/include/syscall.h @@ -28,7 +28,7 @@ #define SYS_SOCKET 20 #define SYS_SHM_OPEN 21 #define SYS_FTRUNCATE 22 -#define SYS_STAT 23 +#define SYS_FSTAT 23 #define SYS_MSLEEP 24 #define SYS_UPTIME 25 #define SYS_MKDIR 26 @@ -167,9 +167,4 @@ typedef struct SYS_FTRUNCATE_PARAMS { int fildes; size_t length; } __attribute__((packed)) SYS_FTRUNCATE_PARAMS; - -typedef struct SYS_STAT_PARAMS { - const char *pathname; - struct stat *statbuf; -} __attribute__((packed)) SYS_STAT_PARAMS; #endif diff --git a/userland/libc/sys/stat.h b/userland/libc/sys/stat.h deleted file mode 100644 index 2fe6cdc..0000000 --- a/userland/libc/sys/stat.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef STAT_H -#define STAT_H -#include <sys/types.h> -#include <time.h> - -struct stat { - dev_t st_dev; // Device ID of device containing file. - ino_t st_ino; // File serial number. - mode_t st_mode; // Mode of file (see below). - nlink_t st_nlink; // Number of hard links to the file. - uid_t st_uid; // User ID of file. - gid_t st_gid; // Group ID of file. - dev_t st_rdev; // Device ID (if file is character or block special). - off_t st_size; // For regular files, the file size in bytes. - // For symbolic links, the length in bytes of the - // pathname contained in the symbolic link. - // For a shared memory object, the length in bytes. - // For a typed memory object, the length in bytes. - // For other file types, the use of this field is - // unspecified. - struct timespec st_atime; // Last data access timestamp. - struct timespec st_mtime; // Last data modification timestamp. - struct timespec st_ctime; // Last file status change timestamp. - blksize_t st_blksize; // A file system-specific preferred I/O block size - // for this object. In some file system types, this - // may vary from file to file. - blkcnt_t st_blocks; // Number of blocks allocated for this object. -}; -int stat(const char *path, struct stat *buf); -#endif diff --git a/userland/libc/sys/stat/fstat.c b/userland/libc/sys/stat/fstat.c new file mode 100644 index 0000000..13b2b04 --- /dev/null +++ b/userland/libc/sys/stat/fstat.c @@ -0,0 +1,9 @@ +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <sys/stat.h> +#include <syscall.h> + +int fstat(int fd, struct stat *buf) { + RC_ERRNO(syscall(SYS_FSTAT, fd, buf, 0, 0, 0)); +} diff --git a/userland/libc/sys/stat/stat.c b/userland/libc/sys/stat/stat.c index e37223e..00b4f52 100644 --- a/userland/libc/sys/stat/stat.c +++ b/userland/libc/sys/stat/stat.c @@ -1,13 +1,16 @@ #include <assert.h> #include <errno.h> +#include <fcntl.h> #include <stdio.h> #include <sys/stat.h> #include <syscall.h> int stat(const char *path, struct stat *buf) { - SYS_STAT_PARAMS args = { - .pathname = path, - .statbuf = buf, - }; - RC_ERRNO(syscall(SYS_STAT, &args, 0, 0, 0, 0)); + int fd = open(path, O_RDONLY); + if (-1 == fd) { + return -1; + } + int rc = fstat(fd, buf); + close(fd); + return rc; } |