Skip to content

Commit 9c43697

Browse files
authored
Merge pull request #776 from AKuHAK/renameapafix
Support for 8MB APA Partitions, getStat Enhancements, apaRemove per APA specs
2 parents 2a60519 + 15efee2 commit 9c43697

7 files changed

Lines changed: 112 additions & 38 deletions

File tree

iop/hdd/apa/src/apa-opt.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
#ifdef APA_POSIX_VER
88
#define APA_ALLOW_REMOVE_PARTITION_WITH_LEADING_UNDERSCORE 1
9-
#define APA_FORMAT_LOCK_MBR 1
10-
#define APA_FORMAT_MAKE_PARTITIONS 1
11-
#define APA_STAT_RETURN_PART_LBA 1
12-
#define APA_SUPPORT_HDL 1
13-
#define APA_SUPPORT_IOCTL_GETPARTSTART 1
14-
#define APA_SUPPORT_MBR 1
15-
#define APA_WORKAROUND_LESS_THAN_40GB_CAPACITY 1
9+
#define APA_FORMAT_LOCK_MBR 1
10+
#define APA_FORMAT_MAKE_PARTITIONS 1
11+
#define APA_STAT_RETURN_PART_LBA 1
12+
#define APA_SUPPORT_HDL 1
13+
#define APA_SUPPORT_IOCTL_GETPARTSTART 1
14+
#define APA_SUPPORT_MBR 1
15+
#define APA_WORKAROUND_LESS_THAN_40GB_CAPACITY 1
16+
#define APA_8MB_PARTITION_SIZE 1
1617
#else
1718
/* Define APA_OSD_VER in your Makefile to build an OSD version, which will:
1819
1. (currently disabled) When formatting, do not create any partitions other than __mbr.

iop/hdd/apa/src/hdd.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ apa_cache_t *hddAddPartitionHere(s32 device, const apa_params_t *params, u32 *em
116116
u32 i;
117117
u32 tmp, some_size, part_end;
118118
u32 tempSize;
119+
u32 minsize = 0x3FFFF; // 128MB
120+
#ifdef APA_8MB_PARTITION_SIZE
121+
minsize = 0x3FFF; // 8Mb
122+
#endif
119123

120124
// walk empty blocks in case can use one :)
121125
for(i=0;i< 32;i++)
@@ -147,7 +151,7 @@ apa_cache_t *hddAddPartitionHere(s32 device, const apa_params_t *params, u32 *em
147151
while(part_end%params->size)
148152
{
149153
tempSize=params->size>>1;
150-
while(0x3FFFF<tempSize)
154+
while (minsize < tempSize) // 128MB
151155
{
152156
if(!(part_end%tempSize))
153157
{

iop/hdd/apa/src/hdd_fio.c

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,37 @@ static const char *formatPartList[] = {
4444
"__net", "__system", "__sysconf", "__common", NULL};
4545
#endif
4646

47+
#ifndef APA_8MB_PARTITION_SIZE
4748
#define APA_NUMBER_OF_SIZES 9
4849
static const char *sizeList[APA_NUMBER_OF_SIZES] = {
49-
"128M", "256M", "512M", "1G", "2G", "4G", "8G", "16G", "32G"};
50+
"128M",
51+
"256M",
52+
"512M",
53+
"1G",
54+
"2G",
55+
"4G",
56+
"8G",
57+
"16G",
58+
"32G",
59+
};
60+
#else
61+
#define APA_NUMBER_OF_SIZES 13
62+
static const char *sizeList[APA_NUMBER_OF_SIZES] = {
63+
"8M",
64+
"16M",
65+
"32M",
66+
"64M",
67+
"128M",
68+
"256M",
69+
"512M",
70+
"1G",
71+
"2G",
72+
"4G",
73+
"8G",
74+
"16G",
75+
"32G",
76+
};
77+
#endif
5078

5179
///////////////////////////////////////////////////////////////////////////////
5280
// Function declarations
@@ -66,7 +94,11 @@ static int fioPartitionSizeLookUp(char *str)
6694

6795
for (i = 0; i < APA_NUMBER_OF_SIZES; i++) {
6896
if (strcmp(str, sizeList[i]) == 0)
69-
return (256 * 1024) << i;
97+
#ifndef APA_8MB_PARTITION_SIZE
98+
return (2 * 128 * 1024) << i; // 128MB
99+
#else
100+
return (2 * 8 * 1024) << i; // 8MB
101+
#endif
70102
}
71103
APA_PRINTF(APA_DRV_NAME ": Error: Invalid partition size, %s.\n", str);
72104
return -EINVAL;
@@ -663,19 +695,27 @@ int hddLseek(iomanX_iop_file_t *f, int post, int whence)
663695

664696
static void fioGetStatFiller(apa_cache_t *clink, iox_stat_t *stat)
665697
{
666-
stat->mode = clink->header->type;
667-
stat->attr = clink->header->flags;
698+
stat->mode = clink->header->type;
699+
stat->attr = clink->header->flags;
668700
stat->hisize = 0;
669-
stat->size = clink->header->length;
701+
stat->size = clink->header->length;
670702
memcpy(&stat->ctime, &clink->header->created, sizeof(apa_ps2time_t));
671703
memcpy(&stat->atime, &clink->header->created, sizeof(apa_ps2time_t));
672704
memcpy(&stat->mtime, &clink->header->created, sizeof(apa_ps2time_t));
705+
stat->private_1 = 0;
706+
stat->private_2 = 0;
673707
if (clink->header->flags & APA_FLAG_SUB)
674708
stat->private_0 = clink->header->number;
675-
else
709+
else {
676710
stat->private_0 = clink->header->nsub;
677-
stat->private_1 = 0;
678-
stat->private_2 = 0;
711+
712+
u64 totalsize = (u64)clink->header->length;
713+
for (int i = 0; i < clink->header->nsub; i++) {
714+
totalsize += (u64)clink->header->subs[i].length;
715+
}
716+
stat->private_1 = (u32)(totalsize & 0xFFFFFFFF); // low size
717+
stat->private_2 = (u32)(totalsize >> 32); // high size
718+
}
679719
stat->private_3 = 0;
680720
stat->private_4 = 0;
681721
#ifndef APA_STAT_RETURN_PART_LBA

iop/hdd/hdck/src/hdck.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,12 @@ static void RecoverPartitionIfSub(int device, apa_cache_t *clink)
377377
static apa_cache_t *apaCreateAlignedEmptyPartition(apa_cache_t *clink, u32 lba, u32 length)
378378
{
379379
apa_cache_t *result;
380+
u32 minsize = 0x3FFFF; // 128MB
381+
#ifdef APA_8MB_PARTITION_SIZE
382+
minsize = 0x3FFF; // 8MB
383+
#endif
380384

381-
for (length >>= 1; 0x0003FFFF < length; length >>= 1) {
385+
for (length >>= 1; minsize < length; length >>= 1) {
382386
if (lba % length == 0) {
383387
result = apaRemovePartition(clink->device, lba, lba + length, clink->header->start, length);
384388
clink->header->next = lba;

iop/hdd/hdsk/src/sim.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,33 @@ void hdskSimGetFreeSectors(s32 device, struct hdskStat *stat, apa_device_t *devi
2727

2828
sectors = 0;
2929
stat->free = 0;
30+
u32 maxsize = 0x1FFFFF; // 1GB
31+
u32 minsize = 0x3FFFF; // 128MB
32+
#ifdef APA_8MB_PARTITION_SIZE
33+
minsize = 0x3FFF; // 8MB
34+
#endif
3035
for (i = 0; hdskBitmap[i].next != hdskBitmap; sectors += hdskBitmap[i].length, i++) {
3136
if (hdskBitmap[i].type == 0) {
32-
if ((0x001FFFFF < hdskBitmap[i].length) || ((stat->free & hdskBitmap[i].length) == 0)) {
37+
if ((maxsize < hdskBitmap[i].length) || ((stat->free & hdskBitmap[i].length) == 0)) {
3338
stat->free += hdskBitmap[i].length;
3439
}
3540
sectors += hdskBitmap[i].length;
3641
}
3742
}
3843

39-
for (partMax = deviceinfo[device].partitionMaxSize; 0x0003FFFF < partMax; partMax = deviceinfo[device].partitionMaxSize) { // As weird as it looks, this was how it was done in the original HDD.IRX.
40-
for (; 0x0003FFFF < partMax; partMax /= 2) {
44+
for (partMax = deviceinfo[device].partitionMaxSize; minsize < partMax; partMax = deviceinfo[device].partitionMaxSize) { // As weird as it looks, this was how it was done in the original HDD.IRX.
45+
for (; minsize < partMax; partMax /= 2) {
4146
// Non-SONY: Perform 64-bit arithmetic here to avoid overflows when dealing with large disks.
4247
if ((sectors % partMax == 0) && ((u64)sectors + partMax < deviceinfo[device].totalLBA)) {
43-
if ((0x001FFFFF < partMax) || (stat->free & partMax) == 0) {
48+
if ((maxsize < partMax) || (stat->free & partMax) == 0) {
4449
stat->free += partMax;
4550
}
4651
sectors += partMax;
4752
break;
4853
}
4954
}
5055

51-
if (0x0003FFFF >= partMax) {
56+
if (minsize >= partMax) {
5257
break;
5358
}
5459
}

iop/hdd/libapa/src/apa.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ apa_cache_t *apaDeleteFixPrev(apa_cache_t *clink, int *err)
257257
u32 saved_next = clink->header->next;
258258
u32 saved_length = clink->header->length;
259259
u32 tmp;
260+
// TODO: switch to HDDDevices.partitionMaxSize
261+
u32 maxsize = 0x1FFFFF; // 1Gb
260262

261263
while (header->start) {
262264
if (!(clink2 = apaCacheGetHeader(device, header->prev, APA_IO_MODE_READ, err))) {
@@ -265,6 +267,11 @@ apa_cache_t *apaDeleteFixPrev(apa_cache_t *clink, int *err)
265267
}
266268
header = clink2->header;
267269
tmp = header->length + length;
270+
// Check if the new size is larger than the maximum allowed size per APA specs
271+
if (tmp > maxsize) {
272+
apaCacheFree(clink2);
273+
break;
274+
}
268275
if (header->type != 0) {
269276
apaCacheFree(clink2);
270277
break;
@@ -302,6 +309,8 @@ apa_cache_t *apaDeleteFixNext(apa_cache_t *clink, int *err)
302309
u32 lnext = header->next;
303310
u32 device = clink->device;
304311
u32 tmp;
312+
// TODO: switch to HDDDevices.partitionMaxSize
313+
u32 maxsize = 0x1FFFFF; // 1Gb
305314

306315
while (lnext != 0) {
307316
apa_cache_t *clink1;
@@ -312,6 +321,11 @@ apa_cache_t *apaDeleteFixNext(apa_cache_t *clink, int *err)
312321
}
313322
header = clink1->header;
314323
tmp = header->length + length;
324+
// Check if the new size is larger than the maximum allowed size per APA specs
325+
if (tmp > maxsize) {
326+
apaCacheFree(clink1);
327+
break;
328+
}
315329
if (header->type != 0) {
316330
apaCacheFree(clink1);
317331
break;

iop/hdd/libapa/src/free.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,33 @@
2424

2525
static void apaCalculateFreeSpace(u32 *free, u32 sectors)
2626
{
27-
if(0x1FFFFF < sectors)
28-
{
29-
*free += sectors;
30-
return;
31-
}
32-
33-
if((*free & sectors) == 0)
34-
{
35-
*free |= sectors;
36-
return;
37-
}
27+
u32 maxsize = 0x1FFFFF; // 1GB
28+
u32 minsize = 0x3FFFF; // 128MB
29+
#ifdef APA_8MB_PARTITION_SIZE
30+
minsize = 0x3FFF; // 8Mb
31+
#endif
32+
if (maxsize < sectors) {
33+
*free += sectors;
34+
return;
35+
}
3836

39-
for(sectors /= 2; 0x3FFFF < sectors; sectors /= 2)
40-
*free |= sectors;
37+
if ((*free & sectors) == 0) {
38+
*free |= sectors;
39+
return;
40+
}
41+
for (sectors /= 2; minsize < sectors; sectors /= 2)
42+
*free |= sectors;
4143
}
4244

4345
int apaGetFreeSectors(s32 device, u32 *free, apa_device_t *deviceinfo)
4446
{
4547
u32 sectors, partMax;
4648
int rv;
4749
apa_cache_t *clink;
50+
u32 minsize = 0x3FFFF; // 128MB
51+
#ifdef APA_8MB_PARTITION_SIZE
52+
minsize = 0x3FFF; // 8Mb
53+
#endif
4854

4955
sectors = 0;
5056
*free = 0;
@@ -59,9 +65,9 @@ int apaGetFreeSectors(s32 device, u32 *free, apa_device_t *deviceinfo)
5965

6066
if(rv == 0)
6167
{
62-
for(partMax = deviceinfo[device].partitionMaxSize; 0x0003FFFF < partMax; partMax = deviceinfo[device].partitionMaxSize)
68+
for(partMax = deviceinfo[device].partitionMaxSize; minsize < partMax; partMax = deviceinfo[device].partitionMaxSize)
6369
{ //As weird as it looks, this was how it was done in the original HDD.IRX.
64-
for( ; 0x0003FFFF < partMax; partMax /= 2)
70+
for( ; minsize < partMax; partMax /= 2)
6571
{
6672
//Non-SONY: Perform 64-bit arithmetic here to avoid overflows when dealing with large disks.
6773
if((sectors % partMax == 0) && ((u64)sectors + partMax < deviceinfo[device].totalLBA))
@@ -72,7 +78,7 @@ int apaGetFreeSectors(s32 device, u32 *free, apa_device_t *deviceinfo)
7278
}
7379
}
7480

75-
if(0x0003FFFF >= partMax)
81+
if(minsize >= partMax)
7682
break;
7783
}
7884

0 commit comments

Comments
 (0)