Skip to content

Commit

Permalink
Merges fcntl module into fd module
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Nov 3, 2024
1 parent 1f75719 commit a786000
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion kernel-1100/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use self::thread::Thread;
use self::ucred::Ucred;
use self::uio::Uio;
use core::ffi::{c_char, c_int};
use okf::fcntl::OpenFlags;
use okf::fd::OpenFlags;
use okf::malloc::MallocFlags;
use okf::queue::TailQueue;
use okf::socket::SockAddr;
Expand Down
23 changes: 0 additions & 23 deletions src/fcntl/mod.rs

This file was deleted.

23 changes: 22 additions & 1 deletion src/fd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::errno::Errno;
use crate::fcntl::OpenFlags;
use crate::pcpu::Pcpu;
use crate::thread::Thread;
use crate::uio::{IoVec, Uio, UioRw, UioSeg};
use crate::Kernel;
use bitflags::bitflags;
use core::ffi::{c_char, c_int};
use core::marker::PhantomData;

pub const AT_FDCWD: c_int = -100;

/// # Safety
/// `path` cannot be null and must point to a null-terminated string if `seg` is [`UioSeg::Kernel`].
pub unsafe fn openat<K: Kernel>(
Expand Down Expand Up @@ -57,6 +59,25 @@ pub unsafe fn write<K: Kernel>(
}
}

bitflags! {
/// Flags for `open` and related functions.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OpenFlags: c_int {
const O_RDONLY = 0x00000000;
const O_WRONLY = 0x00000001;
const O_RDWR = 0x00000002;
const O_ACCMODE = Self::O_WRONLY.bits() | Self::O_RDWR.bits();
const O_SHLOCK = 0x00000010;
const O_EXLOCK = 0x00000020;
const O_CREAT = 0x00000200;
const O_TRUNC = 0x00000400;
const O_EXCL = 0x00000800;
const O_EXEC = 0x00040000;
const O_CLOEXEC = 0x00100000;
}
}

/// RAII struct to call [`Kernel::kern_close()`] when dropped.
pub struct OwnedFd<K: Kernel> {
kern: K,
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

use self::fcntl::OpenFlags;
use self::fd::OpenFlags;
use self::file::File;
use self::lock::{LockObject, Mtx};
use self::malloc::{Malloc, MallocFlags};
Expand All @@ -17,7 +17,6 @@ use core::ops::Deref;
pub use okf_macros::*;

pub mod errno;
pub mod fcntl;
pub mod fd;
pub mod file;
pub mod lock;
Expand Down

0 comments on commit a786000

Please sign in to comment.