Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 9486f3c

Browse files
committed
Moved types.rs to c_types.rs so types can be used for higher level abstractions
1 parent de8fa75 commit 9486f3c

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const INCLUDED_VARS: &[&str] = &[
2929
fn main() {
3030
let mut builder = bindgen::Builder::default()
3131
.use_core()
32-
.ctypes_prefix("types")
32+
.ctypes_prefix("c_types")
3333
.no_copy(".*")
3434
.derive_default(true)
3535
.rustfmt_bindings(true);

src/allocator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::heap::{AllocErr, GlobalAlloc, Layout, Opaque};
22

33
use bindings;
4-
use types;
4+
use c_types;
55

66
pub struct KernelAllocator;
77

@@ -10,14 +10,14 @@ unsafe impl GlobalAlloc for KernelAllocator {
1010
// krealloc is used instead of kmalloc because kmalloc is an inline function and can't be
1111
// bound to as a result
1212
return bindings::krealloc(
13-
0 as *const types::c_void,
13+
0 as *const c_types::c_void,
1414
layout.size(),
1515
bindings::GFP_KERNEL,
1616
) as *mut Opaque;
1717
}
1818

1919
unsafe fn dealloc(&self, ptr: *mut Opaque, _layout: Layout) {
20-
bindings::kfree(ptr as *const types::c_void);
20+
bindings::kfree(ptr as *const c_types::c_void);
2121
}
2222
}
2323

src/bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case, improper_ctypes)]
22

3-
use types;
3+
use c_types;
44

55
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
66

File renamed without changes.

src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use bindings;
2-
use types;
2+
use c_types;
33

4-
pub struct Error(types::c_int);
4+
pub struct Error(c_types::c_int);
55

66
impl Error {
77
pub const EINVAL: Self = Error(-(bindings::EINVAL as i32));
88

9-
pub fn from_kernel_errno(errno: types::c_int) -> Error {
9+
pub fn from_kernel_errno(errno: c_types::c_int) -> Error {
1010
return Error(errno);
1111
}
1212

13-
pub fn to_kernel_errno(&self) -> types::c_int {
13+
pub fn to_kernel_errno(&self) -> c_types::c_int {
1414
return self.0;
1515
}
1616
}

src/filesystem.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::mem;
55

66
use bindings;
77
use error;
8-
use types;
8+
use c_types;
99

1010
pub struct FileSystemRegistration<T: FileSystem> {
1111
_phantom: marker::PhantomData<T>,
@@ -25,12 +25,12 @@ pub trait FileSystem {
2525
}
2626

2727
bitflags! {
28-
pub struct FileSystemFlags: types::c_int {
29-
const FS_REQUIRES_DEV = bindings::FS_REQUIRES_DEV as types::c_int;
30-
const FS_BINARY_MOUNTDATA = bindings::FS_BINARY_MOUNTDATA as types::c_int;
31-
const FS_HAS_SUBTYPE = bindings::FS_HAS_SUBTYPE as types::c_int;
32-
const FS_USERNS_MOUNT = bindings::FS_USERNS_MOUNT as types::c_int;
33-
const FS_RENAME_DOES_D_MOVE = bindings::FS_RENAME_DOES_D_MOVE as types::c_int;
28+
pub struct FileSystemFlags: c_types::c_int {
29+
const FS_REQUIRES_DEV = bindings::FS_REQUIRES_DEV as c_types::c_int;
30+
const FS_BINARY_MOUNTDATA = bindings::FS_BINARY_MOUNTDATA as c_types::c_int;
31+
const FS_HAS_SUBTYPE = bindings::FS_HAS_SUBTYPE as c_types::c_int;
32+
const FS_USERNS_MOUNT = bindings::FS_USERNS_MOUNT as c_types::c_int;
33+
const FS_RENAME_DOES_D_MOVE = bindings::FS_RENAME_DOES_D_MOVE as c_types::c_int;
3434
}
3535
}
3636

@@ -42,9 +42,9 @@ impl FileSystemFlags {
4242

4343
extern "C" fn fill_super_callback<T: FileSystem>(
4444
_sb: *mut bindings::super_block,
45-
_data: *mut types::c_void,
46-
_silent: types::c_int,
47-
) -> types::c_int {
45+
_data: *mut c_types::c_void,
46+
_silent: c_types::c_int,
47+
) -> c_types::c_int {
4848
// T::fill_super(...)
4949
// This should actually create an object that gets dropped by
5050
// file_system_registration::kill_sb. You can point to it with
@@ -54,9 +54,9 @@ extern "C" fn fill_super_callback<T: FileSystem>(
5454

5555
extern "C" fn mount_callback<T: FileSystem>(
5656
fs_type: *mut bindings::file_system_type,
57-
flags: types::c_int,
58-
_dev_name: *const types::c_char,
59-
data: *mut types::c_void,
57+
flags: c_types::c_int,
58+
_dev_name: *const c_types::c_char,
59+
data: *mut c_types::c_void,
6060
) -> *mut bindings::dentry {
6161
unsafe { bindings::mount_nodev(fs_type, flags, data, Some(fill_super_callback::<T>)) }
6262
}

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ pub mod bindings;
1010
mod error;
1111
pub mod filesystem;
1212
pub mod printk;
13-
pub mod types;
13+
mod c_types;
1414

1515
pub use alloc::format;
1616

1717
pub use error::{Error, KernelResult};
1818

19+
pub type _InitResult = c_types::c_int;
20+
1921
#[macro_export]
2022
macro_rules! kernel_module {
2123
($module:ty, $($name:ident : $value:expr),*) => {
2224
static mut __MOD: Option<$module> = None;
2325
#[no_mangle]
24-
pub extern "C" fn init_module() -> $crate::types::c_int {
26+
pub extern "C" fn init_module() -> $crate::_InitResult {
2527
match <$module as $crate::KernelModule>::init() {
2628
Ok(m) => {
2729
unsafe {

src/printk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::cmp;
22
use core::fmt;
33

4-
use types::c_int;
4+
use c_types::c_int;
55

66
pub struct KernelConsole;
77

0 commit comments

Comments
 (0)