@@ -75,13 +75,19 @@ 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 (
85
+ & self ,
86
+ blocks : & mut [ Block ] ,
87
+ start_block_idx : BlockIdx ,
88
+ ) -> Result < ( ) , Self :: Error > ;
83
89
/// Write one or more blocks, starting at the given block index.
84
- fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
90
+ async fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
85
91
/// Determine how many blocks this device can hold.
86
92
fn num_blocks ( & self ) -> Result < BlockCount , Self :: Error > ;
87
93
}
@@ -110,31 +116,36 @@ where
110
116
}
111
117
112
118
/// Read a block, and return a reference to it.
113
- pub fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
119
+ #[ maybe_async:: maybe_async]
120
+ pub async fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
114
121
if self . block_idx != Some ( block_idx) {
115
122
self . block_idx = None ;
116
- self . block_device . read ( & mut self . block , block_idx) ?;
123
+ self . block_device . read ( & mut self . block , block_idx) . await ?;
117
124
self . block_idx = Some ( block_idx) ;
118
125
}
119
126
Ok ( & self . block [ 0 ] )
120
127
}
121
128
122
129
/// Read a block, and return a reference to it.
123
- pub fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
130
+ #[ maybe_async:: maybe_async]
131
+ pub async fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
124
132
if self . block_idx != Some ( block_idx) {
125
133
self . block_idx = None ;
126
- self . block_device . read ( & mut self . block , block_idx) ?;
134
+ self . block_device . read ( & mut self . block , block_idx) . await ?;
127
135
self . block_idx = Some ( block_idx) ;
128
136
}
129
137
Ok ( & mut self . block [ 0 ] )
130
138
}
131
139
132
140
/// Write back a block you read with [`Self::read_mut`] and then modified.
133
- pub fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
134
- self . block_device . write (
135
- & self . block ,
136
- self . block_idx . expect ( "write_back with no read" ) ,
137
- )
141
+ #[ maybe_async:: maybe_async]
142
+ pub async fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
143
+ self . block_device
144
+ . write (
145
+ & self . block ,
146
+ self . block_idx . expect ( "write_back with no read" ) ,
147
+ )
148
+ . await
138
149
}
139
150
140
151
/// Access a blank sector
0 commit comments