1
- use crate :: errno:: Errno ;
1
+ use crate :: errno:: { Errno , EINTR , EIO } ;
2
2
use crate :: pcpu:: Pcpu ;
3
3
use crate :: thread:: Thread ;
4
4
use crate :: uio:: { IoVec , Uio , UioRw , UioSeg } ;
@@ -11,6 +11,7 @@ pub const AT_FDCWD: c_int = -100;
11
11
12
12
/// # Safety
13
13
/// `path` cannot be null and must point to a null-terminated string if `seg` is [`UioSeg::Kernel`].
14
+ #[ inline( never) ]
14
15
pub unsafe fn openat < K : Kernel > (
15
16
kern : K ,
16
17
fd : c_int ,
@@ -33,20 +34,46 @@ pub unsafe fn openat<K: Kernel>(
33
34
}
34
35
35
36
/// # Safety
36
- /// - `buf` cannot be null and must be valid up to `len` if `seg` is [`UioSeg::Kernel`].
37
- /// - `td` cannot be null.
37
+ /// `td` cannot be null.
38
+ #[ inline( never) ]
39
+ pub unsafe fn write_all < K : Kernel > (
40
+ kern : K ,
41
+ fd : c_int ,
42
+ mut data : & [ u8 ] ,
43
+ seg : UioSeg ,
44
+ td : * mut K :: Thread ,
45
+ ) -> Result < ( ) , Errno > {
46
+ while !data. is_empty ( ) {
47
+ let written = match write ( kern, fd, data, seg, td) {
48
+ Ok ( v) => v,
49
+ Err ( EINTR ) => continue ,
50
+ Err ( e) => return Err ( e) ,
51
+ } ;
52
+
53
+ if written == 0 {
54
+ return Err ( EIO ) ;
55
+ }
56
+
57
+ data = & data[ written..] ;
58
+ }
59
+
60
+ Ok ( ( ) )
61
+ }
62
+
63
+ /// # Safety
64
+ /// `td` cannot be null.
65
+ #[ inline( never) ]
38
66
pub unsafe fn write < K : Kernel > (
39
67
kern : K ,
40
68
fd : c_int ,
41
- buf : * const u8 ,
69
+ data : & [ u8 ] ,
42
70
seg : UioSeg ,
43
- len : usize ,
44
71
td : * mut K :: Thread ,
45
72
) -> Result < usize , Errno > {
46
73
// Setup iovec.
47
74
let mut vec = IoVec {
48
- ptr : buf . cast_mut ( ) ,
49
- len,
75
+ ptr : data . as_ptr ( ) . cast_mut ( ) ,
76
+ len : data . len ( ) ,
50
77
} ;
51
78
52
79
// Write.
@@ -92,6 +119,7 @@ impl<K: Kernel> OwnedFd<K> {
92
119
}
93
120
94
121
impl < K : Kernel > Drop for OwnedFd < K > {
122
+ #[ inline( never) ]
95
123
fn drop ( & mut self ) {
96
124
// This drop must be called from the same process as the one that created the FD.
97
125
assert_eq ! (
0 commit comments