mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel: Move InodeWatcher::Event into Kernel/API/InodeWatcherEvent
This allows userspace code to parse these events.
This commit is contained in:
parent
b4842d33bb
commit
345abc3132
Notes:
sideshowbarker
2024-07-19 00:51:12 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/345abc31327 Pull-request: https://github.com/SerenityOS/serenity/pull/3738 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
4 changed files with 51 additions and 19 deletions
42
Kernel/API/InodeWatcherEvent.h
Normal file
42
Kernel/API/InodeWatcherEvent.h
Normal file
|
@ -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 <AK/Types.h>
|
||||||
|
|
||||||
|
struct [[gnu::packed]] InodeWatcherEvent
|
||||||
|
{
|
||||||
|
enum class Type {
|
||||||
|
Invalid = 0,
|
||||||
|
Modified,
|
||||||
|
ChildAdded,
|
||||||
|
ChildRemoved,
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type { Type::Invalid };
|
||||||
|
unsigned inode_index { 0 };
|
||||||
|
};
|
|
@ -28,6 +28,7 @@
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <Kernel/API/InodeWatcherEvent.h>
|
||||||
#include <Kernel/FileSystem/Custody.h>
|
#include <Kernel/FileSystem/Custody.h>
|
||||||
#include <Kernel/FileSystem/Inode.h>
|
#include <Kernel/FileSystem/Inode.h>
|
||||||
#include <Kernel/FileSystem/InodeWatcher.h>
|
#include <Kernel/FileSystem/InodeWatcher.h>
|
||||||
|
@ -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.
|
// We don't always end up on this particular code path, for instance when writing to an ext2fs file.
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
for (auto& watcher : m_watchers) {
|
for (auto& watcher : m_watchers) {
|
||||||
watcher->notify_inode_event({}, InodeWatcher::Event::Type::Modified);
|
watcher->notify_inode_event({}, InodeWatcherEvent::Type::Modified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ KResultOr<size_t> InodeWatcher::read(FileDescription&, size_t, UserOrKernelBuffe
|
||||||
|
|
||||||
auto event = m_queue.dequeue();
|
auto event = m_queue.dequeue();
|
||||||
|
|
||||||
if (buffer_size < sizeof(Event))
|
if (buffer_size < sizeof(InodeWatcherEvent))
|
||||||
return buffer_size;
|
return buffer_size;
|
||||||
|
|
||||||
size_t bytes_to_write = min(buffer_size, sizeof(event));
|
size_t bytes_to_write = min(buffer_size, sizeof(event));
|
||||||
|
@ -94,7 +94,7 @@ String InodeWatcher::absolute_path(const FileDescription&) const
|
||||||
return "InodeWatcher:(gone)";
|
return "InodeWatcher:(gone)";
|
||||||
}
|
}
|
||||||
|
|
||||||
void InodeWatcher::notify_inode_event(Badge<Inode>, Event::Type event_type)
|
void InodeWatcher::notify_inode_event(Badge<Inode>, InodeWatcherEvent::Type event_type)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
m_queue.enqueue({ event_type });
|
m_queue.enqueue({ event_type });
|
||||||
|
@ -104,14 +104,14 @@ void InodeWatcher::notify_inode_event(Badge<Inode>, Event::Type event_type)
|
||||||
void InodeWatcher::notify_child_added(Badge<Inode>, const InodeIdentifier& child_id)
|
void InodeWatcher::notify_child_added(Badge<Inode>, const InodeIdentifier& child_id)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
m_queue.enqueue({ Event::Type::ChildAdded, child_id.index() });
|
m_queue.enqueue({ InodeWatcherEvent::Type::ChildAdded, child_id.index() });
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InodeWatcher::notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id)
|
void InodeWatcher::notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
m_queue.enqueue({ Event::Type::ChildRemoved, child_id.index() });
|
m_queue.enqueue({ InodeWatcherEvent::Type::ChildRemoved, child_id.index() });
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <AK/CircularQueue.h>
|
#include <AK/CircularQueue.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
|
#include <Kernel/API/InodeWatcherEvent.h>
|
||||||
#include <Kernel/FileSystem/File.h>
|
#include <Kernel/FileSystem/File.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
|
|
||||||
|
@ -41,18 +42,6 @@ public:
|
||||||
static NonnullRefPtr<InodeWatcher> create(Inode&);
|
static NonnullRefPtr<InodeWatcher> create(Inode&);
|
||||||
virtual ~InodeWatcher() override;
|
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_read(const FileDescription&, size_t) const override;
|
||||||
virtual bool can_write(const FileDescription&, size_t) const override;
|
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||||
virtual KResultOr<size_t> read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override;
|
||||||
|
@ -60,7 +49,7 @@ public:
|
||||||
virtual String absolute_path(const FileDescription&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
virtual const char* class_name() const override { return "InodeWatcher"; };
|
virtual const char* class_name() const override { return "InodeWatcher"; };
|
||||||
|
|
||||||
void notify_inode_event(Badge<Inode>, Event::Type);
|
void notify_inode_event(Badge<Inode>, InodeWatcherEvent::Type);
|
||||||
void notify_child_added(Badge<Inode>, const InodeIdentifier& child_id);
|
void notify_child_added(Badge<Inode>, const InodeIdentifier& child_id);
|
||||||
void notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id);
|
void notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id);
|
||||||
|
|
||||||
|
@ -69,7 +58,7 @@ private:
|
||||||
|
|
||||||
Lock m_lock;
|
Lock m_lock;
|
||||||
WeakPtr<Inode> m_inode;
|
WeakPtr<Inode> m_inode;
|
||||||
CircularQueue<Event, 32> m_queue;
|
CircularQueue<InodeWatcherEvent, 32> m_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue