summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2014-08-15 00:16:06 -0700
committerCarl Lerche <me@carllerche.com>2014-08-15 00:16:06 -0700
commit4e7c65d3a1cf5c8999da9dcc3f55d1ba38b8c816 (patch)
treef3d2d426a07932a2b1824215c6a008f62130ba8b
parent05134909671ba8dc306f559fd9f9fac29d517b1b (diff)
downloadnix-4e7c65d3a1cf5c8999da9dcc3f55d1ba38b8c816.zip
Add mknod, mkdev, and umask APIs
-rw-r--r--src/lib.rs1
-rw-r--r--src/mount.rs6
-rw-r--r--src/sys.rs51
3 files changed, 56 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 259f92e4..2d2fe600 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,5 +9,6 @@ pub mod errno;
pub mod fcntl;
pub mod mount;
pub mod sched;
+pub mod sys;
pub mod syscall;
pub mod unistd;
diff --git a/src/mount.rs b/src/mount.rs
index 5b083b86..cae6d239 100644
--- a/src/mount.rs
+++ b/src/mount.rs
@@ -71,12 +71,14 @@ mod ffi {
pub fn mount(
source: Option<&Path>,
target: &Path,
- fstype: Option<&CString>,
+ fstype: Option<&str>,
flags: MsFlags,
- data: Option<&CString>) -> SysResult<()> {
+ data: Option<&str>) -> SysResult<()> {
let source = source.map(|s| s.to_c_str());
let target = target.to_c_str();
+ let fstype = fstype.map(|s| s.to_c_str());
+ let data = data.map(|s| s.to_c_str());
let res = unsafe {
ffi::mount(
diff --git a/src/sys.rs b/src/sys.rs
new file mode 100644
index 00000000..1aa19534
--- /dev/null
+++ b/src/sys.rs
@@ -0,0 +1,51 @@
+pub mod stat {
+ pub use libc::dev_t;
+
+ use std::fmt;
+ use std::io::FilePermission;
+ use std::path::Path;
+ use libc::mode_t;
+ use errno::{SysResult, from_ffi};
+
+ mod ffi {
+ use libc::{c_char, c_int, mode_t, dev_t};
+
+ extern {
+ pub fn mknod(pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int;
+ pub fn umask(mask: mode_t) -> mode_t;
+ }
+ }
+
+ bitflags!(
+ flags SFlag: mode_t {
+ static S_IFREG = 0o100000,
+ static S_IFCHR = 0o020000,
+ static S_IFBLK = 0o060000,
+ static S_IFIFO = 0o010000,
+ static S_IFSOCK = 0o140000
+ }
+ )
+
+ impl fmt::Show for SFlag {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ write!(fmt, "SFlag {{ bits: {} }}", self.bits())
+ }
+ }
+
+ pub fn mknod(path: &Path, kind: SFlag, perm: FilePermission, dev: dev_t) -> SysResult<()> {
+ let res = unsafe { ffi::mknod(path.to_c_str().as_ptr(), kind.bits | perm.bits(), dev) };
+ from_ffi(res)
+ }
+
+ static MINORBITS: uint = 20;
+ static MINORMASK: dev_t = ((1 << MINORBITS) - 1);
+
+ pub fn mkdev(major: u64, minor: u64) -> dev_t {
+ (major << MINORBITS) | minor
+ }
+
+ pub fn umask(mode: FilePermission) -> FilePermission {
+ let prev = unsafe { ffi::umask(mode.bits()) };
+ FilePermission::from_bits(prev).expect("[BUG] umask returned invalid FilePermission")
+ }
+}