commit 55d36f29b11474b54f680cbed7a3dbcfea4c7bbc Author: Nicolas Stalder Date: Sun Dec 8 03:36:55 2019 +0100 Expose v2.1.4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6936990 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +Cargo.lock diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0c7625c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "littlefs"] + path = littlefs + url = https://github.com/ARMmbed/littlefs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..959bd01 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "littlefs2-sys" +description = "Low-level bindings to LittleFS" +version = "0.1.0" +authors = ["Nicolas Stalder "] +edition = "2018" +license = "BSD-3-Clause" +readme = "README.md" +categories = ["embedded", "filesystem", "no-std"] +repository = "https://github.com/nickray/littlefs2-sys" + +[dependencies] +cty = "0.2.1" + +[build-dependencies] +bindgen = "0.52.0" +cc = "1.0.25" diff --git a/LICENSE-BSD3 b/LICENSE-BSD3 new file mode 100644 index 0000000..ed69bea --- /dev/null +++ b/LICENSE-BSD3 @@ -0,0 +1,24 @@ +Copyright (c) 2017, Arm Limited. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name of ARM nor the names of its contributors may be used to + endorse or promote products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a5dcf53 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +

littlefs2-sys

+
+ + Low-level bindings to LittleFS + +
+ +
+ +
+ + + Crates.io version + + + + Download + + + + main branch API docs + +
+ +## What is this? + +Low-level bindings to the [littlefs](littlefs) microcontroller filesystem. + +[littlefs]: https://github.com/ARMmbed/littlefs + +Currently, release v2.1.4 is exposed. + +#### License + +LittleFS licensed under [BSD-3-Clause](LICENSE-BSD3), as are these bindings. +
+The file `strings.c` is licensed under GPL-2.0 diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..c120602 --- /dev/null +++ b/build.rs @@ -0,0 +1,28 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + cc::Build::new() + .flag("-std=c11") + .flag("-DLFS_NO_MALLOC") + .flag("-DLFS_NO_ASSERT") + .flag("-DLFS_NO_DEBUG") + .flag("-DLFS_NO_WARN") + .flag("-DLFS_NO_ERROR") + .file("littlefs/lfs.c") + .file("littlefs/lfs_util.c") + .file("string.c") + .compile("lfs-sys"); + + let bindings = bindgen::Builder::default() + .header("littlefs/lfs.h") + .use_core() + .ctypes_prefix("cty") + .generate() + .expect("Unable to generate bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/littlefs b/littlefs new file mode 160000 index 0000000..ce2c01f --- /dev/null +++ b/littlefs @@ -0,0 +1 @@ +Subproject commit ce2c01f098f4d2b9479de5a796c3bb531f1fe14c diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..4e4ebb6 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +#![no_std] +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/string.c b/string.c new file mode 100644 index 0000000..a2ab96c --- /dev/null +++ b/string.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * linux/lib/string.c + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +#include + +size_t strspn(const char *s, const char *accept) +{ + const char *p; + const char *a; + size_t count = 0; + + for (p = s; *p != '\0'; ++p) { + for (a = accept; *a != '\0'; ++a) { + if (*p == *a) + break; + } + if (*a == '\0') + return count; + ++count; + } + return count; +} + +size_t strcspn(const char *s, const char *reject) +{ + const char *p; + const char *r; + size_t count = 0; + + for (p = s; *p != '\0'; ++p) { + for (r = reject; *r != '\0'; ++r) { + if (*p == *r) + return count; + } + ++count; + } + return count; +} + +size_t strlen(const char *s) +{ + const char *sc; + + for (sc = s; *sc != '\0'; ++sc) + /* nothing */; + return sc - s; +} + +char *strchr(const char *s, int c) +{ + for (; *s != (char)c; ++s) + if (*s == '\0') + return NULL; + return (char *)s; +}