Kernel: Add FIBMAP ioctl to Ext2FileSystem

FIBMAP is a linux ioctl that gives the location on disk of a specific
block of a file
This commit is contained in:
Peter Elliott 2021-01-30 13:12:49 -07:00 committed by Andreas Kling
parent e8aae033f1
commit c0e88b9710
Notes: sideshowbarker 2024-07-18 22:43:13 +09:00
6 changed files with 53 additions and 1 deletions

View file

@ -32,6 +32,8 @@
#include <Kernel/Process.h>
#include <Kernel/VM/PrivateInodeVMObject.h>
#include <Kernel/VM/SharedInodeVMObject.h>
#include <LibC/errno_numbers.h>
#include <LibC/sys/ioctl_numbers.h>
namespace Kernel {
@ -69,6 +71,36 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, size_t offset,
return nwritten;
}
int InodeFile::ioctl(FileDescription& description, unsigned request, FlatPtr arg)
{
(void)description;
switch (request) {
case FIBMAP: {
if (!Process::current()->is_superuser())
return -EPERM;
int block_number = 0;
if (!copy_from_user(&block_number, (int*)arg))
return -EFAULT;
if (block_number < 0)
return -EINVAL;
auto block_address = inode().get_block_address(block_number);
if (block_address.is_error())
return block_address.error();
if (!copy_to_user((int*)arg, &block_address.value()))
return -EFAULT;
return 0;
}
default:
return -EINVAL;
}
}
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& description, const Range& range, size_t offset, int prot, bool shared)
{
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.