2021-05-19 11:31:43 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Justin Mietzner <sw1tchbl4d3@sw1tchbl4d3.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/FileSystem/Custody.h>
|
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-07 00:09:48 +01:00
|
|
|
ErrorOr<FlatPtr> Process::do_statvfs(FileSystem const& fs, Custody const* custody, statvfs* buf)
|
2021-05-19 11:31:43 +02:00
|
|
|
{
|
|
|
|
statvfs kernelbuf = {};
|
|
|
|
|
|
|
|
kernelbuf.f_bsize = static_cast<u64>(fs.block_size());
|
|
|
|
kernelbuf.f_frsize = fs.fragment_size();
|
|
|
|
kernelbuf.f_blocks = fs.total_block_count();
|
|
|
|
kernelbuf.f_bfree = fs.free_block_count();
|
|
|
|
|
|
|
|
// FIXME: Implement "available blocks" into Filesystem
|
|
|
|
kernelbuf.f_bavail = fs.free_block_count();
|
|
|
|
|
|
|
|
kernelbuf.f_files = fs.total_inode_count();
|
|
|
|
kernelbuf.f_ffree = fs.free_inode_count();
|
|
|
|
kernelbuf.f_favail = fs.free_inode_count(); // FIXME: same as f_bavail
|
|
|
|
|
2021-11-18 15:11:31 +01:00
|
|
|
kernelbuf.f_fsid = fs.fsid().value();
|
2021-05-19 11:31:43 +02:00
|
|
|
|
|
|
|
kernelbuf.f_namemax = 255;
|
|
|
|
|
2022-03-29 02:53:12 +02:00
|
|
|
(void)fs.class_name().copy_characters_to_buffer(kernelbuf.f_basetype, FSTYPSZ);
|
|
|
|
|
2021-11-07 00:09:48 +01:00
|
|
|
if (custody)
|
|
|
|
kernelbuf.f_flag = custody->mount_flags();
|
2021-05-19 11:31:43 +02:00
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
TRY(copy_to_user(buf, &kernelbuf));
|
|
|
|
return 0;
|
2021-05-19 11:31:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
ErrorOr<FlatPtr> Process::sys$statvfs(Userspace<Syscall::SC_statvfs_params const*> user_params)
|
2021-05-19 11:31:43 +02:00
|
|
|
{
|
2021-07-18 11:20:12 -07:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2021-12-29 01:11:45 -08:00
|
|
|
TRY(require_promise(Pledge::rpath));
|
2021-09-05 17:51:37 +02:00
|
|
|
auto params = TRY(copy_typed_from_user(user_params));
|
2021-05-19 11:31:43 +02:00
|
|
|
|
2021-09-05 17:58:55 +02:00
|
|
|
auto path = TRY(get_syscall_path_argument(params.path));
|
2021-11-07 00:09:48 +01:00
|
|
|
|
|
|
|
auto custody = TRY(VirtualFileSystem::the().resolve_path(path->view(), current_directory(), nullptr, 0));
|
|
|
|
auto& inode = custody->inode();
|
|
|
|
auto const& fs = inode.fs();
|
|
|
|
|
|
|
|
return do_statvfs(fs, custody, params.buf);
|
2021-05-19 11:31:43 +02:00
|
|
|
}
|
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<FlatPtr> Process::sys$fstatvfs(int fd, statvfs* buf)
|
2021-05-19 11:31:43 +02:00
|
|
|
{
|
2022-03-08 15:37:32 +01:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 01:11:45 -08:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-05-19 11:31:43 +02:00
|
|
|
|
2022-01-29 01:22:28 +01:00
|
|
|
auto description = TRY(open_file_description(fd));
|
2021-12-18 18:37:21 +01:00
|
|
|
auto const* inode = description->inode();
|
2021-11-07 00:09:48 +01:00
|
|
|
if (inode == nullptr)
|
|
|
|
return ENOENT;
|
|
|
|
|
|
|
|
// FIXME: The custody that we pass in might be outdated. However, this only affects the mount flags.
|
|
|
|
return do_statvfs(inode->fs(), description->custody(), buf);
|
2021-05-19 11:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|