sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
libapa.h
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
15#ifndef __LIBAPA_H__
16#define __LIBAPA_H__
17
18#include <types.h>
19#include <hdd-ioctl.h>
20
21#ifndef APA_OPT_H
22#define APA_OPT_H "apa-opt.h"
23#endif
24
25#include APA_OPT_H
26
27// Sectors for this and that ;)
28#define APA_SECTOR_MBR 0
29#ifdef APA_SUPPORT_GPT
30#define APA_SECTOR_SECTOR_ERROR 34 // 6 use for last sector that had a error...
31#else
32// TODO: In DVRP firmware, the following value is 0x1000 when 48-bit
33#define APA_SECTOR_SECTOR_ERROR 6 // 6 use for last sector that had a error...
34#endif
35#define APA_SECTOR_PART_ERROR APA_SECTOR_SECTOR_ERROR + 1 // 7 use for last partition that had a error...
36#define APA_SECTOR_APAL APA_SECTOR_PART_ERROR + 1 // 8
37#define APA_SECTOR_APAL_HEADERS APA_SECTOR_APAL + 2 // 10-262
38#define APA_SECTOR_MIN_OSDSTART APA_SECTOR_APAL_HEADERS + 252 + 1 // OSD program cannot overlap the journal
39
40// APA Partition
41#define APA_MAGIC 0x00415041 // 'APA\0'
42#define APA_MBR_VERSION 2
43
44#define APA_MODVER ((APA_MODVER_MAJOR << 8) | APA_MODVER_MINOR)
45
46typedef struct
47{
48 u8 unused;
49 u8 sec;
50 u8 min;
51 u8 hour;
52 u8 day;
53 u8 month;
54 u16 year;
56
57//
58// MAIN APA defines/struct
59//
60typedef struct
61{
62 u32 start; // Sector address
63 u32 length; // Sector count
64} apa_sub_t;
65
66typedef struct
67{
68 u32 checksum;
69 u32 magic; // APA_MAGIC
70 u32 next;
71 u32 prev;
72 char id[APA_IDMAX];
73 char rpwd[APA_PASSMAX];
74 char fpwd[APA_PASSMAX];
75 u32 start;
76 u32 length;
77 u16 type;
78 u16 flags;
79 u32 nsub;
80 apa_ps2time_t created;
81 u32 main;
82 u32 number;
83 u32 modver;
84 u32 pading1[7];
85 char pading2[128];
86 struct
87 {
88 char magic[32];
89 u32 version;
90 u32 nsector;
91 apa_ps2time_t created;
92 u32 osdStart;
93 u32 osdSize;
94#ifdef APA_SUPPORT_GPT
95 char pading3[128];
96 struct
97 {
98 u32 UniqueMbrSignature;
99 u16 Unknown;
100 struct
101 {
102 u8 BootIndicator;
103 u8 StartHead;
104 u8 StartSector;
105 u8 StartTrack;
106 u8 OSIndicator;
107 u8 EndHead;
108 u8 EndSector;
109 u8 EndTrack;
110 u32 StartingLBA;
111 u32 SizeInLBA;
112 } partition_record1;
113 u8 partition_record234[48];
114 u16 Signature;
115 } protective_mbr;
116#else
117 char pading3[200];
118#endif
119 } mbr;
120 apa_sub_t subs[APA_MAXSUB];
122
123#define APA_CACHE_FLAG_DIRTY 0x01
124typedef struct sapa_cache
125{
126 struct sapa_cache *next;
127 struct sapa_cache *tail;
128 u16 flags;
129 u16 nused;
130 s32 device;
131 u32 sector;
132 union
133 {
134 apa_header_t *header;
135 u32 *error_lba;
136 };
137} apa_cache_t;
138
139typedef struct
140{
141 char id[APA_IDMAX];
142 char fpwd[APA_PASSMAX];
143 char rpwd[APA_PASSMAX];
144 u32 size;
145 u16 type;
146 u16 flags;
147 u32 main;
148 u32 number;
150
151extern void apaSaveError(s32 device, void *buffer, u32 lba, u32 err_lba);
152extern void apaSetPartErrorSector(s32 device, u32 lba);
153extern int apaGetPartErrorSector(s32 device, u32 lba, u32 *lba_out);
154extern int apaGetPartErrorName(s32 device, char *name);
155
156extern apa_cache_t *apaFillHeader(s32 device, const apa_params_t *params, u32 start, u32 next, u32 prev, u32 length, int *err);
157extern apa_cache_t *apaInsertPartition(s32 device, const apa_params_t *params, u32 sector, int *err);
158extern apa_cache_t *apaFindPartition(s32 device, const char *id, int *err);
159extern void apaAddEmptyBlock(apa_header_t *header, u32 *emptyBlocks);
160extern apa_cache_t *apaRemovePartition(s32 device, u32 start, u32 next, u32 prev, u32 length);
161extern void apaMakeEmpty(apa_cache_t *clink);
162extern apa_cache_t *apaDeleteFixPrev(apa_cache_t *clink1, int *err);
163extern apa_cache_t *apaDeleteFixNext(apa_cache_t *clink, int *err);
164extern int apaDelete(apa_cache_t *clink);
165extern int apaCheckSum(apa_header_t *header, int fullcheck);
166extern int apaReadHeader(s32 device, apa_header_t *header, u32 lba);
167extern int apaWriteHeader(s32 device, apa_header_t *header, u32 lba);
168extern int apaGetFormat(s32 device, int *format);
169extern u32 apaGetPartitionMax(u32 totalLBA);
170extern apa_cache_t *apaGetNextHeader(apa_cache_t *clink, int *err);
171
173
174extern int apaCacheInit(u32 size);
175extern int apaCacheDeinit(void);
176extern void apaCacheLink(apa_cache_t *clink, apa_cache_t *cnew);
177extern apa_cache_t *apaCacheUnLink(apa_cache_t *clink);
178extern int apaCacheTransfer(apa_cache_t *clink, int type);
179extern void apaCacheFlushDirty(apa_cache_t *clink);
180extern int apaCacheFlushAllDirty(s32 device);
181extern apa_cache_t *apaCacheGetHeader(s32 device, u32 sector, u32 mode, int *err);
182extern void apaCacheFree(apa_cache_t *clink);
183extern apa_cache_t *apaCacheAlloc(void);
184
186
187#define APAL_MAGIC 0x4150414C // 'APAL'
188typedef struct
189{
190 u32 magic; // APAL_MAGIC
191 s32 num;
192 u32 sectors[126];
194
195#define journalCheckSum(header) apaCheckSum((apa_header_t *)header, 1)
196extern int apaJournalReset(s32 device);
197extern int apaJournalFlush(s32 device);
198extern int apaJournalWrite(apa_cache_t *clink);
199extern int apaJournalRestore(s32 device);
200
202
203extern void *apaAllocMem(int size);
204extern void apaFreeMem(void *ptr);
205extern int apaGetTime(apa_ps2time_t *tm);
206extern int apaGetIlinkID(u8 *idbuf);
207
209extern int apaPassCmp(const char *password1, const char *password2);
210extern void apaEncryptPassword(const char *id, char *password_out, const char *password_in);
211
213typedef struct
214{
215 u32 totalLBA;
216 u32 partitionMaxSize;
217 int format;
218 int status;
220
221extern int apaGetFreeSectors(s32 device, u32 *free, apa_device_t *deviceinfo);
222
223#endif /* __LIBAPA_H__ */
#define APA_MAXSUB
Definition hdd-ioctl.h:49