Skip to content

Commit

Permalink
Merge pull request #1 from MabezDev/device
Browse files Browse the repository at this point in the history
Add async `StreamSlice` and `BlockDevice` helper structs behind `device` feature
  • Loading branch information
MabezDev authored Jul 18, 2023
2 parents 8254142 + 5dc8067 commit b5a0130
Show file tree
Hide file tree
Showing 17 changed files with 728 additions and 116 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
args: --verbose --features device
if: ${{ matrix.run_tests }}

- name: Run cargo build - no_std
Expand All @@ -58,3 +58,8 @@ jobs:
with:
command: build
args: --no-default-features --features alloc,lfn,unicode
- name: Run cargo build - no_std, alloc, lfn, unicode, device
uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features --features alloc,lfn,unicode,device
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ lfn = []
alloc = []
# Full Unicode support. Disabling it reduces code size by avoiding Unicode-aware character case conversion
unicode = []
# device traits, structs and helpers
device = ["elain"]
# Enable only error-level logging
log_level_error = []
# Enable logging levels warn and up
Expand All @@ -45,6 +47,7 @@ embedded-io-adapters = {version = "0.1", git = "https://github.com/mabezdev/embe
chrono = { version = "0.4", default-features = false, features = ["clock"], optional = true }
tokio = { version = "1", default-features = false, optional = true }
async-iterator = { version = "2.0.0", git = "https://github.com/MabezDev/async-iterator", branch = "no-std-support", default-features = false }
elain = { version = "0.3", optional = true }

[dev-dependencies]
env_logger = "0.9"
Expand Down
6 changes: 4 additions & 2 deletions examples/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ async fn main() -> anyhow::Result<()> {
let file = tokio::fs::File::open("resources/fat32.img").await?;
let fs = FileSystem::new(file, FsOptions::new()).await?;
let root_dir = fs.root_dir();
let mut file = root_dir.open_file(&env::args().nth(1).expect("filename expected")).await?;
let buf = read_to_end(&mut file).await?;
let mut file = root_dir
.open_file(&env::args().nth(1).expect("filename expected"))
.await?;
let buf = read_to_end(&mut file).await?;
print!("{}", String::from_utf8_lossy(&buf));
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ls.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;

use async_iterator::Iterator as AsyncIterator;
use chrono::{DateTime, Local};
use embedded_fatfs::{FileSystem, FsOptions};
use async_iterator::Iterator as AsyncIterator;

fn format_file_size(size: u64) -> String {
const KB: u64 = 1024;
Expand Down
4 changes: 2 additions & 2 deletions examples/mkfatfs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::env;

use embedded_io_adapters::tokio_1::FromTokio;
use embedded_fatfs::{format_volume, FormatVolumeOptions};
use tokio::io::BufStream;
use embedded_io_adapters::tokio_1::FromTokio;
use tokio::fs;
use tokio::io::BufStream;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
9 changes: 7 additions & 2 deletions examples/write.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use anyhow::Context;
use embedded_io::Write;
use embedded_fatfs::{FileSystem, FsOptions};
use embedded_io::Write;
use tokio::fs::OpenOptions;
use tokio::io::BufStream;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let img_file = OpenOptions::new().read(true).write(true).open("fat.img").await.context("Failed to open image!")?;
let img_file = OpenOptions::new()
.read(true)
.write(true)
.open("fat.img")
.await
.context("Failed to open image!")?;
let buf_stream = BufStream::new(img_file);
let options = FsOptions::new().update_accessed_date(true);
let fs = FileSystem::new(buf_stream, options).await?;
Expand Down
5 changes: 2 additions & 3 deletions src/boot_sector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,8 @@ mod tests {
}
total_sectors_vec.push(u32::MAX);
for total_sectors in total_sectors_vec {
let (boot, _) =
format_boot_sector::<Dummy>(&FormatVolumeOptions::new(), total_sectors, bytes_per_sector)
.expect("format_boot_sector");
let (boot, _) = format_boot_sector::<Dummy>(&FormatVolumeOptions::new(), total_sectors, bytes_per_sector)
.expect("format_boot_sector");
boot.validate::<Dummy>().expect("validate");
}
}
Expand Down
Loading

0 comments on commit b5a0130

Please sign in to comment.