ext2 0.1.1

Read and write on Ext2 partitions without mount
Documentation
mod tests_common;

use rand::random;
use tests_common::*;

use ext2::OpenOptions;

use std::fs::File;
use std::io::{Read, Write};

#[test]
fn read() {
    fn read_of_size(size: usize) {
        //create a disk of size of the file + a little space for metadata
        create_disk(size + 1024 * 1024 * 10);
        mount_disk();

        let filename = "/simple_read";

        /* WRITE with the std */
        let v = {
            let filename_mounted = DISK_MOUNTED_NAME.to_owned() + "/" + filename;
            let mut f = File::create(&filename_mounted).expect(&format!(
                "open on mounted filesystem failed {}",
                &filename_mounted
            ));
            // random bytes to write
            let v: Vec<u8> = (0..(size)).map(|_| random::<u8>()).collect();
            f.write_all(&v).expect("write on mouted filesystem failed");
            v
        };
        umount_disk();

        /* READ with the ext2 */
        let mut buf = vec![42; size];

        let ext2 = new_ext2_instance::<File>();
        let mut f = OpenOptions::new()
            .read(true)
            .write(true)
            .create(true)
            .open(&filename, ext2)
            .unwrap();
        let count = f.read(&mut buf).unwrap();
        assert_eq!(count, size);

        assert_eq!(buf[..], v[..]);
    }
    let sizes = &[
        42,
        DIRECT_MAX_SIZE + 42,
        SINGLY_MAX_SIZE + 42,
        DOUBLY_MAX_SIZE + 42,
    ];
    for size in sizes {
        read_of_size(*size);
    }
}