mod.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. use super::task::Thread;
  2. use crate::prelude::*;
  3. use alloc::sync::Arc;
  4. use bindings::{dev_t, S_IFBLK, S_IFCHR, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG};
  5. use dentry::Dentry;
  6. use eonix_sync::LazyLock;
  7. use inode::Mode;
  8. pub mod dentry;
  9. pub mod file;
  10. pub mod filearray;
  11. pub mod inode;
  12. pub mod mount;
  13. pub mod vfs;
  14. pub type DevId = dev_t;
  15. pub fn s_isreg(mode: Mode) -> bool {
  16. (mode & S_IFMT) == S_IFREG
  17. }
  18. pub fn s_isdir(mode: Mode) -> bool {
  19. (mode & S_IFMT) == S_IFDIR
  20. }
  21. pub fn s_ischr(mode: Mode) -> bool {
  22. (mode & S_IFMT) == S_IFCHR
  23. }
  24. pub fn s_isblk(mode: Mode) -> bool {
  25. (mode & S_IFMT) == S_IFBLK
  26. }
  27. pub fn s_islnk(mode: Mode) -> bool {
  28. (mode & S_IFMT) == S_IFLNK
  29. }
  30. #[derive(Clone, Copy, Default)]
  31. #[repr(C)]
  32. pub struct TimeSpec {
  33. pub sec: u64,
  34. pub nsec: u64,
  35. }
  36. #[derive(Clone)]
  37. pub struct FsContext {
  38. pub fsroot: Arc<Dentry>,
  39. pub cwd: Spin<Arc<Dentry>>,
  40. pub umask: Spin<Mode>,
  41. }
  42. static GLOBAL_FS_CONTEXT: LazyLock<Arc<FsContext>> = LazyLock::new(|| {
  43. Arc::new(FsContext {
  44. fsroot: Dentry::root().clone(),
  45. cwd: Spin::new(Dentry::root().clone()),
  46. umask: Spin::new(0o022),
  47. })
  48. });
  49. impl TimeSpec {
  50. pub const fn default() -> Self {
  51. Self { sec: 0, nsec: 0 }
  52. }
  53. }
  54. impl FsContext {
  55. pub fn get_current<'lt>() -> &'lt Arc<Self> {
  56. &Thread::current().borrow().fs_context
  57. }
  58. pub fn global() -> &'static Arc<Self> {
  59. &GLOBAL_FS_CONTEXT
  60. }
  61. pub fn new_cloned(other: &Self) -> Arc<Self> {
  62. Arc::new(Self {
  63. fsroot: other.fsroot.clone(),
  64. cwd: other.cwd.clone(),
  65. umask: other.umask.clone(),
  66. })
  67. }
  68. #[allow(dead_code)]
  69. pub fn new_shared(other: &Arc<Self>) -> Arc<Self> {
  70. other.clone()
  71. }
  72. }