Skip to content

Commit 0aa13bf

Browse files
authored
Merge pull request #72 from bkoropoff/device-handle
Add alternate device_characteristics/sector_size methods which pass file handle
2 parents e96fe28 + c00dd7d commit 0aa13bf

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/mock.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pub trait Hooks {
4747
) -> Result<Option<String>, PragmaErr> {
4848
Err(PragmaErr::NotFound)
4949
}
50-
fn sector_size(&mut self) {}
51-
fn device_characteristics(&mut self) {
50+
fn sector_size(&mut self, handle: MockHandle) {}
51+
fn device_characteristics(&mut self, handle: MockHandle) {
5252
println!("device_characteristics");
5353
}
5454
}
@@ -297,17 +297,17 @@ impl Vfs for MockVfs {
297297
state.hooks.pragma(*meta, pragma)
298298
}
299299

300-
fn sector_size(&self) -> i32 {
300+
fn sector_size(&self, handle: &mut Self::Handle) -> VfsResult<i32> {
301301
let mut state = self.state();
302302
state.log(format_args!("sector_size"));
303-
state.hooks.sector_size();
304-
DEFAULT_SECTOR_SIZE
303+
state.hooks.sector_size(*handle);
304+
Ok(DEFAULT_SECTOR_SIZE)
305305
}
306306

307-
fn device_characteristics(&self) -> i32 {
307+
fn device_characteristics(&self, handle: &mut Self::Handle) -> VfsResult<i32> {
308308
let mut state = self.state();
309309
state.log(format_args!("device_characteristics"));
310-
state.hooks.device_characteristics();
311-
DEFAULT_DEVICE_CHARACTERISTICS
310+
state.hooks.device_characteristics(*handle);
311+
Ok(DEFAULT_DEVICE_CHARACTERISTICS)
312312
}
313313
}

src/vfs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ pub trait Vfs: Send + Sync {
179179
}
180180

181181
// system queries
182-
fn sector_size(&self) -> i32 {
183-
DEFAULT_SECTOR_SIZE
182+
fn sector_size(&self, handle: &mut Self::Handle) -> VfsResult<i32> {
183+
Ok(DEFAULT_SECTOR_SIZE)
184184
}
185185

186-
fn device_characteristics(&self) -> i32 {
187-
DEFAULT_DEVICE_CHARACTERISTICS
186+
fn device_characteristics(&self, handle: &mut Self::Handle) -> VfsResult<i32> {
187+
Ok(DEFAULT_DEVICE_CHARACTERISTICS)
188188
}
189189
}
190190

@@ -623,15 +623,15 @@ unsafe extern "C" fn x_sector_size<T: Vfs>(p_file: *mut ffi::sqlite3_file) -> c_
623623
fallible(|| {
624624
let file = unwrap_file!(p_file, T)?;
625625
let vfs = unwrap_vfs!(file.vfs, T)?;
626-
Ok(vfs.sector_size())
626+
vfs.sector_size(unsafe { file.handle.assume_init_mut() })
627627
})
628628
}
629629

630630
unsafe extern "C" fn x_device_characteristics<T: Vfs>(p_file: *mut ffi::sqlite3_file) -> c_int {
631631
fallible(|| {
632632
let file = unwrap_file!(p_file, T)?;
633633
let vfs = unwrap_vfs!(file.vfs, T)?;
634-
Ok(vfs.device_characteristics())
634+
vfs.device_characteristics(unsafe { file.handle.assume_init_mut() })
635635
})
636636
}
637637

0 commit comments

Comments
 (0)