@@ -75,13 +75,15 @@ impl Default for Block {
75
75
76
76
/// A block device - a device which can read and write blocks (or
77
77
/// sectors). Only supports devices which are <= 2 TiB in size.
78
+ #[ allow( async_fn_in_trait) ]
79
+ #[ maybe_async:: maybe_async( AFIT ) ]
78
80
pub trait BlockDevice {
79
81
/// The errors that the `BlockDevice` can return. Must be debug formattable.
80
82
type Error : core:: fmt:: Debug ;
81
83
/// Read one or more blocks, starting at the given block index.
82
- fn read ( & self , blocks : & mut [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
84
+ async fn read ( & self , blocks : & mut [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
83
85
/// Write one or more blocks, starting at the given block index.
84
- fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
86
+ async fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
85
87
/// Determine how many blocks this device can hold.
86
88
fn num_blocks ( & self ) -> Result < BlockCount , Self :: Error > ;
87
89
}
@@ -110,31 +112,34 @@ where
110
112
}
111
113
112
114
/// Read a block, and return a reference to it.
113
- pub fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
115
+ #[ maybe_async:: maybe_async]
116
+ pub async fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
114
117
if self . block_idx != Some ( block_idx) {
115
118
self . block_idx = None ;
116
- self . block_device . read ( & mut self . block , block_idx) ?;
119
+ self . block_device . read ( & mut self . block , block_idx) . await ?;
117
120
self . block_idx = Some ( block_idx) ;
118
121
}
119
122
Ok ( & self . block [ 0 ] )
120
123
}
121
124
122
125
/// Read a block, and return a reference to it.
123
- pub fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
126
+ #[ maybe_async:: maybe_async]
127
+ pub async fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
124
128
if self . block_idx != Some ( block_idx) {
125
129
self . block_idx = None ;
126
- self . block_device . read ( & mut self . block , block_idx) ?;
130
+ self . block_device . read ( & mut self . block , block_idx) . await ?;
127
131
self . block_idx = Some ( block_idx) ;
128
132
}
129
133
Ok ( & mut self . block [ 0 ] )
130
134
}
131
135
132
136
/// Write back a block you read with [`Self::read_mut`] and then modified.
133
- pub fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
137
+ #[ maybe_async:: maybe_async]
138
+ pub async fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
134
139
self . block_device . write (
135
140
& self . block ,
136
141
self . block_idx . expect ( "write_back with no read" ) ,
137
- )
142
+ ) . await
138
143
}
139
144
140
145
/// Access a blank sector
0 commit comments