From 85b886c2e0dcffaccc28c6494c32034c83f73ef8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 2 Dec 2018 23:34:50 +0100 Subject: [PATCH] Make it possible to build the Kernel on a macOS host. It still requires an ELF compiler and linker, but at least it builds. I need to get rid of the "Unix" namespace. This does a lot of that. --- AK/BufferStream.h | 4 ++-- AK/Types.h | 9 +++++++-- Kernel/FIFO.h | 4 ++-- Kernel/Process.h | 2 +- Kernel/StdLib.h | 2 +- Kernel/TTY.cpp | 4 ++-- Kernel/TTY.h | 4 ++-- Kernel/elf.h | 12 ++---------- Kernel/kmalloc.cpp | 8 ++++---- Kernel/kmalloc.h | 8 ++++---- Kernel/types.h | 1 - VirtualFileSystem/CharacterDevice.h | 4 ++-- VirtualFileSystem/DiskBackedFileSystem.h | 4 ++-- VirtualFileSystem/Ext2FileSystem.cpp | 18 +++++++++--------- VirtualFileSystem/Ext2FileSystem.h | 4 ++-- VirtualFileSystem/FileDescriptor.cpp | 10 +++++----- VirtualFileSystem/FileDescriptor.h | 6 +++--- VirtualFileSystem/FileSystem.cpp | 14 +++++++------- VirtualFileSystem/FileSystem.h | 8 ++++---- VirtualFileSystem/FullDevice.cpp | 6 +++--- VirtualFileSystem/FullDevice.h | 4 ++-- VirtualFileSystem/Limits.h | 2 +- VirtualFileSystem/NullDevice.cpp | 4 ++-- VirtualFileSystem/NullDevice.h | 4 ++-- VirtualFileSystem/RandomDevice.cpp | 8 ++++---- VirtualFileSystem/RandomDevice.h | 4 ++-- VirtualFileSystem/SyntheticFileSystem.cpp | 8 ++++---- VirtualFileSystem/SyntheticFileSystem.h | 4 ++-- VirtualFileSystem/UnixTypes.h | 2 -- VirtualFileSystem/ZeroDevice.cpp | 6 +++--- VirtualFileSystem/ZeroDevice.h | 4 ++-- 31 files changed, 88 insertions(+), 94 deletions(-) diff --git a/AK/BufferStream.h b/AK/BufferStream.h index 6d83e73b583..5316e375618 100644 --- a/AK/BufferStream.h +++ b/AK/BufferStream.h @@ -49,11 +49,11 @@ public: m_buffer[m_offset++] = ch; } - Unix::size_t offset() const { return m_offset; } + size_t offset() const { return m_offset; } private: ByteBuffer& m_buffer; - Unix::size_t m_offset { 0 }; + size_t m_offset { 0 }; }; } diff --git a/AK/Types.h b/AK/Types.h index 14e90e0fabd..ba1f1778c45 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -11,18 +11,23 @@ typedef signed short signed_word; typedef signed int signed_dword; typedef signed long long int signed_qword; -typedef dword size_t; -typedef signed_dword ssize_t; +typedef unsigned long size_t; +typedef long ssize_t; + +static_assert(sizeof(size_t) == sizeof(dword)); +static_assert(sizeof(ssize_t) == sizeof(signed_dword)); typedef signed_dword ptrdiff_t; typedef byte uint8_t; typedef word uint16_t; typedef dword uint32_t; +typedef qword uint64_t; typedef signed_byte int8_t; typedef signed_word int16_t; typedef signed_dword int32_t; +typedef signed_qword int64_t; #else #include diff --git a/Kernel/FIFO.h b/Kernel/FIFO.h index 2cb65c4e034..91392cc5aa8 100644 --- a/Kernel/FIFO.h +++ b/Kernel/FIFO.h @@ -16,8 +16,8 @@ public: void open(Direction); void close(Direction); - Unix::ssize_t write(const byte*, Unix::size_t); - Unix::ssize_t read(byte*, Unix::size_t); + ssize_t write(const byte*, size_t); + ssize_t read(byte*, size_t); bool can_read() const; bool can_write() const; diff --git a/Kernel/Process.h b/Kernel/Process.h index 02a2fdc80c5..f036397f2b3 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -141,7 +141,7 @@ public: void* sys$mmap(const Syscall::SC_mmap_params*); int sys$munmap(void*, size_t size); int sys$set_mmap_name(void*, size_t, const char*); - int sys$get_dir_entries(int fd, void*, size_t); + ssize_t sys$get_dir_entries(int fd, void*, size_t); int sys$getcwd(char*, size_t); int sys$chdir(const char*); int sys$sleep(unsigned seconds); diff --git a/Kernel/StdLib.h b/Kernel/StdLib.h index af95546aeb4..d93bfae7d06 100644 --- a/Kernel/StdLib.h +++ b/Kernel/StdLib.h @@ -7,7 +7,7 @@ extern "C" { void memcpy(void*, const void*, dword); void strcpy(char*, const char*); int strcmp(char const*, const char*); -dword strlen(const char*); +size_t strlen(const char*); void *memset(void*, byte, dword); char *strdup(const char*); int memcmp(const void*, const void*, size_t); diff --git a/Kernel/TTY.cpp b/Kernel/TTY.cpp index 8325f56c4ff..a615cecbf22 100644 --- a/Kernel/TTY.cpp +++ b/Kernel/TTY.cpp @@ -14,13 +14,13 @@ void DoubleBuffer::flip() m_read_buffer_index = 0; } -Unix::ssize_t DoubleBuffer::write(const byte* data, size_t size) +ssize_t DoubleBuffer::write(const byte* data, size_t size) { m_write_buffer->append(data, size); return size; } -Unix::ssize_t DoubleBuffer::read(byte* data, size_t size) +ssize_t DoubleBuffer::read(byte* data, size_t size) { if (m_read_buffer_index >= m_read_buffer->size() && !m_write_buffer->isEmpty()) flip(); diff --git a/Kernel/TTY.h b/Kernel/TTY.h index 5d58c44c3f1..dda95e7d41d 100644 --- a/Kernel/TTY.h +++ b/Kernel/TTY.h @@ -13,8 +13,8 @@ public: { } - Unix::ssize_t write(const byte*, size_t); - Unix::ssize_t read(byte*, size_t); + ssize_t write(const byte*, size_t); + ssize_t read(byte*, size_t); bool is_empty() const { return m_read_buffer_index >= m_read_buffer->size() && m_write_buffer->isEmpty(); } diff --git a/Kernel/elf.h b/Kernel/elf.h index c541774d985..4cfe4338ee3 100644 --- a/Kernel/elf.h +++ b/Kernel/elf.h @@ -17,16 +17,11 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef _ELF_H -#define _ELF_H 1 - -#include - -__BEGIN_DECLS +#pragma once /* Standard ELF types. */ -#include +#include /* Type for a 16-bit quantity. */ typedef uint16_t Elf32_Half; @@ -2640,6 +2635,3 @@ typedef Elf32_Addr Elf32_Conflict; #define R_M32R_NUM 256 /* Keep this the last entry. */ -__END_DECLS - -#endif /* elf.h */ diff --git a/Kernel/kmalloc.cpp b/Kernel/kmalloc.cpp index 3ae00605947..09508bc75e0 100644 --- a/Kernel/kmalloc.cpp +++ b/Kernel/kmalloc.cpp @@ -29,8 +29,8 @@ typedef struct static byte alloc_map[POOL_SIZE / CHUNK_SIZE / 8]; -volatile dword sum_alloc = 0; -volatile dword sum_free = POOL_SIZE; +volatile size_t sum_alloc = 0; +volatile size_t sum_free = POOL_SIZE; volatile size_t kmalloc_sum_eternal = 0; volatile size_t kmalloc_sum_page_aligned = 0; @@ -193,12 +193,12 @@ void kfree(void *ptr) #endif } -void* operator new(unsigned int size) +void* operator new(size_t size) { return kmalloc(size); } -void* operator new[](unsigned int size) +void* operator new[](size_t size) { return kmalloc(size); } diff --git a/Kernel/kmalloc.h b/Kernel/kmalloc.h index a4e97319f6a..1cdc26b1c96 100644 --- a/Kernel/kmalloc.h +++ b/Kernel/kmalloc.h @@ -8,10 +8,10 @@ void kfree(void*); bool is_kmalloc_address(void*); -extern volatile dword sum_alloc; -extern volatile dword sum_free; -extern volatile dword kmalloc_sum_eternal; -extern volatile dword kmalloc_sum_page_aligned; +extern volatile size_t sum_alloc; +extern volatile size_t sum_free; +extern volatile size_t kmalloc_sum_eternal; +extern volatile size_t kmalloc_sum_page_aligned; inline void* operator new(size_t, void* p) { return p; } inline void* operator new[](size_t, void* p) { return p; } diff --git a/Kernel/types.h b/Kernel/types.h index f7a46b4fd7e..ce1e380d600 100644 --- a/Kernel/types.h +++ b/Kernel/types.h @@ -17,7 +17,6 @@ typedef dword gid_t; typedef int pid_t; typedef dword time_t; typedef dword suseconds_t; -typedef dword size_t; struct timeval { time_t tv_sec; diff --git a/VirtualFileSystem/CharacterDevice.h b/VirtualFileSystem/CharacterDevice.h index 3c78a84da53..5f2cb778207 100644 --- a/VirtualFileSystem/CharacterDevice.h +++ b/VirtualFileSystem/CharacterDevice.h @@ -14,8 +14,8 @@ public: virtual bool hasDataAvailableForRead() const = 0; - virtual Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) = 0; - virtual Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) = 0; + virtual ssize_t read(byte* buffer, size_t bufferSize) = 0; + virtual ssize_t write(const byte* buffer, size_t bufferSize) = 0; unsigned major() const { return m_major; } unsigned minor() const { return m_minor; } diff --git a/VirtualFileSystem/DiskBackedFileSystem.h b/VirtualFileSystem/DiskBackedFileSystem.h index 934917e96b7..51d3815b02c 100644 --- a/VirtualFileSystem/DiskBackedFileSystem.h +++ b/VirtualFileSystem/DiskBackedFileSystem.h @@ -12,7 +12,7 @@ public: DiskDevice& device() { return *m_device; } const DiskDevice& device() const { return *m_device; } - unsigned blockSize() const { return m_blockSize; } + size_t blockSize() const { return m_blockSize; } protected: explicit DiskBackedFS(RetainPtr&&); @@ -27,7 +27,7 @@ protected: bool writeBlocks(unsigned index, unsigned count, const ByteBuffer&); private: - unsigned m_blockSize { 0 }; + size_t m_blockSize { 0 }; RetainPtr m_device; mutable SpinLock m_blockCacheLock; diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index 7393bf2f29c..96947297fd1 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -325,7 +325,7 @@ RetainPtr Ext2FS::get_inode(InodeIdentifier inode) const return new_inode; } -Unix::ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) +ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) { ASSERT(offset >= 0); if (m_raw_inode.i_size == 0) @@ -335,7 +335,7 @@ Unix::ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, Unix::size_t count, by // This avoids wasting an entire block on short links. (Most links are short.) static const unsigned max_inline_symlink_length = 60; if (is_symlink() && size() < max_inline_symlink_length) { - Unix::ssize_t nread = min((Unix::off_t)size() - offset, static_cast(count)); + ssize_t nread = min((Unix::off_t)size() - offset, static_cast(count)); memcpy(buffer, m_raw_inode.i_block + offset, nread); return nread; } @@ -361,8 +361,8 @@ Unix::ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, Unix::size_t count, by dword offset_into_first_block = offset % block_size; - Unix::ssize_t nread = 0; - Unix::size_t remaining_count = min((Unix::off_t)count, (Unix::off_t)size() - offset); + ssize_t nread = 0; + size_t remaining_count = min((Unix::off_t)count, (Unix::off_t)size() - offset); byte* out = buffer; #ifdef EXT2_DEBUG @@ -387,7 +387,7 @@ Unix::ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, Unix::size_t count, by return nread; } -Unix::ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const +ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const { ASSERT(offset >= 0); ASSERT(inode.fsid() == id()); @@ -411,7 +411,7 @@ Unix::ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset // This avoids wasting an entire block on short links. (Most links are short.) static const unsigned maxInlineSymlinkLength = 60; if (isSymbolicLink(e2inode->i_mode) && e2inode->i_size < maxInlineSymlinkLength) { - Unix::ssize_t nread = min((Unix::off_t)e2inode->i_size - offset, static_cast(count)); + ssize_t nread = min((Unix::off_t)e2inode->i_size - offset, static_cast(count)); memcpy(buffer, e2inode->i_block + offset, nread); return nread; } @@ -431,8 +431,8 @@ Unix::ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset dword offsetIntoFirstBlock = offset % blockSize(); - Unix::ssize_t nread = 0; - Unix::size_t remainingCount = min((Unix::off_t)count, (Unix::off_t)e2inode->i_size - offset); + ssize_t nread = 0; + size_t remainingCount = min((Unix::off_t)count, (Unix::off_t)e2inode->i_size - offset); byte* out = buffer; #ifdef EXT2_DEBUG @@ -453,7 +453,7 @@ Unix::ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset else offsetIntoBlock = 0; - dword numBytesToCopy = min(blockSize() - offsetIntoBlock, remainingCount); + size_t numBytesToCopy = min(blockSize() - offsetIntoBlock, remainingCount); memcpy(out, block.pointer() + offsetIntoBlock, numBytesToCopy); remainingCount -= numBytesToCopy; nread += numBytesToCopy; diff --git a/VirtualFileSystem/Ext2FileSystem.h b/VirtualFileSystem/Ext2FileSystem.h index 194451e0797..1ba6b8ec0bc 100644 --- a/VirtualFileSystem/Ext2FileSystem.h +++ b/VirtualFileSystem/Ext2FileSystem.h @@ -22,7 +22,7 @@ public: private: // ^CoreInode - virtual Unix::ssize_t read_bytes(Unix::off_t, Unix::size_t, byte* buffer, FileDescriptor*) override; + virtual ssize_t read_bytes(Unix::off_t, size_t, byte* buffer, FileDescriptor*) override; virtual void populate_metadata() const override; virtual bool traverse_as_directory(Function) override; virtual InodeIdentifier lookup(const String& name) override; @@ -74,7 +74,7 @@ private: virtual InodeMetadata inodeMetadata(InodeIdentifier) const override; virtual bool set_mtime(InodeIdentifier, dword timestamp) override; virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override; - virtual Unix::ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override; + virtual ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const override; virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) override; virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override; virtual RetainPtr get_inode(InodeIdentifier) const override; diff --git a/VirtualFileSystem/FileDescriptor.cpp b/VirtualFileSystem/FileDescriptor.cpp index aa06a6172a0..d163348688f 100644 --- a/VirtualFileSystem/FileDescriptor.cpp +++ b/VirtualFileSystem/FileDescriptor.cpp @@ -133,7 +133,7 @@ Unix::off_t FileDescriptor::seek(Unix::off_t offset, int whence) return m_currentOffset; } -Unix::ssize_t FileDescriptor::read(byte* buffer, Unix::size_t count) +ssize_t FileDescriptor::read(byte* buffer, size_t count) { if (is_fifo()) { ASSERT(fifo_direction() == FIFO::Reader); @@ -143,12 +143,12 @@ Unix::ssize_t FileDescriptor::read(byte* buffer, Unix::size_t count) // FIXME: What should happen to m_currentOffset? return m_vnode->characterDevice()->read(buffer, count); } - Unix::ssize_t nread = m_vnode->fileSystem()->read_inode_bytes(m_vnode->inode, m_currentOffset, count, buffer, this); + ssize_t nread = m_vnode->fileSystem()->read_inode_bytes(m_vnode->inode, m_currentOffset, count, buffer, this); m_currentOffset += nread; return nread; } -Unix::ssize_t FileDescriptor::write(const byte* data, Unix::size_t size) +ssize_t FileDescriptor::write(const byte* data, size_t size) { if (is_fifo()) { ASSERT(fifo_direction() == FIFO::Writer); @@ -189,7 +189,7 @@ ByteBuffer FileDescriptor::readEntireFile() if (m_vnode->isCharacterDevice()) { auto buffer = ByteBuffer::createUninitialized(1024); - Unix::ssize_t nread = m_vnode->characterDevice()->read(buffer.pointer(), buffer.size()); + ssize_t nread = m_vnode->characterDevice()->read(buffer.pointer(), buffer.size()); buffer.trim(nread); return buffer; } @@ -205,7 +205,7 @@ bool FileDescriptor::isDirectory() const return m_vnode->metadata().isDirectory(); } -ssize_t FileDescriptor::get_dir_entries(byte* buffer, Unix::size_t size) +ssize_t FileDescriptor::get_dir_entries(byte* buffer, size_t size) { auto metadata = m_vnode->metadata(); if (!metadata.isValid()) diff --git a/VirtualFileSystem/FileDescriptor.h b/VirtualFileSystem/FileDescriptor.h index b5836cf4d3c..3c6f655d931 100644 --- a/VirtualFileSystem/FileDescriptor.h +++ b/VirtualFileSystem/FileDescriptor.h @@ -23,14 +23,14 @@ public: int close(); Unix::off_t seek(Unix::off_t, int whence); - Unix::ssize_t read(byte*, Unix::size_t); - Unix::ssize_t write(const byte* data, Unix::size_t); + ssize_t read(byte*, size_t); + ssize_t write(const byte* data, size_t); int stat(Unix::stat*); bool hasDataAvailableForRead(); bool can_write(); - ssize_t get_dir_entries(byte* buffer, Unix::size_t); + ssize_t get_dir_entries(byte* buffer, size_t); ByteBuffer readEntireFile(); diff --git a/VirtualFileSystem/FileSystem.cpp b/VirtualFileSystem/FileSystem.cpp index e454fd352bd..6551cb4271b 100644 --- a/VirtualFileSystem/FileSystem.cpp +++ b/VirtualFileSystem/FileSystem.cpp @@ -44,20 +44,20 @@ ByteBuffer CoreInode::read_entire(FileDescriptor* descriptor) size_t initial_size = metadata().size ? metadata().size : 4096; auto contents = ByteBuffer::createUninitialized(initial_size); - Unix::ssize_t nread; + ssize_t nread; byte buffer[4096]; byte* out = contents.pointer(); Unix::off_t offset = 0; for (;;) { nread = read_bytes(offset, sizeof(buffer), buffer, descriptor); //kprintf("nread: %u, bufsiz: %u, initial_size: %u\n", nread, sizeof(buffer), initial_size); - ASSERT(nread <= (Unix::ssize_t)sizeof(buffer)); + ASSERT(nread <= (ssize_t)sizeof(buffer)); if (nread <= 0) break; memcpy(out, buffer, nread); out += nread; offset += nread; - ASSERT(offset <= (Unix::ssize_t)initial_size); // FIXME: Support dynamically growing the buffer. + ASSERT(offset <= (ssize_t)initial_size); // FIXME: Support dynamically growing the buffer. } if (nread < 0) { kprintf("CoreInode::read_entire: ERROR: %d\n", nread); @@ -82,20 +82,20 @@ ByteBuffer FS::readEntireInode(InodeIdentifier inode, FileDescriptor* handle) co size_t initialSize = metadata.size ? metadata.size : 4096; auto contents = ByteBuffer::createUninitialized(initialSize); - Unix::ssize_t nread; + ssize_t nread; byte buffer[4096]; byte* out = contents.pointer(); Unix::off_t offset = 0; for (;;) { nread = read_inode_bytes(inode, offset, sizeof(buffer), buffer, handle); //kprintf("nread: %u, bufsiz: %u, initialSize: %u\n", nread, sizeof(buffer), initialSize); - ASSERT(nread <= (Unix::ssize_t)sizeof(buffer)); + ASSERT(nread <= (ssize_t)sizeof(buffer)); if (nread <= 0) break; memcpy(out, buffer, nread); out += nread; offset += nread; - ASSERT(offset <= (Unix::ssize_t)initialSize); // FIXME: Support dynamically growing the buffer. + ASSERT(offset <= (ssize_t)initialSize); // FIXME: Support dynamically growing the buffer. } if (nread < 0) { kprintf("[fs] readInode: ERROR: %d\n", nread); @@ -115,7 +115,7 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft) name[name_length] = '\0'; } -FS::DirectoryEntry::DirectoryEntry(const char* n, Unix::size_t nl, InodeIdentifier i, byte ft) +FS::DirectoryEntry::DirectoryEntry(const char* n, size_t nl, InodeIdentifier i, byte ft) : name_length(nl) , inode(i) , fileType(ft) diff --git a/VirtualFileSystem/FileSystem.h b/VirtualFileSystem/FileSystem.h index 2245fd650d0..1cbbb0e2d74 100644 --- a/VirtualFileSystem/FileSystem.h +++ b/VirtualFileSystem/FileSystem.h @@ -33,13 +33,13 @@ public: virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0; virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0; - virtual Unix::ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const = 0; + virtual ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const = 0; struct DirectoryEntry { DirectoryEntry(const char* name, InodeIdentifier, byte fileType); - DirectoryEntry(const char* name, Unix::size_t name_length, InodeIdentifier, byte fileType); + DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte fileType); char name[256]; - Unix::size_t name_length { 0 }; + size_t name_length { 0 }; InodeIdentifier inode; byte fileType { 0 }; }; @@ -80,7 +80,7 @@ public: ByteBuffer read_entire(FileDescriptor* = nullptr); - virtual Unix::ssize_t read_bytes(Unix::off_t, Unix::size_t, byte* buffer, FileDescriptor*) = 0; + virtual ssize_t read_bytes(Unix::off_t, size_t, byte* buffer, FileDescriptor*) = 0; virtual bool traverse_as_directory(Function) = 0; virtual InodeIdentifier lookup(const String& name) = 0; virtual String reverse_lookup(InodeIdentifier) = 0; diff --git a/VirtualFileSystem/FullDevice.cpp b/VirtualFileSystem/FullDevice.cpp index f435876d91f..8c8e2569bb9 100644 --- a/VirtualFileSystem/FullDevice.cpp +++ b/VirtualFileSystem/FullDevice.cpp @@ -18,14 +18,14 @@ bool FullDevice::hasDataAvailableForRead() const return true; } -Unix::ssize_t FullDevice::read(byte* buffer, Unix::size_t bufferSize) +ssize_t FullDevice::read(byte* buffer, size_t bufferSize) { - Unix::size_t count = min(GoodBufferSize, bufferSize); + size_t count = min(GoodBufferSize, bufferSize); memset(buffer, 0, count); return count; } -Unix::ssize_t FullDevice::write(const byte*, Unix::size_t bufferSize) +ssize_t FullDevice::write(const byte*, size_t bufferSize) { if (bufferSize == 0) return 0; diff --git a/VirtualFileSystem/FullDevice.h b/VirtualFileSystem/FullDevice.h index 9ab209d2f9d..2d78470310e 100644 --- a/VirtualFileSystem/FullDevice.h +++ b/VirtualFileSystem/FullDevice.h @@ -8,8 +8,8 @@ public: FullDevice(); virtual ~FullDevice(); - virtual Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override; - virtual Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override; + virtual ssize_t read(byte* buffer, size_t bufferSize) override; + virtual ssize_t write(const byte* buffer, size_t bufferSize) override; virtual bool hasDataAvailableForRead() const override; }; diff --git a/VirtualFileSystem/Limits.h b/VirtualFileSystem/Limits.h index efb058684a1..f04a200d644 100644 --- a/VirtualFileSystem/Limits.h +++ b/VirtualFileSystem/Limits.h @@ -9,6 +9,6 @@ inline static const Unix::off_t maxFileOffset = 2147483647; inline static const Unix::off_t maxFileOffset = std::numeric_limits::max(); #endif -static const Unix::size_t GoodBufferSize = 4096; +static const size_t GoodBufferSize = 4096; diff --git a/VirtualFileSystem/NullDevice.cpp b/VirtualFileSystem/NullDevice.cpp index 85a3171097a..7dcdefe0514 100644 --- a/VirtualFileSystem/NullDevice.cpp +++ b/VirtualFileSystem/NullDevice.cpp @@ -17,12 +17,12 @@ bool NullDevice::hasDataAvailableForRead() const return true; } -Unix::ssize_t NullDevice::read(byte*, Unix::size_t) +ssize_t NullDevice::read(byte*, size_t) { return 0; } -Unix::ssize_t NullDevice::write(const byte*, Unix::size_t bufferSize) +ssize_t NullDevice::write(const byte*, size_t bufferSize) { return min(GoodBufferSize, bufferSize); } diff --git a/VirtualFileSystem/NullDevice.h b/VirtualFileSystem/NullDevice.h index 3c22b1f7814..d977f8f88ac 100644 --- a/VirtualFileSystem/NullDevice.h +++ b/VirtualFileSystem/NullDevice.h @@ -8,8 +8,8 @@ public: NullDevice(); virtual ~NullDevice() override; - virtual Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override; - virtual Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override; + virtual ssize_t read(byte* buffer, size_t bufferSize) override; + virtual ssize_t write(const byte* buffer, size_t bufferSize) override; virtual bool hasDataAvailableForRead() const override; }; diff --git a/VirtualFileSystem/RandomDevice.cpp b/VirtualFileSystem/RandomDevice.cpp index 2f5cb508071..9b2b63891f5 100644 --- a/VirtualFileSystem/RandomDevice.cpp +++ b/VirtualFileSystem/RandomDevice.cpp @@ -34,18 +34,18 @@ bool RandomDevice::hasDataAvailableForRead() const return true; } -Unix::ssize_t RandomDevice::read(byte* buffer, Unix::size_t bufferSize) +ssize_t RandomDevice::read(byte* buffer, size_t bufferSize) { const int range = 'z' - 'a'; - Unix::ssize_t nread = min(bufferSize, GoodBufferSize); - for (Unix::ssize_t i = 0; i < nread; ++i) { + ssize_t nread = min(bufferSize, GoodBufferSize); + for (ssize_t i = 0; i < nread; ++i) { dword r = myrand() % range; buffer[i] = 'a' + r; } return nread; } -Unix::ssize_t RandomDevice::write(const byte*, Unix::size_t bufferSize) +ssize_t RandomDevice::write(const byte*, size_t bufferSize) { // FIXME: Use input for entropy? I guess that could be a neat feature? return min(GoodBufferSize, bufferSize); diff --git a/VirtualFileSystem/RandomDevice.h b/VirtualFileSystem/RandomDevice.h index e91c324c19b..b9a519c7f03 100644 --- a/VirtualFileSystem/RandomDevice.h +++ b/VirtualFileSystem/RandomDevice.h @@ -8,8 +8,8 @@ public: RandomDevice(); virtual ~RandomDevice() override; - virtual Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override; - virtual Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override; + virtual ssize_t read(byte* buffer, size_t bufferSize) override; + virtual ssize_t write(const byte* buffer, size_t bufferSize) override; virtual bool hasDataAvailableForRead() const override; }; diff --git a/VirtualFileSystem/SyntheticFileSystem.cpp b/VirtualFileSystem/SyntheticFileSystem.cpp index d6498288d74..9bde132a94d 100644 --- a/VirtualFileSystem/SyntheticFileSystem.cpp +++ b/VirtualFileSystem/SyntheticFileSystem.cpp @@ -170,7 +170,7 @@ bool SynthFS::writeInode(InodeIdentifier, const ByteBuffer&) return false; } -Unix::ssize_t SynthFS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor* handle) const +ssize_t SynthFS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor* handle) const { ASSERT(inode.fsid() == id()); #ifdef SYNTHFS_DEBUG @@ -200,7 +200,7 @@ Unix::ssize_t SynthFS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offse } auto* data = generatedData ? &generatedData : &file.m_data; - Unix::ssize_t nread = min(static_cast(data->size() - offset), static_cast(count)); + ssize_t nread = min(static_cast(data->size() - offset), static_cast(count)); memcpy(buffer, data->pointer() + offset, nread); if (nread == 0 && handle && handle->generatorCache()) handle->generatorCache().clear(); @@ -249,7 +249,7 @@ void SynthFSInode::populate_metadata() const // Already done when SynthFS created the file. } -Unix::ssize_t SynthFSInode::read_bytes(Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor* descriptor) +ssize_t SynthFSInode::read_bytes(Unix::off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor) { #ifdef SYNTHFS_DEBUG kprintf("SynthFS: read_bytes %u\n", index()); @@ -269,7 +269,7 @@ Unix::ssize_t SynthFSInode::read_bytes(Unix::off_t offset, Unix::size_t count, b } auto* data = generatedData ? &generatedData : &m_data; - Unix::ssize_t nread = min(static_cast(data->size() - offset), static_cast(count)); + ssize_t nread = min(static_cast(data->size() - offset), static_cast(count)); memcpy(buffer, data->pointer() + offset, nread); if (nread == 0 && descriptor && descriptor->generatorCache()) descriptor->generatorCache().clear(); diff --git a/VirtualFileSystem/SyntheticFileSystem.h b/VirtualFileSystem/SyntheticFileSystem.h index f5b528b028b..4b896e97c68 100644 --- a/VirtualFileSystem/SyntheticFileSystem.h +++ b/VirtualFileSystem/SyntheticFileSystem.h @@ -18,7 +18,7 @@ public: virtual InodeMetadata inodeMetadata(InodeIdentifier) const override; virtual bool set_mtime(InodeIdentifier, dword timestamp) override; virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override; - virtual Unix::ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override; + virtual ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const override; virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) override; virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override; virtual RetainPtr get_inode(InodeIdentifier) const override; @@ -50,7 +50,7 @@ public: private: // ^CoreInode - virtual Unix::ssize_t read_bytes(Unix::off_t, Unix::size_t, byte* buffer, FileDescriptor*) override; + virtual ssize_t read_bytes(Unix::off_t, size_t, byte* buffer, FileDescriptor*) override; virtual void populate_metadata() const override; virtual bool traverse_as_directory(Function) override; virtual InodeIdentifier lookup(const String& name) override; diff --git a/VirtualFileSystem/UnixTypes.h b/VirtualFileSystem/UnixTypes.h index f834038f337..d1e0e36efb3 100644 --- a/VirtualFileSystem/UnixTypes.h +++ b/VirtualFileSystem/UnixTypes.h @@ -258,8 +258,6 @@ typedef ::time_t time_t; typedef dword blksize_t; typedef dword blkcnt_t; -typedef dword size_t; -typedef signed_dword ssize_t; #define NCCS 32 diff --git a/VirtualFileSystem/ZeroDevice.cpp b/VirtualFileSystem/ZeroDevice.cpp index 5ee17059a8d..0bde995617f 100644 --- a/VirtualFileSystem/ZeroDevice.cpp +++ b/VirtualFileSystem/ZeroDevice.cpp @@ -17,14 +17,14 @@ bool ZeroDevice::hasDataAvailableForRead() const return true; } -Unix::ssize_t ZeroDevice::read(byte* buffer, Unix::size_t bufferSize) +ssize_t ZeroDevice::read(byte* buffer, size_t bufferSize) { - Unix::size_t count = min(GoodBufferSize, bufferSize); + size_t count = min(GoodBufferSize, bufferSize); memset(buffer, 0, count); return count; } -Unix::ssize_t ZeroDevice::write(const byte*, Unix::size_t bufferSize) +ssize_t ZeroDevice::write(const byte*, size_t bufferSize) { return min(GoodBufferSize, bufferSize); } diff --git a/VirtualFileSystem/ZeroDevice.h b/VirtualFileSystem/ZeroDevice.h index ca0fa7828bb..0801984b83c 100644 --- a/VirtualFileSystem/ZeroDevice.h +++ b/VirtualFileSystem/ZeroDevice.h @@ -8,8 +8,8 @@ public: ZeroDevice(); virtual ~ZeroDevice() override; - virtual Unix::ssize_t read(byte* buffer, Unix::size_t bufferSize) override; - virtual Unix::ssize_t write(const byte* buffer, Unix::size_t bufferSize) override; + virtual ssize_t read(byte* buffer, size_t bufferSize) override; + virtual ssize_t write(const byte* buffer, size_t bufferSize) override; virtual bool hasDataAvailableForRead() const override; };