Serenity Operating System
at portability 87 lines 3.1 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include <AK/InlineLinkedList.h> 30#include <AK/RefCounted.h> 31#include <AK/RefPtr.h> 32#include <AK/String.h> 33#include <Kernel/Forward.h> 34#include <Kernel/Heap/SlabAllocator.h> 35 36namespace Kernel { 37 38// FIXME: Custody needs some locking. 39 40class Custody 41 : public RefCounted<Custody> 42 , public InlineLinkedListNode<Custody> { 43 44 MAKE_SLAB_ALLOCATED(Custody) 45 46public: 47 static Custody* get_if_cached(Custody* parent, const StringView& name); 48 static NonnullRefPtr<Custody> get_or_create(Custody* parent, const StringView& name, Inode&, int mount_flags); 49 static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags) 50 { 51 return adopt(*new Custody(parent, name, inode, mount_flags)); 52 } 53 54 ~Custody(); 55 56 Custody* parent() { return m_parent.ptr(); } 57 const Custody* parent() const { return m_parent.ptr(); } 58 Inode& inode() { return *m_inode; } 59 const Inode& inode() const { return *m_inode; } 60 const String& name() const { return m_name; } 61 String absolute_path() const; 62 63 bool is_deleted() const { return m_deleted; } 64 bool is_mounted_on() const { return m_mounted_on; } 65 66 int mount_flags() const { return m_mount_flags; } 67 68 void did_delete(Badge<VFS>); 69 void did_mount_on(Badge<VFS>); 70 void did_rename(Badge<VFS>, const String& name); 71 72 // For InlineLinkedListNode. 73 Custody* m_next { nullptr }; 74 Custody* m_prev { nullptr }; 75 76private: 77 Custody(Custody* parent, const StringView& name, Inode&, int mount_flags); 78 79 RefPtr<Custody> m_parent; 80 String m_name; 81 NonnullRefPtr<Inode> m_inode; 82 bool m_deleted { false }; 83 bool m_mounted_on { false }; 84 int m_mount_flags { 0 }; 85}; 86 87}