Mount and Unmount

From PSXBrew Wiki
Jump to: navigation, search
Language: English

BE CAREFUL WHEN USING THIS TUTORIAL

Contents

What you can Mount/Unmount

On a ps3 you can Mount and Unmount the following things:

(Reference PS3DEVWIKI)

CELL_FS_IOS:BUILTIN_FLSH4
CELL_FS_IOS:BUILTIN_FLSH3
CELL_FS_IOS:BUILTIN_FLSH2
CELL_FS_IOS:BUILTIN_FLSH1
CELL_FS_IOS:USB_MASS_STORAGE
CELL_FS_IOS:USB_MASS_STORAGE005
CELL_FS_IOS:USB_MASS_STORAGE004
CELL_FS_IOS:USB_MASS_STORAGE003
CELL_FS_IOS:USB_MASS_STORAGE002
CELL_FS_IOS:USB_MASS_STORAGE001
CELL_FS_IOS:USB_MASS_STORAGE000
CELL_FS_IOS:SD_CARD
CELL_FS_IOS:COMPACT_FLASH
CELL_FS_IOS:MEMORY_STICK
CELL_FS_IOS:BUILTIN_FLASH
CELL_FS_IOS:PATA1_BDVD_DRIVE
CELL_FS_IOS:PATA0_BDVD_DRIVE
CELL_FS_IOS:PATA1_HDD_DRIVE
CELL_FS_IOS:PATA0_HDD_DRIVE

Let's start Mountig/Unmounting

Define what you want to mount/unmount

Now let say that we need to mount a USB (dev_usb000):
First thing i need to define a char that say what kind of thing i need to mount. in this case is CELL_FS_IOS:USB_MASS_STORAGE000.

const char* DEV_USB000 = "CELL_FS_IOS:USB_MASS_STORAGE000";	// dev_usb000

Define FileSystem Type

Now you need to define what kind of filesystem is:

These are the filesystems supported by a ps3:

CELL_FS_UFS
CELL_FS_ISO9660
CELL_FS_UDF
CELL_FS_FAT
CELL_FS_SIMPLEFS

in this case i assume that the USB is formatted as FAT32. so we'll choose CELL_FS_FAT; what we need is define a const char with the choosen FS type:

const char* FAT = "CELL_FS_FAT"; //it's also for fat32

Copy the Syscall needed (They are not included with PSL1GHT)

then we need to copy these syscalls. they will do everything we need (you can put them inside a custom header; In this example they will kept in a unique file):

#include <ppu-lv2.h>
#include <lv2/sysfs.h>
 
s32 sysFsMount(const char* MOUNT_POINT, const char* TYPE_OF_FILESYSTEM, const char* PATH_TO_MOUNT, int IF_READ_ONLY){
          lv2syscall8(837, (u64)MOUNT_POINT, (u64)TYPE_OF_FILESYSTEM, (u64)PATH_TO_MOUNT, 0, IF_READ_ONLY, 0, 0, 0);
          return_to_user_prog(s32);
}
 
s32 sysFsUnmount(const char* PATH_TO_UNMOUNT){
          lv2syscall1(838, (u64)PATH_TO_UNMOUNT);
          return_to_user_prog(s32);
}

Mount

Let's say that where i want to mount the USB inside the folder called "PS3_USB_000" in the main directory (i.e. inside / ).

#include <ppu-lv2.h>
#include <lv2/sysfs.h>
 
s32 sysFsMount(const char* MOUNT_POINT, const char* TYPE_OF_FILESYSTEM, const char* PATH_TO_MOUNT, int IF_READ_ONLY){
          lv2syscall8(837, (u64)MOUNT_POINT, (u64)TYPE_OF_FILESYSTEM, (u64)PATH_TO_MOUNT, 0, IF_READ_ONLY, 0, 0, 0);
          return_to_user_prog(s32);
}
 
int main(int argc, const char* argv[]){
          const char* DEV_USB000 = "CELL_FS_IOS:USB_MASS_STORAGE000";	// dev_usb000
          const char* FAT = "CELL_FS_FAT"; //it's also for fat32
          const char* MOUNT_POINT = "/PS3_USB_000"; //our mount point
 
          //we may need to check if it is already mounted:
          sysFSStat dir;
 
          int is_mounted = sysFsStat(MOUNT_POINT, &dir);
          if(is_mounted != 0)
                   sysFsMount(DEV_USB000, FAT, MOUNT_POINT, 0); //the last one will say if it's readonly or not. use "0" if you want to read and write, "1" if only read
          //in this case we will read and write the USB
          return 0;
}

Unmount

We need to unmount the folder. to do that you need only the mount point path: we mounted the USB inside the folder called "PS3_USB_000" in the main directory (i.e. inside / ). This what we do to unmount it

#include <ppu-lv2.h>
#include <lv2/sysfs.h>
 
s32 sysFsUnmount(const char* PATH_TO_UNMOUNT){
          lv2syscall1(838, (u64)PATH_TO_UNMOUNT);
          return_to_user_prog(s32);
}
 
int main(int argc, const char* argv[]){
          const char* MOUNT_POINT = "/PS3_USB_000"; //our mount point
 
          //we may need to check if it is already mounted:
          sysFSStat dir;
 
          int is_mounted = sysFsStat(MOUNT_POINT, &dir);
          if(is_mounted == 0)
                   sysFsUnmount(MOUNT_POINT);
          //this will unmount the filesystem if the folder exist!
          return 0;
}

Compiling

To compile it correctly you need to simply add the following flags in your Makefile :

-llv2 -lsysfs

Samples/Exercises

Becareful when using this example. it mounts/unmount dev_flash1 (run once to mount, run a second time to unmount)
Mount_Unmount_dev_flash1.zip

Authors/Sources/References

Wargio/Deroad;

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox