Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:11.4:Update
eject.import5542
eject-2.1.0-scsi.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File eject-2.1.0-scsi.diff of Package eject.import5542
--- eject.c +++ eject.c @@ -537,58 +537,50 @@ return (status == 0); } - /* - * Eject using SCSI commands. Return 1 if successful, 0 otherwise. + * Eject using SCSI SG_IO commands. Return 1 if successful, 0 otherwise. */ static int EjectScsi(int fd) { - int status; - struct sdata { - int inlen; - int outlen; - char cmd[256]; - } scsi_cmd; - - scsi_cmd.inlen = 0; - scsi_cmd.outlen = 0; - scsi_cmd.cmd[0] = ALLOW_MEDIUM_REMOVAL; - scsi_cmd.cmd[1] = 0; - scsi_cmd.cmd[2] = 0; - scsi_cmd.cmd[3] = 0; - scsi_cmd.cmd[4] = 0; - scsi_cmd.cmd[5] = 0; - status = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd); - if (status != 0) + int status, k; + sg_io_hdr_t io_hdr; + unsigned char allowRmBlk[6] = {ALLOW_MEDIUM_REMOVAL, 0, 0, 0, 0, 0}; + unsigned char startStop1Blk[6] = {START_STOP, 0, 0, 0, 1, 0}; + unsigned char startStop2Blk[6] = {START_STOP, 0, 0, 0, 2, 0}; + unsigned char inqBuff[2]; + unsigned char sense_buffer[32]; + + if ((ioctl(fd, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000)) { + printf("not an sg device, or old sg driver\n"); return 0; + } - scsi_cmd.inlen = 0; - scsi_cmd.outlen = 0; - scsi_cmd.cmd[0] = START_STOP; - scsi_cmd.cmd[1] = 0; - scsi_cmd.cmd[2] = 0; - scsi_cmd.cmd[3] = 0; - scsi_cmd.cmd[4] = 1; - scsi_cmd.cmd[5] = 0; - status = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd); - if (status != 0) + memset(&io_hdr, 0, sizeof(sg_io_hdr_t)); + io_hdr.interface_id = 'S'; + io_hdr.cmd_len = 6; + io_hdr.mx_sb_len = sizeof(sense_buffer); + io_hdr.dxfer_direction = SG_DXFER_NONE; + io_hdr.dxfer_len = 0; + io_hdr.dxferp = inqBuff; + io_hdr.sbp = sense_buffer; + io_hdr.timeout = 8000; + + io_hdr.cmdp = allowRmBlk; + status = ioctl(fd, SG_IO, (void *)&io_hdr); + if (status < 0) return 0; - scsi_cmd.inlen = 0; - scsi_cmd.outlen = 0; - scsi_cmd.cmd[0] = START_STOP; - scsi_cmd.cmd[1] = 0; - scsi_cmd.cmd[2] = 0; - scsi_cmd.cmd[3] = 0; - scsi_cmd.cmd[4] = 2; - scsi_cmd.cmd[5] = 0; - status = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd); - if (status != 0) + io_hdr.cmdp = startStop1Blk; + status = ioctl(fd, SG_IO, (void *)&io_hdr); + if (status < 0) return 0; - /* force kernel to reread partition table when new disc inserted */ - status = ioctl(fd, BLKRRPART); - return (status == 0); + io_hdr.cmdp = startStop2Blk; + status = ioctl(fd, SG_IO, (void *)&io_hdr); + if (status < 0) + return 0; + + return 1; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor