Skip to content

Commit

Permalink
add fstatat syscall
Browse files Browse the repository at this point in the history
Add tzdb installation
  • Loading branch information
rafalmiel committed Oct 19, 2023
1 parent 77098dd commit 57cdeba
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions cykusz-rs/src/kernel/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn syscall_handler(num: u64, a: u64, b: u64, c: u64, d: u64, e: u64, f: u64)
SYS_TICKSNS => sys::sys_ticksns(),
SYS_GETPPID => sys::sys_getppid(),
SYS_GETPGID => sys::sys_getpgid(a),
SYS_FSTATAT => sys::sys_fstatat(a, b, c, d),
a => {
logln!("NO SYS????? {}", a);
Err(SyscallError::ENOSYS)
Expand Down
31 changes: 30 additions & 1 deletion cykusz-rs/src/kernel/syscall/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use syscall_defs::{OpenFlags, SyscallError};
use crate::kernel::fs::dirent::DirEntry;
use crate::kernel::fs::path::Path;
use crate::kernel::fs::poll::PollTable;
use crate::kernel::fs::{lookup_by_path, lookup_by_real_path, LookupMode};
use crate::kernel::fs::{lookup_by_path, lookup_by_path_at, lookup_by_real_path, LookupMode};
use crate::kernel::mm::VirtAddr;
use crate::kernel::net::ip::Ip4;
use crate::kernel::sched::{current_task, current_task_ref, SleepFlags};
Expand Down Expand Up @@ -1117,6 +1117,35 @@ pub fn sys_fstat(fd: u64, stat: u64) -> SyscallResult {
Ok(0)
}

pub fn sys_fstatat(fd: u64, path: u64, path_len: u64, stat: u64) -> SyscallResult {
let fd = OpenFD::try_from(fd)?;
let path = Path::new(make_str(path, path_len));

let task = current_task_ref();

let dirent = match fd {
OpenFD::Fd(fd) => {
task.get_handle(fd).ok_or(SyscallError::EBADFD)?.inode.clone()
}
OpenFD::Cwd => {
task.get_dent().ok_or(SyscallError::EBADFD)?.clone()
}
OpenFD::None => {
return Err(SyscallError::EINVAL);
}
};

let stat = unsafe { VirtAddr(stat as usize).read_mut::<syscall_defs::stat::Stat>() };

let file = lookup_by_path_at(dirent, path, LookupMode::None)?;

*stat = file.inode().stat()?;

logln!("fstatat {:?}, {:?}", fd, stat);

Ok(0)
}

pub fn sys_getrlimit(resource: u64, rlimit: u64) -> SyscallResult {
let resource = syscall_defs::resource::RLimitKind::try_from(resource)?;

Expand Down
1 change: 1 addition & 0 deletions disk_scripts/install_os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ for prog in $PROGS; do
done

cp -r sysroot/cykusz/usr mnt/
cp -r sysroot/cykusz/etc mnt/

#cp -r sysroot/cross/x86_64-cykusz/lib/* mnt/usr/lib/
#cp sysroot/test.c mnt/
Expand Down
5 changes: 5 additions & 0 deletions syscall-defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub const SYS_TICKSNS: usize = 58;

pub const SYS_GETPPID: usize = 59;
pub const SYS_GETPGID: usize = 60;
pub const SYS_FSTATAT: usize = 61;

#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(u64)]
Expand Down Expand Up @@ -184,9 +185,11 @@ pub enum SyscallError {
UnknownError = 0xffff,
}

#[derive(Debug)]
pub enum OpenFD {
Fd(usize),
Cwd,
None,
}

impl TryFrom<u64> for OpenFD {
Expand All @@ -197,6 +200,7 @@ impl TryFrom<u64> for OpenFD {

match v {
-100 => Ok(OpenFD::Cwd),
-1 => Ok(OpenFD::None),
a if a >= 0 && a < 256 => Ok(OpenFD::Fd(a as usize)),
_ => Err(SyscallError::EINVAL),
}
Expand All @@ -208,6 +212,7 @@ impl From<OpenFD> for usize {
match v {
OpenFD::Fd(a) => a,
OpenFD::Cwd => (-100isize) as usize,
OpenFD::None => (-1isize) as usize,
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions sysroot/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MPFR_SRC_DIR=$SRC_DIR/mpfr
MPC_SRC_DIR=$SRC_DIR/mpc
DOOM_SRC_DIR=$SRC_DIR/doomgeneric
COREUTILS_SRC_DIR=$SRC_DIR/coreutils
TZDB_SRC_DIR=$SRC_DIR/tzdb

BUILD_DIR=$CYKUSZ_DIR/sysroot/build
BINUTILS_BUILD_DIR=$BUILD_DIR/binutils-gdb
Expand All @@ -31,6 +32,7 @@ MLIBC_BUILD_DIR=$BUILD_DIR/mlibc
GMP_BUILD_DIR=$BUILD_DIR/gmp
MPFR_BUILD_DIR=$BUILD_DIR/mpfr
MPC_BUILD_DIR=$BUILD_DIR/mpc
TZDB_BUILD_DIR=$BUILD_DIR/tzdb

SYSROOT=$CYKUSZ_DIR/sysroot/cykusz
CROSS=$CYKUSZ_DIR/sysroot/cross
Expand Down Expand Up @@ -110,6 +112,13 @@ function _prepare_coreutils {
fi
}

function _prepare_tzdb {
if [ ! -d $TZDB_SRC_DIR ]; then
mkdir -p $SRC_DIR
git clone --depth 1 -b cykusz https://github.com/rafalmiel/tzdb.git $TZDB_SRC_DIR
fi
}

function _prepare_nano {
if [ ! -d $NANO_SRC_DIR ]; then
mkdir -p $SRC_DIR
Expand Down Expand Up @@ -212,6 +221,18 @@ function _libstd {
make -C $GCC_BUILD_DIR install-target-libstdc++-v3
}

function _tzdb {
_prepare_tzdb

make -C $TZDB_SRC_DIR
make -C $TZDB_SRC_DIR DESTDIR=$SYSROOT install

pushd .
cd $SYSROOT/etc
ln -sf ../usr/share/zoneinfo/Europe/London localtime
popd
}

function _cykusz_binutils {
_prepare_binutils

Expand Down
3 changes: 3 additions & 0 deletions sysroot/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ $SPATH/build.sh gcc > $LOGDIR/gcc.log 2>&1
echo "Building mlibc..."
$SPATH/build.sh mlibc > $LOGDIR/mlibc.log 2>&1

echo "Building tzdb..."
$SPATH/build.sh tzdb > $LOGDIR/tzdb.log 2>&1

echo "Building libgcc..."
$SPATH/build.sh libgcc > $LOGDIR/libgcc.log 2>&1

Expand Down

0 comments on commit 57cdeba

Please sign in to comment.