libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_fs_utils.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuDirEntry and common filesystem utilities
3 * \ingroup file_system
4 *
5 * This file contains accessors for EvmuDirEntry as
6 * well as other general-purpose filesystem related
7 * functionality.
8 *
9 * \author 2023 Falco Girgis
10 * \copyright MIT License
11 */
12#ifndef EVMU_FS_UTILS_H
13#define EVMU_FS_UTILS_H
14
15#include "../evmu_api.h"
16#include <gimbal/utils/gimbal_date_time.h>
17
18/*! \name Directory Entry Info
19 * \brief Struct and field sizes for EvmuDirEntry
20 * @{
21 */
22#define EVMU_DIRECTORY_ENTRY_SIZE 32 //!< Size in bytes of a directory entry
23#define EVMU_DIRECTORY_FILE_NAME_SIZE 12 //!< Maximum file name size in bytes for a directory entry (no NULL terminator)
24#define EVMU_DIRECTORY_UNUSED_SIZE 4 //!< Size of unused region in a directory entry
25//! @}
26
27GBL_DECLS_BEGIN
28
29//! Type of file stored on the filesystem
30typedef enum EVMU_FILE_TYPE {
31 EVMU_FILE_TYPE_NONE = 0x00, //!< Not a file
32 EVMU_FILE_TYPE_DATA = 0x33, //!< Save DATA file
33 EVMU_FILE_TYPE_GAME = 0xcc //!< Mini GAME file
34} EVMU_FILE_TYPE;
35
36//! Copy protection type byte
38 EVMU_COPY_ALLOWED = 0x00, //!< Not copy protected
39 EVMU_COPY_PROTECTED = 0xff, //!< Copy protected
40 EVMU_COPY_UNKNOWN = 0x01 //!< Unknown/Other
41} EVMU_COPY_PROTECTION;
42
43
44//! Properties for creating a new file on flash
45typedef struct EvmuNewFileInfo {
46 //! Name on the filesystem (see EvmuDirEntry::fileName)
48 size_t bytes; //!< Size in bytes
49 uint8_t type; //!< File type
50 uint8_t copy; //!< Copy protection setting
51} EvmuNewFileInfo;
52
53//! Filesystem timestamp, stored in BCD format
54typedef struct EvmuTimestamp {
55 uint8_t century; //!< Date century (first two digits) (BCD)
56 uint8_t year; //!< Date year (last two digits) (BCD)
57 uint8_t month; //!< Date month (1-12) (BCD)
58 uint8_t day; //!< Date day (1-31) (BCD)
59 uint8_t hour; //!< Time hour (0-23) (BCD)
60 uint8_t minute; //!< Time minute (0-59) (BCD)
61 uint8_t second; //!< Time second (0-59) (BCD)
62 uint8_t weekDay; //!< Day of the week (0-6) (BCD)
63} EvmuTimestamp;
64
65/*! Represents a single entry into the FAT directory
66 * \ingroup file_system
67 */
68typedef struct EvmuDirEntry {
69 uint8_t fileType; //!< EVMU_FILE_TYPE for file
70 uint8_t copyProtection; //!< EVMU_COPY_TYPE for file
71 uint16_t firstBlock; //!< Location of first FAT block
72 //! File name: Shift-JS encoding without NULL terminator
74 EvmuTimestamp timestamp; //!< File creation date timestamp
75 uint16_t fileSize; //!< Size of file in blocks
76 uint16_t headerOffset; //!< Offset of VMS header in blocks (1 for GAME, 0 for DATA)
77 //! Unused/reserved bytes (all 0s)
79} EvmuDirEntry;
80
81//! User callabck for iterating over all directory entries, return GBL_TRUE to break early
82typedef GblBool (*EvmuDirEntryIterFn)(EvmuDirEntry* pEntry, void* pClosure);
83
84GBL_STATIC_ASSERT(sizeof(EvmuDirEntry) == 32);
85
86/*! \name Accessor Methods
87 * \brief EvmuDirEntry read/write methods
88 * \relatesalso EvmuDirEntry
89 * @{
90 */
91//! Fills the buffer with the EvmuDirEntry::fileName field and returns a pointer to its internal C string
92EVMU_EXPORT const char* EvmuDirEntry_name (const EvmuDirEntry* pSelf,
93 GblStringBuffer* pStr) GBL_NOEXCEPT;
94//! Writes the given string to the EvmuDirEntry::fileName field, returning number of bytes written
95EVMU_EXPORT size_t EvmuDirEntry_setName (EvmuDirEntry* pSelf,
96 const char* pStr) GBL_NOEXCEPT;
97//! Returns the a string representation of EvmuDirEntry::fileType
98EVMU_EXPORT const char* EvmuDirEntry_fileTypeStr (const EvmuDirEntry* pSelf) GBL_NOEXCEPT;
99//! Returns the a string representation of EvmuDirEntry::copyProtection
100EVMU_EXPORT const char* EvmuDirEntry_protectedStr (const EvmuDirEntry* pSelf) GBL_NOEXCEPT;
101//! @}
102
103/*! \name Conversion Methods
104 * \brief Methods for going to/from GblDateTime
105 * \relatesalso EvmuTimestamp
106 * @{
107 */
108//! Converts the given EvmuTimestamp into the given GblDateTime, also returning it
109EVMU_EXPORT GblDateTime* EvmuTimestamp_dateTime (const EvmuTimestamp* pSelf,
110 GblDateTime* pDateTime) GBL_NOEXCEPT;
111//! Converts the given GblDateTime into an EvmuTimestamp
112EVMU_EXPORT void EvmuTimestamp_setDateTime (EvmuTimestamp* pSelf,
113 const GblDateTime* pDateTime) GBL_NOEXCEPT;
114//! @}
115
116/*! \name Accessor Methods
117 * \brief Method(s) for EvmuNewFileInfo
118 * \relatesalso EvmuNewFileInfo
119 * @{
120 */
121//! Initializes an EvmuNewFileInfo structure with the given properties
122EVMU_EXPORT void EvmuNewFileInfo_init(EvmuNewFileInfo* pSelf,
123 const char* pFileName,
124 size_t fileSize,
125 EVMU_FILE_TYPE fileType,
126 EVMU_COPY_PROTECTION copyProtection) GBL_NOEXCEPT;
127//! Populates the GblStringBuffer with the filename, returning a pointer to its internal storage
128EVMU_EXPORT const char* EvmuNewFileInfo_name(const EvmuNewFileInfo* pSelf,
129 GblStringBuffer* pBuffer) GBL_NOEXCEPT;
130//! @}
131
132GBL_DECLS_END
133
134#endif // EVMU_FS_UTILS_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
#define EVMU_DIRECTORY_UNUSED_SIZE
#define EVMU_DIRECTORY_FILE_NAME_SIZE
Maximum file name size in bytes for a directory entry (no NULL terminator)
EVMU_FILE_TYPE
Type of file stored on the filesystem.
@ EVMU_FILE_TYPE_NONE
Not a file.
@ EVMU_FILE_TYPE_DATA
Save DATA file.
@ EVMU_FILE_TYPE_GAME
Mini GAME file.
EVMU_COPY_PROTECTION
Copy protection type byte.
@ EVMU_COPY_ALLOWED
Not copy protected.
@ EVMU_COPY_UNKNOWN
Unknown/Other.
@ EVMU_COPY_PROTECTED
Copy protected.
uint8_t GblBool
Represents a single entry into the FAT directory.
uint8_t copyProtection
EVMU_COPY_TYPE for file.
uint8_t unused[4]
Unused/reserved bytes (all 0s)
const char * EvmuDirEntry_fileTypeStr(const EvmuDirEntry *pSelf)
Returns the a string representation of EvmuDirEntry::fileType.
const char * EvmuDirEntry_protectedStr(const EvmuDirEntry *pSelf)
Returns the a string representation of EvmuDirEntry::copyProtection.
const char * EvmuDirEntry_name(const EvmuDirEntry *pSelf, GblStringBuffer *pStr)
Fills the buffer with the EvmuDirEntry::fileName field and returns a pointer to its internal C string...
uint16_t headerOffset
size_t EvmuDirEntry_setName(EvmuDirEntry *pSelf, const char *pStr)
Writes the given string to the EvmuDirEntry::fileName field, returning number of bytes written.
uint16_t firstBlock
char fileName[12]
File name: Shift-JS encoding without NULL terminator.
uint16_t fileSize
Size of file in blocks.
EvmuTimestamp timestamp
File creation date timestamp.
uint8_t fileType
EVMU_FILE_TYPE for file.
Properties for creating a new file on flash.
char name[12]
Name on the filesystem (see EvmuDirEntry::fileName)
uint8_t copy
Copy protection setting.
size_t bytes
Size in bytes.
void EvmuNewFileInfo_init(EvmuNewFileInfo *pSelf, const char *pFileName, size_t fileSize, EVMU_FILE_TYPE fileType, EVMU_COPY_PROTECTION copyProtection)
Initializes an EvmuNewFileInfo structure with the given properties.
uint8_t type
File type.
const char * EvmuNewFileInfo_name(const EvmuNewFileInfo *pSelf, GblStringBuffer *pBuffer)
Populates the GblStringBuffer with the filename, returning a pointer to its internal storage.
Filesystem timestamp, stored in BCD format.
uint8_t year
Date year (last two digits) (BCD)
uint8_t day
Date day (1-31) (BCD)
uint8_t century
Date century (first two digits) (BCD)
void EvmuTimestamp_setDateTime(EvmuTimestamp *pSelf, const GblDateTime *pDateTime)
Converts the given GblDateTime into an EvmuTimestamp.
uint8_t hour
Time hour (0-23) (BCD)
uint8_t minute
Time minute (0-59) (BCD)
uint8_t month
Date month (1-12) (BCD)
uint8_t weekDay
Day of the week (0-6) (BCD)
GblDateTime * EvmuTimestamp_dateTime(const EvmuTimestamp *pSelf, GblDateTime *pDateTime)
Converts the given EvmuTimestamp into the given GblDateTime, also returning it.
uint8_t second
Time second (0-59) (BCD)