Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support aligned partition allocation (APA) #39

Open
frno7 opened this issue Aug 15, 2021 · 7 comments
Open

Support aligned partition allocation (APA) #39

frno7 opened this issue Aug 15, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@frno7
Copy link
Owner

frno7 commented Aug 15, 2021

Aligned partition allocation (APA) is a proprietary disk partition scheme used on the PlayStation 2. There are two kinds of partitions: main and sub partitions. A main partition can have up to 64 sub partitions. Partition sizes are restricted to powers of 2, from 128 MiB to 32 GiB. There is tooling for Linux 2.x to have game data coexist with Linux on the same disk. It needs to be reviewed for Linux 5.x.

See also #18 (comment) and ideas for a hybrid APA and GPT partition scheme.

@frno7 frno7 added the enhancement New feature or request label Aug 15, 2021
@uyjulian
Copy link

PFS and APA partitions can be managed from userspace using PFS Shell. https://github.com/ps2homebrew/pfsshell

The linux partition types EXT2, ReiserFS, and swap are all the partition types implemented in the HDD driver.
I think for future expandability with other filesystems e.g. ext4 and >2TB access, targeting a APA protective header+GPT (for HDD boot only) or APA+GPT hybrid scheme (for HDD boot+APA/PFS backwards compatibility) would be the best idea.

This would require support in partitioning tools e.g. parted to detect the APA header and recalculate the checksum and protective area.

@uyjulian
Copy link

For reference, here is the APA partition driver as implemented by SCE: https://github.com/rickgaiser/linux-2.4.17-ps2/blob/69d1691010e92b14133758864c1433042de028cf/fs/partitions/ps2.c

@frno7
Copy link
Owner Author

frno7 commented Dec 14, 2022

Thanks, @uyjulian! I found fs/partitions/ps2.c on the ps2-v2.6.35.14 branch, with updates made by @jur and the commit message

Partitions which are fragmented/splitted over the disc are not fully supported.
Either apascan or device mapper should be used to merge it.
Both tools use different formats. apascan is compatible with the old Linux.

@bignaux
Copy link

bignaux commented Dec 14, 2022

To remember i started to port https://gitlab.com/ps2max/linux/linux/-/blob/ps2-v3.8/block/partitions/ps2.c to latest kernel, i should be able to back to that soon.

@uyjulian
Copy link

uyjulian commented Jun 26, 2023

A problem with implementing APA in the kernel is that it may be non trivial to implement. So it may be better to have a userspace program like apascan do the mapping instead.

On PS2 Linux beta kernel 2.2.1, the offset before the main partition filesystem data start is 4096 (drivers/block/genhd.c, PAGE_SIZE=4096) bytes.
On PSBBN kernel 2.4.17, the offset before the main partition filesystem data start is 4194304 (fs/partitions/ps2.h, PS2_PART_RESV_MAIN=4 * 1024 * 1024) bytes.

On both systems, the offset before the sub partition filesystem data start is 4096 (2.2.1: drivers/block/genhd.c, PAGE_SIZE=4096; 2.4.17: fs/partitions/ps2.h, PS2_PART_RESV_SUB=4 * 1024)

On both systems, the data between 0 and 4096 is the APA partition header.
For patched kernel 2.4.17, the data between 4096 and 4194304 is the PS2ICON3D data.

Partitions may be fragmented. Even if the sub-partitions are together, there is still the APA header between them.

@frno7
Copy link
Owner Author

frno7 commented Jun 26, 2023

Thanks, @mirh!

@uyjulian, this repo has both ps2-v2.2.1:drivers/block/genhd.c, and ps2-v2.6.35.14:fs/partitions/ps2.h which I believe has improvements over 2.4.17, see #39 (comment).

A problem with implementing APA in the kernel is that it may be non trivial to implement. So it may be better to have a userspace program like apascan do the mapping instead.

The entire block device would be available, so user space programs would work nicely regardless of APA in the kernel. The only issue is that as per #18 (comment) the ATA driver isn’t quite stable yet. :-)

Partitions may be fragmented. Even if the sub-partitions are together, there is still the APA header between them.

Yeah, @jur mentioned in the comment mentioned above that fragments aren’t entirely supported, but that they apparently can be merged using apascan or a device mapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants