dentry.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include <string>
  3. #include <bits/alltypes.h>
  4. #include <types/hash.hpp>
  5. #include <types/path.hpp>
  6. #include <kernel/async/lock.hpp>
  7. namespace fs {
  8. static constexpr unsigned long D_PRESENT = 1 << 0;
  9. static constexpr unsigned long D_DIRECTORY = 1 << 1;
  10. static constexpr unsigned long D_LOADED = 1 << 2;
  11. static constexpr unsigned long D_MOUNTPOINT = 1 << 3;
  12. static constexpr unsigned long D_SYMLINK = 1 << 4;
  13. struct rust_vfs_handle {
  14. void* data[2];
  15. };
  16. struct rust_inode_handle {
  17. void* data[2];
  18. };
  19. struct inode_data {
  20. uint64_t ino;
  21. uint64_t size;
  22. uint64_t nlink;
  23. struct timespec atime;
  24. struct timespec mtime;
  25. struct timespec ctime;
  26. uint32_t uid;
  27. uint32_t gid;
  28. uint32_t mode;
  29. };
  30. struct dentry {
  31. struct rust_vfs_handle fs;
  32. struct rust_inode_handle inode;
  33. struct dcache* cache;
  34. struct dentry* parent;
  35. // list head
  36. struct dentry* prev;
  37. struct dentry* next;
  38. unsigned long flags;
  39. types::hash_t hash;
  40. // TODO: use atomic
  41. std::size_t refcount;
  42. std::string name;
  43. };
  44. struct dentry_deleter {
  45. void operator()(struct dentry* dentry) const;
  46. };
  47. using dentry_pointer = std::unique_ptr<struct dentry, dentry_deleter>;
  48. struct dcache {
  49. struct dentry** arr;
  50. int hash_bits;
  51. std::size_t size;
  52. };
  53. std::pair<struct dentry*, int> d_find(struct dentry* parent,
  54. types::string_view name);
  55. std::string d_path(const struct dentry* dentry, const struct dentry* root);
  56. dentry_pointer d_get(const dentry_pointer& dp);
  57. struct dentry* d_get(struct dentry* dentry);
  58. struct dentry* d_put(struct dentry* dentry);
  59. void dcache_init(struct dcache* cache, int hash_bits);
  60. void dcache_drop(struct dcache* cache);
  61. struct dentry* dcache_alloc(struct dcache* cache);
  62. void dcache_init_root(struct dcache* cache, struct dentry* root);
  63. } // namespace fs
  64. struct rust_get_cxx_string_result {
  65. const char* data;
  66. size_t len;
  67. };
  68. void rust_get_cxx_string(const std::string* str,
  69. rust_get_cxx_string_result* out_result);
  70. void rust_operator_eql_cxx_string(const std::string* str, std::string* dst);