summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-08 15:38:44 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-08 15:38:44 +0200
commit0e75aba7c39c7a2d3b0becc2416aa0e251d62070 (patch)
tree19bc08a69423db6ab1c6669c06eaab81f494a564 /Kernel
parent567551bc12945c25b49c65579ceb545668dbb7eb (diff)
downloadserenity-0e75aba7c39c7a2d3b0becc2416aa0e251d62070.zip
StringView: Rename characters() to characters_without_null_termination().
This should make you think twice before trying to use the const char* from a StringView as if it's a null-terminated string.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp10
-rw-r--r--Kernel/FileSystem/InodeIdentifier.h7
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp16
-rw-r--r--Kernel/Net/NetworkAdapter.cpp6
4 files changed, 25 insertions, 14 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 69f57d6e23..e357baad5b 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -761,7 +761,7 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name,
ASSERT(is_directory());
//#ifdef EXT2_DEBUG
- dbgprintf("Ext2FS: Adding inode %u with name '%s' and mode %o to directory %u\n", child_id.index(), name.characters(), mode, index());
+ dbg() << "Ext2FSInode::add_child(): Adding inode " << child_id.index() << " with name '" << name << " and mode " << mode << " to directory " << index();
//#endif
Vector<FS::DirectoryEntry> entries;
@@ -775,7 +775,7 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name,
return true;
});
if (name_already_exists) {
- kprintf("Ext2FS: Name '%s' already exists in directory inode %u\n", name.characters(), index());
+ dbg() << "Ext2FSInode::add_child(): Name '" << name << "' already exists in inode " << index();
return KResult(-EEXIST);
}
@@ -783,7 +783,7 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name,
if (child_inode)
child_inode->increment_link_count();
- entries.append({ name.characters(), name.length(), child_id, to_ext2_file_type(mode) });
+ entries.append({ name.characters_without_null_termination(), name.length(), child_id, to_ext2_file_type(mode) });
bool success = write_directory(entries);
if (success)
m_lookup_cache.set(name, child_id.index());
@@ -794,7 +794,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
{
LOCKER(m_lock);
#ifdef EXT2_DEBUG
- dbgprintf("Ext2FSInode::remove_child(%s) in inode %u\n", name.characters(), index());
+ dbg() << "Ext2FSInode::remove_child(" << name << ") in inode " << index();
#endif
ASSERT(is_directory());
@@ -807,7 +807,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
InodeIdentifier child_id { fsid(), child_inode_index };
//#ifdef EXT2_DEBUG
- dbgprintf("Ext2FS: Removing '%s' in directory %u\n", name.characters(), index());
+ dbg() << "Ext2FSInode::remove_child(): Removing '" << name << "' in directory " << index();
//#endif
Vector<FS::DirectoryEntry> entries;
diff --git a/Kernel/FileSystem/InodeIdentifier.h b/Kernel/FileSystem/InodeIdentifier.h
index 2a3958aff9..bf95dd7d96 100644
--- a/Kernel/FileSystem/InodeIdentifier.h
+++ b/Kernel/FileSystem/InodeIdentifier.h
@@ -42,3 +42,10 @@ private:
u32 m_fsid { 0 };
u32 m_index { 0 };
};
+
+inline const LogStream& operator<<(const LogStream& stream, const InodeIdentifier& value)
+{
+ stream << value.fsid() << ':' << value.index();
+ return stream;
+}
+
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index da45f8b861..b4b0c3513c 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -40,11 +40,11 @@ bool VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
{
auto result = resolve_path(path, root_custody());
if (result.is_error()) {
- kprintf("VFS: mount can't resolve mount point '%s'\n", path.characters());
+ dbg() << "VFS: mount can't resolve mount point '" << path << "'";
return false;
}
auto& inode = result.value()->inode();
- kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", file_system->class_name(), file_system.ptr(), path.characters(), inode.index());
+ dbg() << "VFS: Mounting " << file_system->class_name() << " at " << path << " (inode: " << inode.identifier() << ")";
// FIXME: check that this is not already a mount point
auto mount = make<Mount>(*result.value(), move(file_system));
m_mounts.append(move(mount));
@@ -221,7 +221,7 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
return KResult(-EACCES);
FileSystemPath p(path);
- dbgprintf("VFS::mknod: '%s' mode=%o dev=%u in %u:%u\n", p.basename().characters(), mode, dev, parent_inode.fsid(), parent_inode.index());
+ dbg() << "VFS::mknod: '" << p.basename() << "' mode=" << mode << " dev=" << dev << " in " << parent_inode.identifier();
int error;
auto new_file = parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), mode, 0, dev, error);
if (!new_file)
@@ -243,7 +243,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
if (!parent_inode.metadata().may_write(current->process()))
return KResult(-EACCES);
FileSystemPath p(path);
- dbgprintf("VFS::create_file: '%s' in %u:%u\n", p.basename().characters(), parent_inode.fsid(), parent_inode.index());
+ dbg() << "VFS::create: '" << p.basename() << "' in " << parent_inode.identifier();
int error;
auto new_file = parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), mode, 0, 0, error);
if (!new_file)
@@ -269,7 +269,7 @@ KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
return KResult(-EACCES);
FileSystemPath p(path);
- dbgprintf("VFS::mkdir: '%s' in %u:%u\n", p.basename().characters(), parent_inode.fsid(), parent_inode.index());
+ dbg() << "VFS::mkdir: '" << p.basename() << "' in " << parent_inode.identifier();
int error;
auto new_dir = parent_inode.fs().create_directory(parent_inode.identifier(), p.basename(), mode, error);
if (new_dir)
@@ -423,7 +423,7 @@ KResult VFS::chown(Inode& inode, uid_t a_uid, gid_t a_gid)
new_gid = a_gid;
}
- dbgprintf("VFS::chown(): inode %u:%u <- uid:%d, gid:%d\n", inode.fsid(), inode.index(), new_uid, new_gid);
+ dbg() << "VFS::chown(): inode " << inode.identifier() << " <- uid:" << new_uid << " gid:" << new_gid;
return inode.chown(new_uid, new_gid);
}
@@ -511,12 +511,12 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
return KResult(-EACCES);
FileSystemPath p(linkpath);
- dbgprintf("VFS::symlink: '%s' (-> '%s') in %u:%u\n", p.basename().characters(), target.characters(), parent_inode.fsid(), parent_inode.index());
+ dbg() << "VFS::symlink: '" << p.basename() << "' (-> '" << target << "') in " << parent_inode.identifier();
int error;
auto new_file = parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), 0120644, 0, 0, error);
if (!new_file)
return KResult(error);
- ssize_t nwritten = new_file->write_bytes(0, target.length(), (const u8*)target.characters(), nullptr);
+ ssize_t nwritten = new_file->write_bytes(0, target.length(), (const u8*)target.characters_without_null_termination(), nullptr);
if (nwritten < 0)
return KResult(nwritten);
return KSuccess;
diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp
index bb39a869ea..f1eaffc245 100644
--- a/Kernel/Net/NetworkAdapter.cpp
+++ b/Kernel/Net/NetworkAdapter.cpp
@@ -1,4 +1,5 @@
#include <AK/HashTable.h>
+#include <AK/StringBuilder.h>
#include <Kernel/Lock.h>
#include <Kernel/Net/EtherType.h>
#include <Kernel/Net/EthernetFrameHeader.h>
@@ -100,7 +101,10 @@ void NetworkAdapter::set_ipv4_address(const IPv4Address& address)
void NetworkAdapter::set_interface_name(const StringView& basename)
{
// FIXME: Find a unique name for this interface, starting with $basename.
- m_name = String::format("%s0", basename.characters());
+ StringBuilder builder;
+ builder.append(basename);
+ builder.append('0');
+ m_name = builder.to_string();
}
bool PacketQueueAlarm::is_ringing() const