Skip to main content

littlefs_rust/
metadata.rs

1use alloc::string::String;
2use bitflags::bitflags;
3
4/// Type of a filesystem entry.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum FileType {
7    File,
8    Dir,
9}
10
11/// Metadata for a file or directory, as returned by [`Filesystem::stat`](crate::Filesystem::stat).
12#[derive(Debug, Clone)]
13pub struct Metadata {
14    pub file_type: FileType,
15    pub size: u32,
16    pub name: String,
17}
18
19/// A single entry from a directory listing.
20#[derive(Debug, Clone)]
21pub struct DirEntry {
22    pub name: String,
23    pub file_type: FileType,
24    pub size: u32,
25}
26
27bitflags! {
28    /// Flags for opening a file. Combine with `|`.
29    ///
30    /// Common combinations:
31    /// - Read-only: `OpenFlags::READ`
32    /// - Create or overwrite: `OpenFlags::WRITE | OpenFlags::CREATE | OpenFlags::TRUNC`
33    /// - Append: `OpenFlags::WRITE | OpenFlags::CREATE | OpenFlags::APPEND`
34    /// - Create only (fail if exists): `OpenFlags::WRITE | OpenFlags::CREATE | OpenFlags::EXCL`
35    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
36    pub struct OpenFlags: u32 {
37        const READ   = 0x1;
38        const WRITE  = 0x2;
39        const CREATE = 0x100;
40        const EXCL   = 0x200;
41        const TRUNC  = 0x400;
42        const APPEND = 0x800;
43    }
44}
45
46/// Position for [`File::seek`](crate::File::seek).
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum SeekFrom {
49    /// Start of file.
50    Start(u32),
51    /// Current position (offset can be negative).
52    Current(i32),
53    /// End of file (offset can be negative).
54    End(i32),
55}