diff --git a/Kernel/API/InodeWatcherEvent.h b/Kernel/API/InodeWatcherEvent.h new file mode 100644 index 00000000000..ca607d34b3d --- /dev/null +++ b/Kernel/API/InodeWatcherEvent.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +struct [[gnu::packed]] InodeWatcherEvent +{ + enum class Type { + Invalid = 0, + Modified, + ChildAdded, + ChildRemoved, + }; + + Type type { Type::Invalid }; + unsigned inode_index { 0 }; +}; diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index e19ffcac904..1cc0b8438a0 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -229,7 +230,7 @@ void Inode::set_metadata_dirty(bool metadata_dirty) // We don't always end up on this particular code path, for instance when writing to an ext2fs file. LOCKER(m_lock); for (auto& watcher : m_watchers) { - watcher->notify_inode_event({}, InodeWatcher::Event::Type::Modified); + watcher->notify_inode_event({}, InodeWatcherEvent::Type::Modified); } } } diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index d4d698440b9..df03df8845b 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -67,7 +67,7 @@ KResultOr InodeWatcher::read(FileDescription&, size_t, UserOrKernelBuffe auto event = m_queue.dequeue(); - if (buffer_size < sizeof(Event)) + if (buffer_size < sizeof(InodeWatcherEvent)) return buffer_size; size_t bytes_to_write = min(buffer_size, sizeof(event)); @@ -94,7 +94,7 @@ String InodeWatcher::absolute_path(const FileDescription&) const return "InodeWatcher:(gone)"; } -void InodeWatcher::notify_inode_event(Badge, Event::Type event_type) +void InodeWatcher::notify_inode_event(Badge, InodeWatcherEvent::Type event_type) { LOCKER(m_lock); m_queue.enqueue({ event_type }); @@ -104,14 +104,14 @@ void InodeWatcher::notify_inode_event(Badge, Event::Type event_type) void InodeWatcher::notify_child_added(Badge, const InodeIdentifier& child_id) { LOCKER(m_lock); - m_queue.enqueue({ Event::Type::ChildAdded, child_id.index() }); + m_queue.enqueue({ InodeWatcherEvent::Type::ChildAdded, child_id.index() }); evaluate_block_conditions(); } void InodeWatcher::notify_child_removed(Badge, const InodeIdentifier& child_id) { LOCKER(m_lock); - m_queue.enqueue({ Event::Type::ChildRemoved, child_id.index() }); + m_queue.enqueue({ InodeWatcherEvent::Type::ChildRemoved, child_id.index() }); evaluate_block_conditions(); } diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h index 33961590645..ba5a9bef365 100644 --- a/Kernel/FileSystem/InodeWatcher.h +++ b/Kernel/FileSystem/InodeWatcher.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -41,18 +42,6 @@ public: static NonnullRefPtr create(Inode&); virtual ~InodeWatcher() override; - struct Event { - enum class Type { - Invalid = 0, - Modified, - ChildAdded, - ChildRemoved, - }; - - Type type { Type::Invalid }; - unsigned inode_index { 0 }; - }; - virtual bool can_read(const FileDescription&, size_t) const override; virtual bool can_write(const FileDescription&, size_t) const override; virtual KResultOr read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override; @@ -60,7 +49,7 @@ public: virtual String absolute_path(const FileDescription&) const override; virtual const char* class_name() const override { return "InodeWatcher"; }; - void notify_inode_event(Badge, Event::Type); + void notify_inode_event(Badge, InodeWatcherEvent::Type); void notify_child_added(Badge, const InodeIdentifier& child_id); void notify_child_removed(Badge, const InodeIdentifier& child_id); @@ -69,7 +58,7 @@ private: Lock m_lock; WeakPtr m_inode; - CircularQueue m_queue; + CircularQueue m_queue; }; }