mod.rs 1.5 KB

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