The details between the file system and the USB Mass Storage under vxworks

0

I am implementing a virtual USB Mass Storage Under vxWorks. There are some problems here,The driver has executed the mount phase which function is usb2MscXbdMount.

following is the process i had combed:

usb2MscXbdMount:

taskSpawn(pSvrTaskName,
                                    usrUsb2MscServiceTaskPriorityGet(),
                                    usrUsb2MscServiceTaskOptionsGet(),
                                    (size_t)usrUsb2MscServiceTaskStackSizeGet(),
                                    (FUNCPTR)usb2MscXbdService,
                                    (long)pXbdLun,
                                    0, 0, 0, 0, 0, 0, 0, 0, 0);

this function opened up a usb2MscXbdService thread,in the usb2MscXbdService,driver has following action:

while ((pBio = usb2MscXbdGetNextBio(pXbdLun)) != NULL)
            {
            USB2_MSC_VDBG("Got new BIO\n", 1, 2, 3, 4, 5, 6);
            usb2MscXbdRunBio (pXbdLun, pBio);
            }

then in the usb2MscXbdRunBio(pXbdLun,PBio),driver has following action:

if (pBio->bio_flags & BIO_READ)
        {
        /* Call the driver's read routine *

        status = pXbdLun->xbdRead(pXbd, 
                                  (UINT32) pBio->bio_blkno,
                                  (UINT32) nblocks,
                                  pBio->bio_data);
        (void) errnoSet(status);       
        }

pXbdLun->xbdRead <==> usb2MscXbdRead,so then driver jump to usb2MscXbdRead in which produce an SCSI command:usb2MscScsiRead10,following is the implementation of usb2MscXbdRead:

    LOCAL STATUS usb2MscXbdRead
        (
        XBD *     pXbd,                 /* pointer to bulk device         */
        int       startBlk,             /* logical block number           */
        int       numBlks,              /* number of blocks to read       */
        char *    pBuffer               /* store for data                 */
        )
        {
        USB2_MSC_XBD_LUN *      pXbdLun = (USB2_MSC_XBD_LUN *)pXbd;
        USB2_MSC_LUN_DEVICE *   pMscLunDevice = pXbdLun->pMscLunDevice;
        STATUS                  status;
        UINT32                  requiredSize;
        UINT32                  actualSize;

        actualSize =
            requiredSize =
                (UINT32)numBlks * pMscLunDevice->bytesPerSector;

        status = usb2MscScsiRead10(pMscLunDevice,
                                   startBlk,
                                   numBlks,
                                   (UINT8 *)pBuffer,
                                   &actualSize);

        /* Check if transfer succeeded */
        if (status != OK)
            {
            USB2_MSC_ERR("usb2MscScsiRead10 failed,"\
                         " actualSize %d but required %d\n",
                         actualSize, requiredSize,
                         3, 4, 5, 6);

            /* Set the errno to let the filesystem know the failure */
            (void) errnoSet(S_ioLib_DEVICE_ERROR);

            return ERROR;
            }
        else
            {
            return OK;
            }
        }

usb2MscScsiRead10 Generate the request that i can received.

I accept the request and call the libusb interface in the following three steps(I extracted some highlights):

  • src is 0x55534243 0x00000005 0x00020000 0x80000a28 0x00000000 0x00000001 0x00000000 0x000000

    do {
            r = libusb_bulk_transfer(handle, endpoint, src, 31, &size, 1000);
            if (r == LIBUSB_ERROR_PIPE) {
                libusb_clear_halt(handle, endpoint);
            }
            i++;
        } while ((r == LIBUSB_ERROR_PIPE) && (i < RETRY_MAX));
    
  • dest is used to store the received data,which has 512 bytes so i don't list here. The data is true that I have verified.

    do {
            r = libusb_bulk_transfer(handle, endpoint, dest, len, &size, 1000);
            if (r == LIBUSB_ERROR_PIPE) {
                libusb_clear_halt(handle, endpoint);
            }
            i++;
        } while ((r == LIBUSB_ERROR_PIPE) && (i < RETRY_MAX));
    

I then call libusb interface to get the csw, and the process also ensures that it is correct

Until this step is normal,then i get the src from driver which has some error:

0x55534243 0x00000006 0x00020000 0x80000a28 0x01cdffff 0x00000100 0x00000000 0x000000

0x1cdffff <==> 30,277,631‬ <==> 15138816 * 2(KB),this is the capacity of my usb device. but when i call libusb interface all data return is 0x47(have 512 0x47). Theoretically, after this step, the vxworks operating system can read the relevant information of the device and see bd0 after calling devs.So does anyone know the specific details about this piece that led me to this problem,thanks!

usb
libusb
vxworks
asked on Stack Overflow Feb 6, 2020 by tym • edited Feb 6, 2020 by tym

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0