2018-06-29 00:13:07 +08:00
|
|
|
extern crate env_logger;
|
2017-10-09 20:59:52 +08:00
|
|
|
extern crate fatfs;
|
2018-06-16 23:57:29 +08:00
|
|
|
extern crate fscommon;
|
2017-10-09 20:59:52 +08:00
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
use std::io;
|
2018-06-29 00:13:07 +08:00
|
|
|
use std::io::prelude::*;
|
2018-06-29 21:35:37 +08:00
|
|
|
use std::mem;
|
2017-10-09 20:59:52 +08:00
|
|
|
use std::str;
|
|
|
|
|
2018-06-16 23:57:29 +08:00
|
|
|
use fatfs::FsOptions;
|
|
|
|
use fscommon::BufStream;
|
2017-10-09 20:59:52 +08:00
|
|
|
|
|
|
|
const FAT12_IMG: &str = "fat12.img";
|
|
|
|
const FAT16_IMG: &str = "fat16.img";
|
|
|
|
const FAT32_IMG: &str = "fat32.img";
|
|
|
|
const IMG_DIR: &str = "resources";
|
|
|
|
const TMP_DIR: &str = "tmp";
|
|
|
|
const TEST_STR: &str = "Hi there Rust programmer!\n";
|
2018-06-06 19:56:59 +08:00
|
|
|
const TEST_STR2: &str = "Rust is cool!\n";
|
2017-10-09 20:59:52 +08:00
|
|
|
|
2018-06-14 05:24:08 +08:00
|
|
|
type FileSystem = fatfs::FileSystem<BufStream<fs::File>>;
|
|
|
|
|
2018-06-29 21:35:37 +08:00
|
|
|
fn call_with_tmp_img(f: &Fn(&str) -> (), filename: &str, test_seq: u32) {
|
2018-04-28 21:00:01 +08:00
|
|
|
let _ = env_logger::try_init();
|
2017-10-09 20:59:52 +08:00
|
|
|
let img_path = format!("{}/{}", IMG_DIR, filename);
|
2017-10-10 03:14:28 +08:00
|
|
|
let tmp_path = format!("{}/{}-{}", TMP_DIR, test_seq, filename);
|
2017-10-09 20:59:52 +08:00
|
|
|
fs::create_dir(TMP_DIR).ok();
|
|
|
|
fs::copy(&img_path, &tmp_path).unwrap();
|
2018-06-29 21:35:37 +08:00
|
|
|
f(tmp_path.as_str());
|
2017-10-10 03:14:28 +08:00
|
|
|
fs::remove_file(tmp_path).unwrap();
|
2017-10-09 20:59:52 +08:00
|
|
|
}
|
|
|
|
|
2018-06-29 21:35:37 +08:00
|
|
|
fn open_filesystem_rw(tmp_path: &str) -> FileSystem {
|
|
|
|
let file = fs::OpenOptions::new().read(true).write(true).open(&tmp_path).unwrap();
|
|
|
|
let buf_file = BufStream::new(file);
|
|
|
|
let options = FsOptions::new().update_accessed_date(true);
|
|
|
|
FileSystem::new(buf_file, options).unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call_with_fs(f: &Fn(FileSystem) -> (), filename: &str, test_seq: u32) {
|
2018-10-11 03:26:31 +08:00
|
|
|
let callback = |tmp_path: &str| {
|
2018-06-29 21:35:37 +08:00
|
|
|
let fs = open_filesystem_rw(tmp_path);
|
|
|
|
f(fs);
|
2018-10-11 03:26:31 +08:00
|
|
|
};
|
|
|
|
call_with_tmp_img(&callback, filename, test_seq);
|
2018-06-29 21:35:37 +08:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:14:28 +08:00
|
|
|
fn test_write_short_file(fs: FileSystem) {
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
2017-10-09 20:59:52 +08:00
|
|
|
let mut file = root_dir.open_file("short.txt").expect("open file");
|
2017-10-10 03:14:28 +08:00
|
|
|
file.truncate().unwrap();
|
2017-10-10 22:05:19 +08:00
|
|
|
file.write_all(&TEST_STR.as_bytes()).unwrap();
|
2017-10-09 20:59:52 +08:00
|
|
|
file.seek(io::SeekFrom::Start(0)).unwrap();
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
file.read_to_end(&mut buf).unwrap();
|
|
|
|
assert_eq!(TEST_STR, str::from_utf8(&buf).unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_write_file_fat12() {
|
2017-10-10 03:14:28 +08:00
|
|
|
call_with_fs(&test_write_short_file, FAT12_IMG, 1)
|
2017-10-09 20:59:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_write_file_fat16() {
|
2017-10-10 03:14:28 +08:00
|
|
|
call_with_fs(&test_write_short_file, FAT16_IMG, 1)
|
2017-10-09 20:59:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_write_file_fat32() {
|
2017-10-10 03:14:28 +08:00
|
|
|
call_with_fs(&test_write_short_file, FAT32_IMG, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_write_long_file(fs: FileSystem) {
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
2017-10-10 03:14:28 +08:00
|
|
|
let mut file = root_dir.open_file("long.txt").expect("open file");
|
|
|
|
file.truncate().unwrap();
|
2018-12-06 04:10:59 +08:00
|
|
|
let test_str = TEST_STR.repeat(1000);
|
2017-10-10 22:05:19 +08:00
|
|
|
file.write_all(&test_str.as_bytes()).unwrap();
|
2017-10-10 03:14:28 +08:00
|
|
|
file.seek(io::SeekFrom::Start(0)).unwrap();
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
file.read_to_end(&mut buf).unwrap();
|
|
|
|
assert_eq!(test_str, str::from_utf8(&buf).unwrap());
|
|
|
|
file.seek(io::SeekFrom::Start(1234)).unwrap();
|
|
|
|
file.truncate().unwrap();
|
|
|
|
file.seek(io::SeekFrom::Start(0)).unwrap();
|
|
|
|
buf.clear();
|
|
|
|
file.read_to_end(&mut buf).unwrap();
|
|
|
|
assert_eq!(&test_str[..1234], str::from_utf8(&buf).unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_write_long_file_fat12() {
|
|
|
|
call_with_fs(&test_write_long_file, FAT12_IMG, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_write_long_file_fat16() {
|
|
|
|
call_with_fs(&test_write_long_file, FAT16_IMG, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_write_long_file_fat32() {
|
|
|
|
call_with_fs(&test_write_long_file, FAT32_IMG, 2)
|
2017-10-09 20:59:52 +08:00
|
|
|
}
|
2017-10-16 04:42:26 +08:00
|
|
|
|
|
|
|
fn test_remove(fs: FileSystem) {
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
2017-10-16 04:42:26 +08:00
|
|
|
assert!(root_dir.remove("very/long/path").is_err());
|
|
|
|
let dir = root_dir.open_dir("very/long/path").unwrap();
|
|
|
|
let mut names = dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt"]);
|
|
|
|
root_dir.remove("very/long/path/test.txt").unwrap();
|
|
|
|
names = dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", ".."]);
|
|
|
|
assert!(root_dir.remove("very/long/path").is_ok());
|
2017-10-25 23:20:27 +08:00
|
|
|
|
2017-10-16 04:42:26 +08:00
|
|
|
names = root_dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, ["long.txt", "short.txt", "very", "very-long-dir-name"]);
|
|
|
|
root_dir.remove("long.txt").unwrap();
|
|
|
|
names = root_dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, ["short.txt", "very", "very-long-dir-name"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_fat12() {
|
|
|
|
call_with_fs(&test_remove, FAT12_IMG, 3)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_fat16() {
|
|
|
|
call_with_fs(&test_remove, FAT16_IMG, 3)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_fat32() {
|
|
|
|
call_with_fs(&test_remove, FAT32_IMG, 3)
|
|
|
|
}
|
2017-10-21 21:35:26 +08:00
|
|
|
|
|
|
|
fn test_create_file(fs: FileSystem) {
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
|
|
|
let dir = root_dir.open_dir("very/long/path").unwrap();
|
2017-10-21 21:35:26 +08:00
|
|
|
let mut names = dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt"]);
|
|
|
|
{
|
2017-11-08 07:07:06 +08:00
|
|
|
// test some invalid names
|
|
|
|
assert!(root_dir.create_file("very/long/path/:").is_err());
|
|
|
|
assert!(root_dir.create_file("very/long/path/\0").is_err());
|
|
|
|
// create file
|
2017-10-21 21:35:26 +08:00
|
|
|
let mut file = root_dir.create_file("very/long/path/new-file-with-long-name.txt").unwrap();
|
|
|
|
file.write_all(&TEST_STR.as_bytes()).unwrap();
|
|
|
|
}
|
2017-11-08 07:07:06 +08:00
|
|
|
// check for dir entry
|
2017-10-21 21:35:26 +08:00
|
|
|
names = dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt", "new-file-with-long-name.txt"]);
|
2017-11-08 07:07:06 +08:00
|
|
|
names = dir.iter().map(|r| r.unwrap().short_file_name()).collect::<Vec<String>>();
|
2018-05-30 23:43:18 +08:00
|
|
|
assert_eq!(names, [".", "..", "TEST.TXT", "NEW-FI~1.TXT"]);
|
2017-10-21 21:35:26 +08:00
|
|
|
{
|
2017-11-08 07:07:06 +08:00
|
|
|
// check contents
|
2017-10-21 21:35:26 +08:00
|
|
|
let mut file = root_dir.open_file("very/long/path/new-file-with-long-name.txt").unwrap();
|
|
|
|
let mut content = String::new();
|
|
|
|
file.read_to_string(&mut content).unwrap();
|
|
|
|
assert_eq!(&content, &TEST_STR);
|
|
|
|
}
|
2017-10-27 21:03:54 +08:00
|
|
|
// Create enough entries to allocate next cluster
|
2018-06-29 00:13:07 +08:00
|
|
|
for i in 0..512 / 32 {
|
2017-10-27 21:03:54 +08:00
|
|
|
let name = format!("test{}", i);
|
|
|
|
dir.create_file(&name).unwrap();
|
|
|
|
}
|
|
|
|
names = dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
2018-06-29 00:13:07 +08:00
|
|
|
assert_eq!(names.len(), 4 + 512 / 32);
|
2018-06-18 03:46:54 +08:00
|
|
|
// check creating existing file opens it
|
|
|
|
{
|
|
|
|
let mut file = root_dir.create_file("very/long/path/new-file-with-long-name.txt").unwrap();
|
|
|
|
let mut content = String::new();
|
|
|
|
file.read_to_string(&mut content).unwrap();
|
|
|
|
assert_eq!(&content, &TEST_STR);
|
|
|
|
}
|
|
|
|
// check using create_file with existing directory fails
|
|
|
|
assert!(root_dir.create_file("very").is_err());
|
2017-10-21 21:35:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_file_fat12() {
|
|
|
|
call_with_fs(&test_create_file, FAT12_IMG, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_file_fat16() {
|
|
|
|
call_with_fs(&test_create_file, FAT16_IMG, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_file_fat32() {
|
|
|
|
call_with_fs(&test_create_file, FAT32_IMG, 4)
|
|
|
|
}
|
2017-10-27 20:12:53 +08:00
|
|
|
|
|
|
|
fn test_create_dir(fs: FileSystem) {
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
2017-10-27 20:12:53 +08:00
|
|
|
let parent_dir = root_dir.open_dir("very/long/path").unwrap();
|
|
|
|
let mut names = parent_dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt"]);
|
|
|
|
{
|
|
|
|
let subdir = root_dir.create_dir("very/long/path/new-dir-with-long-name").unwrap();
|
|
|
|
names = subdir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", ".."]);
|
|
|
|
}
|
|
|
|
// check if new entry is visible in parent
|
|
|
|
names = parent_dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt", "new-dir-with-long-name"]);
|
|
|
|
{
|
|
|
|
// Check if new directory can be opened and read
|
|
|
|
let subdir = root_dir.open_dir("very/long/path/new-dir-with-long-name").unwrap();
|
|
|
|
names = subdir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", ".."]);
|
|
|
|
}
|
|
|
|
// Check if '.' is alias for new directory
|
|
|
|
{
|
|
|
|
let subdir = root_dir.open_dir("very/long/path/new-dir-with-long-name/.").unwrap();
|
|
|
|
names = subdir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", ".."]);
|
|
|
|
}
|
|
|
|
// Check if '..' is alias for parent directory
|
|
|
|
{
|
|
|
|
let subdir = root_dir.open_dir("very/long/path/new-dir-with-long-name/..").unwrap();
|
|
|
|
names = subdir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt", "new-dir-with-long-name"]);
|
|
|
|
}
|
2018-06-18 03:46:54 +08:00
|
|
|
// check if creating existing directory returns it
|
|
|
|
{
|
|
|
|
let subdir = root_dir.create_dir("very").unwrap();
|
|
|
|
names = subdir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", "..", "long"]);
|
|
|
|
}
|
2019-07-16 17:05:40 +08:00
|
|
|
// check short names validity after create_dir
|
|
|
|
{
|
|
|
|
let subdir = root_dir.create_dir("test").unwrap();
|
|
|
|
names = subdir.iter().map(|r| r.unwrap().short_file_name()).collect::<Vec<String>>();
|
|
|
|
assert_eq!(names, [".", ".."]);
|
|
|
|
}
|
|
|
|
|
2018-06-18 03:46:54 +08:00
|
|
|
// check using create_dir with existing file fails
|
|
|
|
assert!(root_dir.create_dir("very/long/path/test.txt").is_err());
|
2017-10-27 20:12:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_dir_fat12() {
|
|
|
|
call_with_fs(&test_create_dir, FAT12_IMG, 5)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_dir_fat16() {
|
|
|
|
call_with_fs(&test_create_dir, FAT16_IMG, 5)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_create_dir_fat32() {
|
|
|
|
call_with_fs(&test_create_dir, FAT32_IMG, 5)
|
|
|
|
}
|
2018-06-06 19:56:59 +08:00
|
|
|
|
|
|
|
fn test_rename_file(fs: FileSystem) {
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
|
|
|
let parent_dir = root_dir.open_dir("very/long/path").unwrap();
|
2018-06-06 19:56:59 +08:00
|
|
|
let entries = parent_dir.iter().map(|r| r.unwrap()).collect::<Vec<_>>();
|
|
|
|
let names = entries.iter().map(|r| r.file_name()).collect::<Vec<_>>();
|
|
|
|
assert_eq!(names, [".", "..", "test.txt"]);
|
|
|
|
assert_eq!(entries[2].len(), 14);
|
|
|
|
let stats = fs.stats().unwrap();
|
|
|
|
|
2018-06-12 06:07:30 +08:00
|
|
|
parent_dir.rename("test.txt", &parent_dir, "new-long-name.txt").unwrap();
|
2018-06-06 19:56:59 +08:00
|
|
|
let entries = parent_dir.iter().map(|r| r.unwrap()).collect::<Vec<_>>();
|
|
|
|
let names = entries.iter().map(|r| r.file_name()).collect::<Vec<_>>();
|
|
|
|
assert_eq!(names, [".", "..", "new-long-name.txt"]);
|
|
|
|
assert_eq!(entries[2].len(), TEST_STR2.len() as u64);
|
|
|
|
let mut file = parent_dir.open_file("new-long-name.txt").unwrap();
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
file.read_to_end(&mut buf).unwrap();
|
|
|
|
assert_eq!(str::from_utf8(&buf).unwrap(), TEST_STR2);
|
|
|
|
|
2018-06-12 06:07:30 +08:00
|
|
|
parent_dir.rename("new-long-name.txt", &root_dir, "moved-file.txt").unwrap();
|
2018-06-06 19:56:59 +08:00
|
|
|
let entries = root_dir.iter().map(|r| r.unwrap()).collect::<Vec<_>>();
|
|
|
|
let names = entries.iter().map(|r| r.file_name()).collect::<Vec<_>>();
|
|
|
|
assert_eq!(names, ["long.txt", "short.txt", "very", "very-long-dir-name", "moved-file.txt"]);
|
|
|
|
assert_eq!(entries[4].len(), TEST_STR2.len() as u64);
|
|
|
|
let mut file = root_dir.open_file("moved-file.txt").unwrap();
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
file.read_to_end(&mut buf).unwrap();
|
|
|
|
assert_eq!(str::from_utf8(&buf).unwrap(), TEST_STR2);
|
|
|
|
|
2018-06-18 04:25:22 +08:00
|
|
|
assert!(root_dir.rename("moved-file.txt", &root_dir, "short.txt").is_err());
|
|
|
|
let entries = root_dir.iter().map(|r| r.unwrap()).collect::<Vec<_>>();
|
|
|
|
let names = entries.iter().map(|r| r.file_name()).collect::<Vec<_>>();
|
|
|
|
assert_eq!(names, ["long.txt", "short.txt", "very", "very-long-dir-name", "moved-file.txt"]);
|
|
|
|
|
2018-06-18 04:26:07 +08:00
|
|
|
assert!(root_dir.rename("moved-file.txt", &root_dir, "moved-file.txt").is_ok());
|
|
|
|
|
2018-06-06 19:56:59 +08:00
|
|
|
let new_stats = fs.stats().unwrap();
|
2018-06-06 20:01:19 +08:00
|
|
|
assert_eq!(new_stats.free_clusters(), stats.free_clusters());
|
2018-06-06 19:56:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rename_file_fat12() {
|
|
|
|
call_with_fs(&test_rename_file, FAT12_IMG, 6)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rename_file_fat16() {
|
|
|
|
call_with_fs(&test_rename_file, FAT16_IMG, 6)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rename_file_fat32() {
|
|
|
|
call_with_fs(&test_rename_file, FAT32_IMG, 6)
|
|
|
|
}
|
2018-06-29 21:35:37 +08:00
|
|
|
|
2018-06-29 21:38:27 +08:00
|
|
|
fn test_dirty_flag(tmp_path: &str) {
|
|
|
|
// Open filesystem, make change, and forget it - should become dirty
|
|
|
|
let fs = open_filesystem_rw(tmp_path);
|
|
|
|
let status_flags = fs.read_status_flags().unwrap();
|
|
|
|
assert_eq!(status_flags.dirty(), false);
|
|
|
|
assert_eq!(status_flags.io_error(), false);
|
|
|
|
fs.root_dir().create_file("abc.txt").unwrap();
|
|
|
|
mem::forget(fs);
|
|
|
|
// Check if volume is dirty now
|
|
|
|
let fs = open_filesystem_rw(tmp_path);
|
|
|
|
let status_flags = fs.read_status_flags().unwrap();
|
|
|
|
assert_eq!(status_flags.dirty(), true);
|
|
|
|
assert_eq!(status_flags.io_error(), false);
|
|
|
|
fs.unmount().unwrap();
|
|
|
|
// Make sure remounting does not clear the dirty flag
|
|
|
|
let fs = open_filesystem_rw(tmp_path);
|
|
|
|
let status_flags = fs.read_status_flags().unwrap();
|
|
|
|
assert_eq!(status_flags.dirty(), true);
|
|
|
|
assert_eq!(status_flags.io_error(), false);
|
|
|
|
}
|
|
|
|
|
2018-06-29 21:35:37 +08:00
|
|
|
#[test]
|
2018-06-29 21:38:27 +08:00
|
|
|
fn test_dirty_flag_fat12() {
|
|
|
|
call_with_tmp_img(&test_dirty_flag, FAT12_IMG, 7)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dirty_flag_fat16() {
|
|
|
|
call_with_tmp_img(&test_dirty_flag, FAT16_IMG, 7)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dirty_flag_fat32() {
|
|
|
|
call_with_tmp_img(&test_dirty_flag, FAT32_IMG, 7)
|
2018-06-29 21:35:37 +08:00
|
|
|
}
|
2021-01-22 07:17:48 +08:00
|
|
|
|
|
|
|
fn test_multiple_files_in_directory(fs: FileSystem) {
|
|
|
|
let dir = fs.root_dir().create_dir("/TMP").unwrap();
|
|
|
|
for i in 0..8 {
|
|
|
|
let name = format!("T{}.TXT", i);
|
|
|
|
let mut file = dir.create_file(&name).unwrap();
|
|
|
|
file.write_all(TEST_STR.as_bytes()).unwrap();
|
|
|
|
file.flush().unwrap();
|
|
|
|
|
|
|
|
let file = dir.iter()
|
|
|
|
.map(|r| r.unwrap())
|
|
|
|
.filter(|e| e.file_name() == name)
|
|
|
|
.next()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(TEST_STR.len() as u64, file.len(), "Wrong file len on iteration {}", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_files_in_directory_fat12() {
|
|
|
|
call_with_fs(&test_multiple_files_in_directory, FAT12_IMG, 8)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_files_in_directory_fat16() {
|
|
|
|
call_with_fs(&test_multiple_files_in_directory, FAT16_IMG, 8)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_files_in_directory_fat32() {
|
|
|
|
call_with_fs(&test_multiple_files_in_directory, FAT32_IMG, 8)
|
|
|
|
}
|