1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate core;
pub use std::io::{Error,Result};

/**
 * Some writable and readable devices (disk drives, media cards) have a block size (number of bytes
 * that are read or written at a time) associated with them.
 *
 * These devices also have a (relatively) fixed (or at least known) number of blocks that limits
 * their length. At least, they can't be appended to.
 *
 */
// TODO: consider if we should require ReadAt &/or WriteAt
// TODO: consider if we should provide (here or in a seperate trait) read/write methods on blocks
// of data.
// TODO: consider providing block_sz_physical?
pub trait BlockSize {
    /// The number of bytes in each logical block
    fn block_size_logical(&self) -> Result<u64>;

    /// The total number of logical blocks
    fn block_count(&self) -> Result<u64>;

    /// The number of bytes in each physical block
    ///
    /// This is only a best guess. Many devices do not report a physical block size or do not
    /// report and accurate physical block size. Results will vary, be wary.
    fn block_size_physical(&self) -> Result<u64> {
        self.block_size_logical()
    }

    // fn write_block();
    // fn read_block();
}

mod file;
pub use file::BlockFile;

pub mod os;