Skip to main content
The PSL1GHT SDK provides comprehensive filesystem APIs for accessing the PS3’s various storage devices including the hard disk drive (HDD), USB devices, and optical discs.

Overview

Filesystem operations are provided through two header files:
  • sys/file.h - Low-level syscall wrappers
  • lv2/sysfs.h - High-level filesystem functions and data structures

Storage Mount Points

The PS3 filesystem uses specific mount points for different storage devices:
#include <sys/paths.h>

// Application home directory
SYS_APP_HOME    "/app_home"

// Hard disk drive
SYS_DEV_HDD0    "/dev_hdd0"

// USB devices
SYS_DEV_USB     "/dev_usb"

// Blu-ray disc
SYS_DEV_BDVD    "/dev_bdvd"

// Memory stick
SYS_DEV_MS      "/dev_ms"

// Remote host (for debugging)
SYS_HOST_ROOT   "/host_root"
/dev_hdd1 is reserved for system use only and should not be accessed by applications.

File Operations

Opening Files

Files are opened using sysFsOpen() with various flags to control access mode.
s32 sysFsOpen(const char *path, s32 oflags, s32 *fd, 
              const void *arg, u64 argsize);
path
const char*
required
Full path to the file to open
oflags
s32
required
Open flags controlling access mode and behavior
fd
s32*
required
Pointer to receive the file descriptor
arg
const void*
Additional arguments (usually NULL)
argsize
u64
Size of additional arguments (usually 0)
return
s32
Returns 0 on success, non-zero error code on failure

Open Flags

FlagValueDescription
SYS_O_RDONLY0Open for reading only
SYS_O_WRONLY1Open for writing only
SYS_O_RDWR2Open for reading and writing
SYS_O_ACCMODE3Access mode mask
FlagDescription
SYS_O_CREATCreate file if it doesn’t exist
SYS_O_EXCLFail if file already exists (use with CREAT)
SYS_O_TRUNCTruncate file to zero length
SYS_O_APPENDAppend to end of file
SYS_O_MSELFOpen as MSELF encrypted file

Reading and Writing

s32 sysFsRead(s32 fd, void *ptr, u64 len, u64 *read);

Seeking

s32 sysFsLseek(s32 fd, s64 offset, s32 whence, u64 *position);
whence
s32
  • SEEK_SET - Offset from beginning of file
  • SEEK_CUR - Offset from current position
  • SEEK_END - Offset from end of file

Closing Files

s32 sysFsClose(s32 fd);

File Information

File Statistics

s32 sysFsStat(const char *path, sysFSStat *stat);
s32 sysFsFstat(s32 fd, sysFSStat *stat);

Directory Operations

Opening and Reading Directories

s32 sysFsOpendir(const char *path, s32 *fd);
s32 sysFsReaddir(s32 fd, sysFSDirent *entry, u64 *read);
s32 sysFsClosedir(s32 fd);

Creating and Removing Directories

s32 sysFsMkdir(const char *path, s32 mode);

File Management

Deleting Files

s32 sysFsUnlink(const char *path);

Renaming Files

LV2_SYSCALL sysLv2FsRename(const char *path, const char *newpath);

File Permissions

s32 sysFsChmod(const char *path, s32 mode);

File Truncation

LV2_SYSCALL sysLv2FsTruncate(const char *path, u64 size);
LV2_SYSCALL sysLv2FsFtruncate(s32 fd, u64 size);

Advanced Features

Asynchronous I/O

PSL1GHT supports asynchronous file operations for non-blocking I/O.
typedef struct _sys_fs_aio {
    s32 fd;           // File descriptor
    u64 offset;       // Offset in file
    u32 buffer_addr;  // Buffer address
    u64 size;         // Transfer size
    u64 usrdata;      // User data
} sysFSAio;

typedef void (*sysFsAioCallback)(sysFSAio *aio, s32 error, 
                                  s32 xid, u64 size);

I/O Buffering

s32 sysFsSetIoBuffer(s32 fd, size_t bufferSizeLimit, 
                     s32 pageType, sys_mem_container_t container);

Free Space Information

s32 sysFsGetFreeSize(const char *path, u32 *blockSize, u64 *freeBlocks);

Complete Example

#include <stdio.h>
#include <string.h>
#include <lv2/sysfs.h>
#include <sys/paths.h>

int save_game_data(const char *filename, const void *data, size_t size) {
    s32 fd;
    s32 ret;
    u64 written;
    char path[256];
    
    // Build full path
    snprintf(path, sizeof(path), "%s/game/MYAPP00001/%s",
             SYS_DEV_HDD0, filename);
    
    // Open file for writing, create if needed
    ret = sysFsOpen(path, SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC,
                    &fd, NULL, 0);
    if (ret != 0) {
        printf("Failed to open %s: %d\n", path, ret);
        return ret;
    }
    
    // Write data
    ret = sysFsWrite(fd, data, size, &written);
    if (ret != 0) {
        printf("Write failed: %d\n", ret);
        sysFsClose(fd);
        return ret;
    }
    
    // Ensure data is flushed to disk
    sysLv2FsFsync(fd);
    
    // Close file
    sysFsClose(fd);
    
    printf("Saved %llu bytes to %s\n", written, filename);
    return 0;
}

int load_game_data(const char *filename, void *buffer, size_t max_size) {
    s32 fd;
    s32 ret;
    u64 bytes_read;
    char path[256];
    sysFSStat stat;
    
    // Build full path
    snprintf(path, sizeof(path), "%s/game/MYAPP00001/%s",
             SYS_DEV_HDD0, filename);
    
    // Check file exists and get size
    ret = sysFsStat(path, &stat);
    if (ret != 0) {
        printf("File not found: %s\n", path);
        return ret;
    }
    
    if (stat.st_size > max_size) {
        printf("File too large: %llu > %zu\n", stat.st_size, max_size);
        return -1;
    }
    
    // Open file for reading
    ret = sysFsOpen(path, SYS_O_RDONLY, &fd, NULL, 0);
    if (ret != 0) {
        printf("Failed to open %s: %d\n", path, ret);
        return ret;
    }
    
    // Read data
    ret = sysFsRead(fd, buffer, stat.st_size, &bytes_read);
    sysFsClose(fd);
    
    if (ret != 0) {
        printf("Read failed: %d\n", ret);
        return ret;
    }
    
    printf("Loaded %llu bytes from %s\n", bytes_read, filename);
    return bytes_read;
}

Error Handling

All filesystem functions return 0 on success and a negative error code on failure. Common error codes are defined in sys/lv2errno.h.
Always check return values and handle errors appropriately. File operations can fail for many reasons including:
  • File not found
  • Permission denied
  • Disk full
  • Invalid file descriptor
  • Device not ready

Best Practices

Always Close Files

Always close file descriptors when done to prevent resource leaks.

Check Return Values

Verify all filesystem operations succeed before continuing.

Use Full Paths

Always use absolute paths starting with a mount point like /dev_hdd0.

Flush Critical Data

Use sysLv2FsFsync() to ensure important data is written to disk.

See Also

Build docs developers (and LLMs) love