From 29a6d24309bf9a6b2401b81dfd41ed16659d4408 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Thu, 22 Mar 2018 17:40:52 -0700 Subject: [PATCH 1/8] chmod and fchmod --- src/platform/src/linux/mod.rs | 16 ++++++++++++---- src/platform/src/redox/mod.rs | 28 ++++++++++++++++++++++------ src/stat/src/lib.rs | 4 ++-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index f26076e6c1..96db8eb18b 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -32,6 +32,10 @@ pub fn chdir(path: *const c_char) -> c_int { e(unsafe { syscall!(CHDIR, path) }) as c_int } +pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { + e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path, mode, 0) }) as c_int +} + pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path, owner as u32, group as u32) }) as c_int } @@ -55,14 +59,18 @@ pub fn exit(status: c_int) -> ! { loop {} } -pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { - e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int -} - pub fn fchdir(fildes: c_int) -> c_int { e(unsafe { syscall!(FCHDIR, fildes) }) as c_int } +pub fn fchmod(fildes: c_int, mode: mode_t) -> c_int { + e(unsafe { syscall!(FCHMOD, fildes, mode) }) as c_int +} + +pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { + e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int +} + pub fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { e(unsafe { syscall!(FCNTL, fildes, cmd, arg) }) as c_int } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index f125166fa9..87910d06cc 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -30,10 +30,22 @@ pub fn chdir(path: *const c_char) -> c_int { e(syscall::chdir(path)) as c_int } +pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { c_str(path) }; + let result = syscall::open(path, 0x0001); + match result { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => e(syscall::fchmod(fd as usize, mode)) as c_int, + } +} + pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { let path = unsafe { c_str(path) }; - let fd = syscall::open(path, 0x0001).unwrap(); - e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int + let result = syscall::open(path, 0x0001); + match result { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int, + } } pub fn close(fd: c_int) -> c_int { @@ -53,10 +65,6 @@ pub fn exit(status: c_int) -> ! { loop {} } -pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int { - e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int -} - pub fn fchdir(fd: c_int) -> c_int { let path: &mut [u8] = &mut [0; 4096]; if e(syscall::fpath(fd as usize, path)) == !0 { @@ -66,6 +74,14 @@ pub fn fchdir(fd: c_int) -> c_int { } } +pub fn fchmod(fd: c_int, mode: mode_t) -> c_int { + e(syscall::fchmod(fd as usize, mode)) as c_int +} + +pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int { + e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int +} + pub fn fcntl(fd: c_int, cmd: c_int, args: c_int) -> c_int { e(syscall::fcntl(fd as usize, cmd as usize, args as usize)) as c_int } diff --git a/src/stat/src/lib.rs b/src/stat/src/lib.rs index b8e2db5743..7e40fbbaa6 100644 --- a/src/stat/src/lib.rs +++ b/src/stat/src/lib.rs @@ -24,12 +24,12 @@ pub struct stat { #[no_mangle] pub extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int { - unimplemented!(); + platform::chmod(path, mode) } #[no_mangle] pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int { - unimplemented!(); + platform::fchmod(fildes, mode) } #[no_mangle] From 304473b68fbca36c6377a4e5b12edcd589577704 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Fri, 23 Mar 2018 13:27:41 -0700 Subject: [PATCH 2/8] Implement fstat, stat, lstat --- src/platform/src/lib.rs | 4 +++ src/platform/src/linux/mod.rs | 15 +++++++++++ src/platform/src/redox/mod.rs | 50 ++++++++++++++++++++++++++++++++--- src/platform/src/types.rs | 16 +++++++++++ src/stat/src/lib.rs | 6 ++--- 5 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 5f57298db7..63732fbf61 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -54,6 +54,10 @@ pub unsafe fn c_str_n(s: *const c_char, n: usize) -> &'static [u8] { slice::from_raw_parts(s as *const u8, size as usize) } +pub unsafe fn cstr_from_bytes_with_nul_unchecked(bytes: &[u8]) -> *const c_char { + &*(bytes as *const [u8] as *const c_char) +} + pub struct FileWriter(pub c_int); impl FileWriter { diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 96db8eb18b..01d4fa232b 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -4,7 +4,9 @@ use errno; use types::*; const AT_FDCWD: c_int = -100; +const AT_EMPTY_PATH: c_int = 0x1000; const AT_REMOVEDIR: c_int = 0x200; +const AT_SYMLINK_NOFOLLOW: c_int = 0x100; pub fn e(sys: usize) -> usize { if (sys as isize) < 0 && (sys as isize) >= -256 { @@ -71,6 +73,11 @@ pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int } +pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int { + let empty_cstr: *const c_char = unsafe { ::cstr_from_bytes_with_nul_unchecked(b"\0") }; + e(unsafe { syscall!(NEWFSTATAT, fildes, empty_cstr, buf, AT_EMPTY_PATH) }) as c_int +} + pub fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { e(unsafe { syscall!(FCNTL, fildes, cmd, arg) }) as c_int } @@ -127,6 +134,10 @@ pub fn link(path1: *const c_char, path2: *const c_char) -> c_int { e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int } +pub fn lstat(file: *const c_char, buf: *mut stat) -> c_int { + e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, AT_SYMLINK_NOFOLLOW) }) as c_int +} + pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int } @@ -163,6 +174,10 @@ pub fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int } +pub fn stat(file: *const c_char, buf: *mut stat) -> c_int { + e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int +} + pub fn unlink(path: *const c_char) -> c_int { e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 87910d06cc..ac09922c7e 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -4,6 +4,7 @@ use core::mem; use syscall; use syscall::flag::*; use syscall::data::TimeSpec as redox_timespec; +use syscall::data::Stat as redox_stat; use c_str; use errno; @@ -32,8 +33,7 @@ pub fn chdir(path: *const c_char) -> c_int { pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; - let result = syscall::open(path, 0x0001); - match result { + match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, Ok(fd) => e(syscall::fchmod(fd as usize, mode)) as c_int, } @@ -41,8 +41,7 @@ pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { let path = unsafe { c_str(path) }; - let result = syscall::open(path, 0x0001); - match result { + match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, Ok(fd) => e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int, } @@ -90,6 +89,33 @@ pub fn fork() -> pid_t { e(unsafe { syscall::clone(0) }) as pid_t } +pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int { + let mut redox_buf: redox_stat = redox_stat::default(); + match e(syscall::fstat(fildes as usize, &mut redox_buf)) { + 0 => { + unsafe { + if !buf.is_null() { + (*buf).st_dev = redox_buf.st_dev as dev_t; + (*buf).st_ino = redox_buf.st_ino as ino_t; + (*buf).st_nlink = redox_buf.st_nlink as nlink_t; + (*buf).st_mode = redox_buf.st_mode; + (*buf).st_uid = redox_buf.st_uid as uid_t; + (*buf).st_gid = redox_buf.st_gid as gid_t; + // TODO st_rdev + (*buf).st_rdev = 0; + (*buf).st_size = redox_buf.st_size as off_t; + (*buf).st_blksize = redox_buf.st_blksize as blksize_t; + (*buf).st_atim = redox_buf.st_atime as time_t; + (*buf).st_mtim = redox_buf.st_mtime as time_t; + (*buf).st_ctim = redox_buf.st_ctime as time_t; + } + } + 0 + }, + _ => -1, + } +} + pub fn fsync(fd: c_int) -> c_int { e(syscall::fsync(fd as usize)) as c_int } @@ -141,6 +167,14 @@ pub fn link(path1: *const c_char, path2: *const c_char) -> c_int { e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int } +pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_RDONLY | O_NOFOLLOW) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => fstat(fd as i32, buf), + } +} + pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; let path = unsafe { c_str(path) }; @@ -209,6 +243,14 @@ pub fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { e(syscall::setreuid(ruid as usize, euid as usize)) as c_int } +pub fn stat(path: *const c_char, buf: *mut stat) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_RDONLY) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => fstat(fd as i32, buf), + } +} + pub fn unlink(path: *const c_char) -> c_int { let path = unsafe { c_str(path) }; e(syscall::unlink(path)) as c_int diff --git a/src/platform/src/types.rs b/src/platform/src/types.rs index d6e19dbd58..f721d674e0 100644 --- a/src/platform/src/types.rs +++ b/src/platform/src/types.rs @@ -82,3 +82,19 @@ impl<'a> From<&'a timespec> for redox_timespec { } } } + +#[repr(C)] +pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_mode: mode_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_atim: time_t, + pub st_mtim: time_t, + pub st_ctim: time_t, +} diff --git a/src/stat/src/lib.rs b/src/stat/src/lib.rs index 7e40fbbaa6..6e4232cd54 100644 --- a/src/stat/src/lib.rs +++ b/src/stat/src/lib.rs @@ -34,12 +34,12 @@ pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int { #[no_mangle] pub extern "C" fn fstat(fildes: c_int, buf: *mut stat) -> c_int { - unimplemented!(); + platform::fstat(fildes, buf) } #[no_mangle] pub extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { - unimplemented!(); + platform::lstat(path, buf) } #[no_mangle] @@ -59,7 +59,7 @@ pub extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int #[no_mangle] pub extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { - unimplemented!(); + platform::stat(file, buf) } #[no_mangle] From 35dbc8d351bf72ac356fb6c39ec385460038fe97 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Fri, 23 Mar 2018 13:37:56 -0700 Subject: [PATCH 3/8] minor fixes --- src/platform/src/redox/mod.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index ac09922c7e..998d3d091f 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -35,7 +35,11 @@ pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, - Ok(fd) => e(syscall::fchmod(fd as usize, mode)) as c_int, + Ok(fd) => { + let res = syscall::fchmod(fd as usize, mode); + let _ = syscall::close(fd); + e(res) as c_int + } } } @@ -43,7 +47,11 @@ pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, - Ok(fd) => e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int, + Ok(fd) => { + let res = syscall::fchown(fd as usize, owner as u32, group as u32); + let _ = syscall::close(fd); + e(res) as c_int + } } } @@ -60,7 +68,7 @@ pub fn dup2(fd1: c_int, fd2: c_int) -> c_int { } pub fn exit(status: c_int) -> ! { - syscall::exit(status as usize); + let _ = syscall::exit(status as usize); loop {} } @@ -171,7 +179,11 @@ pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_RDONLY | O_NOFOLLOW) { Err(err) => e(Err(err)) as c_int, - Ok(fd) => fstat(fd as i32, buf), + Ok(fd) => { + let res = fstat(fd as i32, buf); + let _ = syscall::close(fd); + res + } } } @@ -180,7 +192,7 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, flags) { Ok(fd) => { - syscall::close(fd); + let _ = syscall::close(fd); 0 } Err(err) => e(Err(err)) as c_int, @@ -247,7 +259,11 @@ pub fn stat(path: *const c_char, buf: *mut stat) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_RDONLY) { Err(err) => e(Err(err)) as c_int, - Ok(fd) => fstat(fd as i32, buf), + Ok(fd) => { + let res = fstat(fd as i32, buf); + let _ = syscall::close(fd); + res + } } } From cafb76abdd29d4b6fa6686178312d350e5a60ecd Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Mon, 26 Mar 2018 15:47:36 -0700 Subject: [PATCH 4/8] mkfifo and constants --- src/platform/src/linux/mod.rs | 4 ++++ src/platform/src/redox/mod.rs | 13 ++++++++++++- src/stat/src/lib.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 01d4fa232b..7bf42be63d 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -142,6 +142,10 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int } +pub fn mkfifo(path: *const c_char mode: mode_t) -> c_int { + e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) +} + pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { e(unsafe { syscall!(NANOSLEEP, rqtp, rmtp) }) as c_int } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 998d3d091f..4155f62760 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -1,6 +1,5 @@ use core::ptr; use core::slice; -use core::mem; use syscall; use syscall::flag::*; use syscall::data::TimeSpec as redox_timespec; @@ -199,6 +198,18 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { } } +pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + let flags = O_CREAT | MODE_FIFO | mode as usize & 0o777; + let path = unsafe { c_str(path) }; + match syscall::open(path, flags) { + Ok(fd) => { + let _ = syscall::close(fd); + 0 + } + Err(err) => e(Err(err)) as c_int, + } +} + pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { let redox_rqtp = unsafe { redox_timespec::from(&*rqtp) }; let mut redox_rmtp: redox_timespec; diff --git a/src/stat/src/lib.rs b/src/stat/src/lib.rs index 6e4232cd54..d2c3d04663 100644 --- a/src/stat/src/lib.rs +++ b/src/stat/src/lib.rs @@ -6,6 +6,32 @@ extern crate platform; use platform::types::*; +pub const S_IFMT: c_int = 00170000; +pub const S_IFBLK: c_int = 0060000; +pub const S_IFCHR: c_int = 0020000; +pub const S_IFIFO: c_int = 0010000; +pub const S_IFREG: c_int = 0100000; +pub const S_IFDIR: c_int = 0040000; +pub const S_IFLNK: c_int = 0120000; + +pub const S_IRWXU: c_int = 00700; +pub const S_IRUSR: c_int = 00400; +pub const S_IWUSR: c_int = 00200; +pub const S_IXUSR: c_int = 00100; + +pub const S_IRWXG: c_int = 00070; +pub const S_IRGRP: c_int = 00040; +pub const S_IWGRP: c_int = 00020; +pub const S_IXGRP: c_int = 00010; + +pub const S_IRWXO: c_int = 00007; +pub const S_IROTH: c_int = 00004; +pub const S_IWOTH: c_int = 00002; +pub const S_IXOTH: c_int = 00001; +pub const S_ISUID: c_int = 04000; +pub const S_ISGID: c_int = 02000; +pub const S_ISVTX: c_int = 01000; + #[repr(C)] pub struct stat { pub st_dev: dev_t, @@ -49,7 +75,7 @@ pub extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int { #[no_mangle] pub extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - unimplemented!(); + platform::mkfifo(path, mode) } #[no_mangle] From c7e9ec8ae2593f50442403cf8b2c762dcf527378 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Mon, 26 Mar 2018 15:59:49 -0700 Subject: [PATCH 5/8] fix --- include/sys/types.h | 2 ++ src/platform/src/linux/mod.rs | 4 ++-- src/platform/src/types.rs | 2 ++ src/stat/src/lib.rs | 21 +++++++++++---------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/sys/types.h b/include/sys/types.h index 3efc6300b3..3a466d2b2a 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -35,6 +35,8 @@ typedef int clockid_t; typedef void* timer_t; +typedef unsigned long int blkcnt_t; + #ifdef __linux__ #define _SC_PAGE_SIZE 30 #endif diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index bf9a6169b3..86a883bc0a 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -154,8 +154,8 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int } -pub fn mkfifo(path: *const c_char mode: mode_t) -> c_int { - e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) +pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) as c_int } pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { diff --git a/src/platform/src/types.rs b/src/platform/src/types.rs index 1993edbe18..29ed354d1b 100644 --- a/src/platform/src/types.rs +++ b/src/platform/src/types.rs @@ -59,6 +59,7 @@ pub type dev_t = usize; pub type ino_t = usize; pub type nlink_t = usize; pub type blksize_t = isize; +pub type blkcnt_t = u64; pub type useconds_t = i32; pub type suseconds_t = i64; @@ -98,4 +99,5 @@ pub struct stat { pub st_atim: time_t, pub st_mtim: time_t, pub st_ctim: time_t, + pub st_blocks: blkcnt_t, } diff --git a/src/stat/src/lib.rs b/src/stat/src/lib.rs index d2c3d04663..5b4a389d7d 100644 --- a/src/stat/src/lib.rs +++ b/src/stat/src/lib.rs @@ -6,13 +6,13 @@ extern crate platform; use platform::types::*; -pub const S_IFMT: c_int = 00170000; -pub const S_IFBLK: c_int = 0060000; -pub const S_IFCHR: c_int = 0020000; -pub const S_IFIFO: c_int = 0010000; -pub const S_IFREG: c_int = 0100000; -pub const S_IFDIR: c_int = 0040000; -pub const S_IFLNK: c_int = 0120000; +pub const S_IFMT: c_int = 00170000; +pub const S_IFBLK: c_int = 0060000; +pub const S_IFCHR: c_int = 0020000; +pub const S_IFIFO: c_int = 0010000; +pub const S_IFREG: c_int = 0100000; +pub const S_IFDIR: c_int = 0040000; +pub const S_IFLNK: c_int = 0120000; pub const S_IRWXU: c_int = 00700; pub const S_IRUSR: c_int = 00400; @@ -46,6 +46,7 @@ pub struct stat { pub st_atim: time_t, pub st_mtim: time_t, pub st_ctim: time_t, + pub st_blocks: blkcnt_t, } #[no_mangle] @@ -59,12 +60,12 @@ pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int { } #[no_mangle] -pub extern "C" fn fstat(fildes: c_int, buf: *mut stat) -> c_int { +pub extern "C" fn fstat(fildes: c_int, buf: *mut platform::types::stat) -> c_int { platform::fstat(fildes, buf) } #[no_mangle] -pub extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { +pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> c_int { platform::lstat(path, buf) } @@ -84,7 +85,7 @@ pub extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int } #[no_mangle] -pub extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { +pub extern "C" fn stat(file: *const c_char, buf: *mut platform::types::stat) -> c_int { platform::stat(file, buf) } From 14957bb8dccf45f74f3d22a8394495c39937cdaf Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Mon, 26 Mar 2018 21:14:38 -0700 Subject: [PATCH 6/8] fix harder --- src/platform/src/redox/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 03c4b5cf5f..437a957823 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -200,6 +200,7 @@ pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int { res } } +} pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; From bc0763f3ef8cffb860d2943b080d57d534ebb30d Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Mon, 26 Mar 2018 21:17:14 -0700 Subject: [PATCH 7/8] fmt --- src/platform/src/redox/mod.rs | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 437a957823..9b1ec593c5 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -47,9 +47,9 @@ pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, Ok(fd) => { - let res = syscall::fchown(fd as usize, owner as u32, group as u32); - let _ = syscall::close(fd); - e(res) as c_int + let res = syscall::fchown(fd as usize, owner as u32, group as u32); + let _ = syscall::close(fd); + e(res) as c_int } } } @@ -97,28 +97,28 @@ pub fn fork() -> pid_t { } pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int { - let mut redox_buf: redox_stat = redox_stat::default(); + let mut redox_buf: redox_stat = redox_stat::default(); match e(syscall::fstat(fildes as usize, &mut redox_buf)) { - 0 => { - unsafe { - if !buf.is_null() { - (*buf).st_dev = redox_buf.st_dev as dev_t; - (*buf).st_ino = redox_buf.st_ino as ino_t; - (*buf).st_nlink = redox_buf.st_nlink as nlink_t; - (*buf).st_mode = redox_buf.st_mode; - (*buf).st_uid = redox_buf.st_uid as uid_t; - (*buf).st_gid = redox_buf.st_gid as gid_t; - // TODO st_rdev - (*buf).st_rdev = 0; - (*buf).st_size = redox_buf.st_size as off_t; - (*buf).st_blksize = redox_buf.st_blksize as blksize_t; - (*buf).st_atim = redox_buf.st_atime as time_t; - (*buf).st_mtim = redox_buf.st_mtime as time_t; - (*buf).st_ctim = redox_buf.st_ctime as time_t; - } + 0 => { + unsafe { + if !buf.is_null() { + (*buf).st_dev = redox_buf.st_dev as dev_t; + (*buf).st_ino = redox_buf.st_ino as ino_t; + (*buf).st_nlink = redox_buf.st_nlink as nlink_t; + (*buf).st_mode = redox_buf.st_mode; + (*buf).st_uid = redox_buf.st_uid as uid_t; + (*buf).st_gid = redox_buf.st_gid as gid_t; + // TODO st_rdev + (*buf).st_rdev = 0; + (*buf).st_size = redox_buf.st_size as off_t; + (*buf).st_blksize = redox_buf.st_blksize as blksize_t; + (*buf).st_atim = redox_buf.st_atime as time_t; + (*buf).st_mtim = redox_buf.st_mtime as time_t; + (*buf).st_ctim = redox_buf.st_ctime as time_t; } - 0 - }, + } + 0 + } _ => -1, } } From 92493a55b939cec806830be9458ad1f600cf0ce7 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Mon, 26 Mar 2018 21:23:36 -0700 Subject: [PATCH 8/8] fix harderer --- src/platform/src/redox/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 9b1ec593c5..5ab3e49155 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -215,7 +215,7 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { } pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - let flags = O_CREAT | MODE_FIFO | mode as usize & 0o777; + let flags = O_CREAT | MODE_FIFO as usize | mode as usize & 0o777; let path = unsafe { c_str(path) }; match syscall::open(path, flags) { Ok(fd) => {