mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 10:15:10 +00:00

It is now possible to mount ext2 `DiskDevice` devices under Serenity on any folder in the root filesystem. Currently any user can do this with any permissions. There's a fair amount of assumptions made here too, that might not be too good, but can be worked on in the future. This is a good start to allow more dynamic operation under the OS itself. It is also currently impossible to unmount and such, and devices will fail to mount in Linux as the FS 'needs to be cleaned'. I'll work on getting `umount` done ASAP to rectify this (as well as working on less assumption-making in the mount syscall. We don't want to just be able to mount DiskDevices!). This could probably be fixed with some `-t` flag or something similar.
30 lines
915 B
C++
30 lines
915 B
C++
#include <Kernel/Devices/DiskDevice.h>
|
|
|
|
DiskDevice::DiskDevice(int major, int minor)
|
|
: BlockDevice(major, minor)
|
|
{
|
|
}
|
|
|
|
DiskDevice::~DiskDevice()
|
|
{
|
|
}
|
|
|
|
bool DiskDevice::read(DiskOffset offset, unsigned length, u8* out) const
|
|
{
|
|
ASSERT((offset % block_size()) == 0);
|
|
ASSERT((length % block_size()) == 0);
|
|
u32 first_block = offset / block_size();
|
|
u32 end_block = (offset + length) / block_size();
|
|
return const_cast<DiskDevice*>(this)->read_blocks(first_block, end_block - first_block, out);
|
|
}
|
|
|
|
bool DiskDevice::write(DiskOffset offset, unsigned length, const u8* in)
|
|
{
|
|
ASSERT((offset % block_size()) == 0);
|
|
ASSERT((length % block_size()) == 0);
|
|
u32 first_block = offset / block_size();
|
|
u32 end_block = (offset + length) / block_size();
|
|
ASSERT(first_block <= 0xffffffff);
|
|
ASSERT(end_block <= 0xffffffff);
|
|
return write_blocks(first_block, end_block - first_block, in);
|
|
}
|