Serenity Operating System
at hosted 85 lines 3.4 kB view raw
1/* 2 * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@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/Types.h> 30#include <Kernel/FileSystem/FileSystem.h> 31#include <Kernel/FileSystem/Inode.h> 32 33namespace Kernel { 34 35class SlavePTY; 36class DevPtsFSInode; 37 38class DevPtsFS final : public FS { 39public: 40 virtual ~DevPtsFS() override; 41 static NonnullRefPtr<DevPtsFS> create(); 42 43 virtual bool initialize() override; 44 virtual const char* class_name() const override { return "DevPtsFS"; } 45 46 virtual InodeIdentifier root_inode() const override; 47 virtual KResultOr<NonnullRefPtr<Inode>> create_inode(InodeIdentifier parent_id, const String& name, mode_t, off_t size, dev_t, uid_t, gid_t) override; 48 virtual KResult create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t) override; 49 virtual RefPtr<Inode> get_inode(InodeIdentifier) const override; 50 51 static void register_slave_pty(SlavePTY&); 52 static void unregister_slave_pty(SlavePTY&); 53 54private: 55 DevPtsFS(); 56 57 RefPtr<DevPtsFSInode> m_root_inode; 58}; 59 60class DevPtsFSInode final : public Inode { 61 friend class DevPtsFS; 62 63public: 64 virtual ~DevPtsFSInode() override; 65 66private: 67 DevPtsFSInode(DevPtsFS&, unsigned index); 68 69 // ^Inode 70 virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const override; 71 virtual InodeMetadata metadata() const override; 72 virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override; 73 virtual RefPtr<Inode> lookup(StringView name) override; 74 virtual void flush_metadata() override; 75 virtual ssize_t write_bytes(off_t, ssize_t, const u8* buffer, FileDescription*) override; 76 virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override; 77 virtual KResult remove_child(const StringView& name) override; 78 virtual size_t directory_entry_count() const override; 79 virtual KResult chmod(mode_t) override; 80 virtual KResult chown(uid_t, gid_t) override; 81 82 InodeMetadata m_metadata; 83}; 84 85}