mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
AK: Make Vector use size_t for its size and capacity
This commit is contained in:
parent
9c6f7d3e7d
commit
ceec1a7d38
94 changed files with 323 additions and 317 deletions
|
@ -668,15 +668,15 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
|||
|
||||
const int block_size = fs().block_size();
|
||||
|
||||
int first_block_logical_index = offset / block_size;
|
||||
int last_block_logical_index = (offset + count) / block_size;
|
||||
size_t first_block_logical_index = offset / block_size;
|
||||
size_t last_block_logical_index = (offset + count) / block_size;
|
||||
if (last_block_logical_index >= m_block_list.size())
|
||||
last_block_logical_index = m_block_list.size() - 1;
|
||||
|
||||
int offset_into_first_block = offset % block_size;
|
||||
|
||||
ssize_t nread = 0;
|
||||
int remaining_count = min((off_t)count, (off_t)size() - offset);
|
||||
size_t remaining_count = min((off_t)count, (off_t)size() - offset);
|
||||
u8* out = buffer;
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -685,7 +685,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
|||
|
||||
u8 block[max_block_size];
|
||||
|
||||
for (int bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
auto block_index = m_block_list[bi];
|
||||
ASSERT(block_index);
|
||||
bool success = fs().read_block(block_index, block, description);
|
||||
|
@ -694,8 +694,8 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
int offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
int num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
size_t offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
size_t num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
memcpy(out, block + offset_into_block, num_bytes_to_copy);
|
||||
remaining_count -= num_bytes_to_copy;
|
||||
nread += num_bytes_to_copy;
|
||||
|
@ -712,8 +712,8 @@ KResult Ext2FSInode::resize(u64 new_size)
|
|||
return KSuccess;
|
||||
|
||||
u64 block_size = fs().block_size();
|
||||
int blocks_needed_before = ceil_div(old_size, block_size);
|
||||
int blocks_needed_after = ceil_div(new_size, block_size);
|
||||
size_t blocks_needed_before = ceil_div(old_size, block_size);
|
||||
size_t blocks_needed_after = ceil_div(new_size, block_size);
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
dbgprintf("Ext2FSInode::resize(): blocks needed before (size was %Q): %d\n", old_size, blocks_needed_before);
|
||||
|
@ -777,7 +777,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
}
|
||||
}
|
||||
|
||||
const ssize_t block_size = fs().block_size();
|
||||
const size_t block_size = fs().block_size();
|
||||
u64 old_size = size();
|
||||
u64 new_size = max(static_cast<u64>(offset) + count, (u64)size());
|
||||
|
||||
|
@ -793,17 +793,17 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
int first_block_logical_index = offset / block_size;
|
||||
int last_block_logical_index = (offset + count) / block_size;
|
||||
size_t first_block_logical_index = offset / block_size;
|
||||
size_t last_block_logical_index = (offset + count) / block_size;
|
||||
if (last_block_logical_index >= m_block_list.size())
|
||||
last_block_logical_index = m_block_list.size() - 1;
|
||||
|
||||
int offset_into_first_block = offset % block_size;
|
||||
size_t offset_into_first_block = offset % block_size;
|
||||
|
||||
int last_logical_block_index_in_file = new_size / block_size;
|
||||
size_t last_logical_block_index_in_file = new_size / block_size;
|
||||
|
||||
ssize_t nwritten = 0;
|
||||
int remaining_count = min((off_t)count, (off_t)new_size - offset);
|
||||
size_t remaining_count = min((off_t)count, (off_t)new_size - offset);
|
||||
const u8* in = data;
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -811,9 +811,9 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
#endif
|
||||
|
||||
auto buffer_block = ByteBuffer::create_uninitialized(block_size);
|
||||
for (int bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
int offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
int num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
size_t offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
size_t num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
|
||||
ByteBuffer block;
|
||||
if (offset_into_block != 0 || num_bytes_to_copy != block_size) {
|
||||
|
@ -828,8 +828,8 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
|
||||
memcpy(block.data() + offset_into_block, in, num_bytes_to_copy);
|
||||
if (bi == last_logical_block_index_in_file && num_bytes_to_copy < block_size) {
|
||||
int padding_start = new_size % block_size;
|
||||
int padding_bytes = block_size - padding_start;
|
||||
size_t padding_start = new_size % block_size;
|
||||
size_t padding_bytes = block_size - padding_start;
|
||||
#ifdef EXT2_DEBUG
|
||||
dbg() << "Ext2FS: Padding last block of file with zero x " << padding_bytes << " (new_size=" << new_size << ", offset_into_block=" << offset_into_block << ", num_bytes_to_copy=" << num_bytes_to_copy << ")";
|
||||
#endif
|
||||
|
@ -905,7 +905,7 @@ bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
|
|||
auto directory_data = ByteBuffer::create_uninitialized(occupied_size);
|
||||
|
||||
BufferStream stream(directory_data);
|
||||
for (int i = 0; i < entries.size(); ++i) {
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
auto& entry = entries[i];
|
||||
|
||||
int record_length = EXT2_DIR_REC_LEN(entry.name_length);
|
||||
|
@ -1087,7 +1087,7 @@ Ext2FS::BlockIndex Ext2FS::allocate_block(GroupIndex preferred_group_index)
|
|||
return block_index;
|
||||
}
|
||||
|
||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_index, int count)
|
||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -1424,7 +1424,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(InodeIdentifier parent_id,
|
|||
dbgprintf("Ext2FS: Adding inode '%s' (mode %o) to parent directory %u:\n", name.characters(), mode, parent_inode->identifier().index());
|
||||
#endif
|
||||
|
||||
auto needed_blocks = ceil_div(size, block_size());
|
||||
size_t needed_blocks = ceil_div(size, block_size());
|
||||
if ((size_t)needed_blocks > super_block().s_free_blocks_count) {
|
||||
dbg() << "Ext2FS: create_inode: not enough free blocks";
|
||||
return KResult(-ENOSPC);
|
||||
|
|
|
@ -135,7 +135,7 @@ private:
|
|||
|
||||
BlockIndex first_block_index() const;
|
||||
InodeIndex find_a_free_inode(GroupIndex preferred_group, off_t expected_size);
|
||||
Vector<BlockIndex> allocate_blocks(GroupIndex preferred_group_index, int count);
|
||||
Vector<BlockIndex> allocate_blocks(GroupIndex preferred_group_index, size_t count);
|
||||
BlockIndex allocate_block(GroupIndex preferred_group_index);
|
||||
GroupIndex group_index_from_inode(InodeIndex) const;
|
||||
GroupIndex group_index_from_block_index(BlockIndex) const;
|
||||
|
|
|
@ -145,7 +145,7 @@ static inline int to_fd(const InodeIdentifier& identifier)
|
|||
return (identifier.index() & 0xff) - FI_MaxStaticFileIndex;
|
||||
}
|
||||
|
||||
static inline int to_sys_index(const InodeIdentifier& identifier)
|
||||
static inline size_t to_sys_index(const InodeIdentifier& identifier)
|
||||
{
|
||||
ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
|
||||
ASSERT(to_proc_file_type(identifier) == FI_Root_sys_variable);
|
||||
|
@ -1271,7 +1271,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
|||
break;
|
||||
|
||||
case FI_Root_sys:
|
||||
for (int i = 1; i < sys_variables().size(); ++i) {
|
||||
for (size_t i = 1; i < sys_variables().size(); ++i) {
|
||||
auto& variable = sys_variables()[i];
|
||||
callback({ variable.name.characters(), variable.name.length(), sys_var_to_identifier(fsid(), i), 0 });
|
||||
}
|
||||
|
@ -1356,7 +1356,7 @@ RefPtr<Inode> ProcFSInode::lookup(StringView name)
|
|||
}
|
||||
|
||||
if (proc_file_type == FI_Root_sys) {
|
||||
for (int i = 1; i < sys_variables().size(); ++i) {
|
||||
for (size_t i = 1; i < sys_variables().size(); ++i) {
|
||||
auto& variable = sys_variables()[i];
|
||||
if (name == variable.name)
|
||||
return fs().get_inode(sys_var_to_identifier(fsid(), i));
|
||||
|
|
|
@ -93,7 +93,7 @@ KResult VFS::unmount(InodeIdentifier guest_inode_id)
|
|||
LOCKER(m_lock);
|
||||
dbg() << "VFS: unmount called with inode " << guest_inode_id;
|
||||
|
||||
for (int i = 0; i < m_mounts.size(); ++i) {
|
||||
for (size_t i = 0; i < m_mounts.size(); ++i) {
|
||||
auto& mount = m_mounts.at(i);
|
||||
if (mount.guest() == guest_inode_id) {
|
||||
auto result = mount.guest_fs().prepare_to_unmount();
|
||||
|
@ -788,7 +788,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
|
|||
|
||||
NonnullRefPtr<Custody> custody = path[0] == '/' ? current_root : base;
|
||||
|
||||
for (int i = 0; i < parts.size(); ++i) {
|
||||
for (size_t i = 0; i < parts.size(); ++i) {
|
||||
Custody& parent = custody;
|
||||
auto parent_metadata = parent.inode().metadata();
|
||||
if (!parent_metadata.is_directory())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue