Components/IFS/src/include/IFS/Error.h
Go to the documentation of this file.
1 /****
2  * Error.h
3  * IFS Error codes and related stuff
4  *
5  * Created: August 2018
6  *
7  * Copyright 2019 mikee47 <mike@sillyhouse.net>
8  *
9  * This file is part of the IFS Library
10  *
11  * This library is free software: you can redistribute it and/or modify it under the terms of the
12  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with this library.
19  * If not, see <https://www.gnu.org/licenses/>.
20  *
21  ****/
22 
29 #pragma once
30 
31 #include "Types.h"
32 
33 namespace IFS
34 {
35 using ErrorCode = int;
36 
37 namespace Error
38 {
51 #define IFS_ERROR_MAP(XX) \
52  XX(Success, "Success") \
53  XX(NoFileSystem, "File system has not been set") \
54  XX(NoPartition, "Partition not found / undefined") \
55  XX(BadPartition, "Partition is not valid for this filesystem") \
56  XX(BadVolumeIndex, "Volume index is invalid") \
57  XX(NotMounted, "File system is not mounted") \
58  XX(BadObject, "Malformed filesystem object") \
59  XX(BadFileSystem, "File system corruption detected") \
60  XX(BadParam, "Invalid parameter(s)") \
61  XX(NotImplemented, "File system or method not yet implemented") \
62  XX(NotSupported, "Parameter value not supported") \
63  XX(NoMem, "Memory allocation failed") \
64  XX(NameTooLong, "File name or path is too long for buffer") \
65  XX(BufferTooSmall, "Data is too long for buffer") \
66  XX(NotFound, "Object not found") \
67  XX(Exists, "File/directory exists") \
68  XX(ReadOnly, "Media is read-only") \
69  XX(ReadFailure, "Media read failed") \
70  XX(WriteFailure, "Media write failed") \
71  XX(EraseFailure, "Media erase failed") \
72  XX(InvalidHandle, "File handle is outside valid range") \
73  XX(EndOfObjects, "Last object in filing system has been read") \
74  XX(FileNotOpen, "File handle is valid but the file is not open") \
75  XX(SeekBounds, "seek would give an invalid file offset") \
76  XX(NoMoreFiles, "readdir has no more files to return") \
77  XX(OutOfFileDescs, "Cannot open another file until one is closed") \
78  XX(Denied, "Operation denied") \
79  XX(NoSpace, "No free space") \
80  XX(TooBig, "File size too big")
81 
82 enum class Value {
83 #define XX(tag, text) tag,
85 #undef XX
86  MAX, // Mark end of value range
87 };
88 
89 // Define the Error::xxx codes as negative versions of the enumerated values
90 #define XX(tag, text) constexpr int tag{-int(Value::tag)};
91 IFS_ERROR_MAP(XX)
92 #undef XX
93 
94 constexpr ErrorCode USER{-100}; // Start of user-defined codes
95 constexpr ErrorCode SYSTEM{-1000}; // Non-FWFS filing systems map custom codes starting here
96 
102 String toString(int err);
103 
107 inline bool isSystem(int err)
108 {
109  return err <= SYSTEM;
110 }
111 
115 inline int fromSystem(int syscode)
116 {
117  return (syscode < 0) ? SYSTEM + syscode : syscode;
118 }
119 
123 inline int toSystem(int err)
124 {
125  return isSystem(err) ? (err - SYSTEM) : err;
126 }
127 
128 } // namespace Error
129 
130 constexpr ErrorCode FS_OK = Error::Success;
131 
132 } // namespace IFS
The String class.
Definition: WString.h:137
#define IFS_ERROR_MAP(XX)
IFS return codes.
Definition: Components/IFS/src/include/IFS/Error.h:51
int ErrorCode
Definition: Components/IFS/src/include/IFS/Error.h:35
String toString(int err)
get text for an error code
int fromSystem(int syscode)
Translate system error code into IFS error code.
Definition: Components/IFS/src/include/IFS/Error.h:115
int toSystem(int err)
Translate IFS error code into SYSTEM code.
Definition: Components/IFS/src/include/IFS/Error.h:123
constexpr ErrorCode FS_OK
Definition: Components/IFS/src/include/IFS/Error.h:130
Value
Definition: Components/IFS/src/include/IFS/Error.h:82
bool isSystem(int err)
Determine if the given IFS error code is system-specific.
Definition: Components/IFS/src/include/IFS/Error.h:107
constexpr ErrorCode USER
Definition: Components/IFS/src/include/IFS/Error.h:94
constexpr ErrorCode SYSTEM
Definition: Components/IFS/src/include/IFS/Error.h:95
Definition: DirectoryTemplate.h:37
Error
Definition: Libraries/DiskStorage/src/include/Storage/Disk/Error.h:37