forked from Bananymous/banan-os
Kenrel: RamInode now implements truncate()
This commit is contained in:
parent
1a1e584cba
commit
5a5656b2d3
|
@ -33,6 +33,8 @@ namespace Kernel
|
|||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
||||
|
||||
virtual BAN::ErrorOr<void> truncate(size_t) override;
|
||||
|
||||
void add_link() { m_inode_info.nlink++; }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -57,20 +57,19 @@ namespace Kernel
|
|||
BAN::ErrorOr<size_t> RamInode::write(size_t offset, const void* buffer, size_t bytes)
|
||||
{
|
||||
if (offset + bytes > (size_t)size())
|
||||
{
|
||||
TRY(m_data.resize(offset + bytes));
|
||||
if (offset > (size_t)size())
|
||||
memset(m_data.data() + offset, 0, offset - size());
|
||||
|
||||
m_inode_info.size = m_data.size();
|
||||
m_inode_info.blocks = BAN::Math::div_round_up<size_t>(size(), blksize());
|
||||
}
|
||||
|
||||
TRY(truncate(offset + bytes));
|
||||
memcpy(m_data.data() + offset, buffer, bytes);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> RamInode::truncate(size_t new_size)
|
||||
{
|
||||
TRY(m_data.resize(new_size, 0));
|
||||
m_inode_info.size = m_data.size();
|
||||
m_inode_info.blocks = BAN::Math::div_round_up<size_t>(size(), blksize());
|
||||
return {};
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
RAM DIRECTORY INODE
|
||||
|
|
Loading…
Reference in New Issue