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