Big, possibly complete sweep of naming changes.

This commit is contained in:
Andreas Kling 2019-01-31 17:31:23 +01:00
parent 27fa09aee4
commit ffab6897aa
Notes: sideshowbarker 2024-07-19 15:54:26 +09:00
93 changed files with 830 additions and 885 deletions

View file

@ -15,7 +15,7 @@ public:
String() { }
String(const String& other)
: m_impl(const_cast<String&>(other).m_impl.copyRef())
: m_impl(const_cast<String&>(other).m_impl.copy_ref())
{
}
@ -44,7 +44,7 @@ public:
{
}
unsigned toUInt(bool& ok) const;
unsigned to_uint(bool& ok) const;
String to_lowercase() const
{
@ -89,7 +89,7 @@ public:
String& operator=(const String& other)
{
if (this != &other)
m_impl = const_cast<String&>(other).m_impl.copyRef();
m_impl = const_cast<String&>(other).m_impl.copy_ref();
return *this;
}

View file

@ -8,9 +8,9 @@
namespace AK {
inline void notImplemented() { ASSERT(false); }
inline void not_implemented() { ASSERT(false); }
}
using AK::notImplemented;
using AK::not_implemented;

View file

@ -51,7 +51,7 @@ private:
, m_owned(true)
{
ASSERT(m_size != 0);
size_t size_to_allocate = ceilDiv(size, 8u);
size_t size_to_allocate = ceil_div(size, 8u);
m_data = reinterpret_cast<byte*>(kmalloc(size_to_allocate));
memset(m_data, default_value ? 0xff : 0x00, size_to_allocate);
}

View file

@ -11,7 +11,7 @@ public:
ByteBuffer() { }
ByteBuffer(std::nullptr_t) { }
ByteBuffer(const ByteBuffer& other)
: m_impl(other.m_impl.copyRef())
: m_impl(other.m_impl.copy_ref())
{
}
ByteBuffer(ByteBuffer&& other)
@ -26,7 +26,7 @@ public:
}
ByteBuffer& operator=(const ByteBuffer& other)
{
m_impl = other.m_impl.copyRef();
m_impl = other.m_impl.copy_ref();
return *this;
}

View file

@ -48,7 +48,7 @@ public:
append_node(new Node(value));
}
bool containsSlow(const T& value) const
bool contains_slow(const T& value) const
{
for (auto* node = m_head; node; node = node->next) {
if (node->value == value)

View file

@ -40,7 +40,7 @@ bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
builder.append('/');
builder.append(cpart);
}
m_string = builder.build();
m_string = builder.to_string();
return true;
}

View file

@ -41,41 +41,41 @@ public:
template<typename CallableType, class = typename EnableIf<!(IsPointer<CallableType>::value && IsFunction<typename RemovePointer<CallableType>::Type>::value) && IsRvalueReference<CallableType&&>::value>::Type>
Function(CallableType&& callable)
: m_callableWrapper(make<CallableWrapper<CallableType>>(move(callable)))
: m_callable_wrapper(make<CallableWrapper<CallableType>>(move(callable)))
{
}
template<typename FunctionType, class = typename EnableIf<IsPointer<FunctionType>::value && IsFunction<typename RemovePointer<FunctionType>::Type>::value>::Type>
Function(FunctionType f)
: m_callableWrapper(make<CallableWrapper<FunctionType>>(move(f)))
: m_callable_wrapper(make<CallableWrapper<FunctionType>>(move(f)))
{
}
Out operator()(In... in) const
{
ASSERT(m_callableWrapper);
return m_callableWrapper->call(forward<In>(in)...);
ASSERT(m_callable_wrapper);
return m_callable_wrapper->call(forward<In>(in)...);
}
explicit operator bool() const { return !!m_callableWrapper; }
explicit operator bool() const { return !!m_callable_wrapper; }
template<typename CallableType, class = typename EnableIf<!(IsPointer<CallableType>::value && IsFunction<typename RemovePointer<CallableType>::Type>::value) && IsRvalueReference<CallableType&&>::value>::Type>
Function& operator=(CallableType&& callable)
{
m_callableWrapper = make<CallableWrapper<CallableType>>(move(callable));
m_callable_wrapper = make<CallableWrapper<CallableType>>(move(callable));
return *this;
}
template<typename FunctionType, class = typename EnableIf<IsPointer<FunctionType>::value && IsFunction<typename RemovePointer<FunctionType>::Type>::value>::Type>
Function& operator=(FunctionType f)
{
m_callableWrapper = make<CallableWrapper<FunctionType>>(move(f));
m_callable_wrapper = make<CallableWrapper<FunctionType>>(move(f));
return *this;
}
Function& operator=(std::nullptr_t)
{
m_callableWrapper = nullptr;
m_callable_wrapper = nullptr;
return *this;
}
@ -103,7 +103,7 @@ private:
CallableType m_callable;
};
OwnPtr<CallableWrapperBase> m_callableWrapper;
OwnPtr<CallableWrapperBase> m_callable_wrapper;
};
}

View file

@ -2,7 +2,7 @@
#include "Types.h"
inline unsigned intHash(dword key)
inline unsigned int_hash(dword key)
{
key += ~(key << 15);
key ^= (key >> 10);
@ -13,8 +13,8 @@ inline unsigned intHash(dword key)
return key;
}
inline unsigned pairIntHash(dword key1, dword key2)
inline unsigned pair_int_hash(dword key1, dword key2)
{
return intHash((intHash(key1) * 209) ^ (intHash(key2 * 413)));
return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
}

View file

@ -54,7 +54,7 @@ public:
void set(const K&, const V&);
void set(const K&, V&&);
void remove(const K&);
void removeOneRandomly() { m_table.remove(m_table.begin()); }
void remove_one_randomly() { m_table.remove(m_table.begin()); }
typedef HashTable<Entry, EntryTraits> HashTableType;
typedef typename HashTableType::Iterator IteratorType;

View file

@ -6,40 +6,40 @@
namespace AK {
MappedFile::MappedFile(String&& fileName)
: m_fileName(std::move(fileName))
MappedFile::MappedFile(String&& file_name)
: m_file_name(std::move(file_name))
{
m_fileLength = 1024;
m_fd = open(m_fileName.characters(), O_RDONLY);
m_file_length = 1024;
m_fd = open(m_file_name.characters(), O_RDONLY);
if (m_fd != -1) {
struct stat st;
fstat(m_fd, &st);
m_fileLength = st.st_size;
m_map = mmap(nullptr, m_fileLength, PROT_READ, MAP_SHARED, m_fd, 0);
m_file_length = st.st_size;
m_map = mmap(nullptr, m_file_length, PROT_READ, MAP_SHARED, m_fd, 0);
if (m_map == MAP_FAILED)
perror("");
}
printf("MappedFile{%s} := { m_fd=%d, m_fileLength=%zu, m_map=%p }\n", m_fileName.characters(), m_fd, m_fileLength, m_map);
printf("MappedFile{%s} := { m_fd=%d, m_file_length=%zu, m_map=%p }\n", m_file_name.characters(), m_fd, m_file_length, m_map);
}
MappedFile::~MappedFile()
{
if (m_map != (void*)-1) {
ASSERT(m_fd != -1);
munmap(m_map, m_fileLength);
munmap(m_map, m_file_length);
}
}
MappedFile::MappedFile(MappedFile&& other)
: m_fileName(std::move(other.m_fileName))
, m_fileLength(other.m_fileLength)
: m_file_name(std::move(other.m_file_name))
, m_file_length(other.m_file_length)
, m_fd(other.m_fd)
, m_map(other.m_map)
{
other.m_fileLength = 0;
other.m_file_length = 0;
other.m_fd = -1;
other.m_map = (void*)-1;
}

View file

@ -7,19 +7,19 @@ namespace AK {
class MappedFile {
public:
MappedFile() { }
explicit MappedFile(String&& fileName);
explicit MappedFile(String&& file_name);
MappedFile(MappedFile&&);
~MappedFile();
bool isValid() const { return m_map != (void*)-1; }
bool is_valid() const { return m_map != (void*)-1; }
void* pointer() { return m_map; }
const void* pointer() const { return m_map; }
size_t fileLength() const { return m_fileLength; }
size_t file_length() const { return m_file_length; }
private:
String m_fileName;
size_t m_fileLength { 0 };
String m_file_name;
size_t m_file_length { 0 };
int m_fd { -1 };
void* m_map { (void*)-1 };
};

View file

@ -11,8 +11,8 @@ class OwnPtr {
public:
OwnPtr() { }
explicit OwnPtr(T* ptr) : m_ptr(ptr) { }
OwnPtr(OwnPtr&& other) : m_ptr(other.leakPtr()) { }
template<typename U> OwnPtr(OwnPtr<U>&& other) : m_ptr(static_cast<T*>(other.leakPtr())) { }
OwnPtr(OwnPtr&& other) : m_ptr(other.leak_ptr()) { }
template<typename U> OwnPtr(OwnPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ptr())) { }
OwnPtr(std::nullptr_t) { };
~OwnPtr()
{
@ -29,7 +29,7 @@ public:
{
if (this != &other) {
delete m_ptr;
m_ptr = other.leakPtr();
m_ptr = other.leak_ptr();
}
return *this;
}
@ -39,7 +39,7 @@ public:
{
if (this != static_cast<void*>(&other)) {
delete m_ptr;
m_ptr = other.leakPtr();
m_ptr = other.leak_ptr();
}
return *this;
}
@ -69,7 +69,7 @@ public:
typedef T* OwnPtr::*UnspecifiedBoolType;
operator UnspecifiedBoolType() const { return m_ptr ? &OwnPtr::m_ptr : nullptr; }
T* leakPtr()
T* leak_ptr()
{
T* leakedPtr = m_ptr;
m_ptr = nullptr;

View file

@ -6,14 +6,14 @@
namespace AK {
template<typename T>
inline void retainIfNotNull(T* ptr)
inline void retain_if_not_null(T* ptr)
{
if (ptr)
ptr->retain();
}
template<typename T>
inline void releaseIfNotNull(T* ptr)
inline void release_if_not_null(T* ptr)
{
if (ptr)
ptr->release();
@ -25,15 +25,15 @@ public:
enum AdoptTag { Adopt };
RetainPtr() { }
RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retainIfNotNull(m_ptr); }
RetainPtr(T* ptr) : m_ptr(ptr) { retainIfNotNull(m_ptr); }
RetainPtr(const T* ptr) : m_ptr(const_cast<T*>(ptr)) { retain_if_not_null(m_ptr); }
RetainPtr(T* ptr) : m_ptr(ptr) { retain_if_not_null(m_ptr); }
RetainPtr(T& object) : m_ptr(&object) { m_ptr->retain(); }
RetainPtr(AdoptTag, T& object) : m_ptr(&object) { }
RetainPtr(RetainPtr& other) : m_ptr(other.copyRef().leakRef()) { }
RetainPtr(RetainPtr&& other) : m_ptr(other.leakRef()) { }
template<typename U> RetainPtr(RetainPtr<U>&& other) : m_ptr(static_cast<T*>(other.leakRef())) { }
RetainPtr(const RetainPtr& other) : m_ptr(const_cast<RetainPtr&>(other).copyRef().leakRef()) { }
template<typename U> RetainPtr(const RetainPtr<U>& other) : m_ptr(const_cast<RetainPtr<U>&>(other).copyRef().leakRef()) { }
RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
template<typename U> RetainPtr(RetainPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ref())) { }
RetainPtr(const RetainPtr& other) : m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref()) { }
template<typename U> RetainPtr(const RetainPtr<U>& other) : m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref()) { }
~RetainPtr()
{
clear();
@ -49,8 +49,8 @@ public:
RetainPtr& operator=(RetainPtr&& other)
{
if (this != &other) {
releaseIfNotNull(m_ptr);
m_ptr = other.leakRef();
release_if_not_null(m_ptr);
m_ptr = other.leak_ref();
}
return *this;
}
@ -59,8 +59,8 @@ public:
RetainPtr& operator=(RetainPtr<U>&& other)
{
if (this != static_cast<void*>(&other)) {
releaseIfNotNull(m_ptr);
m_ptr = other.leakRef();
release_if_not_null(m_ptr);
m_ptr = other.leak_ref();
}
return *this;
}
@ -68,18 +68,18 @@ public:
RetainPtr& operator=(T* ptr)
{
if (m_ptr != ptr)
releaseIfNotNull(m_ptr);
release_if_not_null(m_ptr);
m_ptr = ptr;
retainIfNotNull(m_ptr);
retain_if_not_null(m_ptr);
return *this;
}
RetainPtr& operator=(T& object)
{
if (m_ptr != &object)
releaseIfNotNull(m_ptr);
release_if_not_null(m_ptr);
m_ptr = &object;
retainIfNotNull(m_ptr);
retain_if_not_null(m_ptr);
return *this;
}
@ -89,14 +89,14 @@ public:
return *this;
}
RetainPtr copyRef() const
RetainPtr copy_ref() const
{
return RetainPtr(m_ptr);
}
void clear()
{
releaseIfNotNull(m_ptr);
release_if_not_null(m_ptr);
m_ptr = nullptr;
}
@ -105,7 +105,7 @@ public:
typedef T* RetainPtr::*UnspecifiedBoolType;
operator UnspecifiedBoolType() const { return m_ptr ? &RetainPtr::m_ptr : nullptr; }
T* leakRef()
T* leak_ref()
{
T* leakedPtr = m_ptr;
m_ptr = nullptr;

View file

@ -50,28 +50,28 @@ public:
void initialize(byte* base)
{
m_base = base;
m_free = capacityInAllocations();
m_free = capacity_in_allocations();
dump();
}
static constexpr dword capacityInAllocations()
static constexpr dword capacity_in_allocations()
{
return 1048576 / chunkSize;
}
static constexpr dword capacityInBytes()
static constexpr dword capacity_in_bytes()
{
return capacityInAllocations() * chunkSize;
return capacity_in_allocations() * chunkSize;
}
byte* allocate()
{
auto bitmap = this->bitmap();
for (dword i = 0; i < capacityInAllocations(); ++i) {
for (dword i = 0; i < capacity_in_allocations(); ++i) {
if (!bitmap.get(i)) {
bitmap.set(i, true);
--m_free;
return pointerToChunk(i);
return pointer_to_chunk(i);
}
}
return nullptr;
@ -84,57 +84,57 @@ public:
void free(byte* ptr)
{
ASSERT(isInAllocator(ptr));
ASSERT(is_in_allocator(ptr));
auto bitmap = this->bitmap();
auto chunkIndex = chunkIndexFromPointer(ptr);
ASSERT(bitmap.get(chunkIndex));
bitmap.set(chunkIndex, false);
auto chunk_index = chunk_index_from_pointer(ptr);
ASSERT(bitmap.get(chunk_index));
bitmap.set(chunk_index, false);
++m_free;
}
bool isInAllocator(byte* ptr)
bool is_in_allocator(byte* ptr)
{
return ptr >= pointerToChunk(0) && ptr <= addressAfterThisAllocator();
return ptr >= pointer_to_chunk(0) && ptr <= address_after_this_allocator();
}
dword chunkIndexFromPointer(byte* ptr)
dword chunk_index_from_pointer(byte* ptr)
{
return (ptr - pointerToChunk(0)) / chunkSize;
return (ptr - pointer_to_chunk(0)) / chunkSize;
}
byte* pointerToChunk(dword index)
byte* pointer_to_chunk(dword index)
{
return m_base + sizeOfAllocationBitmapInBytes() + (index * chunkSize);
return m_base + size_of_allocation_bitmap_in_bytes() + (index * chunkSize);
}
AllocationBitmap bitmap()
{
return AllocationBitmap::wrap(m_base, capacityInAllocations());
return AllocationBitmap::wrap(m_base, capacity_in_allocations());
}
static constexpr dword sizeOfAllocationBitmapInBytes()
static constexpr dword size_of_allocation_bitmap_in_bytes()
{
return capacityInAllocations() / 8;
return capacity_in_allocations() / 8;
}
byte* addressAfterThisAllocator() const
byte* address_after_this_allocator() const
{
return m_base + sizeOfAllocationBitmapInBytes() + capacityInBytes();
return m_base + size_of_allocation_bitmap_in_bytes() + capacity_in_bytes();
}
dword numberOfFreeChunks() const
dword number_of_free_chunks() const
{
return m_free;
}
private:
byte* m_base { nullptr };
dword m_free { capacityInAllocations() };
dword m_free { capacity_in_allocations() };
};
struct Allocator {
void initialize();
void initializeIfNeeded();
void initialize_if_needed();
void dump();
ChunkAllocator<8> alloc8;
@ -148,7 +148,7 @@ struct Allocator {
static Allocator allocator;
void Allocator::initializeIfNeeded()
void Allocator::initialize_if_needed()
{
if (initialized)
return;
@ -161,9 +161,9 @@ void Allocator::initialize()
space = (byte*)mmap((void*)0x20000000, 32 * MB, PROT_WRITE | PROT_READ | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT(space != MAP_FAILED);
alloc8.initialize(space + 0x10000);
alloc16.initialize(alloc8.addressAfterThisAllocator());
alloc4096.initialize(alloc16.addressAfterThisAllocator());
alloc16384.initialize(alloc4096.addressAfterThisAllocator());
alloc16.initialize(alloc8.address_after_this_allocator());
alloc4096.initialize(alloc16.address_after_this_allocator());
alloc16384.initialize(alloc4096.address_after_this_allocator());
}
void Allocator::dump()
@ -188,7 +188,7 @@ byte* allocate(dword size)
{
if (!size)
return nullptr;
allocator.initializeIfNeeded();
allocator.initialize_if_needed();
if (size <= 8) {
if (auto* ptr = allocator.alloc8.allocate())
return ptr;
@ -210,7 +210,7 @@ byte* allocate(dword size)
return nullptr;
}
byte* allocateZeroed(dword size)
byte* allocate_zeroed(dword size)
{
auto* ptr = allocate(size);
if (!ptr)
@ -232,20 +232,20 @@ void free(byte* ptr)
{
if (!ptr)
return;
allocator.initializeIfNeeded();
if (allocator.alloc8.isInAllocator(ptr)) {
allocator.initialize_if_needed();
if (allocator.alloc8.is_in_allocator(ptr)) {
allocator.alloc8.free(ptr);
return;
}
if (allocator.alloc16.isInAllocator(ptr)) {
if (allocator.alloc16.is_in_allocator(ptr)) {
allocator.alloc16.free(ptr);
return;
}
if (allocator.alloc4096.isInAllocator(ptr)) {
if (allocator.alloc4096.is_in_allocator(ptr)) {
allocator.alloc4096.free(ptr);
return;
}
if (allocator.alloc16384.isInAllocator(ptr)) {
if (allocator.alloc16384.is_in_allocator(ptr)) {
allocator.alloc16384.free(ptr);
return;
}

View file

@ -7,7 +7,7 @@ namespace SimpleMalloc {
void initialize();
void dump();
byte* allocate(dword);
byte* allocateZeroed(dword);
byte* allocate_zeroed(dword);
void free(byte*);
byte* reallocate(byte*, dword);

View file

@ -47,7 +47,7 @@ public:
m_tail = node;
}
bool containsSlow(const T& value) const
bool contains_slow(const T& value) const
{
for (auto* node = m_head; node; node = node->next) {
if (node->value == value)

View file

@ -45,7 +45,7 @@ inline T max(const T& a, const T& b)
template<typename T, typename U>
static inline T ceilDiv(T a, U b)
static inline T ceil_div(T a, U b)
{
static_assert(sizeof(T) == sizeof(U));
T result = a / b;
@ -173,5 +173,5 @@ using AK::move;
using AK::forward;
using AK::exchange;
using AK::swap;
using AK::ceilDiv;
using AK::ceil_div;

View file

@ -42,10 +42,10 @@ String String::substring(size_t start, size_t length) const
ASSERT(start + length <= m_impl->length());
// FIXME: This needs some input bounds checking.
char* buffer;
auto newImpl = StringImpl::create_uninitialized(length, buffer);
auto new_impl = StringImpl::create_uninitialized(length, buffer);
memcpy(buffer, characters() + start, length);
buffer[length] = '\0';
return newImpl;
return new_impl;
}
Vector<String> String::split(const char separator) const
@ -79,7 +79,7 @@ ByteBuffer String::to_byte_buffer() const
return ByteBuffer::copy(reinterpret_cast<const byte*>(characters()), length());
}
unsigned String::toUInt(bool& ok) const
unsigned String::to_uint(bool& ok) const
{
unsigned value = 0;
for (size_t i = 0; i < length(); ++i) {
@ -101,7 +101,7 @@ String String::format(const char* fmt, ...)
va_start(ap, fmt);
builder.appendvf(fmt, ap);
va_end(ap);
return builder.build();
return builder.to_string();
}
}

View file

@ -43,7 +43,7 @@ void StringBuilder::append(char ch)
void StringBuilder::appendvf(const char* fmt, va_list ap)
{
printfInternal([this] (char*&, char ch) {
printf_internal([this] (char*&, char ch) {
append(ch);
}, nullptr, fmt, ap);
}
@ -62,7 +62,7 @@ ByteBuffer StringBuilder::to_byte_buffer()
return move(m_buffer);
}
String StringBuilder::build()
String StringBuilder::to_string()
{
auto string = String((const char*)m_buffer.pointer(), m_length);
m_buffer.clear();

View file

@ -17,7 +17,7 @@ public:
void appendf(const char*, ...);
void appendvf(const char*, va_list);
String build();
String to_string();
ByteBuffer to_byte_buffer();
private:

View file

@ -55,7 +55,7 @@ StringImpl::~StringImpl()
#endif
}
static inline size_t allocationSizeForStringImpl(size_t length)
static inline size_t allocation_size_for_stringimpl(size_t length)
{
return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char);
}
@ -63,14 +63,14 @@ static inline size_t allocationSizeForStringImpl(size_t length)
RetainPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*& buffer)
{
ASSERT(length);
void* slot = kmalloc(allocationSizeForStringImpl(length));
void* slot = kmalloc(allocation_size_for_stringimpl(length));
if (!slot)
return nullptr;
auto newStringImpl = adopt(*new (slot) StringImpl(ConstructWithInlineBuffer, length));
buffer = const_cast<char*>(newStringImpl->m_characters);
auto new_stringimpl = adopt(*new (slot) StringImpl(ConstructWithInlineBuffer, length));
buffer = const_cast<char*>(new_stringimpl->m_characters);
buffer[length] = '\0';
return newStringImpl;
return new_stringimpl;
}
RetainPtr<StringImpl> StringImpl::create(const char* cstring, size_t length, ShouldChomp shouldChomp)
@ -82,17 +82,17 @@ RetainPtr<StringImpl> StringImpl::create(const char* cstring, size_t length, Sho
return the_empty_stringimpl();
char* buffer;
auto newStringImpl = create_uninitialized(length, buffer);
if (!newStringImpl)
auto new_stringimpl = create_uninitialized(length, buffer);
if (!new_stringimpl)
return nullptr;
memcpy(buffer, cstring, length * sizeof(char));
if (shouldChomp && buffer[length - 1] == '\n') {
buffer[length - 1] = '\0';
--newStringImpl->m_length;
--new_stringimpl->m_length;
}
return newStringImpl;
return new_stringimpl;
}
RetainPtr<StringImpl> StringImpl::create(const char* cstring, ShouldChomp shouldChomp)
@ -103,26 +103,26 @@ RetainPtr<StringImpl> StringImpl::create(const char* cstring, ShouldChomp should
return create(cstring, strlen(cstring), shouldChomp);
}
static inline bool isASCIILowercase(char c)
static inline bool is_ascii_lowercase(char c)
{
return c >= 'a' && c <= 'z';
}
static inline bool isASCIIUppercase(char c)
static inline bool is_ascii_uppercase(char c)
{
return c >= 'A' && c <= 'Z';
}
static inline char toASCIILowercase(char c)
static inline char to_ascii_lowercase(char c)
{
if (isASCIIUppercase(c))
if (is_ascii_uppercase(c))
return c | 0x20;
return c;
}
static inline char toASCIIUppercase(char c)
static inline char to_ascii_uppercase(char c)
{
if (isASCIILowercase(c))
if (is_ascii_lowercase(c))
return c & ~0x20;
return c;
}
@ -133,18 +133,18 @@ RetainPtr<StringImpl> StringImpl::to_lowercase() const
return const_cast<StringImpl*>(this);
for (size_t i = 0; i < m_length; ++i) {
if (!isASCIILowercase(m_characters[i]))
goto slowPath;
if (!is_ascii_lowercase(m_characters[i]))
goto slow_path;
}
return const_cast<StringImpl*>(this);
slowPath:
slow_path:
char* buffer;
auto lowercased = create_uninitialized(m_length, buffer);
if (!lowercased)
return nullptr;
for (size_t i = 0; i < m_length; ++i)
buffer[i] = toASCIILowercase(m_characters[i]);
buffer[i] = to_ascii_lowercase(m_characters[i]);
return lowercased;
}
@ -155,18 +155,18 @@ RetainPtr<StringImpl> StringImpl::to_uppercase() const
return const_cast<StringImpl*>(this);
for (size_t i = 0; i < m_length; ++i) {
if (!isASCIIUppercase(m_characters[i]))
goto slowPath;
if (!is_ascii_uppercase(m_characters[i]))
goto slow_path;
}
return const_cast<StringImpl*>(this);
slowPath:
slow_path:
char* buffer;
auto uppercased = create_uninitialized(m_length, buffer);
if (!uppercased)
return nullptr;
for (size_t i = 0; i < m_length; ++i)
buffer[i] = toASCIIUppercase(m_characters[i]);
buffer[i] = to_ascii_uppercase(m_characters[i]);
return uppercased;
}

View file

@ -11,14 +11,14 @@ TemporaryFile::TemporaryFile()
int fd = mkstemp(nameBuffer);
if (fd != -1) {
m_stream = fdopen(fd, "w+");
m_fileName = nameBuffer;
m_file_name = nameBuffer;
}
}
TemporaryFile::~TemporaryFile()
{
if (isValid()) {
unlink(m_fileName.characters());
if (is_valid()) {
unlink(m_file_name.characters());
fclose(m_stream);
}
}

View file

@ -10,14 +10,14 @@ public:
TemporaryFile();
~TemporaryFile();
bool isValid() const { return m_stream; }
bool is_valid() const { return m_stream; }
FILE* stream() { return m_stream; }
String fileName() const { return m_fileName; }
String file_name() const { return m_file_name; }
void sync();
private:
FILE* m_stream { nullptr };
String m_fileName;
String m_file_name;
};
}

View file

@ -12,13 +12,13 @@ struct Traits
template<>
struct Traits<int> {
static unsigned hash(int i) { return intHash(i); }
static unsigned hash(int i) { return int_hash(i); }
static void dump(int i) { kprintf("%d", i); }
};
template<>
struct Traits<unsigned> {
static unsigned hash(unsigned u) { return intHash(u); }
static unsigned hash(unsigned u) { return int_hash(u); }
static void dump(unsigned u) { kprintf("%u", u); }
};
@ -26,7 +26,7 @@ template<typename T>
struct Traits<T*> {
static unsigned hash(const T* p)
{
return intHash((dword)p);
return int_hash((dword)p);
}
static void dump(const T* p) { kprintf("%p", p); }
};

View file

@ -219,16 +219,16 @@ public:
if (capacity() >= neededCapacity)
return;
size_t new_capacity = padded_capacity(neededCapacity);
auto newImpl = VectorImpl<T, Allocator>::create(new_capacity);
auto new_impl = VectorImpl<T, Allocator>::create(new_capacity);
if (m_impl) {
newImpl->m_size = m_impl->m_size;
new_impl->m_size = m_impl->m_size;
for (size_t i = 0; i < size(); ++i) {
new (newImpl->slot(i)) T(move(m_impl->at(i)));
new (new_impl->slot(i)) T(move(m_impl->at(i)));
m_impl->at(i).~T();
}
Allocator::deallocate(m_impl);
}
m_impl = newImpl;
m_impl = new_impl;
}
void resize(size_t new_size)

View file

@ -13,14 +13,14 @@ public:
template<typename U>
WeakPtr(WeakPtr<U>&& other)
: m_link(reinterpret_cast<WeakLink<T>*>(other.leakLink()))
: m_link(reinterpret_cast<WeakLink<T>*>(other.leak_link()))
{
}
template<typename U>
WeakPtr& operator=(WeakPtr<U>&& other)
{
m_link = reinterpret_cast<WeakLink<T>*>(other.leakLink());
m_link = reinterpret_cast<WeakLink<T>*>(other.leak_link());
return *this;
}
@ -38,7 +38,7 @@ public:
bool is_null() const { return !m_link || !m_link->ptr(); }
void clear() { m_link = nullptr; }
WeakLink<T>* leakLink() { return m_link.leakRef(); }
WeakLink<T>* leak_link() { return m_link.leak_ref(); }
private:
WeakPtr(RetainPtr<WeakLink<T>>&& link) : m_link(move(link)) { }
@ -47,11 +47,11 @@ private:
};
template<typename T>
inline WeakPtr<T> Weakable<T>::makeWeakPtr()
inline WeakPtr<T> Weakable<T>::make_weak_ptr()
{
if (!m_link)
m_link = adopt(*new WeakLink<T>(static_cast<T&>(*this)));
return WeakPtr<T>(m_link.copyRef());
return WeakPtr<T>(m_link.copy_ref());
}
}

View file

@ -26,7 +26,7 @@ class Weakable {
private:
class Link;
public:
WeakPtr<T> makeWeakPtr();
WeakPtr<T> make_weak_ptr();
protected:
Weakable() { }

View file

@ -84,7 +84,7 @@ void* kcalloc(size_t nmemb, size_t size)
{
if (!nmemb || !size)
return nullptr;
return SimpleMalloc::allocateZeroed(nmemb * size);
return SimpleMalloc::allocate_zeroed(nmemb * size);
}
void* kmalloc(size_t size)

View file

@ -13,7 +13,7 @@ ALWAYS_INLINE size_t strlen(const char* str)
static constexpr const char* h = "0123456789abcdef";
template<typename PutChFunc>
ALWAYS_INLINE int printHex(PutChFunc putch, char*& bufptr, dword number, byte fields)
ALWAYS_INLINE int print_hex(PutChFunc putch, char*& bufptr, dword number, byte fields)
{
int ret = 0;
byte shr_count = fields * 4;
@ -26,7 +26,7 @@ ALWAYS_INLINE int printHex(PutChFunc putch, char*& bufptr, dword number, byte fi
}
template<typename PutChFunc>
ALWAYS_INLINE int printNumber(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
ALWAYS_INLINE int print_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
{
dword divisor = 1000000000;
char ch;
@ -108,7 +108,7 @@ ALWAYS_INLINE int print_octal_number(PutChFunc putch, char*& bufptr, dword numbe
}
template<typename PutChFunc>
ALWAYS_INLINE int printString(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth)
ALWAYS_INLINE int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth)
{
size_t len = strlen(str);
if (!fieldWidth || fieldWidth < len)
@ -129,17 +129,17 @@ ALWAYS_INLINE int printString(PutChFunc putch, char*& bufptr, const char* str, b
template<typename PutChFunc>
ALWAYS_INLINE int printSignedNumber(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
ALWAYS_INLINE int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
{
if (number < 0) {
putch(bufptr, '-');
return printNumber(putch, bufptr, 0 - number, leftPad, zeroPad, fieldWidth) + 1;
return print_number(putch, bufptr, 0 - number, leftPad, zeroPad, fieldWidth) + 1;
}
return printNumber(putch, bufptr, number, leftPad, zeroPad, fieldWidth);
return print_number(putch, bufptr, number, leftPad, zeroPad, fieldWidth);
}
template<typename PutChFunc>
ALWAYS_INLINE int printfInternal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
{
const char *p;
@ -174,16 +174,16 @@ one_more:
case 's':
{
const char* sp = va_arg(ap, const char*);
ret += printString(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
ret += print_string(putch, bufptr, sp ? sp : "(null)", leftPad, fieldWidth);
}
break;
case 'd':
ret += printSignedNumber(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth);
ret += print_signed_number(putch, bufptr, va_arg(ap, int), leftPad, zeroPad, fieldWidth);
break;
case 'u':
ret += printNumber(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
ret += print_number(putch, bufptr, va_arg(ap, dword), leftPad, zeroPad, fieldWidth);
break;
case 'o':
@ -191,15 +191,15 @@ one_more:
break;
case 'x':
ret += printHex(putch, bufptr, va_arg(ap, dword), 8);
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
break;
case 'w':
ret += printHex(putch, bufptr, va_arg(ap, int), 4);
ret += print_hex(putch, bufptr, va_arg(ap, int), 4);
break;
case 'b':
ret += printHex(putch, bufptr, va_arg(ap, int), 2);
ret += print_hex(putch, bufptr, va_arg(ap, int), 2);
break;
case 'c':
@ -211,7 +211,7 @@ one_more:
putch(bufptr, '0');
putch(bufptr, 'x');
ret += 2;
ret += printHex(putch, bufptr, va_arg(ap, dword), 8);
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8);
break;
}
}

View file

@ -13,7 +13,7 @@
#include "FileSystemPath.h"
#include "Lock.h"
static void testWeakPtr();
static void test_weak_ptr();
void log_locked() { }
void log_unlocked() { }
@ -223,7 +223,7 @@ int main(int c, char** v)
}
{
auto printInts = [] (const Vector<int>& v) {
auto print_ints = [] (const Vector<int>& v) {
printf("Vector {\n size: %zu\n capacity: %zu\n elements: ", v.size(), v.capacity());
for (auto i : v)
printf("%d ", i);
@ -235,23 +235,23 @@ int main(int c, char** v)
v.append(1);
v.append(2);
v.append(3);
printInts(v);
print_ints(v);
v.remove(1);
printInts(v);
print_ints(v);
v.remove(0);
printInts(v);
print_ints(v);
v.remove(0);
printInts(v);
print_ints(v);
v.remove(0);
printInts(v);
print_ints(v);
}
{
auto printInts = [] (const HashTable<int>& h) {
auto print_ints = [] (const HashTable<int>& h) {
printf("HashTable {\n size: %u\n capacity: %u\n elements: ", h.size(), h.capacity());
for (auto i : h)
printf("%d ", i);
@ -268,17 +268,17 @@ int main(int c, char** v)
h.dump();
printInts(h);
print_ints(h);
h.remove(30);
printInts(h);
print_ints(h);
h.set(30);
h.remove(30);
printInts(h);
print_ints(h);
}
testWeakPtr();
test_weak_ptr();
return 0;
}
@ -289,16 +289,16 @@ public:
~TestWeakable() { }
};
void testWeakPtr()
void test_weak_ptr()
{
auto* weakable = new TestWeakable;
auto weakPtr = weakable->makeWeakPtr();
ASSERT(weakPtr);
ASSERT(weakPtr.ptr() == weakable);
auto weak_ptr = weakable->make_weak_ptr();
ASSERT(weak_ptr);
ASSERT(weak_ptr.ptr() == weakable);
delete weakable;
ASSERT(!weakPtr);
ASSERT(weakPtr.ptr() == nullptr);
ASSERT(!weak_ptr);
ASSERT(weak_ptr.ptr() == nullptr);
}

View file

@ -26,7 +26,7 @@ public:
virtual ssize_t write(Process&, const byte* data, size_t size) override;
virtual const char* class_name() const override { return "Console"; }
void setImplementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
void put_char(char);

View file

@ -42,7 +42,7 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
StringBuilder builder;
builder.appendf("%u", index);
file->m_name = builder.build();
file->m_name = builder.to_string();
auto* device = VFS::the().get_device(11, index);
ASSERT(device);
@ -51,8 +51,8 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
file->m_metadata.uid = device->uid();
file->m_metadata.gid = device->gid();
file->m_metadata.mode = 0020644;
file->m_metadata.majorDevice = device->major();
file->m_metadata.minorDevice = device->minor();
file->m_metadata.major_device = device->major();
file->m_metadata.minor_device = device->minor();
file->m_metadata.mtime = mepoch;
return file;
}

View file

@ -13,63 +13,63 @@ DiskBackedFS::~DiskBackedFS()
{
}
bool DiskBackedFS::writeBlock(unsigned index, const ByteBuffer& data)
bool DiskBackedFS::write_block(unsigned index, const ByteBuffer& data)
{
#ifdef DBFS_DEBUG
kprintf("DiskBackedFileSystem::writeBlock %u, size=%u\n", index, data.size());
kprintf("DiskBackedFileSystem::write_block %u, size=%u\n", index, data.size());
#endif
ASSERT(data.size() == blockSize());
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
return device().write(baseOffset, blockSize(), data.pointer());
ASSERT(data.size() == block_size());
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
return device().write(base_offset, block_size(), data.pointer());
}
bool DiskBackedFS::writeBlocks(unsigned index, unsigned count, const ByteBuffer& data)
bool DiskBackedFS::write_blocks(unsigned index, unsigned count, const ByteBuffer& data)
{
#ifdef DBFS_DEBUG
kprintf("DiskBackedFileSystem::writeBlocks %u x%u\n", index, count);
kprintf("DiskBackedFileSystem::write_blocks %u x%u\n", index, count);
#endif
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
return device().write(baseOffset, count * blockSize(), data.pointer());
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
return device().write(base_offset, count * block_size(), data.pointer());
}
ByteBuffer DiskBackedFS::readBlock(unsigned index) const
ByteBuffer DiskBackedFS::read_block(unsigned index) const
{
#ifdef DBFS_DEBUG
kprintf("DiskBackedFileSystem::readBlock %u\n", index);
kprintf("DiskBackedFileSystem::read_block %u\n", index);
#endif
auto buffer = ByteBuffer::create_uninitialized(blockSize());
//kprintf("created block buffer with size %u\n", blockSize());
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
auto* bufferPointer = buffer.pointer();
bool success = device().read(baseOffset, blockSize(), bufferPointer);
auto buffer = ByteBuffer::create_uninitialized(block_size());
//kprintf("created block buffer with size %u\n", block_size());
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
auto* buffer_pointer = buffer.pointer();
bool success = device().read(base_offset, block_size(), buffer_pointer);
ASSERT(success);
ASSERT(buffer.size() == blockSize());
ASSERT(buffer.size() == block_size());
return buffer;
}
ByteBuffer DiskBackedFS::readBlocks(unsigned index, unsigned count) const
ByteBuffer DiskBackedFS::read_blocks(unsigned index, unsigned count) const
{
if (!count)
return nullptr;
if (count == 1)
return readBlock(index);
auto blocks = ByteBuffer::create_uninitialized(count * blockSize());
return read_block(index);
auto blocks = ByteBuffer::create_uninitialized(count * block_size());
byte* out = blocks.pointer();
for (unsigned i = 0; i < count; ++i) {
auto block = readBlock(index + i);
auto block = read_block(index + i);
if (!block)
return nullptr;
memcpy(out, block.pointer(), block.size());
out += blockSize();
out += block_size();
}
return blocks;
}
void DiskBackedFS::setBlockSize(unsigned blockSize)
void DiskBackedFS::set_block_size(unsigned block_size)
{
if (blockSize == m_blockSize)
if (block_size == m_block_size)
return;
m_blockSize = blockSize;
m_block_size = block_size;
}

View file

@ -10,20 +10,20 @@ public:
DiskDevice& device() { return *m_device; }
const DiskDevice& device() const { return *m_device; }
size_t blockSize() const { return m_blockSize; }
size_t block_size() const { return m_block_size; }
protected:
explicit DiskBackedFS(RetainPtr<DiskDevice>&&);
void setBlockSize(unsigned);
void set_block_size(unsigned);
ByteBuffer readBlock(unsigned index) const;
ByteBuffer readBlocks(unsigned index, unsigned count) const;
ByteBuffer read_block(unsigned index) const;
ByteBuffer read_blocks(unsigned index, unsigned count) const;
bool writeBlock(unsigned index, const ByteBuffer&);
bool writeBlocks(unsigned index, unsigned count, const ByteBuffer&);
bool write_block(unsigned index, const ByteBuffer&);
bool write_blocks(unsigned index, unsigned count, const ByteBuffer&);
private:
size_t m_blockSize { 0 };
size_t m_block_size { 0 };
RetainPtr<DiskDevice> m_device;
};

View file

@ -13,10 +13,10 @@ bool DiskDevice::read(DiskOffset offset, unsigned length, byte* out) const
//kprintf("DD::read %u x%u\n", offset, length);
ASSERT((offset % block_size()) == 0);
ASSERT((length % block_size()) == 0);
dword firstBlock = offset / block_size();
dword endBlock = (offset + length) / block_size();
dword first_block = offset / block_size();
dword end_block = (offset + length) / block_size();
byte* outptr = out;
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
for (unsigned bi = first_block; bi < end_block; ++bi) {
if (!read_block(bi, outptr))
return false;
outptr += block_size();
@ -28,12 +28,12 @@ bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in)
{
ASSERT((offset % block_size()) == 0);
ASSERT((length % block_size()) == 0);
dword firstBlock = offset / block_size();
dword endBlock = (offset + length) / block_size();
ASSERT(firstBlock <= 0xffffffff);
ASSERT(endBlock <= 0xffffffff);
dword first_block = offset / block_size();
dword end_block = (offset + length) / block_size();
ASSERT(first_block <= 0xffffffff);
ASSERT(end_block <= 0xffffffff);
const byte* inptr = in;
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
for (unsigned bi = first_block; bi < end_block; ++bi) {
if (!write_block(bi, inptr))
return false;
inptr += block_size();

View file

@ -11,7 +11,7 @@ ELFImage::~ELFImage()
{
}
static const char* objectFileTypeToString(Elf32_Half type)
static const char* object_file_type_to_string(Elf32_Half type)
{
switch (type) {
case ET_NONE: return "None";
@ -40,14 +40,14 @@ unsigned ELFImage::symbol_count() const
void ELFImage::dump()
{
kprintf("ELFImage{%p} {\n", this);
kprintf(" isValid: %u\n", is_valid());
kprintf(" is_valid: %u\n", is_valid());
if (!is_valid()) {
kprintf("}\n");
return;
}
kprintf(" type: %s\n", objectFileTypeToString(header().e_type));
kprintf(" type: %s\n", object_file_type_to_string(header().e_type));
kprintf(" machine: %u\n", header().e_machine);
kprintf(" entry: %x\n", header().e_entry);
kprintf(" shoff: %u\n", header().e_shoff);
@ -158,8 +158,8 @@ const Elf32_Shdr& ELFImage::section_header(unsigned index) const
const ELFImage::Symbol ELFImage::symbol(unsigned index) const
{
ASSERT(index < symbol_count());
auto* rawSyms = reinterpret_cast<const Elf32_Sym*>(raw_data(section(m_symbol_table_section_index).offset()));
return Symbol(*this, index, rawSyms[index]);
auto* raw_syms = reinterpret_cast<const Elf32_Sym*>(raw_data(section(m_symbol_table_section_index).offset()));
return Symbol(*this, index, raw_syms[index]);
}
const ELFImage::Section ELFImage::section(unsigned index) const
@ -185,23 +185,23 @@ const ELFImage::Relocation ELFImage::RelocationSection::relocation(unsigned inde
const ELFImage::RelocationSection ELFImage::Section::relocations() const
{
// FIXME: This is ugly.
char relocationSectionName[128];
ksprintf(relocationSectionName, ".rel%s", name());
char relocation_sectionName[128];
ksprintf(relocation_sectionName, ".rel%s", name());
#ifdef ELFIMAGE_DEBUG
kprintf("looking for '%s'\n", relocationSectionName);
kprintf("looking for '%s'\n", relocation_sectionName);
#endif
auto relocationSection = m_image.lookupSection(relocationSectionName);
if (relocationSection.type() != SHT_REL)
auto relocation_section = m_image.lookup_section(relocation_sectionName);
if (relocation_section.type() != SHT_REL)
return static_cast<const RelocationSection>(m_image.section(0));
#ifdef ELFIMAGE_DEBUG
kprintf("Found relocations for %s in %s\n", name(), relocationSection.name());
kprintf("Found relocations for %s in %s\n", name(), relocation_section.name());
#endif
return static_cast<const RelocationSection>(relocationSection);
return static_cast<const RelocationSection>(relocation_section);
}
const ELFImage::Section ELFImage::lookupSection(const char* name) const
const ELFImage::Section ELFImage::lookup_section(const char* name) const
{
if (auto it = m_sections.find(name); it != m_sections.end())
return section((*it).value);

View file

@ -150,7 +150,7 @@ public:
// NOTE: Returns section(0) if section with name is not found.
// FIXME: I don't love this API.
const Section lookupSection(const char* name) const;
const Section lookup_section(const char* name) const;
bool is_executable() const { return header().e_type == ET_EXEC; }
bool is_relocatable() const { return header().e_type == ET_REL; }
@ -158,7 +158,7 @@ public:
LinearAddress entry() const { return LinearAddress(header().e_entry); }
private:
bool parseHeader();
bool parse_header();
const char* raw_data(unsigned offset) const;
const Elf32_Ehdr& header() const;
const Elf32_Shdr& section_header(unsigned) const;

View file

@ -142,7 +142,7 @@ bool ELFLoader::perform_relocations()
failed = true;
return false;
}
ptrdiff_t relativeOffset = (char*)target_ptr - ((char*)&patch_ptr + 4);
ptrdiff_t relative_offset = (char*)target_ptr - ((char*)&patch_ptr + 4);
#ifdef ELFLOADER_DEBUG
kprintf("ELFLoader: Relocate PC32: offset=%x, symbol=%u(%s) value=%x target=%p, offset=%d\n",
relocation.offset(),
@ -150,10 +150,10 @@ bool ELFLoader::perform_relocations()
symbol.name(),
symbol.value(),
target_ptr,
relativeOffset
relative_offset
);
#endif
patch_ptr = relativeOffset;
patch_ptr = relative_offset;
break;
}
case R_386_32: {

View file

@ -62,45 +62,45 @@ const ext2_super_block& Ext2FS::super_block() const
const ext2_group_desc& Ext2FS::group_descriptor(unsigned groupIndex) const
{
// FIXME: Should this fail gracefully somehow?
ASSERT(groupIndex <= m_blockGroupCount);
ASSERT(groupIndex <= m_block_group_count);
if (!m_cached_group_descriptor_table) {
unsigned blocksToRead = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
unsigned firstBlockOfBGDT = blockSize() == 1024 ? 2 : 1;
unsigned blocks_to_read = ceil_div(m_block_group_count * (unsigned)sizeof(ext2_group_desc), block_size());
unsigned first_block_of_bgdt = block_size() == 1024 ? 2 : 1;
#ifdef EXT2_DEBUG
kprintf("ext2fs: block group count: %u, blocks-to-read: %u\n", m_blockGroupCount, blocksToRead);
kprintf("ext2fs: first block of BGDT: %u\n", firstBlockOfBGDT);
kprintf("ext2fs: block group count: %u, blocks-to-read: %u\n", m_block_group_count, blocks_to_read);
kprintf("ext2fs: first block of BGDT: %u\n", first_block_of_bgdt);
#endif
m_cached_group_descriptor_table = readBlocks(firstBlockOfBGDT, blocksToRead);
m_cached_group_descriptor_table = read_blocks(first_block_of_bgdt, blocks_to_read);
}
return reinterpret_cast<ext2_group_desc*>(m_cached_group_descriptor_table.pointer())[groupIndex - 1];
}
bool Ext2FS::initialize()
{
auto& superBlock = this->super_block();
auto& super_block = this->super_block();
#ifdef EXT2_DEBUG
kprintf("ext2fs: super block magic: %x (super block size: %u)\n", superBlock.s_magic, sizeof(ext2_super_block));
kprintf("ext2fs: super block magic: %x (super block size: %u)\n", super_block.s_magic, sizeof(ext2_super_block));
#endif
if (superBlock.s_magic != EXT2_SUPER_MAGIC)
if (super_block.s_magic != EXT2_SUPER_MAGIC)
return false;
#ifdef EXT2_DEBUG
kprintf("ext2fs: %u inodes, %u blocks\n", superBlock.s_inodes_count, superBlock.s_blocks_count);
kprintf("ext2fs: block size = %u\n", EXT2_BLOCK_SIZE(&superBlock));
kprintf("ext2fs: first data block = %u\n", superBlock.s_first_data_block);
kprintf("ext2fs: %u inodes, %u blocks\n", super_block.s_inodes_count, super_block.s_blocks_count);
kprintf("ext2fs: block size = %u\n", EXT2_BLOCK_SIZE(&super_block));
kprintf("ext2fs: first data block = %u\n", super_block.s_first_data_block);
kprintf("ext2fs: inodes per block = %u\n", inodes_per_block());
kprintf("ext2fs: inodes per group = %u\n", inodes_per_group());
kprintf("ext2fs: free inodes = %u\n", superBlock.s_free_inodes_count);
kprintf("ext2fs: desc per block = %u\n", EXT2_DESC_PER_BLOCK(&superBlock));
kprintf("ext2fs: desc size = %u\n", EXT2_DESC_SIZE(&superBlock));
kprintf("ext2fs: free inodes = %u\n", super_block.s_free_inodes_count);
kprintf("ext2fs: desc per block = %u\n", EXT2_DESC_PER_BLOCK(&super_block));
kprintf("ext2fs: desc size = %u\n", EXT2_DESC_SIZE(&super_block));
#endif
setBlockSize(EXT2_BLOCK_SIZE(&superBlock));
set_block_size(EXT2_BLOCK_SIZE(&super_block));
m_blockGroupCount = ceilDiv(superBlock.s_blocks_count, superBlock.s_blocks_per_group);
m_block_group_count = ceil_div(super_block.s_blocks_count, super_block.s_blocks_per_group);
if (m_blockGroupCount == 0) {
if (m_block_group_count == 0) {
kprintf("ext2fs: no block groups :(\n");
return false;
}
@ -109,7 +109,7 @@ bool Ext2FS::initialize()
group_descriptor(0);
#ifdef EXT2_DEBUG
for (unsigned i = 1; i <= m_blockGroupCount; ++i) {
for (unsigned i = 1; i <= m_block_group_count; ++i) {
auto& group = group_descriptor(i);
kprintf("ext2fs: group[%u] { block_bitmap: %u, inode_bitmap: %u, inode_table: %u }\n",
i,
@ -132,23 +132,23 @@ InodeIdentifier Ext2FS::root_inode() const
return { fsid(), EXT2_ROOT_INO };
}
ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& blockIndex, unsigned& offset) const
ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& block_index, unsigned& offset) const
{
auto& superBlock = this->super_block();
auto& super_block = this->super_block();
if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&superBlock))
if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&super_block))
return { };
if (inode > superBlock.s_inodes_count)
if (inode > super_block.s_inodes_count)
return { };
auto& bgd = group_descriptor(group_index_from_inode(inode));
offset = ((inode - 1) % inodes_per_group()) * inode_size();
blockIndex = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&superBlock));
offset &= blockSize() - 1;
block_index = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&super_block));
offset &= block_size() - 1;
return readBlock(blockIndex);
return read_block(block_index);
}
Ext2FS::BlockListShape Ext2FS::compute_block_list_shape(unsigned blocks)
@ -192,7 +192,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
set_block_allocation_state(group_index_from_inode(inode_index), bi, true);
}
e2inode.i_blocks = (blocks.size() + new_shape.meta_blocks) * (blockSize() / 512);
e2inode.i_blocks = (blocks.size() + new_shape.meta_blocks) * (block_size() / 512);
unsigned output_block_index = 0;
unsigned remaining_blocks = blocks.size();
@ -212,7 +212,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
{
dbgprintf("Ext2FS: Writing out indirect blockptr block for inode %u\n", inode_index);
auto block_contents = ByteBuffer::create_uninitialized(blockSize());
auto block_contents = ByteBuffer::create_uninitialized(block_size());
BufferStream stream(block_contents);
ASSERT(new_shape.indirect_blocks <= EXT2_ADDR_PER_BLOCK(&super_block()));
for (unsigned i = 0; i < new_shape.indirect_blocks; ++i) {
@ -220,7 +220,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
--remaining_blocks;
}
stream.fill_to_end(0);
writeBlock(e2inode.i_block[EXT2_IND_BLOCK], block_contents);
write_block(e2inode.i_block[EXT2_IND_BLOCK], block_contents);
}
if (!remaining_blocks)
@ -232,11 +232,11 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool include_block_list_blocks) const
{
unsigned entriesPerBlock = EXT2_ADDR_PER_BLOCK(&super_block());
unsigned entries_per_block = EXT2_ADDR_PER_BLOCK(&super_block());
// NOTE: i_blocks is number of 512-byte blocks, not number of fs-blocks.
unsigned blockCount = e2inode.i_blocks / (blockSize() / 512);
unsigned blocksRemaining = blockCount;
unsigned block_count = e2inode.i_blocks / (block_size() / 512);
unsigned blocksRemaining = block_count;
Vector<unsigned> list;
if (include_block_list_blocks) {
// This seems like an excessive over-estimate but w/e.
@ -245,8 +245,8 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
list.ensure_capacity(blocksRemaining);
}
unsigned directCount = min(blockCount, (unsigned)EXT2_NDIR_BLOCKS);
for (unsigned i = 0; i < directCount; ++i) {
unsigned direct_count = min(block_count, (unsigned)EXT2_NDIR_BLOCKS);
for (unsigned i = 0; i < direct_count; ++i) {
list.unchecked_append(e2inode.i_block[i]);
--blocksRemaining;
}
@ -254,13 +254,13 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
if (!blocksRemaining)
return list;
auto processBlockArray = [&] (unsigned arrayBlockIndex, auto&& callback) {
auto process_block_array = [&] (unsigned array_block_index, auto&& callback) {
if (include_block_list_blocks)
callback(arrayBlockIndex);
auto arrayBlock = readBlock(arrayBlockIndex);
ASSERT(arrayBlock);
auto* array = reinterpret_cast<const __u32*>(arrayBlock.pointer());
unsigned count = min(blocksRemaining, entriesPerBlock);
callback(array_block_index);
auto array_block = read_block(array_block_index);
ASSERT(array_block);
auto* array = reinterpret_cast<const __u32*>(array_block.pointer());
unsigned count = min(blocksRemaining, entries_per_block);
for (unsigned i = 0; i < count; ++i) {
if (!array[i]) {
blocksRemaining = 0;
@ -271,15 +271,15 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
}
};
processBlockArray(e2inode.i_block[EXT2_IND_BLOCK], [&] (unsigned entry) {
process_block_array(e2inode.i_block[EXT2_IND_BLOCK], [&] (unsigned entry) {
list.unchecked_append(entry);
});
if (!blocksRemaining)
return list;
processBlockArray(e2inode.i_block[EXT2_DIND_BLOCK], [&] (unsigned entry) {
processBlockArray(entry, [&] (unsigned entry) {
process_block_array(e2inode.i_block[EXT2_DIND_BLOCK], [&] (unsigned entry) {
process_block_array(entry, [&] (unsigned entry) {
list.unchecked_append(entry);
});
});
@ -287,9 +287,9 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
if (!blocksRemaining)
return list;
processBlockArray(e2inode.i_block[EXT2_TIND_BLOCK], [&] (unsigned entry) {
processBlockArray(entry, [&] (unsigned entry) {
processBlockArray(entry, [&] (unsigned entry) {
process_block_array(e2inode.i_block[EXT2_TIND_BLOCK], [&] (unsigned entry) {
process_block_array(entry, [&] (unsigned entry) {
process_block_array(entry, [&] (unsigned entry) {
list.unchecked_append(entry);
});
});
@ -324,9 +324,9 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
void Ext2FS::flush_block_group_descriptor_table()
{
unsigned blocks_to_write = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
unsigned first_block_of_bgdt = blockSize() == 1024 ? 2 : 1;
writeBlocks(first_block_of_bgdt, blocks_to_write, m_cached_group_descriptor_table);
unsigned blocks_to_write = ceil_div(m_block_group_count * (unsigned)sizeof(ext2_group_desc), block_size());
unsigned first_block_of_bgdt = block_size() == 1024 ? 2 : 1;
write_blocks(first_block_of_bgdt, blocks_to_write, m_cached_group_descriptor_table);
}
Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index, const ext2_inode& raw_inode)
@ -349,18 +349,18 @@ InodeMetadata Ext2FSInode::metadata() const
metadata.mode = m_raw_inode.i_mode;
metadata.uid = m_raw_inode.i_uid;
metadata.gid = m_raw_inode.i_gid;
metadata.linkCount = m_raw_inode.i_links_count;
metadata.link_count = m_raw_inode.i_links_count;
metadata.atime = m_raw_inode.i_atime;
metadata.ctime = m_raw_inode.i_ctime;
metadata.mtime = m_raw_inode.i_mtime;
metadata.dtime = m_raw_inode.i_dtime;
metadata.blockSize = fs().blockSize();
metadata.blockCount = m_raw_inode.i_blocks;
metadata.block_size = fs().block_size();
metadata.block_count = m_raw_inode.i_blocks;
if (isBlockDevice(m_raw_inode.i_mode) || isCharacterDevice(m_raw_inode.i_mode)) {
if (::is_block_device(m_raw_inode.i_mode) || ::is_character_device(m_raw_inode.i_mode)) {
unsigned dev = m_raw_inode.i_block[0];
metadata.majorDevice = (dev & 0xfff00) >> 8;
metadata.minorDevice = (dev & 0xff) | ((dev >> 12) & 0xfff00);
metadata.major_device = (dev & 0xfff00) >> 8;
metadata.minor_device = (dev & 0xff) | ((dev >> 12) & 0xfff00);
}
return metadata;
}
@ -414,7 +414,7 @@ RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
if (it != m_inode_cache.end())
return (*it).value;
auto new_inode = adopt(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index(), *raw_inode));
m_inode_cache.set(inode.index(), new_inode.copyRef());
m_inode_cache.set(inode.index(), new_inode.copy_ref());
return new_inode;
}
@ -445,7 +445,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDe
return -EIO;
}
const size_t block_size = fs().blockSize();
const size_t block_size = fs().block_size();
dword first_block_logical_index = offset / block_size;
dword last_block_logical_index = (offset + count) / block_size;
@ -464,9 +464,9 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDe
#endif
for (dword bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
auto block = fs().readBlock(m_block_list[bi]);
auto block = fs().read_block(m_block_list[bi]);
if (!block) {
kprintf("ext2fs: read_bytes: readBlock(%u) failed (lbi: %u)\n", m_block_list[bi], bi);
kprintf("ext2fs: read_bytes: read_block(%u) failed (lbi: %u)\n", m_block_list[bi], bi);
return -EIO;
}
@ -490,11 +490,11 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
ASSERT(offset >= 0);
const size_t block_size = fs().blockSize();
const size_t block_size = fs().block_size();
size_t new_size = max(static_cast<size_t>(offset) + count, size());
unsigned blocks_needed_before = ceilDiv(size(), block_size);
unsigned blocks_needed_after = ceilDiv(new_size, block_size);
unsigned blocks_needed_before = ceil_div(size(), block_size);
unsigned blocks_needed_after = ceil_div(new_size, block_size);
auto block_list = fs().block_list_for_inode(m_raw_inode);
if (blocks_needed_after > blocks_needed_before) {
@ -529,9 +529,9 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
ByteBuffer block;
if (offset_into_block != 0) {
block = fs().readBlock(block_list[bi]);
block = fs().read_block(block_list[bi]);
if (!block) {
kprintf("Ext2FSInode::write_bytes: readBlock(%u) failed (lbi: %u)\n", block_list[bi], bi);
kprintf("Ext2FSInode::write_bytes: read_block(%u) failed (lbi: %u)\n", block_list[bi], bi);
return -EIO;
}
} else
@ -543,9 +543,9 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
#ifdef EXT2_DEBUG
dbgprintf("Ext2FSInode::write_bytes: writing block %u (offset_into_block: %u)\n", block_list[bi], offset_into_block);
#endif
bool success = fs().writeBlock(block_list[bi], block);
bool success = fs().write_block(block_list[bi], block);
if (!success) {
kprintf("Ext2FSInode::write_bytes: writeBlock(%u) failed (lbi: %u)\n", block_list[bi], bi);
kprintf("Ext2FSInode::write_bytes: write_block(%u) failed (lbi: %u)\n", block_list[bi], bi);
return -EIO;
}
remaining_count -= num_bytes_to_copy;
@ -569,7 +569,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
bool Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
{
ASSERT(metadata().isDirectory());
ASSERT(metadata().is_directory());
#ifdef EXT2_DEBUG
kprintf("Ext2Inode::traverse_as_directory: inode=%u:\n", index());
@ -676,40 +676,40 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr
{
dbgprintf("Ext2FS: New directory inode %u contents to write:\n", directoryInode);
unsigned directorySize = 0;
unsigned directory_size = 0;
for (auto& entry : entries) {
//kprintf(" - %08u %s\n", entry.inode.index(), entry.name);
directorySize += EXT2_DIR_REC_LEN(entry.name_length);
directory_size += EXT2_DIR_REC_LEN(entry.name_length);
}
unsigned blocksNeeded = ceilDiv(directorySize, blockSize());
unsigned occupiedSize = blocksNeeded * blockSize();
unsigned blocks_needed = ceil_div(directory_size, block_size());
unsigned occupied_size = blocks_needed * block_size();
dbgprintf("Ext2FS: directory size: %u (occupied: %u)\n", directorySize, occupiedSize);
dbgprintf("Ext2FS: directory size: %u (occupied: %u)\n", directory_size, occupied_size);
auto directoryData = ByteBuffer::create_uninitialized(occupiedSize);
auto directory_data = ByteBuffer::create_uninitialized(occupied_size);
BufferStream stream(directoryData);
BufferStream stream(directory_data);
for (unsigned i = 0; i < entries.size(); ++i) {
auto& entry = entries[i];
unsigned recordLength = EXT2_DIR_REC_LEN(entry.name_length);
unsigned record_length = EXT2_DIR_REC_LEN(entry.name_length);
if (i == entries.size() - 1)
recordLength += occupiedSize - directorySize;
record_length += occupied_size - directory_size;
dbgprintf("* inode: %u", entry.inode.index());
dbgprintf(", name_len: %u", word(entry.name_length));
dbgprintf(", rec_len: %u", word(recordLength));
dbgprintf(", file_type: %u", byte(entry.fileType));
dbgprintf(", rec_len: %u", word(record_length));
dbgprintf(", file_type: %u", byte(entry.file_type));
dbgprintf(", name: %s\n", entry.name);
stream << dword(entry.inode.index());
stream << word(recordLength);
stream << word(record_length);
stream << byte(entry.name_length);
stream << byte(entry.fileType);
stream << byte(entry.file_type);
stream << entry.name;
unsigned padding = recordLength - entry.name_length - 8;
unsigned padding = record_length - entry.name_length - 8;
//dbgprintf(" *** pad %u bytes\n", padding);
for (unsigned j = 0; j < padding; ++j) {
stream << byte(0);
@ -719,9 +719,9 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr
stream.fill_to_end(0);
#if 0
kprintf("data to write (%u):\n", directoryData.size());
for (unsigned i = 0; i < directoryData.size(); ++i) {
kprintf("%02x ", directoryData[i]);
kprintf("data to write (%u):\n", directory_data.size());
for (unsigned i = 0; i < directory_data.size(); ++i) {
kprintf("%02x ", directory_data[i]);
if ((i + 1) % 8 == 0)
kprintf(" ");
if ((i + 1) % 16 == 0)
@ -731,8 +731,8 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr
#endif
auto directory_inode = get_inode({ fsid(), directoryInode });
ssize_t nwritten = directory_inode->write_bytes(0, directoryData.size(), directoryData.pointer(), nullptr);
return nwritten == directoryData.size();
ssize_t nwritten = directory_inode->write_bytes(0, directory_data.size(), directory_data.pointer(), nullptr);
return nwritten == directory_data.size();
}
unsigned Ext2FS::inodes_per_block() const
@ -757,19 +757,19 @@ unsigned Ext2FS::blocks_per_group() const
void Ext2FS::dump_block_bitmap(unsigned groupIndex) const
{
ASSERT(groupIndex <= m_blockGroupCount);
ASSERT(groupIndex <= m_block_group_count);
auto& bgd = group_descriptor(groupIndex);
unsigned blocksInGroup = min(blocks_per_group(), super_block().s_blocks_count);
unsigned blockCount = ceilDiv(blocksInGroup, 8u);
unsigned blocks_in_group = min(blocks_per_group(), super_block().s_blocks_count);
unsigned block_count = ceil_div(blocks_in_group, 8u);
auto bitmapBlocks = readBlocks(bgd.bg_block_bitmap, blockCount);
ASSERT(bitmapBlocks);
auto bitmap_blocks = read_blocks(bgd.bg_block_bitmap, block_count);
ASSERT(bitmap_blocks);
kprintf("ext2fs: group[%u] block bitmap (bitmap occupies %u blocks):\n", groupIndex, blockCount);
kprintf("ext2fs: group[%u] block bitmap (bitmap occupies %u blocks):\n", groupIndex, block_count);
auto bitmap = Bitmap::wrap(bitmapBlocks.pointer(), blocksInGroup);
for (unsigned i = 0; i < blocksInGroup; ++i) {
auto bitmap = Bitmap::wrap(bitmap_blocks.pointer(), blocks_in_group);
for (unsigned i = 0; i < blocks_in_group; ++i) {
kprintf("%c", bitmap.get(i) ? '1' : '0');
}
kprintf("\n");
@ -787,17 +787,17 @@ void Ext2FS::dump_inode_bitmap(unsigned groupIndex) const
template<typename F>
void Ext2FS::traverse_inode_bitmap(unsigned groupIndex, F callback) const
{
ASSERT(groupIndex <= m_blockGroupCount);
ASSERT(groupIndex <= m_block_group_count);
auto& bgd = group_descriptor(groupIndex);
unsigned inodesInGroup = min(inodes_per_group(), super_block().s_inodes_count);
unsigned blockCount = ceilDiv(inodesInGroup, 8u);
unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count);
unsigned block_count = ceil_div(inodes_in_group, 8u);
for (unsigned i = 0; i < blockCount; ++i) {
auto block = readBlock(bgd.bg_inode_bitmap + i);
for (unsigned i = 0; i < block_count; ++i) {
auto block = read_block(bgd.bg_inode_bitmap + i);
ASSERT(block);
bool shouldContinue = callback(i * (blockSize() / 8) + 1, Bitmap::wrap(block.pointer(), inodesInGroup));
if (!shouldContinue)
bool should_continue = callback(i * (block_size() / 8) + 1, Bitmap::wrap(block.pointer(), inodes_in_group));
if (!should_continue)
break;
}
}
@ -805,30 +805,30 @@ void Ext2FS::traverse_inode_bitmap(unsigned groupIndex, F callback) const
template<typename F>
void Ext2FS::traverse_block_bitmap(unsigned groupIndex, F callback) const
{
ASSERT(groupIndex <= m_blockGroupCount);
ASSERT(groupIndex <= m_block_group_count);
auto& bgd = group_descriptor(groupIndex);
unsigned blocksInGroup = min(blocks_per_group(), super_block().s_blocks_count);
unsigned blockCount = ceilDiv(blocksInGroup, 8u);
unsigned blocks_in_group = min(blocks_per_group(), super_block().s_blocks_count);
unsigned block_count = ceil_div(blocks_in_group, 8u);
for (unsigned i = 0; i < blockCount; ++i) {
auto block = readBlock(bgd.bg_block_bitmap + i);
for (unsigned i = 0; i < block_count; ++i) {
auto block = read_block(bgd.bg_block_bitmap + i);
ASSERT(block);
bool shouldContinue = callback(i * (blockSize() / 8) + 1, Bitmap::wrap(block.pointer(), blocksInGroup));
if (!shouldContinue)
bool should_continue = callback(i * (block_size() / 8) + 1, Bitmap::wrap(block.pointer(), blocks_in_group));
if (!should_continue)
break;
}
}
bool Ext2FS::write_ext2_inode(unsigned inode, const ext2_inode& e2inode)
{
unsigned blockIndex;
unsigned block_index;
unsigned offset;
auto block = read_block_containing_inode(inode, blockIndex, offset);
auto block = read_block_containing_inode(inode, block_index, offset);
if (!block)
return false;
memcpy(reinterpret_cast<ext2_inode*>(block.offset_pointer(offset)), &e2inode, inode_size());
writeBlock(blockIndex, block);
write_block(block_index, block);
return true;
}
@ -864,36 +864,36 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(unsigned group, unsigned coun
return blocks;
}
unsigned Ext2FS::allocate_inode(unsigned preferredGroup, unsigned expectedSize)
unsigned Ext2FS::allocate_inode(unsigned preferred_group, unsigned expected_size)
{
dbgprintf("Ext2FS: allocate_inode(preferredGroup: %u, expectedSize: %u)\n", preferredGroup, expectedSize);
dbgprintf("Ext2FS: allocate_inode(preferredGroup: %u, expectedSize: %u)\n", preferred_group, expected_size);
unsigned neededBlocks = ceilDiv(expectedSize, blockSize());
unsigned needed_blocks = ceil_div(expected_size, block_size());
dbgprintf("Ext2FS: minimum needed blocks: %u\n", neededBlocks);
dbgprintf("Ext2FS: minimum needed blocks: %u\n", needed_blocks);
unsigned groupIndex = 0;
auto isSuitableGroup = [this, neededBlocks] (unsigned groupIndex) {
auto is_suitable_group = [this, needed_blocks] (unsigned groupIndex) {
auto& bgd = group_descriptor(groupIndex);
return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= neededBlocks;
return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= needed_blocks;
};
if (preferredGroup && isSuitableGroup(preferredGroup)) {
groupIndex = preferredGroup;
if (preferred_group && is_suitable_group(preferred_group)) {
groupIndex = preferred_group;
} else {
for (unsigned i = 1; i <= m_blockGroupCount; ++i) {
if (isSuitableGroup(i))
for (unsigned i = 1; i <= m_block_group_count; ++i) {
if (is_suitable_group(i))
groupIndex = i;
}
}
if (!groupIndex) {
kprintf("Ext2FS: allocate_inode: no suitable group found for new inode with %u blocks needed :(\n", neededBlocks);
kprintf("Ext2FS: allocate_inode: no suitable group found for new inode with %u blocks needed :(\n", needed_blocks);
return 0;
}
dbgprintf("Ext2FS: allocate_inode: found suitable group [%u] for new inode with %u blocks needed :^)\n", groupIndex, neededBlocks);
dbgprintf("Ext2FS: allocate_inode: found suitable group [%u] for new inode with %u blocks needed :^)\n", groupIndex, needed_blocks);
unsigned firstFreeInodeInGroup = 0;
traverse_inode_bitmap(groupIndex, [&firstFreeInodeInGroup] (unsigned firstInodeInBitmap, const Bitmap& bitmap) {
@ -931,10 +931,10 @@ bool Ext2FS::get_inode_allocation_state(InodeIndex index) const
if (index == 0)
return true;
auto& bgd = group_descriptor(group_index_from_inode(index));
unsigned inodes_per_bitmap_block = blockSize() * 8;
unsigned inodes_per_bitmap_block = block_size() * 8;
unsigned bitmap_block_index = (index - 1) / inodes_per_bitmap_block;
unsigned bit_index = (index - 1) % inodes_per_bitmap_block;
auto block = readBlock(bgd.bg_inode_bitmap + bitmap_block_index);
auto block = read_block(bgd.bg_inode_bitmap + bitmap_block_index);
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), block.size());
return bitmap.get(bit_index);
@ -945,20 +945,20 @@ bool Ext2FS::set_inode_allocation_state(unsigned index, bool newState)
auto& bgd = group_descriptor(group_index_from_inode(index));
// Update inode bitmap
unsigned inodes_per_bitmap_block = blockSize() * 8;
unsigned inodes_per_bitmap_block = block_size() * 8;
unsigned bitmap_block_index = (index - 1) / inodes_per_bitmap_block;
unsigned bit_index = (index - 1) % inodes_per_bitmap_block;
auto block = readBlock(bgd.bg_inode_bitmap + bitmap_block_index);
auto block = read_block(bgd.bg_inode_bitmap + bitmap_block_index);
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), block.size());
bool currentState = bitmap.get(bit_index);
dbgprintf("Ext2FS: set_inode_allocation_state(%u) %u -> %u\n", index, currentState, newState);
bool current_state = bitmap.get(bit_index);
dbgprintf("Ext2FS: set_inode_allocation_state(%u) %u -> %u\n", index, current_state, newState);
if (currentState == newState)
if (current_state == newState)
return true;
bitmap.set(bit_index, newState);
writeBlock(bgd.bg_inode_bitmap + bitmap_block_index, block);
write_block(bgd.bg_inode_bitmap + bitmap_block_index, block);
// Update superblock
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
@ -970,53 +970,53 @@ bool Ext2FS::set_inode_allocation_state(unsigned index, bool newState)
write_super_block(sb);
// Update BGD
auto& mutableBGD = const_cast<ext2_group_desc&>(bgd);
auto& mutable_bgd = const_cast<ext2_group_desc&>(bgd);
if (newState)
--mutableBGD.bg_free_inodes_count;
--mutable_bgd.bg_free_inodes_count;
else
++mutableBGD.bg_free_inodes_count;
++mutable_bgd.bg_free_inodes_count;
dbgprintf("Ext2FS: group free inode count %u -> %u\n", bgd.bg_free_inodes_count, bgd.bg_free_inodes_count - 1);
flush_block_group_descriptor_table();
return true;
}
bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool newState)
bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool new_state)
{
dbgprintf("Ext2FS: set_block_allocation_state(group=%u, block=%u, state=%u)\n", group, bi, newState);
dbgprintf("Ext2FS: set_block_allocation_state(group=%u, block=%u, state=%u)\n", group, bi, new_state);
auto& bgd = group_descriptor(group);
// Update block bitmap
unsigned blocksPerBitmapBlock = blockSize() * 8;
unsigned bitmapBlockIndex = (bi - 1) / blocksPerBitmapBlock;
unsigned bitIndex = (bi - 1) % blocksPerBitmapBlock;
auto block = readBlock(bgd.bg_block_bitmap + bitmapBlockIndex);
unsigned blocks_per_bitmap_block = block_size() * 8;
unsigned bitmap_block_index = (bi - 1) / blocks_per_bitmap_block;
unsigned bit_index = (bi - 1) % blocks_per_bitmap_block;
auto block = read_block(bgd.bg_block_bitmap + bitmap_block_index);
ASSERT(block);
auto bitmap = Bitmap::wrap(block.pointer(), blocksPerBitmapBlock);
bool currentState = bitmap.get(bitIndex);
dbgprintf("Ext2FS: block %u state: %u -> %u\n", bi, currentState, newState);
auto bitmap = Bitmap::wrap(block.pointer(), blocks_per_bitmap_block);
bool current_state = bitmap.get(bit_index);
dbgprintf("Ext2FS: block %u state: %u -> %u\n", bi, current_state, new_state);
if (currentState == newState)
if (current_state == new_state)
return true;
bitmap.set(bitIndex, newState);
writeBlock(bgd.bg_block_bitmap + bitmapBlockIndex, block);
bitmap.set(bit_index, new_state);
write_block(bgd.bg_block_bitmap + bitmap_block_index, block);
// Update superblock
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
dbgprintf("Ext2FS: superblock free block count %u -> %u\n", sb.s_free_blocks_count, sb.s_free_blocks_count - 1);
if (newState)
if (new_state)
--sb.s_free_blocks_count;
else
++sb.s_free_blocks_count;
write_super_block(sb);
// Update BGD
auto& mutableBGD = const_cast<ext2_group_desc&>(bgd);
if (newState)
--mutableBGD.bg_free_blocks_count;
auto& mutable_bgd = const_cast<ext2_group_desc&>(bgd);
if (new_state)
--mutable_bgd.bg_free_blocks_count;
else
++mutableBGD.bg_free_blocks_count;
++mutable_bgd.bg_free_blocks_count;
dbgprintf("Ext2FS: group free block count %u -> %u\n", bgd.bg_free_blocks_count, bgd.bg_free_blocks_count - 1);
flush_block_group_descriptor_table();
@ -1034,7 +1034,7 @@ RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const Strin
// NOTE: When creating a new directory, make the size 1 block.
// There's probably a better strategy here, but this works for now.
auto inode = create_inode(parent_id, name, mode, blockSize(), error);
auto inode = create_inode(parent_id, name, mode, block_size(), error);
if (!inode)
return nullptr;
@ -1077,7 +1077,7 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
return { };
}
auto needed_blocks = ceilDiv(size, blockSize());
auto needed_blocks = ceil_div(size, block_size());
auto blocks = allocate_blocks(group_index_from_inode(inode_id), needed_blocks);
if (blocks.size() != needed_blocks) {
kprintf("Ext2FS: create_inode: allocate_blocks failed\n");
@ -1085,24 +1085,24 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
return { };
}
byte fileType = 0;
if (isRegularFile(mode))
fileType = EXT2_FT_REG_FILE;
else if (isDirectory(mode))
fileType = EXT2_FT_DIR;
else if (isCharacterDevice(mode))
fileType = EXT2_FT_CHRDEV;
else if (isBlockDevice(mode))
fileType = EXT2_FT_BLKDEV;
else if (isFIFO(mode))
fileType = EXT2_FT_FIFO;
else if (isSocket(mode))
fileType = EXT2_FT_SOCK;
else if (isSymbolicLink(mode))
fileType = EXT2_FT_SYMLINK;
byte file_type = 0;
if (is_regular_file(mode))
file_type = EXT2_FT_REG_FILE;
else if (is_directory(mode))
file_type = EXT2_FT_DIR;
else if (is_character_device(mode))
file_type = EXT2_FT_CHRDEV;
else if (is_block_device(mode))
file_type = EXT2_FT_BLKDEV;
else if (is_fifo(mode))
file_type = EXT2_FT_FIFO;
else if (is_socket(mode))
file_type = EXT2_FT_SOCK;
else if (is_symlink(mode))
file_type = EXT2_FT_SYMLINK;
// Try adding it to the directory first, in case the name is already in use.
bool success = parent_inode->add_child({ fsid(), inode_id }, name, fileType, error);
bool success = parent_inode->add_child({ fsid(), inode_id }, name, file_type, error);
if (!success)
return { };
@ -1115,11 +1115,11 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
ASSERT(success);
}
unsigned initialLinksCount;
if (isDirectory(mode))
initialLinksCount = 2; // (parent directory + "." entry in self)
unsigned initial_links_count;
if (is_directory(mode))
initial_links_count = 2; // (parent directory + "." entry in self)
else
initialLinksCount = 1;
initial_links_count = 1;
auto timestamp = RTC::now();
ext2_inode e2inode;
@ -1132,7 +1132,7 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
e2inode.i_mtime = timestamp;
e2inode.i_dtime = 0;
e2inode.i_gid = 0;
e2inode.i_links_count = initialLinksCount;
e2inode.i_links_count = initial_links_count;
success = write_block_list_for_inode(inode_id, e2inode, blocks);
ASSERT(success);

View file

@ -18,7 +18,7 @@ public:
virtual ~Ext2FSInode() override;
size_t size() const { return m_raw_inode.i_size; }
bool is_symlink() const { return isSymbolicLink(m_raw_inode.i_mode); }
bool is_symlink() const { return ::is_symlink(m_raw_inode.i_mode); }
// ^Inode (Retainable magic)
virtual void one_retain_left() override;
@ -78,7 +78,7 @@ private:
unsigned inode_size() const;
bool write_ext2_inode(unsigned, const ext2_inode&);
ByteBuffer read_block_containing_inode(unsigned inode, unsigned& blockIndex, unsigned& offset) const;
ByteBuffer read_block_containing_inode(unsigned inode, unsigned& block_index, unsigned& offset) const;
ByteBuffer read_super_block() const;
bool write_super_block(const ext2_super_block&);
@ -102,7 +102,7 @@ private:
template<typename F> void traverse_inode_bitmap(unsigned groupIndex, F) const;
template<typename F> void traverse_block_bitmap(unsigned groupIndex, F) const;
bool add_inode_to_directory(InodeIndex parent, InodeIndex child, const String& name, byte fileType, int& error);
bool add_inode_to_directory(InodeIndex parent, InodeIndex child, const String& name, byte file_type, int& error);
bool write_directory_inode(unsigned directoryInode, Vector<DirectoryEntry>&&);
bool get_inode_allocation_state(InodeIndex) const;
bool set_inode_allocation_state(unsigned inode, bool);
@ -121,7 +121,7 @@ private:
BlockListShape compute_block_list_shape(unsigned blocks);
unsigned m_blockGroupCount { 0 };
unsigned m_block_group_count { 0 };
mutable ByteBuffer m_cached_super_block;
mutable ByteBuffer m_cached_group_descriptor_table;

View file

@ -47,7 +47,7 @@ bool FileBackedDiskDevice::write_block(unsigned index, const byte* data)
bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byte* out) const
{
#ifndef IGNORE_FILE_LENGTH
if (offset + length >= m_fileLength)
if (offset + length >= m_file_length)
return false;
#endif
#ifdef FBBD_DEBUG
@ -62,7 +62,7 @@ bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byt
bool FileBackedDiskDevice::write_internal(DiskOffset offset, unsigned length, const byte* data)
{
#ifndef IGNORE_FILE_LENGTH
if (offset + length >= m_fileLength)
if (offset + length >= m_file_length)
return false;
#endif
#ifdef FBBD_DEBUG

View file

@ -60,10 +60,10 @@ RetainPtr<FileDescriptor> FileDescriptor::clone()
: FileDescriptor::create_pipe_writer(*m_fifo);
} else {
if (m_device) {
descriptor = FileDescriptor::create(m_device.copyRef());
descriptor->m_inode = m_inode.copyRef();
descriptor = FileDescriptor::create(m_device.copy_ref());
descriptor->m_inode = m_inode.copy_ref();
} else {
descriptor = FileDescriptor::create(m_inode.copyRef());
descriptor = FileDescriptor::create(m_inode.copy_ref());
}
}
if (!descriptor)
@ -74,7 +74,7 @@ RetainPtr<FileDescriptor> FileDescriptor::clone()
return descriptor;
}
bool additionWouldOverflow(off_t a, off_t b)
bool addition_would_overflow(off_t a, off_t b)
{
ASSERT(a > 0);
uint64_t ua = a;
@ -88,19 +88,19 @@ int FileDescriptor::fstat(stat* buffer)
return -EBADF;
auto metadata = this->metadata();
if (!metadata.isValid())
if (!metadata.is_valid())
return -EIO;
buffer->st_dev = encodedDevice(metadata.majorDevice, metadata.minorDevice);
buffer->st_dev = encoded_device(metadata.major_device, metadata.minor_device);
buffer->st_ino = metadata.inode.index();
buffer->st_mode = metadata.mode;
buffer->st_nlink = metadata.linkCount;
buffer->st_nlink = metadata.link_count;
buffer->st_uid = metadata.uid;
buffer->st_gid = metadata.gid;
buffer->st_rdev = 0; // FIXME
buffer->st_size = metadata.size;
buffer->st_blksize = metadata.blockSize;
buffer->st_blocks = metadata.blockCount;
buffer->st_blksize = metadata.block_size;
buffer->st_blocks = metadata.block_count;
buffer->st_atime = metadata.atime;
buffer->st_mtime = metadata.mtime;
buffer->st_ctime = metadata.ctime;
@ -116,10 +116,10 @@ off_t FileDescriptor::seek(off_t offset, int whence)
// FIXME: The file type should be cached on the vnode.
// It's silly that we have to do a full metadata lookup here.
auto metadata = this->metadata();
if (!metadata.isValid())
if (!metadata.is_valid())
return -EIO;
if (metadata.isSocket() || metadata.isFIFO())
if (metadata.is_socket() || metadata.is_fifo())
return -ESPIPE;
off_t newOffset;
@ -217,23 +217,23 @@ ByteBuffer FileDescriptor::read_entire_file(Process& process)
bool FileDescriptor::is_directory() const
{
ASSERT(!is_fifo());
return metadata().isDirectory();
return metadata().is_directory();
}
ssize_t FileDescriptor::get_dir_entries(byte* buffer, size_t size)
{
auto metadata = this->metadata();
if (!metadata.isValid())
if (!metadata.is_valid())
return -EIO;
if (!metadata.isDirectory())
if (!metadata.is_directory())
return -ENOTDIR;
// FIXME: Compute the actual size needed.
auto tempBuffer = ByteBuffer::create_uninitialized(2048);
BufferStream stream(tempBuffer);
auto temp_buffer = ByteBuffer::create_uninitialized(2048);
BufferStream stream(temp_buffer);
VFS::the().traverse_directory_inode(*m_inode, [&stream] (auto& entry) {
stream << (dword)entry.inode.index();
stream << (byte)entry.fileType;
stream << (byte)entry.file_type;
stream << (dword)entry.name_length;
stream << entry.name;
return true;
@ -242,7 +242,7 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, size_t size)
if (size < stream.offset())
return -1;
memcpy(buffer, tempBuffer.pointer(), stream.offset());
memcpy(buffer, temp_buffer.pointer(), stream.offset());
return stream.offset();
}

View file

@ -76,7 +76,7 @@ ByteBuffer Inode::read_entire(FileDescriptor* descriptor) const
FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft)
: name_length(strlen(n))
, inode(i)
, fileType(ft)
, file_type(ft)
{
memcpy(name, n, name_length);
name[name_length] = '\0';
@ -85,7 +85,7 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft)
FS::DirectoryEntry::DirectoryEntry(const char* n, size_t nl, InodeIdentifier i, byte ft)
: name_length(nl)
, inode(i)
, fileType(ft)
, file_type(ft)
{
memcpy(name, n, nl);
name[nl] = '\0';

View file

@ -37,12 +37,12 @@ public:
bool is_readonly() const { return m_readonly; }
struct DirectoryEntry {
DirectoryEntry(const char* name, InodeIdentifier, byte fileType);
DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte fileType);
DirectoryEntry(const char* name, InodeIdentifier, byte file_type);
DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte file_type);
char name[256];
size_t name_length { 0 };
InodeIdentifier inode;
byte fileType { 0 };
byte file_type { 0 };
};
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, unsigned size, int& error) = 0;
@ -71,9 +71,9 @@ public:
unsigned index() const { return m_index; }
size_t size() const { return metadata().size; }
bool is_symlink() const { return metadata().isSymbolicLink(); }
bool is_directory() const { return metadata().isDirectory(); }
bool is_character_device() const { return metadata().isCharacterDevice(); }
bool is_symlink() const { return metadata().is_symlink(); }
bool is_directory() const { return metadata().is_directory(); }
bool is_character_device() const { return metadata().is_character_device(); }
mode_t mode() const { return metadata().mode; }
InodeIdentifier identifier() const { return { fsid(), index() }; }

View file

@ -9,8 +9,8 @@ struct InodeMetadata;
class InodeIdentifier {
public:
InodeIdentifier() { }
InodeIdentifier(dword fileSystemID, dword inode)
: m_fsid(fileSystemID)
InodeIdentifier(dword fsid, dword inode)
: m_fsid(fsid)
, m_index(inode)
{
}

View file

@ -4,21 +4,21 @@
#include "UnixTypes.h"
#include <AK/HashTable.h>
inline bool isDirectory(mode_t mode) { return (mode & 0170000) == 0040000; }
inline bool isCharacterDevice(mode_t mode) { return (mode & 0170000) == 0020000; }
inline bool isBlockDevice(mode_t mode) { return (mode & 0170000) == 0060000; }
inline bool isRegularFile(mode_t mode) { return (mode & 0170000) == 0100000; }
inline bool isFIFO(mode_t mode) { return (mode & 0170000) == 0010000; }
inline bool isSymbolicLink(mode_t mode) { return (mode & 0170000) == 0120000; }
inline bool isSocket(mode_t mode) { return (mode & 0170000) == 0140000; }
inline bool isSticky(mode_t mode) { return mode & 01000; }
inline bool isSetUID(mode_t mode) { return mode & 04000; }
inline bool isSetGID(mode_t mode) { return mode & 02000; }
inline bool is_directory(mode_t mode) { return (mode & 0170000) == 0040000; }
inline bool is_character_device(mode_t mode) { return (mode & 0170000) == 0020000; }
inline bool is_block_device(mode_t mode) { return (mode & 0170000) == 0060000; }
inline bool is_regular_file(mode_t mode) { return (mode & 0170000) == 0100000; }
inline bool is_fifo(mode_t mode) { return (mode & 0170000) == 0010000; }
inline bool is_symlink(mode_t mode) { return (mode & 0170000) == 0120000; }
inline bool is_socket(mode_t mode) { return (mode & 0170000) == 0140000; }
inline bool is_sticky(mode_t mode) { return mode & 01000; }
inline bool is_setuid(mode_t mode) { return mode & 04000; }
inline bool is_setgid(mode_t mode) { return mode & 02000; }
struct InodeMetadata {
bool isValid() const { return inode.is_valid(); }
bool is_valid() const { return inode.is_valid(); }
bool mayExecute(uid_t u, const HashTable<gid_t>& g) const
bool may_execute(uid_t u, const HashTable<gid_t>& g) const
{
if (uid == u)
return mode & 0100;
@ -27,31 +27,31 @@ struct InodeMetadata {
return mode & 0001;
}
bool isDirectory() const { return ::isDirectory(mode); }
bool isCharacterDevice() const { return ::isCharacterDevice(mode); }
bool isBlockDevice() const { return ::isBlockDevice(mode); }
bool isRegularFile() const { return ::isRegularFile(mode); }
bool isFIFO() const { return ::isFIFO(mode); }
bool isSymbolicLink() const { return ::isSymbolicLink(mode); }
bool isSocket() const { return ::isSocket(mode); }
bool isSticky() const { return ::isSticky(mode); }
bool isSetUID() const { return ::isSetUID(mode); }
bool isSetGID() const { return ::isSetGID(mode); }
bool is_directory() const { return ::is_directory(mode); }
bool is_character_device() const { return ::is_character_device(mode); }
bool is_block_device() const { return ::is_block_device(mode); }
bool is_regular_file() const { return ::is_regular_file(mode); }
bool is_fifo() const { return ::is_fifo(mode); }
bool is_symlink() const { return ::is_symlink(mode); }
bool is_socket() const { return ::is_socket(mode); }
bool is_sticky() const { return ::is_sticky(mode); }
bool is_setuid() const { return ::is_setuid(mode); }
bool is_setgid() const { return ::is_setgid(mode); }
InodeIdentifier inode;
off_t size { 0 };
mode_t mode { 0 };
uid_t uid { 0 };
gid_t gid { 0 };
nlink_t linkCount { 0 };
nlink_t link_count { 0 };
time_t atime { 0 };
time_t ctime { 0 };
time_t mtime { 0 };
time_t dtime { 0 };
blkcnt_t blockCount { 0 };
blksize_t blockSize { 0 };
unsigned majorDevice { 0 };
unsigned minorDevice { 0 };
blkcnt_t block_count { 0 };
blksize_t block_size { 0 };
unsigned major_device { 0 };
unsigned minor_device { 0 };
};

View file

@ -89,21 +89,21 @@ void dump_backtrace(bool use_ksyms)
};
Vector<RecognizedSymbol> recognized_symbols;
if (use_ksyms) {
for (dword* stackPtr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stackPtr)); stackPtr = (dword*)*stackPtr) {
dword retaddr = stackPtr[1];
for (dword* stack_ptr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
dword retaddr = stack_ptr[1];
if (auto* ksym = ksymbolicate(retaddr))
recognized_symbols.append({ retaddr, ksym });
}
} else{
for (dword* stackPtr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stackPtr)); stackPtr = (dword*)*stackPtr) {
dword retaddr = stackPtr[1];
kprintf("%x (next: %x)\n", retaddr, stackPtr ? (dword*)*stackPtr : 0);
for (dword* stack_ptr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
dword retaddr = stack_ptr[1];
kprintf("%x (next: %x)\n", retaddr, stack_ptr ? (dword*)*stack_ptr : 0);
}
return;
}
size_t bytesNeeded = 0;
size_t bytes_needed = 0;
for (auto& symbol : recognized_symbols) {
bytesNeeded += strlen(symbol.ksym->name) + 8 + 16;
bytes_needed += strlen(symbol.ksym->name) + 8 + 16;
}
for (auto& symbol : recognized_symbols) {
unsigned offset = symbol.address - symbol.ksym->address;

View file

@ -112,7 +112,7 @@ RetainPtr<PhysicalPage> MemoryManager::allocate_page_table(PageDirectory& page_d
auto physical_page = allocate_supervisor_physical_page();
if (!physical_page)
return nullptr;
page_directory.m_physical_pages.set(index, physical_page.copyRef());
page_directory.m_physical_pages.set(index, physical_page.copy_ref());
return physical_page;
}
@ -144,7 +144,7 @@ auto MemoryManager::ensure_pte(PageDirectory& page_directory, LinearAddress ladd
#endif
if (page_directory_index == 0) {
ASSERT(&page_directory == m_kernel_page_directory.ptr());
pde.setPageTableBase((dword)m_page_table_zero);
pde.set_page_table_base((dword)m_page_table_zero);
pde.set_user_allowed(false);
pde.set_present(true);
pde.set_writable(true);
@ -161,14 +161,14 @@ auto MemoryManager::ensure_pte(PageDirectory& page_directory, LinearAddress ladd
page_table->paddr().get());
#endif
pde.setPageTableBase(page_table->paddr().get());
pde.set_page_table_base(page_table->paddr().get());
pde.set_user_allowed(true);
pde.set_present(true);
pde.set_writable(true);
page_directory.m_physical_pages.set(page_directory_index, move(page_table));
}
}
return PageTableEntry(&pde.pageTableBase()[page_table_index]);
return PageTableEntry(&pde.page_table_base()[page_table_index]);
}
void MemoryManager::map_protected(LinearAddress laddr, size_t length)
@ -176,13 +176,13 @@ void MemoryManager::map_protected(LinearAddress laddr, size_t length)
InterruptDisabler disabler;
// FIXME: ASSERT(linearAddress is 4KB aligned);
for (dword offset = 0; offset < length; offset += PAGE_SIZE) {
auto pteAddress = laddr.offset(offset);
auto pte = ensure_pte(kernel_page_directory(), pteAddress);
pte.set_physical_page_base(pteAddress.get());
auto pte_address = laddr.offset(offset);
auto pte = ensure_pte(kernel_page_directory(), pte_address);
pte.set_physical_page_base(pte_address.get());
pte.set_user_allowed(false);
pte.set_present(false);
pte.set_writable(false);
flush_tlb(pteAddress);
flush_tlb(pte_address);
}
}
@ -191,13 +191,13 @@ void MemoryManager::create_identity_mapping(PageDirectory& page_directory, Linea
InterruptDisabler disabler;
ASSERT((laddr.get() & ~PAGE_MASK) == 0);
for (dword offset = 0; offset < size; offset += PAGE_SIZE) {
auto pteAddress = laddr.offset(offset);
auto pte = ensure_pte(page_directory, pteAddress);
pte.set_physical_page_base(pteAddress.get());
auto pte_address = laddr.offset(offset);
auto pte = ensure_pte(page_directory, pte_address);
pte.set_physical_page_base(pte_address.get());
pte.set_user_allowed(false);
pte.set_present(true);
pte.set_writable(true);
page_directory.flush(pteAddress);
page_directory.flush(pte_address);
}
}
@ -560,7 +560,7 @@ RetainPtr<Region> Region::clone()
if (m_shared || (m_readable && !m_writable)) {
// Create a new region backed by the same VMObject.
return adopt(*new Region(laddr(), size(), m_vmo.copyRef(), m_offset_in_vmo, String(m_name), m_readable, m_writable));
return adopt(*new Region(laddr(), size(), m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_readable, m_writable));
}
dbgprintf("%s<%u> Region::clone(): cowing %s (L%x)\n",
@ -647,7 +647,7 @@ RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode, size_
InterruptDisabler disabler;
if (inode->vmo())
return static_cast<VMObject*>(inode->vmo());
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
auto vmo = adopt(*new VMObject(move(inode), size));
vmo->inode()->set_vmo(vmo.ptr());
return vmo;
@ -655,13 +655,13 @@ RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode, size_
RetainPtr<VMObject> VMObject::create_anonymous(size_t size)
{
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
return adopt(*new VMObject(size));
}
RetainPtr<VMObject> VMObject::create_framebuffer_wrapper(PhysicalAddress paddr, size_t size)
{
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
return adopt(*new VMObject(paddr, size));
}

View file

@ -264,8 +264,8 @@ private:
struct PageDirectoryEntry {
explicit PageDirectoryEntry(dword* pde) : m_pde(pde) { }
dword* pageTableBase() { return reinterpret_cast<dword*>(raw() & 0xfffff000u); }
void setPageTableBase(dword value)
dword* page_table_base() { return reinterpret_cast<dword*>(raw() & 0xfffff000u); }
void set_page_table_base(dword value)
{
*m_pde &= 0xfff;
*m_pde |= value & 0xfffff000;

View file

@ -90,7 +90,7 @@ void initialize()
#endif
}
word getISR()
word get_isr()
{
IO::out8(PIC0_CTL, 0x0b);
IO::out8(PIC1_CTL, 0x0b);

View file

@ -8,7 +8,7 @@ void enable(byte number);
void disable(byte number);
void eoi(byte number);
void initialize();
word getISR();
word get_isr();
word get_irr();
}

View file

@ -94,21 +94,21 @@ ByteBuffer procfs$pid_vmo(Process& process)
ByteBuffer procfs$pid_stack(Process& process)
{
ProcessInspectionHandle handle(process);
ProcessPagingScope pagingScope(process);
ProcessPagingScope paging_scope(process);
struct RecognizedSymbol {
dword address;
const KSym* ksym;
};
Vector<RecognizedSymbol> recognizedSymbols;
if (auto* eipKsym = ksymbolicate(process.tss().eip))
recognizedSymbols.append({ process.tss().eip, eipKsym });
for (dword* stackPtr = (dword*)process.framePtr(); process.validate_read_from_kernel(LinearAddress((dword)stackPtr)); stackPtr = (dword*)*stackPtr) {
dword retaddr = stackPtr[1];
Vector<RecognizedSymbol> recognized_symbols;
if (auto* eip_ksym = ksymbolicate(process.tss().eip))
recognized_symbols.append({ process.tss().eip, eip_ksym });
for (dword* stack_ptr = (dword*)process.frame_ptr(); process.validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
dword retaddr = stack_ptr[1];
if (auto* ksym = ksymbolicate(retaddr))
recognizedSymbols.append({ retaddr, ksym });
recognized_symbols.append({ retaddr, ksym });
}
StringBuilder builder;
for (auto& symbol : recognizedSymbols) {
for (auto& symbol : recognized_symbols) {
unsigned offset = symbol.address - symbol.ksym->address;
builder.appendf("%p %s +%u\n", symbol.address, symbol.ksym->name, offset);
}
@ -306,7 +306,7 @@ ByteBuffer procfs$kmalloc(SynthFSInode&)
ByteBuffer procfs$summary(SynthFSInode&)
{
InterruptDisabler disabler;
auto processes = Process::allProcesses();
auto processes = Process::all_processes();
StringBuilder builder;
builder.appendf("PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n");
for (auto* process : processes) {
@ -316,9 +316,9 @@ ByteBuffer procfs$summary(SynthFSInode&)
process->pgid(),
process->sid(),
process->uid(),
toString(process->state()),
to_string(process->state()),
process->ppid(),
process->timesScheduled(),
process->times_scheduled(),
process->number_of_open_file_descriptors(),
process->tty() ? strrchr(process->tty()->tty_name().characters(), '/') + 1 : "n/a",
process->name().characters());

View file

@ -19,7 +19,6 @@ public:
void remove_process(Process&);
void add_sys_file(String&&, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback);
void add_sys_bool(String&&, bool*, Function<void()>&& change_callback = nullptr);
private:

View file

@ -27,22 +27,22 @@
#define SIGNAL_DEBUG
#define MAX_PROCESS_GIDS 32
static const dword defaultStackSize = 16384;
static const dword default_stack_size = 16384;
static pid_t next_pid;
InlineLinkedList<Process>* g_processes;
static String* s_hostname;
static String& hostnameStorage(InterruptDisabler&)
static String& hostname_storage(InterruptDisabler&)
{
ASSERT(s_hostname);
return *s_hostname;
}
static String getHostname()
static String get_hostname()
{
InterruptDisabler disabler;
return hostnameStorage(disabler).isolated_copy();
return hostname_storage(disabler).isolated_copy();
}
CoolGlobals* g_cool_globals;
@ -59,7 +59,7 @@ void Process::initialize()
initialize_gui_statics();
}
Vector<Process*> Process::allProcesses()
Vector<Process*> Process::all_processes()
{
InterruptDisabler disabler;
Vector<Process*> processes;
@ -74,8 +74,8 @@ Region* Process::allocate_region(LinearAddress laddr, size_t size, String&& name
size = PAGE_ROUND_UP(size);
// FIXME: This needs sanity checks. What if this overlaps existing regions?
if (laddr.is_null()) {
laddr = m_nextRegion;
m_nextRegion = m_nextRegion.offset(size).offset(PAGE_SIZE);
laddr = m_next_region;
m_next_region = m_next_region.offset(size).offset(PAGE_SIZE);
}
laddr.mask(0xfffff000);
m_regions.append(adopt(*new Region(laddr, size, move(name), is_readable, is_writable)));
@ -90,8 +90,8 @@ Region* Process::allocate_file_backed_region(LinearAddress laddr, size_t size, R
size = PAGE_ROUND_UP(size);
// FIXME: This needs sanity checks. What if this overlaps existing regions?
if (laddr.is_null()) {
laddr = m_nextRegion;
m_nextRegion = m_nextRegion.offset(size).offset(PAGE_SIZE);
laddr = m_next_region;
m_next_region = m_next_region.offset(size).offset(PAGE_SIZE);
}
laddr.mask(0xfffff000);
m_regions.append(adopt(*new Region(laddr, size, move(inode), move(name), is_readable, is_writable)));
@ -105,12 +105,12 @@ Region* Process::allocate_region_with_vmo(LinearAddress laddr, size_t size, Reta
size = PAGE_ROUND_UP(size);
// FIXME: This needs sanity checks. What if this overlaps existing regions?
if (laddr.is_null()) {
laddr = m_nextRegion;
m_nextRegion = m_nextRegion.offset(size).offset(PAGE_SIZE);
laddr = m_next_region;
m_next_region = m_next_region.offset(size).offset(PAGE_SIZE);
}
laddr.mask(0xfffff000);
offset_in_vmo &= PAGE_MASK;
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
m_regions.append(adopt(*new Region(laddr, size, move(vmo), offset_in_vmo, move(name), is_readable, is_writable)));
MM.map_region(*this, *m_regions.last());
return m_regions.last().ptr();
@ -129,7 +129,7 @@ bool Process::deallocate_region(Region& region)
return false;
}
Region* Process::regionFromRange(LinearAddress laddr, size_t size)
Region* Process::region_from_range(LinearAddress laddr, size_t size)
{
for (auto& region : m_regions) {
if (region->laddr() == laddr && region->size() == size)
@ -142,7 +142,7 @@ int Process::sys$set_mmap_name(void* addr, size_t size, const char* name)
{
if (!validate_read_str(name))
return -EFAULT;
auto* region = regionFromRange(LinearAddress((dword)addr), size);
auto* region = region_from_range(LinearAddress((dword)addr), size);
if (!region)
return -EINVAL;
region->set_name(String(name));
@ -193,7 +193,7 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
int Process::sys$munmap(void* addr, size_t size)
{
InterruptDisabler disabler;
auto* region = regionFromRange(LinearAddress((dword)addr), size);
auto* region = region_from_range(LinearAddress((dword)addr), size);
if (!region)
return -1;
if (!deallocate_region(*region))
@ -205,7 +205,7 @@ int Process::sys$gethostname(char* buffer, size_t size)
{
if (!validate_write(buffer, size))
return -EFAULT;
auto hostname = getHostname();
auto hostname = get_hostname();
if (size < (hostname.length() + 1))
return -ENAMETOOLONG;
memcpy(buffer, hostname.characters(), size);
@ -214,7 +214,7 @@ int Process::sys$gethostname(char* buffer, size_t size)
Process* Process::fork(RegisterDump& regs)
{
auto* child = new Process(String(m_name), m_uid, m_gid, m_pid, m_ring, m_cwd.copyRef(), m_executable.copyRef(), m_tty, this);
auto* child = new Process(String(m_name), m_uid, m_gid, m_pid, m_ring, m_cwd.copy_ref(), m_executable.copy_ref(), m_tty, this);
if (!child)
return nullptr;
@ -235,7 +235,7 @@ Process* Process::fork(RegisterDump& regs)
child->m_regions.append(move(cloned_region));
MM.map_region(*child, *child->m_regions.last());
if (region.ptr() == m_display_framebuffer_region.ptr())
child->m_display_framebuffer_region = child->m_regions.last().copyRef();
child->m_display_framebuffer_region = child->m_regions.last().copy_ref();
}
for (auto gid : m_gids)
@ -298,7 +298,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
return error;
}
if (!descriptor->metadata().mayExecute(m_euid, m_gids))
if (!descriptor->metadata().may_execute(m_euid, m_gids))
return -EACCES;
if (!descriptor->metadata().size) {
@ -317,7 +317,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
auto vmo = VMObject::create_file_backed(descriptor->inode(), descriptor->metadata().size);
vmo->set_name(descriptor->absolute_path());
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copyRef(), 0, "helper", true, false);
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copy_ref(), 0, "helper", true, false);
// FIXME: Should we consider doing on-demand paging here? Is it actually useful?
bool success = region->page_in();
@ -332,7 +332,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
ASSERT(size);
ASSERT(alignment == PAGE_SIZE);
size = ((size / 4096) + 1) * 4096; // FIXME: Use ceil_div?
(void) allocate_region_with_vmo(laddr, size, vmo.copyRef(), offset_in_image, String(name), is_readable, is_writable);
(void) allocate_region_with_vmo(laddr, size, vmo.copy_ref(), offset_in_image, String(name), is_readable, is_writable);
return laddr.as_ptr();
};
loader.alloc_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) {
@ -400,10 +400,10 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
m_tss.gs = 0x23;
m_tss.ss = 0x23;
m_tss.cr3 = page_directory().cr3();
m_stack_region = allocate_region(LinearAddress(), defaultStackSize, "stack");
m_stack_region = allocate_region(LinearAddress(), default_stack_size, "stack");
ASSERT(m_stack_region);
m_stackTop3 = m_stack_region->laddr().offset(defaultStackSize).get();
m_tss.esp = m_stackTop3;
m_stack_top3 = m_stack_region->laddr().offset(default_stack_size).get();
m_tss.esp = m_stack_top3;
m_tss.ss0 = 0x10;
m_tss.esp0 = old_esp0;
m_tss.ss2 = m_pid;
@ -490,7 +490,7 @@ Process* Process::create_user_process(const String& path, uid_t uid, gid_t gid,
{
InterruptDisabler disabler;
if (auto* parent = Process::from_pid(parent_pid))
cwd = parent->m_cwd.copyRef();
cwd = parent->m_cwd.copy_ref();
}
if (!cwd)
@ -634,9 +634,9 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
}
if (fork_parent)
m_nextRegion = fork_parent->m_nextRegion;
m_next_region = fork_parent->m_next_region;
else
m_nextRegion = LinearAddress(0x10000000);
m_next_region = LinearAddress(0x10000000);
if (fork_parent) {
memcpy(&m_tss, &fork_parent->m_tss, sizeof(m_tss));
@ -647,7 +647,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
m_tss.eflags = 0x0202;
word cs, ds, ss;
if (isRing0()) {
if (is_ring0()) {
cs = 0x08;
ds = 0x10;
ss = 0x10;
@ -667,34 +667,34 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
m_tss.cr3 = page_directory().cr3();
if (isRing0()) {
if (is_ring0()) {
// FIXME: This memory is leaked.
// But uh, there's also no kernel process termination, so I guess it's not technically leaked...
dword stackBottom = (dword)kmalloc_eternal(defaultStackSize);
m_stackTop0 = (stackBottom + defaultStackSize) & 0xffffff8;
m_tss.esp = m_stackTop0;
dword stack_bottom = (dword)kmalloc_eternal(default_stack_size);
m_stack_top0 = (stack_bottom + default_stack_size) & 0xffffff8;
m_tss.esp = m_stack_top0;
} else {
if (fork_parent) {
m_stackTop3 = fork_parent->m_stackTop3;
m_stack_top3 = fork_parent->m_stack_top3;
} else {
auto* region = allocate_region(LinearAddress(), defaultStackSize, "stack");
auto* region = allocate_region(LinearAddress(), default_stack_size, "stack");
ASSERT(region);
m_stackTop3 = region->laddr().offset(defaultStackSize).get();
m_tss.esp = m_stackTop3;
m_stack_top3 = region->laddr().offset(default_stack_size).get();
m_tss.esp = m_stack_top3;
}
}
if (isRing3()) {
if (is_ring3()) {
// Ring3 processes need a separate stack for Ring0.
m_kernelStack = kmalloc(defaultStackSize);
m_stackTop0 = ((dword)m_kernelStack + defaultStackSize) & 0xffffff8;
m_kernel_stack = kmalloc(default_stack_size);
m_stack_top0 = ((dword)m_kernel_stack + default_stack_size) & 0xffffff8;
m_tss.ss0 = 0x10;
m_tss.esp0 = m_stackTop0;
m_tss.esp0 = m_stack_top0;
}
// HACK: Ring2 SS in the TSS is the current PID.
m_tss.ss2 = m_pid;
m_farPtr.offset = 0x98765432;
m_far_ptr.offset = 0x98765432;
}
Process::~Process()
@ -709,13 +709,13 @@ Process::~Process()
if (selector())
gdt_free_entry(selector());
if (m_kernelStack) {
kfree(m_kernelStack);
m_kernelStack = nullptr;
if (m_kernel_stack) {
kfree(m_kernel_stack);
m_kernel_stack = nullptr;
}
}
void Process::dumpRegions()
void Process::dump_regions()
{
kprintf("Process %s(%u) regions:\n", name().characters(), pid());
kprintf("BEGIN END SIZE NAME\n");
@ -818,7 +818,7 @@ bool Process::dispatch_signal(byte signal)
bool interrupting_in_kernel = (ret_cs & 3) == 0;
if (interrupting_in_kernel) {
dbgprintf("dispatch_signal to %s(%u) in state=%s with return to %w:%x\n", name().characters(), pid(), toString(state()), ret_cs, ret_eip);
dbgprintf("dispatch_signal to %s(%u) in state=%s with return to %w:%x\n", name().characters(), pid(), to_string(state()), ret_cs, ret_eip);
ASSERT(is_blocked());
m_tss_to_resume_kernel = m_tss;
#ifdef SIGNAL_DEBUG
@ -826,19 +826,19 @@ bool Process::dispatch_signal(byte signal)
#endif
}
ProcessPagingScope pagingScope(*this);
ProcessPagingScope paging_scope(*this);
if (interrupting_in_kernel) {
if (!m_signal_stack_user_region) {
m_signal_stack_user_region = allocate_region(LinearAddress(), defaultStackSize, "signal stack (user)");
m_signal_stack_user_region = allocate_region(LinearAddress(), default_stack_size, "signal stack (user)");
ASSERT(m_signal_stack_user_region);
m_signal_stack_kernel_region = allocate_region(LinearAddress(), defaultStackSize, "signal stack (kernel)");
m_signal_stack_kernel_region = allocate_region(LinearAddress(), default_stack_size, "signal stack (kernel)");
ASSERT(m_signal_stack_user_region);
}
m_tss.ss = 0x23;
m_tss.esp = m_signal_stack_user_region->laddr().offset(defaultStackSize).get() & 0xfffffff8;
m_tss.esp = m_signal_stack_user_region->laddr().offset(default_stack_size).get() & 0xfffffff8;
m_tss.ss0 = 0x10;
m_tss.esp0 = m_signal_stack_kernel_region->laddr().offset(defaultStackSize).get() & 0xfffffff8;
m_tss.esp0 = m_signal_stack_kernel_region->laddr().offset(default_stack_size).get() & 0xfffffff8;
push_value_on_stack(ret_eflags);
push_value_on_stack(ret_cs);
push_value_on_stack(ret_eip);
@ -903,7 +903,7 @@ bool Process::dispatch_signal(byte signal)
set_state(Skip1SchedulerPass);
#ifdef SIGNAL_DEBUG
dbgprintf("signal: Okay, %s(%u) {%s} has been primed with signal handler %w:%x\n", name().characters(), pid(), toString(state()), m_tss.cs, m_tss.eip);
dbgprintf("signal: Okay, %s(%u) {%s} has been primed with signal handler %w:%x\n", name().characters(), pid(), to_string(state()), m_tss.cs, m_tss.eip);
#endif
return true;
}
@ -935,7 +935,7 @@ void Process::crash()
ASSERT_INTERRUPTS_DISABLED();
ASSERT(state() != Dead);
m_termination_signal = SIGSEGV;
dumpRegions();
dump_regions();
die();
Scheduler::pick_next_and_switch_now();
ASSERT_NOT_REACHED();
@ -996,10 +996,10 @@ int Process::sys$ttyname_r(int fd, char* buffer, size_t size)
return -EBADF;
if (!descriptor->is_tty())
return -ENOTTY;
auto ttyName = descriptor->tty()->tty_name();
if (size < ttyName.length() + 1)
auto tty_name = descriptor->tty()->tty_name();
if (size < tty_name.length() + 1)
return -ERANGE;
strcpy(buffer, ttyName.characters());
strcpy(buffer, tty_name.characters());
return 0;
}
@ -1246,7 +1246,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
if (!descriptor)
return error;
if (!descriptor->metadata().isSymbolicLink())
if (!descriptor->metadata().is_symlink())
return -EINVAL;
auto contents = descriptor->read_entire_file(*this);
@ -1389,7 +1389,7 @@ int Process::sys$uname(utsname* buf)
strcpy(buf->release, "1.0-dev");
strcpy(buf->version, "FIXME");
strcpy(buf->machine, "i386");
strcpy(buf->nodename, getHostname().characters());
strcpy(buf->nodename, get_hostname().characters());
return 0;
}
@ -1427,9 +1427,9 @@ int Process::sys$sleep(unsigned seconds)
if (!seconds)
return 0;
sleep(seconds * TICKS_PER_SECOND);
if (m_wakeupTime > system.uptime) {
if (m_wakeup_time > system.uptime) {
ASSERT(m_was_interrupted_while_blocked);
dword ticks_left_until_original_wakeup_time = m_wakeupTime - system.uptime;
dword ticks_left_until_original_wakeup_time = m_wakeup_time - system.uptime;
return ticks_left_until_original_wakeup_time / TICKS_PER_SECOND;
}
return 0;
@ -1496,7 +1496,7 @@ int Process::reap(Process& process)
}
}
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), toString(process.state()));
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), to_string(process.state()));
ASSERT(process.state() == Dead);
g_processes->remove(&process);
delete &process;
@ -1576,7 +1576,7 @@ void Process::unblock()
void Process::block(Process::State new_state)
{
if (state() != Process::Running) {
kprintf("Process::block: %s(%u) block(%u/%s) with state=%u/%s\n", name().characters(), pid(), new_state, toString(new_state), state(), toString(state()));
kprintf("Process::block: %s(%u) block(%u/%s) with state=%u/%s\n", name().characters(), pid(), new_state, to_string(new_state), state(), to_string(state()));
}
ASSERT(state() == Process::Running);
system.nblocked++;
@ -1593,7 +1593,7 @@ void block(Process::State state)
void sleep(dword ticks)
{
ASSERT(current->state() == Process::Running);
current->setWakeupTime(system.uptime + ticks);
current->set_wakeup_time(system.uptime + ticks);
current->block(Process::BlockedSleep);
sched_yield();
}
@ -1619,7 +1619,7 @@ bool Process::validate_read_from_kernel(LinearAddress laddr) const
bool Process::validate_read(const void* address, size_t size) const
{
if (isRing0()) {
if (is_ring0()) {
if (is_inside_kernel_code(LinearAddress((dword)address)))
return true;
if (is_kmalloc_address(address))
@ -1639,7 +1639,7 @@ bool Process::validate_read(const void* address, size_t size) const
bool Process::validate_write(void* address, size_t size) const
{
if (isRing0()) {
if (is_ring0()) {
if (is_kmalloc_address(address))
return true;
}

View file

@ -55,7 +55,7 @@ public:
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
~Process();
static Vector<Process*> allProcesses();
static Vector<Process*> all_processes();
enum State {
Invalid = 0,
@ -78,8 +78,8 @@ public:
Ring3 = 3,
};
bool isRing0() const { return m_ring == Ring0; }
bool isRing3() const { return m_ring == Ring3; }
bool is_ring0() const { return m_ring == Ring0; }
bool is_ring3() const { return m_ring == Ring3; }
bool is_blocked() const
{
@ -98,7 +98,7 @@ public:
pid_t sid() const { return m_sid; }
pid_t pgid() const { return m_pgid; }
dword ticks() const { return m_ticks; }
word selector() const { return m_farPtr.selector; }
word selector() const { return m_far_ptr.selector; }
TSS32& tss() { return m_tss; }
State state() const { return m_state; }
uid_t uid() const { return m_uid; }
@ -107,7 +107,7 @@ public:
gid_t egid() const { return m_egid; }
pid_t ppid() const { return m_ppid; }
const FarPtr& farPtr() const { return m_farPtr; }
const FarPtr& far_ptr() const { return m_far_ptr; }
FileDescriptor* file_descriptor(int fd);
const FileDescriptor* file_descriptor(int fd) const;
@ -115,8 +115,8 @@ public:
void block(Process::State);
void unblock();
void setWakeupTime(dword t) { m_wakeupTime = t; }
dword wakeupTime() const { return m_wakeupTime; }
void set_wakeup_time(dword t) { m_wakeup_time = t; }
dword wakeup_time() const { return m_wakeup_time; }
template<typename Callback> static void for_each(Callback);
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
@ -124,10 +124,10 @@ public:
template<typename Callback> static void for_each_not_in_state(State, Callback);
template<typename Callback> void for_each_child(Callback);
bool tick() { ++m_ticks; return --m_ticksLeft; }
void set_ticks_left(dword t) { m_ticksLeft = t; }
bool tick() { ++m_ticks; return --m_ticks_left; }
void set_ticks_left(dword t) { m_ticks_left = t; }
void setSelector(word s) { m_farPtr.selector = s; }
void set_selector(word s) { m_far_ptr.selector = s; }
void set_state(State s) { m_state = s; }
void die();
@ -225,12 +225,12 @@ public:
const TTY* tty() const { return m_tty; }
void set_tty(TTY* tty) { m_tty = tty; }
size_t regionCount() const { return m_regions.size(); }
size_t region_count() const { return m_regions.size(); }
const Vector<RetainPtr<Region>>& regions() const { return m_regions; }
void dumpRegions();
void dump_regions();
void did_schedule() { ++m_timesScheduled; }
dword timesScheduled() const { return m_timesScheduled; }
void did_schedule() { ++m_times_scheduled; }
dword times_scheduled() const { return m_times_scheduled; }
dword m_ticks_in_user { 0 };
dword m_ticks_in_kernel { 0 };
@ -240,9 +240,9 @@ public:
pid_t waitee_pid() const { return m_waitee_pid; }
dword framePtr() const { return m_tss.ebp; }
dword stackPtr() const { return m_tss.esp; }
dword stackTop() const { return m_tss.ss == 0x10 ? m_stackTop0 : m_stackTop3; }
dword frame_ptr() const { return m_tss.ebp; }
dword stack_ptr() const { return m_tss.esp; }
dword stack_top() const { return m_tss.ss == 0x10 ? m_stack_top0 : m_stack_top3; }
bool validate_read_from_kernel(LinearAddress) const;
@ -306,12 +306,12 @@ private:
pid_t m_sid { 0 };
pid_t m_pgid { 0 };
dword m_ticks { 0 };
dword m_ticksLeft { 0 };
dword m_stackTop0 { 0 };
dword m_stackTop3 { 0 };
FarPtr m_farPtr;
dword m_ticks_left { 0 };
dword m_stack_top0 { 0 };
dword m_stack_top3 { 0 };
FarPtr m_far_ptr;
State m_state { Invalid };
dword m_wakeupTime { 0 };
dword m_wakeup_time { 0 };
TSS32 m_tss;
TSS32 m_tss_to_resume_kernel;
FPUState m_fpu_state;
@ -325,8 +325,8 @@ private:
Vector<FileDescriptorAndFlags> m_fds;
RingLevel m_ring { Ring0 };
int m_error { 0 };
void* m_kernelStack { nullptr };
dword m_timesScheduled { 0 };
void* m_kernel_stack { nullptr };
dword m_times_scheduled { 0 };
pid_t m_waitee_pid { -1 };
int m_blocked_fd { -1 };
Vector<int> m_select_read_fds;
@ -349,12 +349,12 @@ private:
Region* allocate_region_with_vmo(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&& name, bool is_readable, bool is_writable);
bool deallocate_region(Region& region);
Region* regionFromRange(LinearAddress, size_t);
Region* region_from_range(LinearAddress, size_t);
Vector<RetainPtr<Region>> m_regions;
// FIXME: Implement some kind of ASLR?
LinearAddress m_nextRegion;
LinearAddress m_next_region;
LinearAddress m_return_to_ring3_from_signal_trampoline;
LinearAddress m_return_to_ring0_from_signal_trampoline;
@ -411,7 +411,7 @@ private:
Process::State m_original_state { Process::Invalid };
};
static inline const char* toString(Process::State state)
static inline const char* to_string(Process::State state)
{
switch (state) {
case Process::Invalid: return "Invalid";

View file

@ -81,7 +81,7 @@ int Process::gui$destroy_window(int window_id)
if (it == m_windows.end())
return -EBADWINDOW;
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
WSMessageLoop::the().post_message((*it).value.leakPtr(), move(message), true);
WSMessageLoop::the().post_message((*it).value.leak_ptr(), move(message), true);
m_windows.remove(window_id);
return 0;
}
@ -264,7 +264,7 @@ void Process::destroy_all_windows()
{
for (auto& it : m_windows) {
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
WSMessageLoop::the().post_message(it.value.leakPtr(), move(message), true);
WSMessageLoop::the().post_message(it.value.leak_ptr(), move(message), true);
}
m_windows.clear();
}

View file

@ -18,21 +18,21 @@ public:
Queue() { }
~Queue()
{
while (!isEmpty())
while (!is_empty())
dequeue();
}
bool isEmpty() const { return !m_head; }
bool is_empty() const { return !m_head; }
void enqueue(T&& item)
{
auto* newNode = new Node(move(item));
auto* new_node = new Node(move(item));
if (!m_head) {
m_head = newNode;
m_tail = newNode;
m_head = new_node;
m_tail = new_node;
} else if (m_tail) {
newNode->prev = m_tail;
m_tail->next = newNode;
m_tail = newNode;
new_node->prev = m_tail;
m_tail->next = new_node;
m_tail = new_node;
}
dump("enqueue");
}

View file

@ -4,34 +4,34 @@
namespace RTC {
static time_t s_bootTime;
static time_t s_boot_time;
void initialize()
{
byte cmosMode = CMOS::read(0x0b);
cmosMode |= 2; // 24 hour mode
cmosMode |= 4; // No BCD mode
CMOS::write(0x0b, cmosMode);
byte cmos_mode = CMOS::read(0x0b);
cmos_mode |= 2; // 24 hour mode
cmos_mode |= 4; // No BCD mode
CMOS::write(0x0b, cmos_mode);
s_bootTime = now();
s_boot_time = now();
}
time_t bootTime()
time_t boot_time()
{
return s_bootTime;
return s_boot_time;
}
static bool updateInProgress()
static bool update_in_progress()
{
return CMOS::read(0x0a) & 0x80;
}
inline bool isLeapYear(unsigned year)
inline bool is_leap_year(unsigned year)
{
return ((year % 4 == 0) && ((year % 100 != 0) || (year % 400) == 0));
}
static unsigned daysInMonthsSinceStartOfYear(unsigned month, unsigned year)
static unsigned days_in_months_since_start_of_year(unsigned month, unsigned year)
{
switch (month) {
case 11: return 30;
@ -44,7 +44,7 @@ static unsigned daysInMonthsSinceStartOfYear(unsigned month, unsigned year)
case 4: return 30;
case 3: return 31;
case 2:
if (isLeapYear(year))
if (is_leap_year(year))
return 29;
return 28;
case 1: return 31;
@ -52,12 +52,12 @@ static unsigned daysInMonthsSinceStartOfYear(unsigned month, unsigned year)
}
}
static unsigned daysInYearsSinceEpoch(unsigned year)
static unsigned days_in_years_since_epoch(unsigned year)
{
unsigned days = 0;
while (year > 1969) {
days += 365;
if (isLeapYear(year))
if (is_leap_year(year))
++days;
--year;
}
@ -69,7 +69,7 @@ time_t now()
// FIXME: We should probably do something more robust here.
// Perhaps read all the values twice and verify that they were identical.
// We don't want to be caught in the middle of an RTC register update.
while (updateInProgress())
while (update_in_progress())
;
unsigned year = (CMOS::read(0x32) * 100) + CMOS::read(0x09);
@ -81,8 +81,8 @@ time_t now()
ASSERT(year >= 2018);
return daysInYearsSinceEpoch(year - 1) * 86400
+ daysInMonthsSinceStartOfYear(month - 1, year) * 86400
return days_in_years_since_epoch(year - 1) * 86400
+ days_in_months_since_start_of_year(month - 1, year) * 86400
+ day * 86400
+ hour * 3600
+ minute * 60

View file

@ -6,7 +6,7 @@ namespace RTC {
void initialize();
time_t now();
time_t bootTime();
time_t boot_time();
}

View file

@ -31,7 +31,7 @@ bool Scheduler::pick_next()
// Check and unblock processes whose wait conditions have been met.
Process::for_each([] (auto& process) {
if (process.state() == Process::BlockedSleep) {
if (process.wakeupTime() <= system.uptime)
if (process.wakeup_time() <= system.uptime)
process.unblock();
return true;
}
@ -139,11 +139,11 @@ bool Scheduler::pick_next()
for (auto* process = g_processes->head(); process; process = process->next()) {
//if (process->state() == Process::BlockedWait || process->state() == Process::BlockedSleep)
// continue;
dbgprintf("[K%x] % 12s %s(%u) @ %w:%x\n", process, toString(process->state()), process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
dbgprintf("[K%x] % 12s %s(%u) @ %w:%x\n", process, to_string(process->state()), process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
}
#endif
auto* prevHead = g_processes->head();
auto* previous_head = g_processes->head();
for (;;) {
// Move head to tail.
g_processes->append(g_processes->remove_head());
@ -156,7 +156,7 @@ bool Scheduler::pick_next()
return context_switch(*process);
}
if (process == prevHead) {
if (process == previous_head) {
// Back at process_head, nothing wants to run. Send in the colonel!
return context_switch(*s_colonel_process);
}
@ -182,7 +182,7 @@ bool Scheduler::yield()
}
s_in_yield = false;
//dbgprintf("yield() jumping to new process: %x (%s)\n", current->farPtr().selector, current->name().characters());
//dbgprintf("yield() jumping to new process: %x (%s)\n", current->far_ptr().selector, current->name().characters());
switch_now();
return 0;
}
@ -201,7 +201,7 @@ void Scheduler::switch_now()
flush_gdt();
asm("sti\n"
"ljmp *(%%eax)\n"
::"a"(&current->farPtr())
::"a"(&current->far_ptr())
);
}
@ -238,10 +238,10 @@ bool Scheduler::context_switch(Process& process)
#endif
if (!process.selector()) {
process.setSelector(gdt_alloc_entry());
process.set_selector(gdt_alloc_entry());
auto& descriptor = get_gdt_entry(process.selector());
descriptor.setBase(&process.tss());
descriptor.setLimit(0xffff);
descriptor.set_base(&process.tss());
descriptor.set_limit(0xffff);
descriptor.dpl = 0;
descriptor.segment_present = 1;
descriptor.granularity = 1;
@ -264,8 +264,8 @@ int sched_yield()
static void initialize_redirection()
{
auto& descriptor = get_gdt_entry(s_redirection.selector);
descriptor.setBase(&s_redirection.tss);
descriptor.setLimit(0xffff);
descriptor.set_base(&s_redirection.tss);
descriptor.set_limit(0xffff);
descriptor.dpl = 0;
descriptor.segment_present = 1;
descriptor.granularity = 1;

View file

@ -202,18 +202,18 @@ ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileD
ASSERT(offset >= 0);
ASSERT(buffer);
ByteBuffer generatedData;
ByteBuffer generated_data;
if (m_generator) {
if (!descriptor) {
generatedData = m_generator(const_cast<SynthFSInode&>(*this));
generated_data = m_generator(const_cast<SynthFSInode&>(*this));
} else {
if (!descriptor->generator_cache())
descriptor->generator_cache() = m_generator(const_cast<SynthFSInode&>(*this));
generatedData = descriptor->generator_cache();
generated_data = descriptor->generator_cache();
}
}
auto* data = generatedData ? &generatedData : &m_data;
auto* data = generated_data ? &generated_data : &m_data;
ssize_t nread = min(static_cast<off_t>(data->size() - offset), static_cast<off_t>(count));
memcpy(buffer, data->pointer() + offset, nread);
if (nread == 0 && descriptor && descriptor->generator_cache())
@ -228,14 +228,14 @@ bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&
kprintf("SynthFS: traverse_as_directory %u\n", index());
#endif
if (!m_metadata.isDirectory())
if (!m_metadata.is_directory())
return false;
callback({ ".", 1, m_metadata.inode, 2 });
callback({ "..", 2, m_parent, 2 });
for (auto& child : m_children)
callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.isDirectory() ? (byte)2 : (byte)1 });
callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.is_directory() ? (byte)2 : (byte)1 });
return true;
}

View file

@ -4,13 +4,13 @@
#include "Console.h"
#include "Scheduler.h"
extern "C" void syscall_entry(RegisterDump&);
extern "C" void syscall_ISR();
extern "C" void syscall_trap_entry(RegisterDump&);
extern "C" void syscall_trap_handler();
extern volatile RegisterDump* syscallRegDump;
asm(
".globl syscall_ISR \n"
"syscall_ISR:\n"
".globl syscall_trap_handler \n"
"syscall_trap_handler:\n"
" pusha\n"
" pushw %ds\n"
" pushw %es\n"
@ -26,7 +26,7 @@ asm(
" popw %fs\n"
" popw %gs\n"
" mov %esp, %eax\n"
" call syscall_entry\n"
" call syscall_trap_entry\n"
" popw %gs\n"
" popw %gs\n"
" popw %fs\n"
@ -40,7 +40,7 @@ namespace Syscall {
void initialize()
{
register_user_callable_interrupt_handler(0x80, syscall_ISR);
register_user_callable_interrupt_handler(0x80, syscall_trap_handler);
kprintf("syscall: int 0x80 handler installed\n");
}
@ -232,7 +232,7 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
}
void syscall_entry(RegisterDump& regs)
void syscall_trap_entry(RegisterDump& regs)
{
dword function = regs.eax;
dword arg1 = regs.edx;

View file

@ -99,7 +99,7 @@ enum Function {
#undef __ENUMERATE_SYSCALL
};
inline constexpr const char* toString(Function function)
inline constexpr const char* to_string(Function function)
{
switch (function) {
#undef __ENUMERATE_SYSCALL

View file

@ -88,7 +88,7 @@ void VirtualConsole::switch_to(unsigned index)
s_consoles[s_active_console]->set_active(false);
s_active_console = index;
s_consoles[s_active_console]->set_active(true);
Console::the().setImplementation(s_consoles[s_active_console]);
Console::the().set_implementation(s_consoles[s_active_console]);
}
void VirtualConsole::set_active(bool b)
@ -128,7 +128,7 @@ inline bool is_valid_final_character(byte ch)
return ch >= 0x40 && ch <= 0x7e;
}
unsigned parseUInt(const String& str, bool& ok)
unsigned parse_uint(const String& str, bool& ok)
{
unsigned value = 0;
for (size_t i = 0; i < str.length(); ++i) {
@ -302,11 +302,11 @@ void VirtualConsole::escape$J(const Vector<unsigned>& params)
switch (mode) {
case 0:
// FIXME: Clear from cursor to end of screen.
notImplemented();
not_implemented();
break;
case 1:
// FIXME: Clear from cursor to beginning of screen.
notImplemented();
not_implemented();
break;
case 2:
clear();
@ -324,7 +324,7 @@ void VirtualConsole::execute_escape_sequence(byte final)
Vector<unsigned> params;
for (auto& parampart : paramparts) {
bool ok;
unsigned value = parseUInt(parampart, ok);
unsigned value = parse_uint(parampart, ok);
if (!ok) {
// FIXME: Should we do something else?
return;

View file

@ -43,9 +43,9 @@ InodeIdentifier VFS::root_inode_id() const
return m_root_inode->identifier();
}
bool VFS::mount(RetainPtr<FS>&& fileSystem, const String& path)
bool VFS::mount(RetainPtr<FS>&& file_system, const String& path)
{
ASSERT(fileSystem);
ASSERT(file_system);
int error;
auto inode = resolve_path(path, root_inode_id(), error);
if (!inode.is_valid()) {
@ -53,21 +53,21 @@ bool VFS::mount(RetainPtr<FS>&& fileSystem, const String& path)
return false;
}
kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", fileSystem->class_name(), fileSystem.ptr(), path.characters(), inode.index());
kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", file_system->class_name(), file_system.ptr(), path.characters(), inode.index());
// FIXME: check that this is not already a mount point
auto mount = make<Mount>(inode, move(fileSystem));
auto mount = make<Mount>(inode, move(file_system));
m_mounts.append(move(mount));
return true;
}
bool VFS::mount_root(RetainPtr<FS>&& fileSystem)
bool VFS::mount_root(RetainPtr<FS>&& file_system)
{
if (m_root_inode) {
kprintf("VFS: mount_root can't mount another root\n");
return false;
}
auto mount = make<Mount>(InodeIdentifier(), move(fileSystem));
auto mount = make<Mount>(InodeIdentifier(), move(file_system));
auto root_inode_id = mount->guest().fs()->root_inode();
auto root_inode = mount->guest().fs()->get_inode(root_inode_id);
@ -112,18 +112,18 @@ bool VFS::is_vfs_root(InodeIdentifier inode) const
void VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::DirectoryEntry&)> callback)
{
dir_inode.traverse_as_directory([&] (const FS::DirectoryEntry& entry) {
InodeIdentifier resolvedInode;
InodeIdentifier resolved_inode;
if (auto mount = find_mount_for_host(entry.inode))
resolvedInode = mount->guest();
resolved_inode = mount->guest();
else
resolvedInode = entry.inode;
resolved_inode = entry.inode;
if (dir_inode.identifier().is_root_inode() && !is_vfs_root(dir_inode.identifier()) && !strcmp(entry.name, "..")) {
auto mount = find_mount_for_guest(entry.inode);
ASSERT(mount);
resolvedInode = mount->host();
resolved_inode = mount->host();
}
callback(FS::DirectoryEntry(entry.name, entry.name_length, resolvedInode, entry.fileType));
callback(FS::DirectoryEntry(entry.name, entry.name_length, resolved_inode, entry.file_type));
return true;
});
}
@ -146,10 +146,10 @@ RetainPtr<FileDescriptor> VFS::open(const String& path, int& error, int options,
return nullptr;
}
auto metadata = inode->metadata();
if (!(options & O_DONT_OPEN_DEVICE) && metadata.isCharacterDevice()) {
auto it = m_character_devices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice));
if (!(options & O_DONT_OPEN_DEVICE) && metadata.is_character_device()) {
auto it = m_character_devices.find(encoded_device(metadata.major_device, metadata.minor_device));
if (it == m_character_devices.end()) {
kprintf("VFS::open: no such character device %u,%u\n", metadata.majorDevice, metadata.minorDevice);
kprintf("VFS::open: no such character device %u,%u\n", metadata.major_device, metadata.minor_device);
return nullptr;
}
auto descriptor = (*it).value->open(error, options);
@ -164,7 +164,7 @@ RetainPtr<FileDescriptor> VFS::create(const String& path, int& error, int option
(void) options;
error = -EWHYTHO;
if (!isSocket(mode) && !isFIFO(mode) && !isBlockDevice(mode) && !isCharacterDevice(mode)) {
if (!is_socket(mode) && !is_fifo(mode) && !is_block_device(mode) && !is_character_device(mode)) {
// Turn it into a regular file. (This feels rather hackish.)
mode |= 0100000;
}
@ -412,7 +412,7 @@ String VFS::absolute_path(Inode& core_inode)
auto parent_inode = get_inode(parent);
builder.append(parent_inode->reverse_lookup(child));
}
return builder.build();
return builder.to_string();
}
InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int& error, int options, InodeIdentifier* parent_id)
@ -447,7 +447,7 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
return { };
}
auto metadata = crumb_inode->metadata();
if (!metadata.isDirectory()) {
if (!metadata.is_directory()) {
#ifdef VFS_DEBUG
kprintf("parent of <%s> not directory, it's inode %u:%u / %u:%u, mode: %u, size: %u\n", part.characters(), inode.fsid(), inode.index(), metadata.inode.fsid(), metadata.inode.index(), metadata.mode, metadata.size);
#endif
@ -482,13 +482,13 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
}
crumb_inode = get_inode(crumb_id);
metadata = crumb_inode->metadata();
if (metadata.isDirectory()) {
if (metadata.is_directory()) {
if (i != parts.size() - 1) {
if (parent_id)
*parent_id = crumb_id;
}
}
if (metadata.isSymbolicLink()) {
if (metadata.is_symlink()) {
if (i == parts.size() - 1) {
if (options & O_NOFOLLOW) {
error = -ELOOP;
@ -517,17 +517,17 @@ VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FS>&& guest_fs)
void VFS::register_character_device(CharacterDevice& device)
{
m_character_devices.set(encodedDevice(device.major(), device.minor()), &device);
m_character_devices.set(encoded_device(device.major(), device.minor()), &device);
}
void VFS::unregister_character_device(CharacterDevice& device)
{
m_character_devices.remove(encodedDevice(device.major(), device.minor()));
m_character_devices.remove(encoded_device(device.major(), device.minor()));
}
CharacterDevice* VFS::get_device(unsigned major, unsigned minor)
{
auto it = m_character_devices.find(encodedDevice(major, minor));
auto it = m_character_devices.find(encoded_device(major, minor));
if (it == m_character_devices.end())
return nullptr;
return (*it).value;

View file

@ -29,7 +29,7 @@
class CharacterDevice;
class FileDescriptor;
inline constexpr dword encodedDevice(unsigned major, unsigned minor)
inline constexpr dword encoded_device(unsigned major, unsigned minor)
{
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
}

View file

@ -20,7 +20,7 @@ static DescriptorTablePointer s_gdtr;
static Descriptor* s_idt;
static Descriptor* s_gdt;
static IRQHandler** s_irqHandler;
static IRQHandler** s_irq_handler;
static Vector<word, KmallocEternalAllocator>* s_gdt_freelist;
@ -125,11 +125,11 @@ asm( \
EH_ENTRY_NO_CODE(6);
void exception_6_handler(RegisterDump& regs)
{
kprintf("%s invalid opcode: %u(%s)\n", current->isRing0() ? "Kernel" : "Process", current->pid(), current->name().characters());
kprintf("%s invalid opcode: %u(%s)\n", current->is_ring0() ? "Kernel" : "Process", current->pid(), current->name().characters());
word ss;
dword esp;
if (current->isRing0()) {
if (current->is_ring0()) {
ss = regs.ds;
esp = regs.esp;
} else {
@ -142,7 +142,7 @@ void exception_6_handler(RegisterDump& regs)
kprintf("eax=%x ebx=%x ecx=%x edx=%x\n", regs.eax, regs.ebx, regs.ecx, regs.edx);
kprintf("ebp=%x esp=%x esi=%x edi=%x\n", regs.ebp, esp, regs.esi, regs.edi);
if (current->isRing0()) {
if (current->is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
HANG;
}
@ -175,11 +175,11 @@ void exception_7_handler(RegisterDump& regs)
}
#ifdef FPU_EXCEPTION_DEBUG
kprintf("%s FPU not available exception: %u(%s)\n", current->isRing0() ? "Kernel" : "Process", current->pid(), current->name().characters());
kprintf("%s FPU not available exception: %u(%s)\n", current->is_ring0() ? "Kernel" : "Process", current->pid(), current->name().characters());
word ss;
dword esp;
if (current->isRing0()) {
if (current->is_ring0()) {
ss = regs.ds;
esp = regs.esp;
} else {
@ -199,11 +199,11 @@ void exception_7_handler(RegisterDump& regs)
EH_ENTRY(13);
void exception_13_handler(RegisterDumpWithExceptionCode& regs)
{
kprintf("%s GPF: %u(%s)\n", current->isRing0() ? "Kernel" : "User", current->pid(), current->name().characters());
kprintf("%s GPF: %u(%s)\n", current->is_ring0() ? "Kernel" : "User", current->pid(), current->name().characters());
word ss;
dword esp;
if (current->isRing0()) {
if (current->is_ring0()) {
ss = regs.ds;
esp = regs.esp;
} else {
@ -217,7 +217,7 @@ void exception_13_handler(RegisterDumpWithExceptionCode& regs)
kprintf("eax=%x ebx=%x ecx=%x edx=%x\n", regs.eax, regs.ebx, regs.ecx, regs.edx);
kprintf("ebp=%x esp=%x esi=%x edi=%x\n", regs.ebp, esp, regs.esi, regs.edi);
if (current->isRing0()) {
if (current->is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
HANG;
}
@ -248,7 +248,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
word ss;
dword esp;
if (current->isRing0()) {
if (current->is_ring0()) {
ss = regs.ds;
esp = regs.esp;
} else {
@ -278,9 +278,9 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
}
};
if (current->isRing0()) {
if (current->is_ring0()) {
dump_registers_and_code();
current->dumpRegions();
current->dump_regions();
HANG;
}
@ -335,7 +335,7 @@ EH(12, "Stack exception")
EH(15, "Unknown error")
EH(16, "Coprocessor error")
static void writeRawGDTEntry(word selector, dword low, dword high)
static void write_raw_gdt_entry(word selector, dword low, dword high)
{
word i = (selector & 0xfffc) >> 3;
s_gdt[i].low = low;
@ -348,7 +348,7 @@ static void writeRawGDTEntry(word selector, dword low, dword high)
void write_gdt_entry(word selector, Descriptor& descriptor)
{
writeRawGDTEntry(selector, descriptor.low, descriptor.high);
write_raw_gdt_entry(selector, descriptor.low, descriptor.high);
}
Descriptor& get_gdt_entry(word selector)
@ -378,11 +378,11 @@ void gdt_init()
s_gdtr.address = s_gdt;
s_gdtr.size = (s_gdtLength * 8) - 1;
writeRawGDTEntry(0x0000, 0x00000000, 0x00000000);
writeRawGDTEntry(0x0008, 0x0000ffff, 0x00cf9a00);
writeRawGDTEntry(0x0010, 0x0000ffff, 0x00cf9200);
writeRawGDTEntry(0x0018, 0x0000ffff, 0x00cffa00);
writeRawGDTEntry(0x0020, 0x0000ffff, 0x00cff200);
write_raw_gdt_entry(0x0000, 0x00000000, 0x00000000);
write_raw_gdt_entry(0x0008, 0x0000ffff, 0x00cf9a00);
write_raw_gdt_entry(0x0010, 0x0000ffff, 0x00cf9200);
write_raw_gdt_entry(0x0018, 0x0000ffff, 0x00cffa00);
write_raw_gdt_entry(0x0020, 0x0000ffff, 0x00cff200);
flush_gdt();
}
@ -395,15 +395,15 @@ static void unimp_trap()
void register_irq_handler(byte irq, IRQHandler& handler)
{
ASSERT(!s_irqHandler[irq]);
s_irqHandler[irq] = &handler;
ASSERT(!s_irq_handler[irq]);
s_irq_handler[irq] = &handler;
register_interrupt_handler(IRQ_VECTOR_BASE + irq, asm_irq_entry);
}
void unregister_irq_handler(byte irq, IRQHandler& handler)
{
ASSERT(s_irqHandler[irq] == &handler);
s_irqHandler[irq] = nullptr;
ASSERT(s_irq_handler[irq] == &handler);
s_irq_handler[irq] = nullptr;
}
void register_interrupt_handler(byte index, void (*f)())
@ -467,9 +467,9 @@ void idt_init()
register_interrupt_handler(0x57, irq7_handler);
s_irqHandler = static_cast<IRQHandler**>(kmalloc_eternal(sizeof(IRQHandler*) * 16));
s_irq_handler = static_cast<IRQHandler**>(kmalloc_eternal(sizeof(IRQHandler*) * 16));
for (byte i = 0; i < 16; ++i) {
s_irqHandler[i] = nullptr;
s_irq_handler[i] = nullptr;
}
flush_idt();
@ -482,7 +482,7 @@ void load_task_register(word selector)
void handle_irq()
{
word isr = PIC::getISR();
word isr = PIC::get_isr();
if (!isr) {
kprintf("Spurious IRQ\n");
return;
@ -498,8 +498,8 @@ void handle_irq()
}
}
if (s_irqHandler[irq])
s_irqHandler[irq]->handle_irq();
if (s_irq_handler[irq])
s_irq_handler[irq]->handle_irq();
PIC::eoi(irq);
}

View file

@ -43,14 +43,14 @@ union Descriptor {
TrapGate_32bit = 0xf,
};
void setBase(void* b)
void set_base(void* b)
{
base_lo = (dword)(b) & 0xffff;
base_hi = ((dword)(b) >> 16) & 0xff;
base_hi2 = ((dword)(b) >> 24) & 0xff;
}
void setLimit(dword l)
void set_limit(dword l)
{
limit_lo = (dword)l & 0xffff;
limit_hi = ((dword)l >> 16) & 0xff;
@ -220,7 +220,7 @@ struct FPUState {
dword st[20];
};
inline constexpr dword pageBaseOf(dword address)
inline constexpr dword page_base_of(dword address)
{
return address & 0xfffff000;
}

View file

@ -4,14 +4,14 @@
#include "PIC.h"
#include "Scheduler.h"
#define IRQ_TIMER 0
#define IRQ_TIMER 0
extern "C" void tick_ISR();
extern "C" void clock_handle(RegisterDump&);
extern "C" void timer_interrupt_entry();
extern "C" void timer_interrupt_handler(RegisterDump&);
asm(
".globl tick_ISR \n"
"tick_ISR: \n"
".globl timer_interrupt_entry \n"
"timer_interrupt_entry: \n"
" pusha\n"
" pushw %ds\n"
" pushw %es\n"
@ -27,7 +27,7 @@ asm(
" popw %fs\n"
" popw %gs\n"
" mov %esp, %eax\n"
" call clock_handle\n"
" call timer_interrupt_handler\n"
" popw %gs\n"
" popw %gs\n"
" popw %fs\n"
@ -53,12 +53,11 @@ asm(
#define MODE_RATE 0x04
#define MODE_SQUARE_WAVE 0x06
#define WRITE_word 0x30
#define WRITE_WORD 0x30
/* Miscellaneous */
#define BASE_FREQUENCY 1193182
void clock_handle(RegisterDump& regs)
void timer_interrupt_handler(RegisterDump& regs)
{
IRQHandlerScope scope(IRQ_TIMER);
Scheduler::timer_tick(regs);
@ -70,7 +69,7 @@ void initialize()
{
word timer_reload;
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_word | MODE_SQUARE_WAVE);
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_WORD | MODE_SQUARE_WAVE);
timer_reload = (BASE_FREQUENCY / TICKS_PER_SECOND);
@ -79,7 +78,7 @@ void initialize()
IO::out8(TIMER0_CTL, LSB(timer_reload));
IO::out8(TIMER0_CTL, MSB(timer_reload));
register_interrupt_handler(IRQ_VECTOR_BASE + IRQ_TIMER, tick_ISR);
register_interrupt_handler(IRQ_VECTOR_BASE + IRQ_TIMER, timer_interrupt_entry);
PIC::enable(IRQ_TIMER);
}

View file

@ -88,10 +88,10 @@ static void init_stage2()
vfs->register_character_device(*tty3);
auto dev_hd0 = IDEDiskDevice::create();
auto e2fs = Ext2FS::create(dev_hd0.copyRef());
auto e2fs = Ext2FS::create(dev_hd0.copy_ref());
e2fs->initialize();
vfs->mount_root(e2fs.copyRef());
vfs->mount_root(e2fs.copy_ref());
load_ksyms();

View file

@ -15,7 +15,7 @@ int kprintf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = printfInternal(console_putch, nullptr, fmt, ap);
int ret = printf_internal(console_putch, nullptr, fmt, ap);
va_end(ap);
return ret;
}
@ -29,7 +29,7 @@ int ksprintf(char* buffer, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
int ret = printf_internal(buffer_putch, buffer, fmt, ap);
buffer[ret] = '\0';
va_end(ap);
return ret;
@ -44,7 +44,7 @@ extern "C" int dbgprintf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = printfInternal(debugger_putch, nullptr, fmt, ap);
int ret = printf_internal(debugger_putch, nullptr, fmt, ap);
va_end(ap);
return ret;
}

View file

@ -98,7 +98,7 @@ next_entry:
auto& e_gid_string = parts[2];
auto& e_members_string = parts[3];
bool ok;
gid_t e_gid = e_gid_string.toUInt(ok);
gid_t e_gid = e_gid_string.to_uint(ok);
if (!ok) {
fprintf(stderr, "getgrent(): Malformed GID on line %u\n", __grdb_line_number);
goto next_entry;

View file

@ -102,12 +102,12 @@ next_entry:
auto& e_dir = parts[5];
auto& e_shell = parts[6];
bool ok;
uid_t e_uid = e_uid_string.toUInt(ok);
uid_t e_uid = e_uid_string.to_uint(ok);
if (!ok) {
fprintf(stderr, "getpwent(): Malformed UID on line %u\n", __pwdb_line_number);
goto next_entry;
}
gid_t e_gid = e_gid_string.toUInt(ok);
gid_t e_gid = e_gid_string.to_uint(ok);
if (!ok) {
fprintf(stderr, "getpwent(): Malformed GID on line %u\n", __pwdb_line_number);
goto next_entry;

View file

@ -35,7 +35,7 @@
#define MAXLN 512
static const char* determineBase(const char* p, int& base)
static const char* determine_base(const char* p, int& base)
{
if (p[0] == '0') {
switch (p[1]) {
@ -111,7 +111,7 @@ int atob(unsigned int* vp, const char* p, int base)
unsigned long v;
if (base == 0)
p = determineBase(p, base);
p = determine_base(p, base);
if (_atob(&v, p, base)) {
*vp = v;
return 1;

View file

@ -237,7 +237,7 @@ int dbgprintf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = printfInternal(sys_putch, nullptr, fmt, ap);
int ret = printf_internal(sys_putch, nullptr, fmt, ap);
va_end(ap);
return ret;
}
@ -256,7 +256,7 @@ static void stream_putch(char*&, char ch)
int vfprintf(FILE* stream, const char* fmt, va_list ap)
{
__current_stream = stream;
return printfInternal(stream_putch, nullptr, fmt, ap);
return printf_internal(stream_putch, nullptr, fmt, ap);
}
int fprintf(FILE* stream, const char* fmt, ...)
@ -272,7 +272,7 @@ int printf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = printfInternal(stdout_putch, nullptr, fmt, ap);
int ret = printf_internal(stdout_putch, nullptr, fmt, ap);
va_end(ap);
return ret;
}
@ -284,7 +284,7 @@ static void buffer_putch(char*& bufptr, char ch)
int vsprintf(char* buffer, const char* fmt, va_list ap)
{
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
int ret = printf_internal(buffer_putch, buffer, fmt, ap);
buffer[ret] = '\0';
return ret;
}
@ -311,7 +311,7 @@ static void sized_buffer_putch(char*& bufptr, char ch)
int vsnprintf(char* buffer, size_t size, const char* fmt, va_list ap)
{
__vsnprintf_space_remaining = size;
int ret = printfInternal(sized_buffer_putch, buffer, fmt, ap);
int ret = printf_internal(sized_buffer_putch, buffer, fmt, ap);
buffer[ret] = '\0';
return ret;
}

View file

@ -190,21 +190,21 @@ char* strrchr(const char* str, int ch)
char* strcat(char *dest, const char *src)
{
size_t destLength = strlen(dest);
size_t dest_length = strlen(dest);
size_t i;
for (i = 0 ; src[i] != '\0' ; i++)
dest[destLength + i] = src[i];
dest[destLength + i] = '\0';
dest[dest_length + i] = src[i];
dest[dest_length + i] = '\0';
return dest;
}
char* strncat(char *dest, const char *src, size_t n)
{
size_t destLength = strlen(dest);
size_t dest_length = strlen(dest);
size_t i;
for (i = 0 ; i < n && src[i] != '\0' ; i++)
dest[destLength + i] = src[i];
dest[destLength + i] = '\0';
dest[dest_length + i] = src[i];
dest[dest_length + i] = '\0';
return dest;
}

View file

@ -1,37 +0,0 @@
#include "ClockWidget.h"
#include <SharedGraphics/Painter.h>
#include <time.h>
ClockWidget::ClockWidget(GWidget* parent)
: GWidget(parent)
{
setWindowRelativeRect({ 0, 0, 100, 40 });
startTimer(250);
}
ClockWidget::~ClockWidget()
{
}
void ClockWidget::paintEvent(PaintEvent&)
{
auto now = time(nullptr);
auto& tm = *localtime(&now);
char timeBuf[128];
sprintf(timeBuf, "%02u:%02u:%02u ", tm.tm_hour, tm.tm_min, tm.tm_sec);
Painter painter(*this);
painter.fill_rect(rect(), Color::MidGray);
painter.draw_text(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black);
}
void ClockWidget::timerEvent(TimerEvent&)
{
auto now = time(nullptr);
if (now == m_lastSeenTimestamp)
return;
m_lastSeenTimestamp = now;
update();
}

View file

@ -1,16 +0,0 @@
#pragma once
#include "Widget.h"
class ClockWidget final : public Widget {
public:
explicit ClockWidget(Widget* parent = nullptr);
virtual ~ClockWidget() override;
private:
virtual void paintEvent(PaintEvent&) override;
virtual void timerEvent(TimerEvent&) override;
dword m_lastSeenTimestamp { 0 };
};

View file

@ -27,7 +27,7 @@ GCheckBox::GCheckBox(GWidget* parent)
: GWidget(parent)
{
if (!s_checked_bitmap)
s_checked_bitmap = CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leakRef();
s_checked_bitmap = CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref();
}
GCheckBox::~GCheckBox()

View file

@ -7,15 +7,15 @@ GObject::GObject(GObject* parent)
: m_parent(parent)
{
if (m_parent)
m_parent->addChild(*this);
m_parent->add_child(*this);
}
GObject::~GObject()
{
if (m_parent)
m_parent->removeChild(*this);
auto childrenToDelete = move(m_children);
for (auto* child : childrenToDelete)
m_parent->remove_child(*this);
auto children_to_delete = move(m_children);
for (auto* child : children_to_delete)
delete child;
}
@ -35,12 +35,12 @@ void GObject::event(GEvent& event)
}
}
void GObject::addChild(GObject& object)
void GObject::add_child(GObject& object)
{
m_children.append(&object);
}
void GObject::removeChild(GObject& object)
void GObject::remove_child(GObject& object)
{
for (unsigned i = 0; i < m_children.size(); ++i) {
if (m_children[i] == &object) {
@ -54,19 +54,19 @@ void GObject::timer_event(GTimerEvent&)
{
}
void GObject::startTimer(int ms)
void GObject::start_timer(int ms)
{
if (m_timerID) {
if (m_timer_id) {
dbgprintf("GObject{%p} already has a timer!\n", this);
ASSERT_NOT_REACHED();
}
}
void GObject::stopTimer()
void GObject::stop_timer()
{
if (!m_timerID)
if (!m_timer_id)
return;
m_timerID = 0;
m_timer_id = 0;
}
void GObject::delete_later()

View file

@ -20,12 +20,12 @@ public:
GObject* parent() { return m_parent; }
const GObject* parent() const { return m_parent; }
void startTimer(int ms);
void stopTimer();
bool hasTimer() const { return m_timerID; }
void start_timer(int ms);
void stop_timer();
bool has_timer() const { return m_timer_id; }
void addChild(GObject&);
void removeChild(GObject&);
void add_child(GObject&);
void remove_child(GObject&);
void delete_later();
@ -34,7 +34,7 @@ private:
GObject* m_parent { nullptr };
int m_timerID { 0 };
int m_timer_id { 0 };
Vector<GObject*> m_children;
};

View file

@ -8,7 +8,7 @@
GTextBox::GTextBox(GWidget* parent)
: GWidget(parent)
{
startTimer(500);
start_timer(500);
}
GTextBox::~GTextBox()
@ -73,12 +73,12 @@ void GTextBox::handle_backspace()
}
char* buffer;
auto newText = StringImpl::create_uninitialized(m_text.length() - 1, buffer);
auto new_text = StringImpl::create_uninitialized(m_text.length() - 1, buffer);
memcpy(buffer, m_text.characters(), m_cursor_position - 1);
memcpy(buffer + m_cursor_position - 1, m_text.characters() + m_cursor_position, m_text.length() - (m_cursor_position - 1));
m_text = move(newText);
m_text = move(new_text);
--m_cursor_position;
update();
}
@ -110,13 +110,13 @@ void GTextBox::keydown_event(GKeyEvent& event)
ASSERT(event.text().length() == 1);
char* buffer;
auto newText = StringImpl::create_uninitialized(m_text.length() + 1, buffer);
auto new_text = StringImpl::create_uninitialized(m_text.length() + 1, buffer);
memcpy(buffer, m_text.characters(), m_cursor_position);
buffer[m_cursor_position] = event.text()[0];
memcpy(buffer + m_cursor_position + 1, m_text.characters() + m_cursor_position, m_text.length() - m_cursor_position);
m_text = move(newText);
m_text = move(new_text);
++m_cursor_position;
update();
return;

View file

@ -207,6 +207,6 @@ void GWindow::set_global_cursor_tracking_widget(GWidget* widget)
ASSERT(m_window_id);
if (widget == m_global_cursor_tracking_widget.ptr())
return;
m_global_cursor_tracking_widget = widget ? widget->makeWeakPtr() : nullptr;
m_global_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
gui_set_global_cursor_tracking_enabled(m_window_id, widget != nullptr);
}

View file

@ -14,7 +14,7 @@ void Font::initialize()
Font& Font::default_font()
{
if (!s_default_font)
s_default_font = adopt(*new Font(DEFAULT_FONT_NAME::glyphs, DEFAULT_FONT_NAME::glyph_width, DEFAULT_FONT_NAME::glyph_height, DEFAULT_FONT_NAME::first_glyph, DEFAULT_FONT_NAME::last_glyph)).leakRef();
s_default_font = adopt(*new Font(DEFAULT_FONT_NAME::glyphs, DEFAULT_FONT_NAME::glyph_width, DEFAULT_FONT_NAME::glyph_height, DEFAULT_FONT_NAME::first_glyph, DEFAULT_FONT_NAME::last_glyph)).leak_ref();
return *s_default_font;
}
@ -28,7 +28,7 @@ Font::Font(const char* const* glyphs, byte glyph_width, byte glyph_height, byte
m_error_bitmap = CharacterBitmap::create_from_ascii(DEFAULT_FONT_NAME::error_glyph, m_glyph_width, m_glyph_height);
for (unsigned ch = 0; ch < 256; ++ch) {
if (ch < m_first_glyph || ch > m_last_glyph) {
m_bitmaps[ch] = m_error_bitmap.copyRef();
m_bitmaps[ch] = m_error_bitmap.copy_ref();
continue;
}
const char* data = m_glyphs[(unsigned)ch - m_first_glyph];

View file

@ -16,12 +16,12 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create(Process& process, const Size& s
GraphicsBitmap::GraphicsBitmap(Process& process, const Size& size)
: m_size(size)
, m_pitch(size.width() * sizeof(RGBA32))
, m_client_process(process.makeWeakPtr())
, m_client_process(process.make_weak_ptr())
{
InterruptDisabler disabler;
size_t size_in_bytes = size.width() * size.height() * sizeof(RGBA32);
auto vmo = VMObject::create_anonymous(size_in_bytes);
m_client_region = process.allocate_region_with_vmo(LinearAddress(), size_in_bytes, vmo.copyRef(), 0, "GraphicsBitmap (client)", true, true);
m_client_region = process.allocate_region_with_vmo(LinearAddress(), size_in_bytes, vmo.copy_ref(), 0, "GraphicsBitmap (client)", true, true);
m_client_region->set_shared(true);
m_client_region->commit();
auto& server = WSMessageLoop::the().server_process();

View file

@ -199,9 +199,9 @@ void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alig
int text_width = text.length() * font().glyph_width();
point = { rect.right() - text_width, rect.center().y() - (font().glyph_height() / 2) };
} else if (alignment == TextAlignment::Center) {
int textWidth = text.length() * font().glyph_width();
int text_width = text.length() * font().glyph_width();
point = rect.center();
point.move_by(-(textWidth / 2), -(font().glyph_height() / 2));
point.move_by(-(text_width / 2), -(font().glyph_height() / 2));
} else {
ASSERT_NOT_REACHED();
}
@ -283,14 +283,14 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color)
const double dy = point2.y() - point1.y();
const double delta_error = fabs(dy / dx);
double error = 0;
const double yStep = dy == 0 ? 0 : (dy > 0 ? 1 : -1);
const double y_step = dy == 0 ? 0 : (dy > 0 ? 1 : -1);
int y = point1.y();
for (int x = point1.x(); x <= point2.x(); ++x) {
m_target->scanline(y)[x] = color.value();
error += delta_error;
if (error >= 0.5) {
y = (double)y + yStep;
y = (double)y + y_step;
error -= 1.0;
}
}

View file

@ -110,7 +110,7 @@ inline bool is_valid_final_character(byte ch)
return ch >= 0x40 && ch <= 0x7e;
}
unsigned parseUInt(const String& str, bool& ok)
unsigned parse_uint(const String& str, bool& ok)
{
unsigned value = 0;
for (size_t i = 0; i < str.length(); ++i) {
@ -341,7 +341,7 @@ void Terminal::execute_xterm_command()
{
m_final = '@';
bool ok;
unsigned value = parseUInt(String((const char*)m_xterm_param1.data(), m_xterm_param1.size()), ok);
unsigned value = parse_uint(String((const char*)m_xterm_param1.data(), m_xterm_param1.size()), ok);
if (ok) {
switch (value) {
case 0:
@ -363,7 +363,7 @@ void Terminal::execute_escape_sequence(byte final)
Vector<unsigned> params;
for (auto& parampart : paramparts) {
bool ok;
unsigned value = parseUInt(parampart, ok);
unsigned value = parse_uint(parampart, ok);
if (!ok) {
// FIXME: Should we do something else?
return;
@ -562,7 +562,7 @@ void Terminal::unimplemented_escape()
builder.append((char)m_intermediates[i]);
}
builder.append("))");
inject_string(builder.build());
inject_string(builder.to_string());
}
void Terminal::unimplemented_xterm_escape()

View file

@ -34,7 +34,7 @@ ClockWidget::ClockWidget(GWidget* parent)
: GWidget(parent)
{
set_relative_rect({ 0, 0, 100, 40 });
startTimer(250);
start_timer(250);
}
void ClockWidget::paint_event(GPaintEvent&)

View file

@ -4,7 +4,7 @@
#include <stdlib.h>
#include <AK/AKString.h>
static unsigned parseUInt(const String& str, bool& ok)
static unsigned parse_uint(const String& str, bool& ok)
{
if (str.is_empty()) {
ok = false;
@ -40,13 +40,13 @@ int main(int argc, char** argv)
pid_argi = 2;
if (argv[1][0] != '-')
print_usage_and_exit();
signum = parseUInt(&argv[1][1], ok);
signum = parse_uint(&argv[1][1], ok);
if (!ok) {
printf("'%s' is not a valid signal number\n", &argv[1][1]);
return 2;
}
}
unsigned pid = parseUInt(argv[pid_argi], ok);
unsigned pid = parse_uint(argv[pid_argi], ok);
if (!ok) {
printf("'%s' is not a valid PID\n", argv[pid_argi]);
return 3;

View file

@ -184,12 +184,12 @@ static int sh_cd(int argc, char** argv)
else
sprintf(pathbuf, "%s/%s", g->cwd.characters(), argv[1]);
FileSystemPath canonicalPath(pathbuf);
if (!canonicalPath.is_valid()) {
FileSystemPath canonical_path(pathbuf);
if (!canonical_path.is_valid()) {
printf("FileSystemPath failed to canonicalize '%s'\n", pathbuf);
return 1;
}
const char* path = canonicalPath.string().characters();
const char* path = canonical_path.string().characters();
struct stat st;
int rc = stat(path, &st);
@ -206,7 +206,7 @@ static int sh_cd(int argc, char** argv)
printf("chdir(%s) failed: %s\n", path, strerror(errno));
return 1;
}
g->cwd = canonicalPath.string();
g->cwd = canonical_path.string();
return 0;
}

View file

@ -3,7 +3,7 @@
#include <signal.h>
#include <AK/AKString.h>
static unsigned parseUInt(const String& str, bool& ok)
static unsigned parse_uint(const String& str, bool& ok)
{
unsigned value = 0;
for (size_t i = 0; i < str.length(); ++i) {
@ -29,7 +29,7 @@ int main(int argc, char** argv)
return 1;
}
bool ok;
unsigned secs = parseUInt(argv[1], ok);
unsigned secs = parse_uint(argv[1], ok);
if (!ok) {
fprintf(stderr, "Not a valid number of seconds: \"%s\"\n", argv[1]);
return 1;

View file

@ -84,7 +84,7 @@ static String read_var(const String& name)
StringBuilder builder;
builder.append("/proc/sys/");
builder.append(name);
auto path = builder.build();
auto path = builder.to_string();
int fd = open(path.characters(), O_RDONLY);
if (fd < 0) {
perror("open");
@ -105,7 +105,7 @@ static void write_var(const String& name, const String& value)
StringBuilder builder;
builder.append("/proc/sys/");
builder.append(name);
auto path = builder.build();
auto path = builder.to_string();
int fd = open(path.characters(), O_WRONLY);
if (fd < 0) {
perror("open");

View file

@ -11,36 +11,36 @@
//#define DEBUG_COUNTERS
static const int windowTitleBarHeight = 16;
static const int window_titlebar_height = 16;
static inline Rect title_bar_rect(const Rect& window)
{
return {
window.x() - 1,
window.y() - windowTitleBarHeight,
window.y() - window_titlebar_height,
window.width() + 2,
windowTitleBarHeight
window_titlebar_height
};
}
static inline Rect title_bar_text_rect(const Rect& window)
{
auto titleBarRect = title_bar_rect(window);
auto titlebar_rect = title_bar_rect(window);
return {
titleBarRect.x() + 2,
titleBarRect.y(),
titleBarRect.width() - 4,
titleBarRect.height()
titlebar_rect.x() + 2,
titlebar_rect.y(),
titlebar_rect.width() - 4,
titlebar_rect.height()
};
}
static inline Rect border_window_rect(const Rect& window)
{
auto titleBarRect = title_bar_rect(window);
return { titleBarRect.x() - 1,
titleBarRect.y() - 1,
titleBarRect.width() + 2,
windowTitleBarHeight + window.height() + 3
auto titlebar_rect = title_bar_rect(window);
return { titlebar_rect.x() - 1,
titlebar_rect.y() - 1,
titlebar_rect.width() + 2,
window_titlebar_height + window.height() + 3
};
}
@ -148,12 +148,12 @@ WSWindowManager::~WSWindowManager()
void WSWindowManager::paint_window_frame(WSWindow& window)
{
LOCKER(m_lock);
//printf("[WM] paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height());
//printf("[WM] paint_window_frame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height());
auto titleBarRect = title_bar_rect(window.rect());
auto titleBarTitleRect = title_bar_text_rect(window.rect());
auto outerRect = outer_window_rect(window.rect());
auto borderRect = border_window_rect(window.rect());
auto titlebar_rect = title_bar_rect(window.rect());
auto titlebar_title_rect = title_bar_text_rect(window.rect());
auto outer_rect = outer_window_rect(window.rect());
auto border_rect = border_window_rect(window.rect());
Rect inner_border_rect {
window.x() - 1,
@ -184,15 +184,15 @@ void WSWindowManager::paint_window_frame(WSWindow& window)
middle_border_color = Color::MidGray;
}
m_back_painter->fill_rect_with_gradient(titleBarRect, border_color, border_color2);
m_back_painter->draw_rect(borderRect, middle_border_color);
m_back_painter->draw_rect(outerRect, border_color);
m_back_painter->fill_rect_with_gradient(titlebar_rect, border_color, border_color2);
m_back_painter->draw_rect(border_rect, middle_border_color);
m_back_painter->draw_rect(outer_rect, border_color);
m_back_painter->draw_rect(inner_border_rect, border_color);
m_back_painter->draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, title_color);
m_back_painter->draw_text(titlebar_title_rect, window.title(), Painter::TextAlignment::CenterLeft, title_color);
Color metadata_color(96, 96, 96);
m_back_painter->draw_text(
titleBarTitleRect,
titlebar_title_rect,
String::format("%d:%d", window.pid(), window.window_id()),
Painter::TextAlignment::CenterRight,
metadata_color
@ -250,7 +250,7 @@ void WSWindowManager::handle_titlebar_mouse_event(WSWindow& window, WSMouseEvent
#ifdef DRAG_DEBUG
printf("[WM] Begin dragging WSWindow{%p}\n", &window);
#endif
m_drag_window = window.makeWeakPtr();;
m_drag_window = window.make_weak_ptr();;
m_drag_origin = event.position();
m_drag_window_origin = window.position();
m_drag_start_rect = outer_window_rect(window.rect());
@ -265,7 +265,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event)
if (event.type() == WSMessage::MouseUp && event.button() == MouseButton::Left) {
if (m_drag_window) {
#ifdef DRAG_DEBUG
printf("[WM] Finish dragging WSWindow{%p}\n", m_dragWindow.ptr());
printf("[WM] Finish dragging WSWindow{%p}\n", m_drag_window.ptr());
#endif
invalidate(*m_drag_window);
m_drag_window->set_is_being_dragged(false);
@ -280,7 +280,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event)
auto old_window_rect = m_drag_window->rect();
Point pos = m_drag_window_origin;
#ifdef DRAG_DEBUG
dbgprintf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_dragOrigin.x(), m_dragOrigin.y(), event.x(), event.y());
dbgprintf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_drag_origin.x(), m_drag_origin.y(), event.x(), event.y());
#endif
pos.move_by(event.x() - m_drag_origin.x(), event.y() - m_drag_origin.y());
m_drag_window->set_position_without_repaint(pos);
@ -429,7 +429,7 @@ void WSWindowManager::set_active_window(WSWindow* window)
WSMessageLoop::the().post_message(previously_active_window, make<WSMessage>(WSMessage::WindowDeactivated));
invalidate(*previously_active_window);
}
m_active_window = window->makeWeakPtr();
m_active_window = window->make_weak_ptr();
if (m_active_window) {
WSMessageLoop::the().post_message(m_active_window.ptr(), make<WSMessage>(WSMessage::WindowActivated));
invalidate(*m_active_window);