mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
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:
parent
e8aae033f1
commit
c0e88b9710
Notes:
sideshowbarker
2024-07-18 22:43:13 +09:00
Author: https://github.com/petelliott
Commit: c0e88b9710
Pull-request: https://github.com/SerenityOS/serenity/pull/5187
6 changed files with 53 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue