Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/include/usbhdfsd-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef struct bd_fragment {
u32 count; /// number of sector in this fragment
} __attribute__((packed)) bd_fragment_t;


// IOCTL function codes
/** Rename opened file. Data input to ioctl() -> new, full filename of file. */
#define USBMASS_IOCTL_RENAME 0x0000
Expand All @@ -37,6 +38,8 @@ typedef struct bd_fragment {
#define USBMASS_IOCTL_GET_FRAGLIST 0x0005
/** Get the device number for the block device backing the mass partition */
#define USBMASS_IOCTL_GET_DEVICE_NUMBER 0x0006
/** Get the physical USB port number where device is connected. 00 = Root Hub, 01=Rightmost port, 02=Leftmost Port */
#define USBMASS_IOCTL_GET_USB_DEVICE_PORT_NUMBER 0x0007

// DEVCTL function codes
/** Issues the SCSI STOP UNIT command to the specified device. Use this to shut down devices properly. */
Expand Down
22 changes: 22 additions & 0 deletions iop/fs/bdmfs_fatfs/src/fs_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,28 @@ int fs_ioctl2(iop_file_t *fd, int cmd, void *data, unsigned int datalen, void *r
*(u32*)rdata = bd->devNr;
ret = 0;
}
break;
case USBMASS_IOCTL_GET_USB_DEVICE_PORT_NUMBER:
struct block_device* bdu = fatfs_fs_driver_get_mounted_bd_from_index(file->obj.fs->pdrv);

ret = -ENXIO;

if(bdu && (strncmp(bdu->name, "mass", 4) == 0)) {
struct scsi_interface *scsi = (struct scsi_interface *)bdu->priv;
if (scsi) {
mass_dev *dev = (mass_dev *)scsi->priv;
if(dev) {
/*
<0 = Invalid
00 = Root Hub,
01 = Rightmost port,
02 = Leftmost Port
*/
ret = dev->usbPortNumber;
}
}
}

break;
}
default:
Expand Down
1 change: 1 addition & 0 deletions iop/fs/bdmfs_fatfs/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ I_memcmp
I_memcpy
I_strlen
I_strcmp
I_strncmp
I_strcpy
I_strncpy
I_strtol
Expand Down
25 changes: 25 additions & 0 deletions iop/fs/bdmfs_fatfs/src/include/fs_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
#include <bdm.h>
#include "ff.h"

struct scsi_interface
{
void *priv;
char *name;
unsigned int max_sectors;

int (*get_max_lun)(struct scsi_interface *scsi);
int (*queue_cmd)(struct scsi_interface *scsi, const unsigned char *cmd, unsigned int cmd_len, unsigned char *data, unsigned int data_len, unsigned int data_wr);
};

typedef struct _mass_dev
{
int controlEp; // config endpoint id
int bulkEpI; // in endpoint id
int bulkEpO; // out endpoint id
int devId; // device id
unsigned char configId; // configuration id
unsigned char status;
unsigned char interfaceNumber; // interface number
unsigned char interfaceAlt; // interface alternate setting
int usbPortNumber; //physical port number the USB device is connected to
int ioSema;
struct scsi_interface scsi;
} mass_dev;

typedef struct fatfs_fs_driver_mount_info_
{
FATFS fatfs;
Expand Down
1 change: 1 addition & 0 deletions iop/usb/usbmass_bd/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ I_sceUsbdClosePipe
I_sceUsbdSetPrivateData
I_sceUsbdTransferPipe
I_sceUsbdRegisterLdd
I_sceUsbdGetDeviceLocation
usbd_IMPORTS_end
10 changes: 10 additions & 0 deletions iop/usb/usbmass_bd/src/usb_mass.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct _mass_dev
unsigned char status;
unsigned char interfaceNumber; // interface number
unsigned char interfaceAlt; // interface alternate setting
int usbPortNumber; //physical port number the USB device is connected to
int ioSema;
struct scsi_interface scsi;
} mass_dev;
Expand Down Expand Up @@ -613,6 +614,13 @@ static int usb_mass_probe(int devId)
return 1;
}

static void usb_get_port_number(int devId, mass_dev *dev) {
dev->usbPortNumber = -1;
u8 path[16];
if(sceUsbdGetDeviceLocation(devId, path) == 0)
dev->usbPortNumber = path[0];
}

static int usb_mass_connect(int devId)
{
int i;
Expand Down Expand Up @@ -642,6 +650,8 @@ static int usb_mass_connect(int devId)
dev->bulkEpI = -1;
dev->bulkEpO = -1;

usb_get_port_number(devId, dev);

/* open the config endpoint */
dev->controlEp = sceUsbdOpenPipe(devId, NULL);

Expand Down