PSP Development/Filesystem

The filesystem contains many media which can be accessed. Some media should never be wrote to, as it could brick the system like the risk using kernel mode has. With kernel mode, the media restricted here will not be talked about, but told what should be restricted.

Pathing Conventions

edit

The PSP is more unix-like than when it comes to paths. The general path convention has forward slashes "/" to delimit protocols, directories, and files. Everything should be uppercase, likewise, any file or directory will be referenced despite it's capitalization - it is not case sensitive. This means "BIN" is "bIN" as well as "bIn". It would make sense to keep everything uniform and uppercase it following this rule, so it is best practice to make files and folders uppercase.

Protocol

edit

A protocol determines the medium in which is being referenced. There are quite a few media in which there is ability to reference. Below are a list of the common ones that are safe to use.

  • umd0:/ - a UMD disc
  • ms0:/ - the memory stick
  • disc0:/ - a UMD disc

Stay away from

  • lflash:/
  • flash0:/
  • flash1:/

The Memorystick Root

edit

The root of the memory stick is the base of all the folders. In windows, this is commonly your C:/ drive. However, with the PSP it is the memorystick. The memorystick may list as any protocol when plugged into your computer. Depending on your PNP settings, it may not mount and will have to be mounted manually.

This is a list of default folders in your memory stick with firmware 6.60 PSP 1000 CFW.

  • MP_ROOT
    • 100MNV01
    • 101ANV01
  • MUSIC
  • PICTURE
  • PSP
    • COMMON
    • GAME
    • RSSCH
    • SAVEDATA
    • SYSTEM
      • BROWSER
      • INFOBOARD
        • TEMP
          • IMAGE
    • THEME
  • VIDEO

The root would be the first level of folders. Inside of those folders aren't the root anymore and colloquially change to 'the GAME folder root', pertaining to anything in the PSP/GAME folder.

PPSSPP Memstick

edit

Since PPSSPP 1.4, fixes have been made to make homebrew easier to test. Placing the folder containing the project inside of PPSSPP/Memstick/PSP/GAME will result in the correct argument passed to main() (ms0:/PSP/GAME/APPLICATION/EBOOT.PBP) instead of umd0:/. The latter path is to support ISO PBP and PS1 games. This means it is possible to emulate a UMD on PPSSPP, but in order to do it on a real PSP, CFW or a signed PBP must be present. Below is a list of default PPSSPP folders, which differs from the PSP initially.

  • MUSIC
  • VIDEO
  • PICTURE
  • PSP
    • COMMON
    • GAME
    • SAVEDATA
    • SYSTEM

Absolute Paths

edit

An absolute path includes a protocol which directly links, through all paths, to a file or directory. Absolute links are the most secure in that they point to a location no matter where the Current Working Directory (CWD) is. It is recommended to use an absolute path when necessary.

Example Paths

  • umd0:/FOLDER/file.txt
  • ms0:/PSP/GAME/APPLICATION/EBOOT.PBP
  • ms0:/MUSIC/HomeBySafia.mp3

Relative Paths

edit

A relative path takes the CWD and builds the path based on it. For example, if the current working directory is ms0:/PSP/GAME/APPLICATION, a relative path could reference GAME/OTHER_APPLICATION. To do this uses a series of double periods to denote previous directory, however, it is not necessary to use previous directories with this method as it builds off the CWD too. This means ms0:/PSP/GAME/APPLICATION could be the CWD and to reference a folder inside called FILES, all there needs to be is /FILES.

Example Paths Filesystem (ms0:/)

  • MUSIC
  • PSP
    • GAME
      • APPLICATION
        • FILES
      • OTHER_APPLICATION
        • FILES
        • DATA

Example Paths for CWD (ms0:/PSP/GAME/APPLICATION)

  • /FILES
  • ../OTHER_APPLICATION
  • ../OTHER_APPLICATION/FILES
  • ../OTHER_APPLICATION/DATA
  • ../../../MUSIC

Path Concatenation

edit

One common trick is to use the literal concatenation strategy, which has the counterpart to where you malloc or calloc some memory, and do the string concatenation there - using dynamic memory. The literal concatenation is not on the dynamic memory and on the automatic stack.

Malloc/Calloc avoiding literal concatenation

// make some zero terminated literals
const char* abc = "abc";
const char* onetwothree = "123";

// concat them by specifying variable
const char* abc_onetwothree = abc onetwothree;
printf(abc_onetwothree); //> abc123

Throwing It All Together

edit

Absolute paths are the way to go. Messing with CWD in PSP is a bit cumbersome. It is even more cumbersome when detecting the medium the EBOOT.PBP came from. As stated in Hello World Application, the parameter passed to main() will tell you the absolute path to the EBOOT.PBP. A better way than to substring this and build off of it is using Path Concatenation. This makes for absolute paths easy. The problem would be the folder's name is dependent on the user not editing the name.

Example

#define TITLE "APPLICATION"
#define ROOT "ms0:/PSP/GAME/" TITLE "/"

Doing this method also enables placing the TITLE macro inside of the PSP_MODULE_INFO() function. If emulating a UMD, the path would be umd0:/ instead of directly from memstick (ms0:/).

Current Working Directory

edit

The PSP has concept of the current working directory (CWD). This is always the boot location of the PBP file. While emulating a UMD, the CWD is the root folder inside the EBOOT.PBP, which is umd0:/. In order to set the CWD, PSPDEV provides the function sceIoChdir(). sceIoChdir() takes in a const char* that points to the new path to be the CWD. Once set, it is unknown to read back the CWD using the provided sceIo* functions. Such a function is found in unistd.h as getcwd() and in windows.h as _getcwd().

Working Example

edit
  • No working example