Stat.h
Go to the documentation of this file.
1 /****
2  * Stat.h
3  *
4  * Created: August 2018
5  *
6  * Copyright 2019 mikee47 <mike@sillyhouse.net>
7  *
8  * This file is part of the IFS Library
9  *
10  * This library is free software: you can redistribute it and/or modify it under the terms of the
11  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with this library.
18  * If not, see <https://www.gnu.org/licenses/>.
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "NameBuffer.h"
25 #include "TimeStamp.h"
26 #include "Access.h"
27 #include "Compression.h"
28 #include "FileAttributes.h"
29 #include <Printable.h>
30 
31 namespace IFS
32 {
33 class IFileSystem;
34 
40 using FileHandle = int16_t;
41 
47 using FileID = uint32_t;
48 
52 struct Stat {
53  IFileSystem* fs{nullptr};
54  NameBuffer name;
55  file_size_t size{0};
56  FileID id{0};
57  TimeStamp mtime{};
58  ACL acl{UserRole::None, UserRole::None};
60  Compression compression{};
61 
62  Stat()
63  {
64  }
65 
66  Stat(char* namebuf, uint16_t bufsize) : name(namebuf, bufsize)
67  {
68  }
69 
75  Stat& operator=(const Stat& rhs)
76  {
77  fs = rhs.fs;
78  name.copy(rhs.name);
79  size = rhs.size;
80  id = rhs.id;
81  compression = rhs.compression;
82  attr = rhs.attr;
83  acl = rhs.acl;
84  mtime = rhs.mtime;
85  return *this;
86  }
87 
91  bool isDir() const
92  {
94  }
95 
96  size_t printTo(Print& p) const;
97 };
98 
103 struct NameStat : public Stat {
104 public:
105  NameStat() : Stat(buffer, sizeof(buffer))
106  {
107  }
108 
109  NameStat(const Stat& other) : NameStat()
110  {
111  *this = other;
112  }
113 
114  NameStat& operator=(const Stat& rhs)
115  {
116  *static_cast<Stat*>(this) = rhs;
117  return *this;
118  }
119 
120 private:
121  char buffer[256];
122 };
123 
124 } // namespace IFS
FileAttributes attr
Definition: Stat.h:78
uint32_t FileID
File identifier.
Definition: Stat.h:66
NameBuffer name
Name of file.
Definition: Stat.h:73
file_size_t size
Size of file in bytes.
Definition: Stat.h:74
Compression compression
Definition: Stat.h:79
version of Stat with integrated name buffer
Definition: Stat.h:122
TimeStamp mtime
File modification time.
Definition: Stat.h:76
size_t printTo(Print &p) const
Definition: DirectoryTemplate.h:36
NameStat & operator=(const Stat &rhs)
Definition: Stat.h:133
Stat()
Definition: Stat.h:81
File Status structure.
Definition: Stat.h:71
NameStat()
Definition: Stat.h:124
int copy(const char *src, uint16_t srclen)
copies text from a source buffer into a name buffer
Definition: NameBuffer.h:133
Provides formatted output to stream.
Definition: Print.h:36
IFS::Directory Directory
Definition: Core/FileSystem.h:33
IFS::FileHandle FileHandle
Definition: Core/FileSystem.h:24
ACL acl
Access Control.
Definition: Stat.h:77
IFileSystem * fs
The filing system owning this file.
Definition: Stat.h:72
Stat & operator=(const Stat &rhs)
assign content from another Stat structure
Definition: Stat.h:94
bool isDir() const
Is this a directory (or mountpoint) ?
Definition: Stat.h:110
uint32_t file_size_t
Definition: Components/IFS/src/include/IFS/Types.h:50