use alloc::sync::Arc;
use core::sync::atomic::{AtomicU64, Ordering};
use crate::sync::IrqMutex;
pub static ROOT_USER_NS: ax_lazyinit::LazyLock<Arc<IrqMutex<UserNamespace>>> =
ax_lazyinit::LazyLock::new(|| Arc::new(IrqMutex::new(UserNamespace::new_root())));
static NEXT_USER_NS_ID: AtomicU64 = AtomicU64::new(1);
pub struct UserNamespace {
pub id: u64,
pub owner_uid: u32,
pub is_root: bool,
pub uid_mapped: bool,
pub gid_mapped: bool,
}
impl UserNamespace {
pub fn new_root() -> Self {
Self {
id: NEXT_USER_NS_ID.fetch_add(1, Ordering::Relaxed),
owner_uid: 0,
is_root: true,
uid_mapped: true,
gid_mapped: true,
}
}
pub fn clone_ns(&self) -> Self {
Self {
id: NEXT_USER_NS_ID.fetch_add(1, Ordering::Relaxed),
owner_uid: self.owner_uid,
is_root: false,
uid_mapped: false,
gid_mapped: false,
}
}
}