File.cpp 998 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringView.h>
  7. #include <Kernel/FileSystem/File.h>
  8. #include <Kernel/FileSystem/FileDescription.h>
  9. #include <Kernel/Process.h>
  10. namespace Kernel {
  11. File::File()
  12. {
  13. }
  14. File::~File()
  15. {
  16. }
  17. KResultOr<NonnullRefPtr<FileDescription>> File::open(int options)
  18. {
  19. auto description = FileDescription::create(*this);
  20. if (!description.is_error()) {
  21. description.value()->set_rw_mode(options);
  22. description.value()->set_file_flags(options);
  23. }
  24. return description;
  25. }
  26. KResult File::close()
  27. {
  28. return KSuccess;
  29. }
  30. int File::ioctl(FileDescription&, unsigned, FlatPtr)
  31. {
  32. return -ENOTTY;
  33. }
  34. KResultOr<Region*> File::mmap(Process&, FileDescription&, const Range&, u64, int, bool)
  35. {
  36. return ENODEV;
  37. }
  38. KResult File::attach(FileDescription&)
  39. {
  40. m_attach_count++;
  41. return KSuccess;
  42. }
  43. void File::detach(FileDescription&)
  44. {
  45. m_attach_count--;
  46. }
  47. }