diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-21 12:56:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-21 16:27:21 +0100 |
commit | 3c1ca61e74090071ec0aba525f3969daab5e780c (patch) | |
tree | d3b11350c15753622ef7a46237a71baad869b314 | |
parent | d5189b66778103fba1b27c99e30371a95922de92 (diff) | |
download | serenity-3c1ca61e74090071ec0aba525f3969daab5e780c.zip |
Kernel: Use KString instead of String in InodeWatcher::Event's path
-rw-r--r-- | Kernel/FileSystem/InodeWatcher.cpp | 15 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeWatcher.h | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index 39bf92e360..eedf5e0938 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -37,10 +37,9 @@ ErrorOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer auto event = m_queue.dequeue(); - size_t name_length = event.path.length() + 1; size_t bytes_to_write = sizeof(InodeWatcherEvent); - if (!event.path.is_null()) - bytes_to_write += name_length; + if (event.path) + bytes_to_write += event.path->length() + 1; if (buffer_size < bytes_to_write) return EINVAL; @@ -53,10 +52,11 @@ ErrorOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer memcpy(bytes.offset(offset), &event.type, sizeof(InodeWatcherEvent::type)); offset += sizeof(InodeWatcherEvent::type); - if (!event.path.is_null()) { + if (event.path) { + size_t name_length = event.path->length() + 1; memcpy(bytes.offset(offset), &name_length, sizeof(InodeWatcherEvent::name_length)); offset += sizeof(InodeWatcherEvent::name_length); - memcpy(bytes.offset(offset), event.path.characters(), name_length); + memcpy(bytes.offset(offset), event.path->characters(), name_length); } else { memset(bytes.offset(offset), 0, sizeof(InodeWatcherEvent::name_length)); } @@ -98,7 +98,10 @@ void InodeWatcher::notify_inode_event(Badge<Inode>, InodeIdentifier inode_id, In if (!(watcher.event_mask & static_cast<unsigned>(event_type))) return; - m_queue.enqueue({ watcher.wd, event_type, name }); + OwnPtr<KString> path; + if (!name.is_null()) + path = KString::try_create(name).release_value_but_fixme_should_propagate_errors(); + m_queue.enqueue({ watcher.wd, event_type, move(path) }); evaluate_block_conditions(); } diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h index f0ff959baf..cec9acb0e1 100644 --- a/Kernel/FileSystem/InodeWatcher.h +++ b/Kernel/FileSystem/InodeWatcher.h @@ -69,7 +69,7 @@ private: struct Event { int wd { 0 }; InodeWatcherEvent::Type type { InodeWatcherEvent::Type::Invalid }; - String path; + OwnPtr<KString> path; }; CircularQueue<Event, 32> m_queue; Checked<int> m_wd_counter { 1 }; |