dentry.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <list>
  3. #include <string>
  4. #include <types/hash.hpp>
  5. #include <types/path.hpp>
  6. #include <kernel/async/lock.hpp>
  7. #include <kernel/vfs/inode.hpp>
  8. namespace fs {
  9. static constexpr unsigned long D_PRESENT = 1 << 0;
  10. static constexpr unsigned long D_DIRECTORY = 1 << 1;
  11. static constexpr unsigned long D_LOADED = 1 << 2;
  12. static constexpr unsigned long D_MOUNTPOINT = 1 << 3;
  13. struct dentry {
  14. struct dcache* cache;
  15. vfs* fs;
  16. struct inode* inode;
  17. struct dentry* parent;
  18. // list head
  19. struct dentry* prev;
  20. struct dentry* next;
  21. unsigned long flags;
  22. types::hash_t hash;
  23. // TODO: use atomic
  24. std::size_t refcount;
  25. std::string name;
  26. };
  27. struct dcache {
  28. struct dentry** arr;
  29. int hash_bits;
  30. std::size_t size;
  31. };
  32. std::pair<struct dentry*, int> d_find(struct dentry* parent, types::string_view name);
  33. std::string d_path(const struct dentry* dentry, const struct dentry* root);
  34. struct dentry* d_get(struct dentry* dentry);
  35. struct dentry* d_put(struct dentry* dentry);
  36. void dcache_init(struct dcache* cache, int hash_bits);
  37. void dcache_drop(struct dcache* cache);
  38. struct dentry* dcache_alloc(struct dcache* cache);
  39. void dcache_init_root(struct dcache* cache, struct dentry* root);
  40. } // namespace fs