# ACTIONPRO X7 ## Research ## Research: File/Drive Access by Action Manager 1.3 Opening Drive/Device: ``` CreateFile(): Desired Access: Generic Read/Write Disposition: Open Options: Synchronous IO Non-Alert, Non-Directory File Attributes: n/a ShareMode: Read, Write AllocationSize: n/a OpenResult: Opened ``` Sending Command: Windows Application sends `IOCTL_SCSI_PASS_THROUGH` with `DeviceIoControl()`. ### Research: Code Snippets using ioctl() Code example #1: ``` #define DEF_TIMEOUT 5000 // 5 seconds char cDiskName[] = "/dev/sg3"; int fd = open(cDiskName, O_RDWR); if (fd < 0) { printf("Open error: %s, errno=%d (%s)\n", cDiskName, errno, strerror(errno)); return 1; } unsigned char turCmbBlk[] = {0x00, 0, 0, 0, 0, 0}; struct sg_io_hdr io_hdr; unsigned char cIOBuffer[100]; // buffer initialization code omitted memset(&io_hdr, 0, sizeof(struct sg_io_hdr)); io_hdr.interface_id = 'S'; io_hdr.cmd_len = sizeof(turCmbBlk); io_hdr.mx_sb_len = sizeof(cIOBuffer); io_hdr.dxfer_direction = SG_DXFER_NONE; io_hdr.cmdp = turCmbBlk; io_hdr.sbp = cIOBuffer; io_hdr.timeout = DEF_TIMEOUT; if (ioctl(fd, SG_IO, &io_hdr) < 0) { printf("ioctl error: errno=%d (%s)\n", errno, strerror(errno)); } // Code returned here without any errors but cIOBuffer remains unchanged. ``` ``` #include #include #include #include #include void main(int argc, char **argv) { const char *filename; int fd; filename = argv[1]; fd = open(filename, O_WRONLY); ioctl(fd, USBDEVFS_RESET, 0); close(fd); return; } ``` ``` #define BUFF_SIZE 100 // - Buffersize #define DEF_TIMEOUT 5000 // 5 seconds char cDiskName[] = "/dev/sg3"; int fd = open(cDiskName, O_RDWR); if (fd < 0) { printf("Open error: %s, errno=%d (%s)\n", cDiskName, errno, strerror(errno)); return 1; } unsigned char turCmbBlk[] = {0x00, 0, 0, 0, 0, 0}; struct sg_io_hdr *p = (struct sg_io_hdr *) malloc(sizeof(struct sg_io_hdr)); // - dynamic memory allocation - free() required somewhere unsigned char cIOBuffer[BUFF_SIZE]; unsigned char replyBuffer[BUFF_SIZE]; // - dxfer buffer // buffer initialization code omitted memset(p, 0, sizeof(struct sg_io_hdr)); p->interface_id = 'S'; p->cmd_len = sizeof(turCmbBlk); p->mx_sb_len = BUFF_SIZE; p->dxfer_direction = SG_DXFER_NONE; p->cmdp = turCmbBlk; p->sbp = cIOBuffer; p->timeout = DEF_TIMEOUT; p->flags = SG_FLAG_DIRECT_IO; // - Does this help? p->dxferp = replyBuffer; // - Set dxferp buffer - (A) p->dxfer_len = BUFF_SIZE; // - buffersize if (ioctl(fd, SG_IO, p) < 0) { printf("ioctl error: errno=%d (%s)\n", errno, strerror(errno)); } // Code returned here without any errors but cIOBuffer remains unchanged. ``` Use for `scsi/sg.h` and `ioctl`.