Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
backup.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
35
36#ifndef __JO_BACKUP_H__
37# define __JO_BACKUP_H__
38
39# ifdef JO_COMPILE_WITH_BACKUP_SUPPORT
40
42# define JO_BACKUP_MAX_FILENAME_LENGTH (12)
43
45# define JO_BACKUP_MAX_FILE (255)
46
48# define JO_BACKUP_MAX_COMMENT_LENGTH (10)
49
59
71
73typedef struct
74{
76 char *fname;
77 char *comment;
78 void *contents;
79 unsigned int content_size;
80
81 /* ▲ Fields bellow are optional ▲ */
82
83 unsigned short partition_number;
84
86 /* OR */
87 unsigned char language_num;
88
89 unsigned int save_timestamp;
90 /* OR */
92} jo_backup;
93
98bool jo_backup_mount(const jo_backup_device backup_device);
99
104bool jo_backup_unmount(const jo_backup_device backup_device);
105
111bool jo_backup_read_device(const jo_backup_device backup_device, jo_list * const filenames);
112
118bool jo_backup_file_exists(const jo_backup_device backup_device, const char * const fname);
119
125
130
136
145static __jo_force_inline bool jo_backup_save_file_contents(const jo_backup_device backup_device, char * const fname, char * const comment,
146 void *contents, unsigned int content_size)
147{
148 jo_backup bkp;
149
151 bkp.backup_device = backup_device;
152 bkp.fname = fname;
153 bkp.comment = comment;
154 bkp.contents = contents;
155 bkp.content_size = content_size;
156 return (jo_backup_save(&bkp));
157}
158
164bool jo_backup_delete_file(const jo_backup_device backup_device, const char * const fname);
165
172bool jo_backup_get_file_last_modified_date(const jo_backup_device backup_device, const char * const fname, jo_datetime *datetime);
173
181bool jo_backup_get_file_size(const jo_backup_device backup_device, const char * const fname, unsigned int* const num_bytes, unsigned int* const num_blocks);
182
193bool jo_backup_get_file_info(const jo_backup_device backup_device, const char * const fname, char* const comment, unsigned char* const language_num, unsigned int* const date, unsigned int* const num_bytes, unsigned int* const num_blocks);
194
200unsigned char *jo_backup_load_file_comment(const jo_backup_device backup_device, const char * const fname);
201
208void *jo_backup_load_file_contents(const jo_backup_device backup_device, const char * const fname, unsigned int *length);
209
215unsigned short jo_backup_get_file_partition(const jo_backup_device backup_device, const char * const fname);
216
222
228
234
235#endif /* !JO_COMPILE_WITH_BACKUP_SUPPORT */
236
237#endif /* !__JO_BACKUP_H__ */
238
239/*
240** END OF FILE
241*/
jo_backup_status
Backup status.
Definition backup.h:62
@ JoBackupStatusOk
Definition backup.h:63
@ JoBackupStatusNoMatch
Definition backup.h:67
@ JoBackupStatusOutOfMemory
Definition backup.h:65
@ JoBackupStatusBroken
Definition backup.h:68
@ JoBackupStatusWriteProtect
Definition backup.h:64
@ JoBackupStatusNotFound
Definition backup.h:66
@ JoBackupStatusUnknown
Definition backup.h:69
bool jo_backup_mount(const jo_backup_device backup_device)
Mount the backup device (must be the first call).
bool jo_backup_format_device(const jo_backup_device backup_device)
Format the device (all data is lost).
bool jo_backup_file_exists(const jo_backup_device backup_device, const char *const fname)
Check if file exists.
jo_datetime save_datetime
Definition backup.h:91
unsigned char language_num
Definition backup.h:87
unsigned int save_timestamp
Definition backup.h:89
jo_backup_status jo_backup_get_last_status(const jo_backup_device backup_device)
Get last backup status (error details).
static __jo_force_inline bool jo_backup_save_file_contents(const jo_backup_device backup_device, char *const fname, char *const comment, void *contents, unsigned int content_size)
Save file contents to the backup device (if the file exists it will be overwritten).
Definition backup.h:145
bool jo_backup_get_file_last_modified_date(const jo_backup_device backup_device, const char *const fname, jo_datetime *datetime)
Get file last modified date on the backup device.
jo_backup_device
Backup device type.
Definition backup.h:54
@ JoInternalMemoryBackup
Definition backup.h:55
@ JoCartridgeMemoryBackup
Definition backup.h:56
@ JoExternalDeviceBackup
Definition backup.h:57
bool jo_backup_get_file_size(const jo_backup_device backup_device, const char *const fname, unsigned int *const num_bytes, unsigned int *const num_blocks)
Get file size in bytes and blocks.
int jo_backup_get_total_block_count(const jo_backup_device backup_device)
Get total block count on the backup device.
unsigned int content_size
Definition backup.h:79
bool jo_backup_save(jo_backup *file)
Save file contents to the backup device (if the file exists it will be overwritten).
unsigned short jo_backup_get_file_partition(const jo_backup_device backup_device, const char *const fname)
Get the partition number where the file is located.
bool jo_backup_get_file_info(const jo_backup_device backup_device, const char *const fname, char *const comment, unsigned char *const language_num, unsigned int *const date, unsigned int *const num_bytes, unsigned int *const num_blocks)
Get file comment, language, date, and size in bytes and blocks.
char * comment
Definition backup.h:77
void jo_backup_init_file(jo_backup *file)
Initialize a backup file in order to save it.
void * jo_backup_load_file_contents(const jo_backup_device backup_device, const char *const fname, unsigned int *length)
Load file contents from the backup device.
unsigned short partition_number
Definition backup.h:83
bool jo_backup_read_device(const jo_backup_device backup_device, jo_list *const filenames)
Read backup device.
jo_language language
Definition backup.h:85
int jo_backup_get_free_block_count(const jo_backup_device backup_device)
Get free block count on the backup device.
unsigned char * jo_backup_load_file_comment(const jo_backup_device backup_device, const char *const fname)
Load file comment from the backup device.
bool jo_backup_delete_file(const jo_backup_device backup_device, const char *const fname)
Delete file on the backup device.
void * contents
Definition backup.h:78
jo_backup_device backup_device
Definition backup.h:75
char * fname
Definition backup.h:76
bool jo_backup_unmount(const jo_backup_device backup_device)
Unmount the backup device (optional).
Backup File struct.
Definition backup.h:74
List struct.
Definition list.h:74
jo_language
Language type.
Definition tools.h:279
DateTime struct.
Definition tools.h:266
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39