rt-thread/port/msc_device.c
int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) {
    // read10 & write10 has their own callback and MUST not be handled here

    void const *response = NULL;
    uint16_t resplen = 0;

    // most scsi handled is input
    bool in_xfer = true;

    switch (scsi_cmd[0]) {
        case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
            // Host is about to read/write etc ... better not to disconnect disk
            resplen = 0;
            break;

        default:
            // Set Sense = Invalid Command Operation
            tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);

            // negative means error -> tinyusb could stall and/or response with failed status
            resplen = -1;
            break;
    }

    // return resplen must not larger than bufsize
    if (resplen > bufsize) resplen = bufsize;

    if (response && (resplen > 0)) {
        if (in_xfer) {
            memcpy(buffer, response, resplen);
        } else {
            // SCSI output
        }
    }

    return resplen;
}
// Callback invoked when received an SCSI command not in built-in list below
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
// - READ10 and WRITE10 has their own callbacks
Callback invoked when received an SCSI command not in built-in list below
READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
READ10 and WRITE10 has their own callbacks
Callback invoked when received an SCSI command not in built - in list below READ_CAPACITY10 READ_FORMAT_CAPACITY INQUIRY MODE_SENSE6 REQUEST_SENSE READ10 and WRITE10 has their own callbacks
int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) {
    void const *response = NULL;
    uint16_t resplen = 0;
    bool in_xfer = true;
    switch (scsi_cmd[0]) {
        case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
            resplen = 0;
            break;
        default:
            tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
            resplen = -1;
            break;
    }
    if (resplen > bufsize) resplen = bufsize;
    if (response && (resplen > 0)) {
        if (in_xfer) {
            memcpy(buffer, response, resplen);
        } else {
        }
    }
    return resplen;
}
int32_t tud_msc_scsi_cb ( uint8_t lun , uint8_t const scsi_cmd [ 16 ] , void * buffer , uint16_t bufsize ) { void const * response = NULL ; uint16_t resplen = 0 ; bool in_xfer = true ; switch ( scsi_cmd [ 0 ] ) { case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL : resplen = 0 ; break ; default : tud_msc_set_sense ( lun , SCSI_SENSE_ILLEGAL_REQUEST , 0x20 , 0x00 ) ; resplen = -1 ; break ; } if ( resplen > bufsize ) resplen = bufsize ; if ( response && ( resplen > 0 ) ) { if ( in_xfer ) { memcpy ( buffer , response , resplen ) ; } else { } } return resplen ; }
Callback invoked when received an SCSI command not in built-in list below
 READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
 READ10 and WRITE10 has their own callbacks
Callback invoked when received an SCSI command not in built - in list below READ_CAPACITY10 READ_FORMAT_CAPACITY INQUIRY MODE_SENSE6 REQUEST_SENSE READ10 and WRITE10 has their own callbacks
// read10 & write10 has their own callback and MUST not be handled here // most scsi handled is input // Host is about to read/write etc ... better not to disconnect disk // Set Sense = Invalid Command Operation // negative means error -> tinyusb could stall and/or response with failed status // return resplen must not larger than bufsize // SCSI output