Basic no_std support

This commit is contained in:
Rafał Harabień 2018-05-10 01:00:24 +02:00
parent 73c6e9a461
commit 11b2a3b956
13 changed files with 1370 additions and 28 deletions

25
Cargo.lock generated
View File

@ -41,6 +41,14 @@ dependencies = [
"time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "core_io"
version = "0.1.20180307"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "env_logger" name = "env_logger"
version = "0.5.10" version = "0.5.10"
@ -60,6 +68,7 @@ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"core_io 0.1.20180307 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -149,6 +158,19 @@ dependencies = [
"ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "rustc_version"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "0.3.6" version = "0.3.6"
@ -243,6 +265,7 @@ dependencies = [
"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87" "checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1cce36c92cb605414e9b824f866f5babe0a0368e39ea07393b9b63cf3844c0e6" "checksum chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1cce36c92cb605414e9b824f866f5babe0a0368e39ea07393b9b63cf3844c0e6"
"checksum core_io 0.1.20180307 (registry+https://github.com/rust-lang/crates.io-index)" = "52c2fc3ad457529bd2ac28471ffc4d8971656de79d3b5fb745ba8117c7c997cc"
"checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a" "checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a"
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e" "checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
@ -256,6 +279,8 @@ dependencies = [
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3" "checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3"
"checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b" "checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83" "checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"

View File

@ -4,7 +4,7 @@ version = "0.2.0"
authors = ["Rafał Harabień <rafalh1992@o2.pl>"] authors = ["Rafał Harabień <rafalh1992@o2.pl>"]
repository = "https://github.com/rafalh/rust-fatfs" repository = "https://github.com/rafalh/rust-fatfs"
readme = "README.md" readme = "README.md"
keywords = ["fat", "filesystem"] keywords = ["fat", "filesystem", "no_std"]
categories = ["filesystem"] categories = ["filesystem"]
license = "MIT" license = "MIT"
description = """ description = """
@ -18,13 +18,15 @@ exclude = [
travis-ci = { repository = "rafalh/rust-fatfs" } travis-ci = { repository = "rafalh/rust-fatfs" }
[features] [features]
default = ["chrono"] std = []
default = ["chrono", "std"]
[dependencies] [dependencies]
byteorder = "1" byteorder = "1"
bitflags = "1.0" bitflags = "1.0"
log = "0.4" log = "0.4"
chrono = { version = "0.4", optional = true } chrono = { version = "0.4", optional = true }
core_io = { version = "0.1", features = ["collections"], optional = true }
[dev-dependencies] [dev-dependencies]
env_logger = "0.5" env_logger = "0.5"

View File

@ -39,6 +39,16 @@ You can start using library now:
See more examples in `examples` subdirectory. See more examples in `examples` subdirectory.
no_std usage
------------
Put this in your `Cargo.toml`:
[dependencies]
fatfs = { version = "0.2", features = ["core_io"], default-features = false }
Note: alloc crate is required at the moment so when std is disabled, custom allocator has to be provided.
License License
------- -------
The MIT license. See LICENSE.txt. The MIT license. See LICENSE.txt.

View File

@ -3,4 +3,4 @@ TODO
* FsInfo sector handling * FsInfo sector handling
* move file API * move file API
* format volume API * format volume API
* no_std support * better no_std support

2
build-nostd.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
cargo build --no-default-features --features core_io

1266
src/byteorder_core_io.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,18 @@
use std::io::prelude::*; use core::slice;
use std::io; use core::iter;
use std::io::{ErrorKind, SeekFrom};
use std::slice; use io::prelude::*;
use std::iter; use io;
use io::{ErrorKind, SeekFrom};
use fs::{FileSystemRef, DiskSlice}; use fs::{FileSystemRef, DiskSlice};
use file::File; use file::File;
use dir_entry::{DirEntry, DirEntryData, DirFileEntryData, DirLfnEntryData, FileAttributes, use dir_entry::{DirEntry, DirEntryData, DirFileEntryData, DirLfnEntryData, FileAttributes,
DIR_ENTRY_SIZE, LFN_PART_LEN, LFN_ENTRY_LAST_FLAG}; DIR_ENTRY_SIZE, LFN_PART_LEN, LFN_ENTRY_LAST_FLAG};
#[cfg(not(feature = "std"))]
use alloc::Vec;
#[derive(Clone)] #[derive(Clone)]
pub(crate) enum DirRawStream<'a, 'b: 'a> { pub(crate) enum DirRawStream<'a, 'b: 'a> {
File(File<'a, 'b>), File(File<'a, 'b>),

View File

@ -1,14 +1,18 @@
use std::fmt; use core::fmt;
use std::io::prelude::*; use io::prelude::*;
use std::io; use io;
use std::io::Cursor; use io::Cursor;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian};
use byteorder_ext::{ReadBytesExt, WriteBytesExt};
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
use chrono::{TimeZone, Local, Datelike, Timelike}; use chrono::{TimeZone, Local, Datelike, Timelike};
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
use chrono; use chrono;
#[cfg(not(feature = "std"))]
use alloc::{Vec, String, string::ToString};
use fs::{FileSystemRef, FatType}; use fs::{FileSystemRef, FatType};
use file::File; use file::File;
use dir::{Dir, DirRawStream}; use dir::{Dir, DirRawStream};

View File

@ -1,7 +1,7 @@
use std::cmp; use core::cmp;
use std::io::prelude::*; use io::prelude::*;
use std::io::{SeekFrom, ErrorKind}; use io::{SeekFrom, ErrorKind};
use std::io; use io;
use fs::FileSystemRef; use fs::FileSystemRef;
use dir_entry::{DirEntryEditor, DateTime, Date}; use dir_entry::{DirEntryEditor, DateTime, Date};

View File

@ -1,15 +1,19 @@
use core::cell::RefCell; use core::cell::RefCell;
use core::cmp; use core::cmp;
use std::io::prelude::*; use io::prelude::*;
use std::io::{Error, ErrorKind, SeekFrom}; use io::{Error, ErrorKind, SeekFrom};
use std::io; use io;
use byteorder::{LittleEndian, ReadBytesExt}; use byteorder::LittleEndian;
use byteorder_ext::ReadBytesExt;
use file::File; use file::File;
use dir::{DirRawStream, Dir}; use dir::{DirRawStream, Dir};
use dir_entry::DIR_ENTRY_SIZE; use dir_entry::DIR_ENTRY_SIZE;
use table::{ClusterIterator, alloc_cluster, read_fat_flags}; use table::{ClusterIterator, alloc_cluster, read_fat_flags};
#[cfg(not(feature = "std"))]
use alloc::{String, string::ToString};
// FAT implementation based on: // FAT implementation based on:
// http://wiki.osdev.org/FAT // http://wiki.osdev.org/FAT
// https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html // https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html

View File

@ -1,8 +1,10 @@
#![crate_type = "lib"] #![crate_type = "lib"]
#![crate_name = "fatfs"] #![crate_name = "fatfs"]
#![cfg_attr(not(feature="std"), no_std)]
#![cfg_attr(not(feature="std"), feature(alloc))]
extern crate byteorder; extern crate byteorder;
extern crate core;
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
@ -13,6 +15,13 @@ extern crate log;
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
extern crate chrono; extern crate chrono;
#[cfg(not(feature = "std"))]
extern crate core_io;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
mod fs; mod fs;
mod dir; mod dir;
mod dir_entry; mod dir_entry;
@ -20,6 +29,21 @@ mod file;
mod table; mod table;
mod utils; mod utils;
#[cfg(not(feature = "std"))]
mod byteorder_core_io;
#[cfg(not(feature = "std"))]
use byteorder_core_io as byteorder_ext;
#[cfg(feature = "std")]
use byteorder as byteorder_ext;
#[cfg(feature = "std")]
use std as core;
#[cfg(not(feature = "std"))]
use core_io as io;
#[cfg(feature = "std")]
use std::io as io;
pub use fs::*; pub use fs::*;
pub use dir::*; pub use dir::*;
pub use dir_entry::*; pub use dir_entry::*;

View File

@ -1,6 +1,7 @@
use std::io; use io;
use std::io::prelude::*; use io::prelude::*;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::LittleEndian;
use byteorder_ext::{ReadBytesExt, WriteBytesExt};
use fs::{FatType, FsStatusFlags, DiskSlice, ReadSeek}; use fs::{FatType, FsStatusFlags, DiskSlice, ReadSeek};
struct Fat<T> { struct Fat<T> {

View File

@ -1,6 +1,6 @@
use std::io::prelude::*; use io::prelude::*;
use std::io; use io;
use std::cmp; use core::cmp;
pub trait ReadSeek: Read + Seek {} pub trait ReadSeek: Read + Seek {}
impl<T> ReadSeek for T where T: Read + Seek {} impl<T> ReadSeek for T where T: Read + Seek {}