From 45a1a7e1e6cb3e88d6f70b161f8b8ada1bded246 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 19 May 2021 11:32:53 +0200 Subject: [PATCH] LibC: Add functions for the new statvfs syscalls This commit adds the statvfs() and fstatvfs() functions into LibC. --- Userland/Libraries/LibC/CMakeLists.txt | 1 + Userland/Libraries/LibC/sys/statvfs.cpp | 26 ++++++++++++++++++ Userland/Libraries/LibC/sys/statvfs.h | 36 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 Userland/Libraries/LibC/sys/statvfs.cpp create mode 100644 Userland/Libraries/LibC/sys/statvfs.h diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index 44f7e46bcc..9df1b2a559 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -46,6 +46,7 @@ set(LIBC_SOURCES sys/socket.cpp sys/uio.cpp sys/wait.cpp + sys/statvfs.cpp termcap.cpp termios.cpp time.cpp diff --git a/Userland/Libraries/LibC/sys/statvfs.cpp b/Userland/Libraries/LibC/sys/statvfs.cpp new file mode 100644 index 0000000000..d49e38623b --- /dev/null +++ b/Userland/Libraries/LibC/sys/statvfs.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021, Justin Mietzner + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +extern "C" { + +int statvfs(const char* path, struct statvfs* buf) +{ + Syscall::SC_statvfs_params params { { path, strlen(path) }, buf }; + int rc = syscall(SC_statvfs, ¶ms); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + +int fstatvfs(int fd, struct statvfs* buf) +{ + int rc = syscall(SC_fstatvfs, fd, buf); + __RETURN_WITH_ERRNO(rc, rc, -1); +} +} diff --git a/Userland/Libraries/LibC/sys/statvfs.h b/Userland/Libraries/LibC/sys/statvfs.h new file mode 100644 index 0000000000..4b34479a69 --- /dev/null +++ b/Userland/Libraries/LibC/sys/statvfs.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021, Justin Mietzner + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +__BEGIN_DECLS + +#define ST_RDONLY 0x1 +#define ST_NOSUID 0x2 + +struct statvfs { + unsigned long f_bsize; + unsigned long f_frsize; + fsblkcnt_t f_blocks; + fsblkcnt_t f_bfree; + fsblkcnt_t f_bavail; + + fsfilcnt_t f_files; + fsfilcnt_t f_ffree; + fsfilcnt_t f_favail; + + unsigned long f_fsid; + unsigned long f_flag; + unsigned long f_namemax; +}; + +int statvfs(const char* path, struct statvfs* buf); +int fstatvfs(int fd, struct statvfs* buf); + +__END_DECLS