2021-05-19 05:31:43 -04: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>
|
2023-02-24 12:45:37 -05:00
|
|
|
#include <Kernel/Tasks/Process.h>
|
2021-05-19 05:31:43 -04:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-06 19:09:48 -04:00
|
|
|
ErrorOr<FlatPtr> Process::do_statvfs(FileSystem const& fs, Custody const* custody, statvfs* buf)
|
2021-05-19 05:31:43 -04:00
|
|
|
{
|
|
|
|
statvfs kernelbuf = {};
|
|
|
|
|
2023-07-24 16:17:19 -04:00
|
|
|
kernelbuf.f_bsize = static_cast<u64>(fs.logical_block_size());
|
2021-05-19 05:31:43 -04:00
|
|
|
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 09:11:31 -05:00
|
|
|
kernelbuf.f_fsid = fs.fsid().value();
|
2021-05-19 05:31:43 -04:00
|
|
|
|
|
|
|
kernelbuf.f_namemax = 255;
|
|
|
|
|
2022-03-28 20:53:12 -04:00
|
|
|
(void)fs.class_name().copy_characters_to_buffer(kernelbuf.f_basetype, FSTYPSZ);
|
|
|
|
|
2021-11-06 19:09:48 -04:00
|
|
|
if (custody)
|
|
|
|
kernelbuf.f_flag = custody->mount_flags();
|
2021-05-19 05:31:43 -04:00
|
|
|
|
2021-11-07 18:51:39 -05:00
|
|
|
TRY(copy_to_user(buf, &kernelbuf));
|
|
|
|
return 0;
|
2021-05-19 05:31:43 -04:00
|
|
|
}
|
|
|
|
|
2022-04-01 13:58:27 -04:00
|
|
|
ErrorOr<FlatPtr> Process::sys$statvfs(Userspace<Syscall::SC_statvfs_params const*> user_params)
|
2021-05-19 05:31:43 -04:00
|
|
|
{
|
2022-08-17 16:03:04 -04:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 04:11:45 -05:00
|
|
|
TRY(require_promise(Pledge::rpath));
|
2021-09-05 11:51:37 -04:00
|
|
|
auto params = TRY(copy_typed_from_user(user_params));
|
2021-05-19 05:31:43 -04:00
|
|
|
|
2021-09-05 11:58:55 -04:00
|
|
|
auto path = TRY(get_syscall_path_argument(params.path));
|
2021-11-06 19:09:48 -04:00
|
|
|
|
2024-07-12 02:21:07 -04:00
|
|
|
auto custody = TRY(VirtualFileSystem::resolve_path(vfs_root_context(), credentials(), path->view(), current_directory(), nullptr, 0));
|
2021-11-06 19:09:48 -04:00
|
|
|
auto& inode = custody->inode();
|
|
|
|
auto const& fs = inode.fs();
|
|
|
|
|
|
|
|
return do_statvfs(fs, custody, params.buf);
|
2021-05-19 05:31:43 -04:00
|
|
|
}
|
|
|
|
|
2021-11-07 18:51:39 -05:00
|
|
|
ErrorOr<FlatPtr> Process::sys$fstatvfs(int fd, statvfs* buf)
|
2021-05-19 05:31:43 -04:00
|
|
|
{
|
2022-03-08 09:37:32 -05:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 04:11:45 -05:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-05-19 05:31:43 -04:00
|
|
|
|
2022-01-28 19:22:28 -05:00
|
|
|
auto description = TRY(open_file_description(fd));
|
2021-12-18 12:37:21 -05:00
|
|
|
auto const* inode = description->inode();
|
2021-11-06 19:09:48 -04: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 05:31:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|