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};
56  FileID id{0};
58  ACL acl{UserRole::None, UserRole::None};
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;
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
uint32_t file_size_t
Definition: Components/IFS/src/include/IFS/Types.h:50
Installable File System base class.
Definition: IFileSystem.h:100
Provides formatted output to stream.
Definition: Print.h:37
IFS::Directory Directory
Definition: Core/FileSystem.h:33
Definition: DirectoryTemplate.h:37
uint32_t FileID
File identifier.
Definition: Stat.h:47
int16_t FileHandle
File handle.
Definition: Stat.h:40
Definition: Access.h:34
A compression descriptor.
Definition: Compression.h:38
defines a 'safe' name buffer
Definition: NameBuffer.h:44
int copy(const char *src, uint16_t srclen)
copies text from a source buffer into a name buffer
Definition: NameBuffer.h:95
version of Stat with integrated name buffer
Definition: Stat.h:103
NameStat & operator=(const Stat &rhs)
Definition: Stat.h:114
NameStat()
Definition: Stat.h:105
NameStat(const Stat &other)
Definition: Stat.h:109
File Status structure.
Definition: Stat.h:52
bool isDir() const
Is this a directory (or mountpoint) ?
Definition: Stat.h:91
Stat(char *namebuf, uint16_t bufsize)
Definition: Stat.h:66
Stat & operator=(const Stat &rhs)
assign content from another Stat structure
Definition: Stat.h:75
ACL acl
Access Control.
Definition: Stat.h:58
TimeStamp mtime
File modification time.
Definition: Stat.h:57
FileID id
Internal file identifier.
Definition: Stat.h:56
IFileSystem * fs
The filing system owning this file.
Definition: Stat.h:53
NameBuffer name
Name of file.
Definition: Stat.h:54
FileAttributes attr
Definition: Stat.h:59
Compression compression
Definition: Stat.h:60
Stat()
Definition: Stat.h:62
file_size_t size
Size of file in bytes.
Definition: Stat.h:55
size_t printTo(Print &p) const
Manage IFS timestamps stored as an unsigned 32-bit value.
Definition: TimeStamp.h:37