Jo Engine 2026.11.6
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
40# define JO_BACKUP_MAX_FILENAME_LENGTH (12)
41
43# define JO_BACKUP_MAX_FILE (255)
44
46# define JO_BACKUP_MAX_COMMENT_LENGTH (10)
47
57
69
71typedef struct
72{
74 char *fname;
75 char *comment;
76 void *contents;
77 unsigned int content_size;
78
79 /* ▲ Fields bellow are optional ▲ */
80
81 unsigned short partition_number;
82
84 /* OR */
85 unsigned char language_num;
86
87 unsigned int save_timestamp;
88 /* OR */
90} jo_backup;
91
96bool jo_backup_mount(const jo_backup_device backup_device);
97
102bool jo_backup_unmount(const jo_backup_device backup_device);
103
109bool jo_backup_read_device(const jo_backup_device backup_device, jo_list * const filenames);
110
116bool jo_backup_file_exists(const jo_backup_device backup_device, const char * const fname);
117
123
128
134
143static __jo_force_inline bool jo_backup_save_file_contents(const jo_backup_device backup_device, char * const fname, char * const comment,
144 void *contents, unsigned int content_size)
145{
146 jo_backup bkp;
147
149 bkp.backup_device = backup_device;
150 bkp.fname = fname;
151 bkp.comment = comment;
152 bkp.contents = contents;
153 bkp.content_size = content_size;
154 return (jo_backup_save(&bkp));
155}
156
162bool jo_backup_delete_file(const jo_backup_device backup_device, const char * const fname);
163
170bool jo_backup_get_file_last_modified_date(const jo_backup_device backup_device, const char * const fname, jo_datetime *datetime);
171
179bool 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);
180
191bool 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);
192
198unsigned char *jo_backup_load_file_comment(const jo_backup_device backup_device, const char * const fname);
199
206void *jo_backup_load_file_contents(const jo_backup_device backup_device, const char * const fname, unsigned int *length);
207
213unsigned short jo_backup_get_file_partition(const jo_backup_device backup_device, const char * const fname);
214
220
226
232
233#endif /* !__JO_BACKUP_H__ */
234
235/*
236** END OF FILE
237*/
jo_backup_status
Backup status.
Definition backup.h:60
@ JoBackupStatusOk
Definition backup.h:61
@ JoBackupStatusNoMatch
Definition backup.h:65
@ JoBackupStatusOutOfMemory
Definition backup.h:63
@ JoBackupStatusBroken
Definition backup.h:66
@ JoBackupStatusWriteProtect
Definition backup.h:62
@ JoBackupStatusNotFound
Definition backup.h:64
@ JoBackupStatusUnknown
Definition backup.h:67
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:89
unsigned char language_num
Definition backup.h:85
unsigned int save_timestamp
Definition backup.h:87
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:143
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:52
@ JoInternalMemoryBackup
Definition backup.h:53
@ JoCartridgeMemoryBackup
Definition backup.h:54
@ JoExternalDeviceBackup
Definition backup.h:55
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:77
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:75
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:81
bool jo_backup_read_device(const jo_backup_device backup_device, jo_list *const filenames)
Read backup device.
jo_language language
Definition backup.h:83
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:76
jo_backup_device backup_device
Definition backup.h:73
char * fname
Definition backup.h:74
bool jo_backup_unmount(const jo_backup_device backup_device)
Unmount the backup device (optional).
Backup File struct.
Definition backup.h:72
List struct.
Definition list.h:74
jo_language
Language type.
Definition tools.h:317
DateTime struct.
Definition tools.h:304
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39