unistd: add umask()
This commit is contained in:
parent
4a4e4d8d13
commit
bfad8bb567
@ -140,6 +140,9 @@ unsafe extern "C" fn fcntl(fd: c_int, cmd: c_int, args: ...) -> CIntCountResult
|
||||
let file = RawFile::e_try_from(fd)?;
|
||||
|
||||
match cmd {
|
||||
// TODO implement these somehow?
|
||||
F_GETFD => CIntCountResult(0),
|
||||
F_SETFD => CIntCountResult(0),
|
||||
_ => todo!("fcntl({}, {}, ...)", fd, cmd),
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use yggdrasil_rt::io::{FileAttr, FileMode, FileType, RawFd};
|
||||
|
||||
use crate::{
|
||||
error::{CIntZeroResult, TryFromExt},
|
||||
io,
|
||||
io, process,
|
||||
util::{self, Nullable},
|
||||
};
|
||||
|
||||
@ -74,8 +74,8 @@ impl From<FileAttr> for stat {
|
||||
}
|
||||
st.st_size = value.size.try_into().unwrap();
|
||||
// TODO
|
||||
st.st_uid = 0;
|
||||
st.st_gid = 0;
|
||||
st.st_uid = u32::from(value.uid).try_into().unwrap();
|
||||
st.st_gid = u32::from(value.gid).try_into().unwrap();
|
||||
// TODO
|
||||
st.st_blksize = 512;
|
||||
st.st_blocks = (st.st_size + 511) / 512;
|
||||
@ -108,7 +108,9 @@ unsafe extern "C" fn fchmodat(
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn umask(mode: mode_t) -> mode_t {
|
||||
todo!()
|
||||
let new = FileMode::new((mode as u32) & 0o777);
|
||||
let old = process::update_umask(new);
|
||||
old.bits() as mode_t
|
||||
}
|
||||
|
||||
// Create stuff
|
||||
|
@ -150,6 +150,7 @@ impl<W: Write> Write for BufWriter<W> {
|
||||
fn write(&mut self, mut data: &[u8]) -> EResult<usize> {
|
||||
if data.len() + self.buffer.len() >= self.buffer.capacity() {
|
||||
self.flush()?;
|
||||
assert_eq!(self.buffer.len(), 0);
|
||||
}
|
||||
|
||||
let len = data.len();
|
||||
@ -167,7 +168,7 @@ impl<W: Write> Write for BufWriter<W> {
|
||||
}
|
||||
|
||||
// Store the data in the buffer
|
||||
assert!(data.len() < self.buffer.capacity());
|
||||
assert!(data.len() <= self.buffer.capacity());
|
||||
self.buffer.extend_from_slice(data);
|
||||
EResult::Ok(len)
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ use core::{ffi::c_char, ptr::null_mut, slice::memchr};
|
||||
|
||||
use alloc::{ffi::CString, vec::Vec};
|
||||
use yggdrasil_rt::{
|
||||
process::{ExitCode, ProgramArgumentInner, Signal},
|
||||
io::FileMode,
|
||||
process::{ExitCode, ProcessInfoElement, ProgramArgumentInner, Signal},
|
||||
sys as syscall,
|
||||
};
|
||||
|
||||
@ -81,6 +82,32 @@ pub fn abort() -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_process_info(info: &mut ProcessInfoElement) -> EResult<()> {
|
||||
unsafe {
|
||||
syscall::get_process_info(info)?;
|
||||
}
|
||||
EResult::Ok(())
|
||||
}
|
||||
|
||||
pub fn set_process_info(info: &ProcessInfoElement) -> EResult<()> {
|
||||
unsafe {
|
||||
syscall::set_process_info(info)?;
|
||||
}
|
||||
EResult::Ok(())
|
||||
}
|
||||
|
||||
pub fn update_umask(new: FileMode) -> FileMode {
|
||||
let mut old = ProcessInfoElement::Umask(FileMode::empty());
|
||||
let new = ProcessInfoElement::Umask(new);
|
||||
|
||||
get_process_info(&mut old).unwrap();
|
||||
set_process_info(&new).unwrap();
|
||||
|
||||
let ProcessInfoElement::Umask(old) = old;
|
||||
|
||||
old
|
||||
}
|
||||
|
||||
// Env
|
||||
|
||||
static mut ENVS: Vec<CString> = Vec::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user