DevPtsFS.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #pragma once
  27. #include <AK/Types.h>
  28. #include <Kernel/FileSystem/FileSystem.h>
  29. #include <Kernel/FileSystem/Inode.h>
  30. namespace Kernel {
  31. class SlavePTY;
  32. class DevPtsFSInode;
  33. class DevPtsFS final : public FS {
  34. friend class DevPtsFSInode;
  35. public:
  36. virtual ~DevPtsFS() override;
  37. static NonnullRefPtr<DevPtsFS> create();
  38. virtual bool initialize() override;
  39. virtual const char* class_name() const override { return "DevPtsFS"; }
  40. virtual NonnullRefPtr<Inode> root_inode() const override;
  41. static void register_slave_pty(SlavePTY&);
  42. static void unregister_slave_pty(SlavePTY&);
  43. private:
  44. DevPtsFS();
  45. RefPtr<Inode> get_inode(InodeIdentifier) const;
  46. RefPtr<DevPtsFSInode> m_root_inode;
  47. };
  48. class DevPtsFSInode final : public Inode {
  49. friend class DevPtsFS;
  50. public:
  51. virtual ~DevPtsFSInode() override;
  52. private:
  53. DevPtsFSInode(DevPtsFS&, unsigned index, SlavePTY*);
  54. // ^Inode
  55. virtual ssize_t read_bytes(off_t, ssize_t, UserOrKernelBuffer& buffer, FileDescription*) const override;
  56. virtual InodeMetadata metadata() const override;
  57. virtual KResult traverse_as_directory(Function<bool(const FS::DirectoryEntryView&)>) const override;
  58. virtual RefPtr<Inode> lookup(StringView name) override;
  59. virtual void flush_metadata() override;
  60. virtual ssize_t write_bytes(off_t, ssize_t, const UserOrKernelBuffer& buffer, FileDescription*) override;
  61. virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
  62. virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
  63. virtual KResult remove_child(const StringView& name) override;
  64. virtual KResultOr<size_t> directory_entry_count() const override;
  65. virtual KResult chmod(mode_t) override;
  66. virtual KResult chown(uid_t, gid_t) override;
  67. WeakPtr<SlavePTY> m_pty;
  68. InodeMetadata m_metadata;
  69. };
  70. }