Skip to content

Commit 8e3461c

Browse files
committed
Allows specify offset to Uio
1 parent 52cbd3a commit 8e3461c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

kernel-1100/src/uio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct Uio {
1616
}
1717

1818
impl okf::uio::Uio<Kernel> for Uio {
19-
unsafe fn write(td: *mut Thread, iov: *mut IoVec) -> Option<Self> {
19+
unsafe fn write(iov: *mut IoVec, td: *mut Thread) -> Option<Self> {
2020
let res = (*iov).len;
2121

2222
if res > Self::io_max() {
@@ -34,7 +34,7 @@ impl okf::uio::Uio<Kernel> for Uio {
3434
})
3535
}
3636

37-
unsafe fn read(td: *mut Thread, iov: *mut IoVec) -> Option<Self> {
37+
unsafe fn read(iov: *mut IoVec, off: usize, td: *mut Thread) -> Option<Self> {
3838
let res = (*iov).len;
3939

4040
if res > Self::io_max() {
@@ -44,7 +44,7 @@ impl okf::uio::Uio<Kernel> for Uio {
4444
Some(Self {
4545
iov,
4646
len: 1,
47-
off: 0,
47+
off: off.try_into().unwrap(),
4848
res: res.try_into().unwrap(),
4949
seg: UioSeg::Kernel,
5050
op: UioRw::Read,

src/fd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub unsafe fn write<K: Kernel>(
7575
};
7676

7777
// Write.
78-
let mut uio = K::Uio::write(td, &mut vec).unwrap();
78+
let mut uio = K::Uio::write(&mut vec, td).unwrap();
7979
let errno = kern.kern_writev(td, fd, &mut uio);
8080

8181
match NonZero::new(errno) {

src/uio/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ pub trait Uio<K: Kernel>: Sized {
77
/// # Safety
88
/// - `td` cannot be null.
99
/// - `iov` cannot be null.
10-
unsafe fn write(td: *mut K::Thread, iov: *mut IoVec) -> Option<Self>;
10+
unsafe fn write(iov: *mut IoVec, td: *mut K::Thread) -> Option<Self>;
1111

1212
/// Returns [`None`] if [`IoVec::len`] of `iov` is greater than [`Uio::io_max()`].
1313
///
1414
/// # Safety
1515
/// - `td` cannot be null.
1616
/// - `iov` cannot be null.
17-
unsafe fn read(td: *mut K::Thread, iov: *mut IoVec) -> Option<Self>;
17+
///
18+
/// # Panics
19+
/// If `off` larger than [`isize::MAX`].
20+
unsafe fn read(iov: *mut IoVec, off: usize, td: *mut K::Thread) -> Option<Self>;
1821

1922
/// Returns value of `UIO_MAXIOV`.
2023
fn vec_max() -> usize {

0 commit comments

Comments
 (0)