Kernel: Make File::truncate() take a u64

No point in taking a signed type here. We validate at the syscall layer
and then pass around a u64 from then on.
This commit is contained in:
Andreas Kling 2020-02-08 12:07:04 +01:00
parent 42d41fdf94
commit 7291370478
Notes: sideshowbarker 2024-07-19 09:31:58 +09:00
11 changed files with 12 additions and 12 deletions

View File

@ -1598,10 +1598,10 @@ KResult Ext2FSInode::chown(uid_t uid, gid_t gid)
return KSuccess;
}
KResult Ext2FSInode::truncate(off_t size)
KResult Ext2FSInode::truncate(u64 size)
{
LOCKER(m_lock);
if ((off_t)m_raw_inode.i_size == size)
if (static_cast<u64>(m_raw_inode.i_size) == size)
return KSuccess;
auto result = resize(size);
if (result.is_error())

View File

@ -70,7 +70,7 @@ private:
virtual size_t directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResult truncate(off_t) override;
virtual KResult truncate(u64) override;
bool write_directory(const Vector<FS::DirectoryEntry>&);
void populate_lookup_cache() const;

View File

@ -82,7 +82,7 @@ public:
virtual String absolute_path(const FileDescription&) const = 0;
virtual KResult truncate(off_t) { return KResult(-EINVAL); }
virtual KResult truncate(u64) { return KResult(-EINVAL); }
virtual KResult chown(uid_t, gid_t) { return KResult(-EBADF); }
virtual KResult chmod(mode_t) { return KResult(-EBADF); }

View File

@ -283,7 +283,7 @@ KResultOr<Region*> FileDescription::mmap(Process& process, VirtualAddress vaddr,
return m_file->mmap(process, *this, vaddr, offset, size, prot);
}
KResult FileDescription::truncate(off_t length)
KResult FileDescription::truncate(u64 length)
{
LOCKER(m_lock);
return m_file->truncate(length);

View File

@ -130,7 +130,7 @@ public:
void set_original_inode(Badge<VFS>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
KResult truncate(off_t);
KResult truncate(u64);
off_t offset() const { return m_current_offset; }

View File

@ -79,7 +79,7 @@ public:
virtual size_t directory_entry_count() const = 0;
virtual KResult chmod(mode_t) = 0;
virtual KResult chown(uid_t, gid_t) = 0;
virtual KResult truncate(off_t) { return KSuccess; }
virtual KResult truncate(u64) { return KSuccess; }
virtual KResultOr<NonnullRefPtr<Custody>> resolve_as_link(Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0) const;
LocalSocket* socket() { return m_socket.ptr(); }

View File

@ -74,7 +74,7 @@ String InodeFile::absolute_path(const FileDescription& description) const
return description.absolute_path();
}
KResult InodeFile::truncate(off_t size)
KResult InodeFile::truncate(u64 size)
{
auto truncate_result = m_inode->truncate(size);
if (truncate_result.is_error())

View File

@ -51,7 +51,7 @@ public:
virtual String absolute_path(const FileDescription&) const override;
virtual KResult truncate(off_t) override;
virtual KResult truncate(u64) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResult chmod(mode_t) override;

View File

@ -327,7 +327,7 @@ KResult TmpFSInode::remove_child(const StringView& name)
return KSuccess;
}
KResult TmpFSInode::truncate(off_t size)
KResult TmpFSInode::truncate(u64 size)
{
LOCKER(m_lock);
ASSERT(!is_directory());

View File

@ -85,7 +85,7 @@ public:
virtual size_t directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResult truncate(off_t) override;
virtual KResult truncate(u64) override;
virtual int set_atime(time_t) override;
virtual int set_ctime(time_t) override;
virtual int set_mtime(time_t) override;

View File

@ -3868,7 +3868,7 @@ int Process::sys$ftruncate(int fd, off_t length)
return -EBADF;
if (!description->is_writable())
return -EBADF;
return description->truncate(length);
return description->truncate(static_cast<u64>(length));
}
int Process::sys$watch_file(const char* user_path, size_t path_length)