Jo Engine  2023.08.26
Jo Sega Saturn Engine
backup.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, 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 */
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 
53 typedef enum
54 {
59 
61 typedef enum
62 {
71 
73 typedef 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 
98 bool jo_backup_mount(const jo_backup_device backup_device);
99 
104 bool jo_backup_unmount(const jo_backup_device backup_device);
105 
111 bool jo_backup_read_device(const jo_backup_device backup_device, jo_list * const filenames);
112 
118 bool jo_backup_file_exists(const jo_backup_device backup_device, const char * const fname);
119 
124 bool jo_backup_format_device(const jo_backup_device backup_device);
125 
130 
136 
145 static __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 
150  jo_backup_init_file(&bkp);
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 
164 bool jo_backup_delete_file(const jo_backup_device backup_device, const char * const fname);
165 
172 bool jo_backup_get_file_last_modified_date(const jo_backup_device backup_device, const char * const fname, jo_datetime *datetime);
173 
181 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);
182 
193 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);
194 
200 unsigned char *jo_backup_load_file_comment(const jo_backup_device backup_device, const char * const fname);
201 
208 void *jo_backup_load_file_contents(const jo_backup_device backup_device, const char * const fname, unsigned int *length);
209 
215 unsigned 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::save_datetime
jo_datetime save_datetime
Definition: backup.h:91
jo_backup_get_file_last_modified_date
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_format_device
bool jo_backup_format_device(const jo_backup_device backup_device)
Format the device (all data is lost)
jo_datetime
DateTime struct.
Definition: tools.h:197
JoCartridgeMemoryBackup
@ JoCartridgeMemoryBackup
Definition: backup.h:56
jo_backup_get_file_info
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.
JoExternalDeviceBackup
@ JoExternalDeviceBackup
Definition: backup.h:57
jo_backup::contents
void * contents
Definition: backup.h:78
jo_backup_get_file_partition
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.
jo_backup_get_last_status
jo_backup_status jo_backup_get_last_status(const jo_backup_device backup_device)
Get last backup status (error details)
jo_backup_load_file_contents
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.
jo_backup_save
bool jo_backup_save(jo_backup *file)
Save file contents to the backup device (if the file exists it will be overwritten)
jo_backup_load_file_comment
unsigned char * jo_backup_load_file_comment(const jo_backup_device backup_device, const char *const fname)
Load file comment from the backup device.
JoBackupStatusUnknown
@ JoBackupStatusUnknown
Definition: backup.h:69
JoBackupStatusWriteProtect
@ JoBackupStatusWriteProtect
Definition: backup.h:64
jo_backup
Backup File struct.
Definition: backup.h:74
jo_backup_delete_file
bool jo_backup_delete_file(const jo_backup_device backup_device, const char *const fname)
Delete file on the backup device.
JoBackupStatusOutOfMemory
@ JoBackupStatusOutOfMemory
Definition: backup.h:65
jo_backup::backup_device
jo_backup_device backup_device
Definition: backup.h:75
jo_backup::fname
char * fname
Definition: backup.h:76
jo_backup_get_free_block_count
int jo_backup_get_free_block_count(const jo_backup_device backup_device)
Get free block count on the backup device.
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: types.h:39
JoBackupStatusNotFound
@ JoBackupStatusNotFound
Definition: backup.h:66
jo_backup::language_num
unsigned char language_num
Definition: backup.h:87
jo_backup::comment
char * comment
Definition: backup.h:77
jo_language
jo_language
Language type.
Definition: tools.h:210
jo_backup_get_file_size
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.
jo_backup_mount
bool jo_backup_mount(const jo_backup_device backup_device)
Mount the backup device (must be the first call)
jo_list
List struct.
Definition: list.h:74
JoBackupStatusOk
@ JoBackupStatusOk
Definition: backup.h:63
jo_backup::partition_number
unsigned short partition_number
Definition: backup.h:83
jo_backup_unmount
bool jo_backup_unmount(const jo_backup_device backup_device)
Unmount the backup device (optional)
JoBackupStatusNoMatch
@ JoBackupStatusNoMatch
Definition: backup.h:67
jo_backup_status
jo_backup_status
Backup status.
Definition: backup.h:62
jo_backup::save_timestamp
unsigned int save_timestamp
Definition: backup.h:89
jo_backup_init_file
void jo_backup_init_file(jo_backup *file)
Initialize a backup file in order to save it.
jo_backup::content_size
unsigned int content_size
Definition: backup.h:79
jo_backup_file_exists
bool jo_backup_file_exists(const jo_backup_device backup_device, const char *const fname)
Check if file exists.
jo_backup_save_file_contents
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
JoInternalMemoryBackup
@ JoInternalMemoryBackup
Definition: backup.h:55
jo_backup::language
jo_language language
Definition: backup.h:85
jo_backup_device
jo_backup_device
Backup device type.
Definition: backup.h:54
JoBackupStatusBroken
@ JoBackupStatusBroken
Definition: backup.h:68
jo_backup_read_device
bool jo_backup_read_device(const jo_backup_device backup_device, jo_list *const filenames)
Read backup device.
jo_backup_get_total_block_count
int jo_backup_get_total_block_count(const jo_backup_device backup_device)
Get total block count on the backup device.