1use core::ffi::CStr;
2
3use alloc::ffi::CString;
4
5use crate::sys::*;
6
7extern crate alloc;
8
9pub struct Spiffs {
11 partition: CString,
12}
13
14impl Spiffs {
15 pub unsafe fn new(partition_label: &str) -> Result<Self, EspError> {
26 Ok(Self {
27 partition: crate::private::cstr::to_cstring_arg(partition_label)?,
28 })
29 }
30
31 pub fn partition_label(&self) -> &CStr {
33 &self.partition
34 }
35
36 pub fn check(&mut self) -> Result<(), EspError> {
38 esp!(unsafe { esp_spiffs_check(self.partition.as_ptr()) })
39 }
40
41 pub fn format(&mut self) -> Result<(), EspError> {
43 esp!(unsafe { esp_spiffs_format(self.partition.as_ptr()) })
44 }
45
46 #[cfg(not(esp_idf_version_major = "4"))]
48 pub fn gc(&mut self, size_to_gc: usize) -> Result<(), EspError> {
49 esp!(unsafe { esp_spiffs_gc(self.partition.as_ptr(), size_to_gc) })
50 }
51}