SelfTTYDevice.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Devices/DeviceManagement.h>
  7. #include <Kernel/Devices/SelfTTYDevice.h>
  8. #include <Kernel/Sections.h>
  9. #include <Kernel/TTY/TTY.h>
  10. namespace Kernel {
  11. UNMAP_AFTER_INIT NonnullRefPtr<SelfTTYDevice> SelfTTYDevice::must_create()
  12. {
  13. auto self_tty_device_or_error = DeviceManagement::try_create_device<SelfTTYDevice>();
  14. // FIXME: Find a way to propagate errors
  15. VERIFY(!self_tty_device_or_error.is_error());
  16. return self_tty_device_or_error.release_value();
  17. }
  18. ErrorOr<NonnullRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
  19. {
  20. // Note: If for some odd reason we try to open this device (early on boot?)
  21. // while there's no current Process assigned, don't fail and return an error.
  22. if (!Process::has_current())
  23. return Error::from_errno(ESRCH);
  24. auto& current_process = Process::current();
  25. RefPtr<TTY> tty = current_process.tty();
  26. if (!tty)
  27. return Error::from_errno(ENXIO);
  28. auto description = TRY(OpenFileDescription::try_create(*tty));
  29. description->set_rw_mode(options);
  30. description->set_file_flags(options);
  31. return description;
  32. }
  33. bool SelfTTYDevice::can_read(OpenFileDescription const&, u64) const
  34. {
  35. VERIFY_NOT_REACHED();
  36. }
  37. bool SelfTTYDevice::can_write(OpenFileDescription const&, u64) const
  38. {
  39. VERIFY_NOT_REACHED();
  40. }
  41. ErrorOr<size_t> SelfTTYDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t)
  42. {
  43. VERIFY_NOT_REACHED();
  44. }
  45. ErrorOr<size_t> SelfTTYDevice::write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t)
  46. {
  47. VERIFY_NOT_REACHED();
  48. }
  49. UNMAP_AFTER_INIT SelfTTYDevice::SelfTTYDevice()
  50. : CharacterDevice(5, 0)
  51. {
  52. }
  53. UNMAP_AFTER_INIT SelfTTYDevice::~SelfTTYDevice()
  54. {
  55. }
  56. }