Mounting the USBHostFS as a standard device?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Mounting the USBHostFS as a standard device?

Post by FreePlay »

I'm attempting to write a module for firmware 1.50 that unassigns ms0 and reassigns the USBHostFS as ms0. I'm not even entirely sure if this is possible. I've got everything set to do what I want except for the actual sceIoAssign statement, which has got me stumped after several hours of fiddling and research.

My main problem is that of the programs that use the USBHostFS to access files on the PC - e.g. IRShell, DAXZISO, etc. - I cannot find a single one with available source. It seems like I should be assigning a device named usbhostfs0: (which makes perfect sense really), but when I actually attempt to assign this device, sceIoAssign returns -1. Not a very helpful return code, really. It's not a NODEV (80020321), which tells me that the device exists at least, but I can't figure out where I've gone wrong in my arguments and such.

Anyways, I'm loading my module with Dark_AleX's firmware mod. It's set up so that pressing the L button loads and starts the usbhostfs.prx module, checks to ensure that it's successful, unassigns ms0, and attempts to reassign usbhostfs0 to ms0.

So... any suggestions? If you'd like me to post my source, I'd be happy to.
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

psplink uses usbhostfs and has included source, that's where it all started. IRShell has/had the ability to remount the usbhostfs as ms0: so it is definitely possible.

When you get it going, post some source up, would be useful to have some available source of how to do it lying around :D
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Have you used this to activate the usbhostfs after loading usbhostfs.prx and before trying to assign the device?

Code: Select all

#include <pspusb.h>

sceUsbStart&#40;PSP_USBBUS_DRIVERNAME, 0, 0&#41;;
sceUsbStart&#40;"USBHostFSDriver", 0, 0&#41;;
sceUsbActivate&#40;0x1C9&#41;;
Btw a little issue about "USBHostFS" or "USBHostFSDriver":

I remember to have used the first one, but looking now at the current sources of usbhostfs, it seems that now it uses the second one.

This mean that either tyranid change the name of the driver in some point, or, probably that i have a bad memory. (so anyways be careful with the usbhostfs.prx version you use in the rare case i had good memory)

After that, an assign like this should work:

Code: Select all

sceIoUnassign&#40;"ms0&#58;"&#41;;
sceIoAssign&#40;"ms0&#58;", "host0&#58;", NULL, IOASSIGN_RDWR, NULL, 0&#41;;

Also, notice a thing. The VSH uses a different fatms driver (fatmsOem) for music and photos, but it uses the standard ms driver for videos, games, for digital camera photos and atrac3 music.

I don't know if this can cause an issue, since i haven't looked yet if the vsh uses also the alias "ms0:" for the fatmsOem driver, or if it uses another one (in this case you should also reassign that other alias).

P.S.: i think i had bad memory, since in the sources that i've found in some remote places of my computer, i used also USBHostFSDriver
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Indeed you do have a bad memory, it has always been USBHostFSDriver except in some really early versions of the code which were never public anyway :)

A quick apihook on sceDopen reveals it uses msoem0: to access photos and music, perhaps it was just some other coder doing those parts and they uses an old version of the name or something.

And ensure you update to using the latest usbhost from psplink as the others around I cant say for sure what they have likely changed, plus the psplink one should even give you the free space once mapped across to ms0: kinda funny to see the vsh showing 200GB free space ;P

And incidently there was always code on this forum to do it, just need to find the right place http://forums.ps2dev.org/viewtopic.php?t=3834&start=180 about half way down.
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Post by FreePlay »

Thanks for the help, guys. I knew I could depend on you for this :)
Slasher
Posts: 5
Joined: Fri Jan 27, 2006 11:39 am

Post by Slasher »

sorry about being a little offtopic; but Tyranid, where can I get the psplink source?
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

You could, you know, do like just about everything else, and check svn.
Shoot Pixels Not People!
Makeshift Development
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Post by FreePlay »

I tried building the latest usbhostfs_pc (under Cygwin) from the SVN and apparently I'm missing usb.h . I assume this is a common problem.

Also: I managed to get my PSP to write files properly over USBHostFS, but I can't get it to read anything, list folder contents, etc. Could this just be because I'm using an old version of usbhostfs_pc, or do I have to 'reactivate' the MS after reassigning the device?
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

I tried building the latest usbhostfs_pc (under Cygwin) from the SVN and apparently I'm missing usb.h . I assume this is a common problem.
you need libusb :)
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Post by FreePlay »

I assumed so :)

I've run into a few more odd glitches. I can delete/write to host0: just fine, and I can view any proper videos stored in /MP_ROOT/100MNV01, but none of the other folders work at all. I've remapped both ms0: and msoem0:, and if I make a /DCIM folder, the PSP crashes when I enter the photo viewer...
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Update

Post by FreePlay »

I've been working on getting this to work on 3.10 OE-A and so far all I can get it to do is load and start the USBHostFS module and activate the USB connection with the driver. If I try to assign host0 to a device, I get the NODEV error. In fact, so far as I can tell, host0 doesn't exist. Any idea what might be causing this?

I've attached my code:

Code: Select all

// USBHostFS-to-MS swap module
// &#40;C&#41; 2007 FreePlay

#include <pspwlan.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include <pspusb.h>
#include <stdio.h>
#include <string.h>
#include <psploadexec_kernel.h>
#include <systemctrl.h>
#include <pspsysmem.h>

PSP_MODULE_INFO&#40;"USBHostFS_to_MS", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int swapstate = 0, loaded = 0;
SceUID stdoutfile;

int loadStartModule&#40;char * path&#41; &#123; // load and start a module. return 0 for success, -1 for failing to load, -2 for failing to start
    u32 loadResult;
    u32 startResult;
    int status;
    loadResult = sceKernelLoadModule&#40;path, 0, NULL&#41;;
    if &#40;loadResult & 0x80000000&#41; return -1;
    else
	startResult = sceKernelStartModule&#40;loadResult, 0, NULL, &status, NULL&#41;;
    if &#40;loadResult != startResult&#41; return -2;
    return 0;
&#125;

int StartUSBHostFSDriver&#40;&#41; &#123; // start the USBHostFS driver; return 0 on success, -1 on startbus failure, -2 on startdriver failure, -4 on activate failure, or a combination of the three.
	int startbus = 0, startdriver = 0, activate = 0;
	
	startbus = sceUsbStart&#40;PSP_USBBUS_DRIVERNAME, 0, 0&#41; ? -1 &#58; 0;
	startdriver = sceUsbStart&#40;"USBHostFSDriver", 0, 0&#41; ? -2 &#58; 0;
	activate = sceUsbActivate&#40;0x1C9&#41; ? -4 &#58; 0;
	
	return startbus + startdriver + activate;
&#125;

void stdoutprint&#40;char *str&#41; &#123; // print to a stdout file
	sceIoWrite&#40;stdoutfile, str, strlen&#40;str&#41;&#41;;
&#125;

void stdoutprintln&#40;char *str&#41; &#123; // same as above, but with a newline
	stdoutprint&#40;str&#41;;
	stdoutprint&#40;"\n"&#41;;
&#125;

unsigned int iserr&#40;unsigned int val&#41; &#123;
   return &#40;val & 0x80000000&#41;;
&#125;

// Get 0x######## error code
char *getError&#40;unsigned int errornumber&#41; &#123;
	static char err&#91;10&#93;;
	sprintf&#40;err, "0x%08X", errornumber&#41;;
	return err;
&#125;

void quitWithMessage&#40;char *str, int err&#41; &#123;
	sceUsbDeactivate&#40;0x1c9&#41;;
	stdoutprint&#40;str&#41;;
	stdoutprint&#40;" &#40;"&#41;;
	stdoutprint&#40;getError&#40;err&#41;&#41;;
	stdoutprintln&#40;"&#41;"&#41;;
	sceIoClose&#40;stdoutfile&#41;;
	sceKernelDelayThread&#40;10000&#41;;
	sceKernelExitGame&#40;&#41;;
&#125;


/***************************************

swap MS for usbhostfs - new version

****************************************/

int swap&#40;SceUID stdoutfile&#41; &#123;
	SceUID res;
	if&#40;swapstate&#41; &#123; // MS is already rerouted to usbhostfs - reset to default
		sceUsbDeactivate&#40;0x1c9&#41;;
		res = sceIoUnassign&#40;"ms0&#58;"&#41;;
		if&#40;!iserr&#40;res&#41;&#41; &#123;
			res = sceIoUnassign&#40;"msoem0&#58;"&#41;;
			if&#40;!iserr&#40;res&#41; || res == 0x80020321&#41; &#123;
				res = sceIoAssign&#40;"ms0&#58;", "msstor0p1&#58;", "fatms0&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
				if&#40;!iserr&#40;res&#41; || res == 0x80020321&#41; &#123;
					res = sceIoAssign&#40;"msoem0&#58;", "msstor0p1&#58;", "fatms0&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
					if&#40;!iserr&#40;res&#41;&#41; &#123;
						swapstate = swapstate ? 0 &#58; 1; // swap state&#58; 1 = rerouted, 0 = normal
					&#125; else quitWithMessage&#40;"defaults&#58; failed to reassign msoem0", res&#41;;
				&#125; else quitWithMessage&#40;"defaults&#58; failed to reassign ms0", res&#41;;
			&#125; else quitWithMessage&#40;"defaults&#58; failed to unassign msoem0", res&#41;;
		&#125;  else quitWithMessage&#40;"defaults&#58; failed to unassign ms0", res&#41;;
	&#125; else &#123; // reroute MS to usbhostfs
		if&#40;loaded&#41; &#123;
			res = StartUSBHostFSDriver&#40;&#41;;
			if&#40;res&#41;
				quitWithMessage&#40;"reroute MS to usbhostfs&#58; StartUSBHostFSDriver fails!", res&#41;;
		&#125; else loaded = 1;
		res = sceIoUnassign&#40;"ms0&#58;"&#41;;
		if&#40;!iserr&#40;res&#41; || res == 0x80020321&#41; &#123;
			res = sceIoUnassign&#40;"msoem0&#58;"&#41;;
			if&#40;!iserr&#40;res&#41; || res == 0x80020321&#41; &#123;
				res = sceIoAssign&#40;"ms0&#58;", "host0&#58;", NULL, IOASSIGN_RDWR, NULL, 0&#41;; 
				if&#40;!iserr&#40;res&#41;&#41; &#123;
					res = sceIoAssign&#40;"msoem0&#58;", "host0&#58;", NULL, IOASSIGN_RDWR, NULL, 0&#41;;
					if&#40;!iserr&#40;res&#41;&#41; &#123;
						swapstate = swapstate ? 0 &#58; 1; // swap state&#58; 1 = rerouted, 0 = normal
					&#125; else quitWithMessage&#40;"rerouting&#58; failed to reassign msoem0", res&#41;;
				&#125; else quitWithMessage&#40;"rerouting&#58; failed to reassign ms0", res&#41;;
			&#125; else quitWithMessage&#40;"rerouting&#58; failed to unassign msoem0", res&#41;;
		&#125; else quitWithMessage&#40;"rerouting&#58; failed to unassign ms0", res&#41;;
	&#125;
	return swapstate; // won't change if it fails
&#125;

/***************************************

main thread

****************************************/

int main_thread&#40;SceSize args, void *argp&#41; &#123;
	unsigned int pad_old = 0;
	SceCtrlData pad;
	int resetcount = 0;
	
	while&#40;1&#41;&#123;
		sceCtrlPeekBufferPositive&#40;&pad, 1&#41;;
		sceKernelDelayThread&#40;100&#41;;
		
		if&#40;!sceWlanGetSwitchState&#40;&#41;&#41; &#123; // only respond if the WLAN switch is off.
		
			if&#40;pad.Buttons != pad_old&#41;&#123;
				// button pressed.
				if&#40;pad.Buttons & PSP_CTRL_LTRIGGER&#41; &#123; // swap MS for USBHOSTFS
					swap&#40;stdoutfile&#41;;
				&#125; else if&#40;pad.Buttons & PSP_CTRL_RTRIGGER&#41; &#123; // soft reboot
					if&#40;resetcount == 0&#41; &#123;
						resetcount++;
					&#125; else &#123;
						quitWithMessage&#40;"exit via double R press", 0&#41;;
					&#125;
				&#125;
			&#125;
		&#125;

		pad_old = pad.Buttons;
	&#125;

	return 0;	
&#125;

int main &#40;int argc, char **argv&#41; &#123;
	stdoutfile = sceIoOpen&#40;"fatms0&#58;/stdout.txt",PSP_O_CREAT|PSP_O_WRONLY|PSP_O_APPEND,0777&#41;;
	stdoutprintln&#40;"started OK"&#41;;

	int res = loadStartModule&#40;"ms0&#58;/seplugins/usbhostfs.prx"&#41;;
	if&#40;res&#41;
		quitWithMessage&#40;"error loading/starting usbhostfs module", res&#41;;

	stdoutprintln&#40;"loadStartModule OK"&#41;;

	res = StartUSBHostFSDriver&#40;&#41;;
	if&#40;res&#41;
		quitWithMessage&#40;"main&#58; StartUSBHostFSDriver fails!", res&#41;;

	stdoutprintln&#40;"main&#58; StartUSBHostFSDriver OK"&#41;;
		

	int thid = sceKernelCreateThread&#40;"USBHostFS_Swap_thread", main_thread, 8, 0x1000, 0, NULL&#41;;
	if&#40;thid >= 0&#41;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	else &#123;
		quitWithMessage&#40;"couldn't create kmode thread!", thid&#41;;
	&#125;
	
	
	sceKernelSleepThread&#40;&#41;;
	
	return 0;
&#125;
I know, it's pretty nasty, but I'm just going for functional at this point. Cleaning up/optimizing comes later :)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Well sony added a blacklist of devices for aliasing purposes to later firmwares. If you are running psplink (and on 3.10OE) you can remove it using the psplink command 'fillb @sceIOFileManager@+0x5074 76 0'
poison
Posts: 17
Joined: Thu Dec 14, 2006 11:07 pm

Post by poison »

TyRaNiD wrote:Well sony added a blacklist of devices for aliasing purposes to later firmwares. If you are running psplink (and on 3.10OE) you can remove it using the psplink command 'fillb @sceIOFileManager@+0x5074 76 0'
Thanks...
actually, I have the same idea to assign host0 as ms0:
it work well in 1.50 kernel game mode..
but when I do it in 310OE vsh mode ... it unassign the original ms0: and connect to usbhost successfully, but I cant assign host0 to ms0:
using
sceIoAssign("ms0:", "host0:", NULL, IOASSIGN_RDWR, NULL, 0);
sceIoAssign("msoem0:", "host0:", NULL, IOASSIGN_RDWR, NULL, 0);
although I add the following code...
SceModule *mod;
mod = sceKernelFindModuleByName("sceIOFileManager");
u8 * addr;
addr = (u8 *)(mod->text_addr + 0x5074);
int i;
for(i = 0; i< 77; i++)
{
addr = 0;
}


anybody can help me out?
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Post by FreePlay »

The 'ban list' is stored in the same memory location every time it's loaded, although it varies from firmware to firmware. You can just write directly to kmem if you want. On 3.03 OE-C, it's loaded into 0x88052854, and on 3.10 OE-A it's at 0x88052854.

Also, in your code:

Code: Select all

...
for&#40;i = 0; i< 77; i++&#41; 
...
This loop is going to write 77 values, not 76.
poison
Posts: 17
Joined: Thu Dec 14, 2006 11:07 pm

Post by poison »

FreePlay wrote:The 'ban list' is stored in the same memory location every time it's loaded, although it varies from firmware to firmware. You can just write directly to kmem if you want. On 3.03 OE-C, it's loaded into 0x88052854, and on 3.10 OE-A it's at 0x88052854.
Thanks a lot... I will have a test of it...
it's loaded into 0x88052854, and on 3.10 OE-A it's at 0x88052854.
is it the same?
And... Do you get it work?
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Post by FreePlay »

Sorry, that should read 0x88052854 for 3.03 OE-C, and 0x88053A74 for 3.10 OE-A. I believe it should be the same for 3.10 OE-A and 3.10 OE-A', though I honestly haven't tested that.
poison
Posts: 17
Joined: Thu Dec 14, 2006 11:07 pm

Post by poison »

FreePlay wrote:Sorry, that should read 0x88052854 for 3.03 OE-C, and 0x88053A74 for 3.10 OE-A. I believe it should be the same for 3.10 OE-A and 3.10 OE-A', though I honestly haven't tested that.
Hey... it works... but every time I enter the memory stick, it freez my PSP after it got the entry list...

It always freez after this usbhost command
Command Num: 8FFC000B
Extra Len: 0
Dread command did: 0
Magic: 782F0812
FreePlay
Posts: 71
Joined: Wed Jan 04, 2006 6:53 pm
Location: Schenectady, New York, USA

Post by FreePlay »

I don't know what causes the freezes. I've had some problems myself. It'll read the listing for games and savedata, but when it tries to read the metadata it'll freeze. For almost everything else, it never gets the listings. The only XMB plugin that actually works for me over USBHostFS is the RSS channel, for some reason.
poison
Posts: 17
Joined: Thu Dec 14, 2006 11:07 pm

Post by poison »

FreePlay wrote:I don't know what causes the freezes. I've had some problems myself. It'll read the listing for games and savedata, but when it tries to read the metadata it'll freeze. For almost everything else, it never gets the listings. The only XMB plugin that actually works for me over USBHostFS is the RSS channel, for some reason.
The same problem here... Is there a methods on which USBHostFS_PC take no respones reading the metadata ?
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Hi,

Does someone know the memory location for the 3.40oe firmware ?
alexp
Posts: 39
Joined: Tue Apr 17, 2007 12:06 am

Post by alexp »

hi, i'm too looking for the correct address to patch in 3.40 firmware.
does anyone know this address, or a way to find it out?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Considering the info on this it shouldn't be hard to find the address, open iofilemgr.prx and find the list of banned devices and extrapolate that to a new firmware, it is still there even in 3.51 ;)
alexp
Posts: 39
Joined: Tue Apr 17, 2007 12:06 am

Post by alexp »

The addres for CF 3.40 is 0x880562dc, thanks for your help
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Thanks to all of you, this lurn me how to make a better use of psplink.

Ps : 0x880534f0 is the new location for firmware 3.52, "fillb @sceIOFileManager@+0x84f0 76 0"
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

I still don't understand why its still not working under the xmb while its working everywhere :x
psychoticsmiley
Posts: 2
Joined: Thu Nov 29, 2007 5:41 am

Heroes! You are all heroes!

Post by psychoticsmiley »

Ok so I have a project that I need usbhostfs to just run off the psp. (maybe not)

Setup:

A USB laptop hard drive enclosure that has a usb host built in and is self powered with a li-ion battery. (one of the newer usb go drives but you use your own hdd)

short usb cable and psp.

I have all the software for usbhostfs for the pc, but with this setup I want to eliminate the use of the pc.

The problem I have run into,

How does the psp call the file list. I know it basically goes like this (in translation)

PSP- I need a file list
Usbhostfs- (points to directory where iso's are) File list
PSP- I need this iso
Usbhostfs- points file.

The problem now is, even if I understand how the psp actually requests the file in coding, how to get the hdd to store a file list that the psp can access to grab the file.

And then once that works, to extend this to mp3, video, etc.
Possibly getting it to do it in a RSS list (especially for mp3 and pictures)

This project is my baby and I want to see it happen, I will work closely as I possibly can with this and donate even to see it happen.
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

You need to write a firmware for your usb enclosure based on the usbhost sources. In short : good luck :)
Post Reply