Skip to content

umockdev-record not capturing USB mass storage ioctl calls #251

@Degoah

Description

@Degoah

Description:

I am trying to use umockdev-record to capture the behavior of my application that interacts with a USB mass storage device. My trivial application, named get_usb_stick_info, uses the ioctl system call with the SG_IO command to retrieve information from the device.

The application code is provided below:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <scsi/sg.h>
#include <sys/ioctl.h>

#define INQUIRY_CMDLEN 6
#define INQUIRY_REPLY_LEN 96
#define SENSE_LEN 32

int main(int argc, char* argv[]) {
  const char *device = argv[1];   
  int fd = open(device, O_RDONLY);
  if (fd < 0) {
    perror("Failed to open device");
    return 1;
  }

  unsigned char inqCmdBlk[INQUIRY_CMDLEN] = {0x12, 0, 0, 0, INQUIRY_REPLY_LEN, 0};
  unsigned char inqBuff[INQUIRY_REPLY_LEN];
  unsigned char senseBuffer[SENSE_LEN];

  sg_io_hdr_t io_hdr;
  memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
  memset(inqBuff, 0, INQUIRY_REPLY_LEN);
  memset(senseBuffer, 0, SENSE_LEN);

  io_hdr.interface_id = 'S';
  io_hdr.cmd_len = sizeof(inqCmdBlk);
  io_hdr.mx_sb_len = sizeof(senseBuffer);
  io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
  io_hdr.dxfer_len = INQUIRY_REPLY_LEN;
  io_hdr.dxferp = inqBuff;
  io_hdr.cmdp = inqCmdBlk;
  io_hdr.sbp = senseBuffer;
  io_hdr.timeout = 2000;  // 2 seconds timeout

  if (ioctl(fd, SG_IO, &io_hdr) < 0) {
    perror("SG_IO ioctl failed");
    close(fd);
    return 1;
  }

  if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
    fprintf(stderr, "SCSI command failed\n");
    close(fd);
    return 1;
  }

  printf("Vendor ID: %.8s\n", &inqBuff[8]);
  printf("Product ID: %.16s\n", &inqBuff[16]);
  printf("Product Revision: %.4s\n", &inqBuff[32]);

  close(fd);
  return 0;
}

However, when I record the interaction using the following command:

umockdev-record /dev/sda > usb_stick.umockdev
umockdev-record --ioctl /dev/sda=usb_stick.ioctl ./get_usb_stick_info /dev/sda

The generated file usb_stick.ioctl file only contains the line @dev /dev/sda.

It seems that umockdev-record is not capturing the actual ioctl system calls being made by my application.

Expected Behavior:

The usb_stick.ioctl file should contain the details of the ioctl system call. This would allow me to replay the interaction with the USB device in a mock environment.

System Information:

umockdev version: 018.1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions