📄 os_netbsd.c
字号:
/* os_netbsd -- system interface for NetBSD Copyright (C) 1996 Dieter Baron and Armin Obersteiner This file is part of libscsi, a library for direct scsi device access The authors can be contacted at <dillo@giga.or.at> <armin.obersteiner@giga.or.at> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include <fcntl.h>#include <stdlib.h>#include <sys/ioctl.h>#include <sys/scsiio.h>#include <scsi/scsi.h>static struct scsireq sc__req;SCSI *sc_open(char *device){ SCSI *scsi; int fd; char b[12]; if (islower(device[0]) && islower(device[1]) && isdigit(device[2]) && device[3] == '\0') { sprintf(b, "/dev/r%sd", device); device = b; } if ((scsi=(SCSI *)malloc(sizeof(SCSI))) == NULL) return NULL; if ((fd=open(device, O_RDWR)) < 0) { free(scsi); return NULL; } scsi->fd = fd; scsi->timeout = 10000; scsi->sense.status = scsi->sense.len = 0; return scsi;}intsc_close(SCSI *s){ int err; err = close(s->fd); free(s); return err;}intsc_send(SCSI *s, int direction, int cmdlen, char *cmd, int datalen, char *data){ switch (direction) { case SC_READ: sc__req.flags = SCCMD_READ; break; case SC_WRITE: sc__req.flags = SCCMD_WRITE; break; default: sc__req.flags = 0; } sc__req.timeout = s->timeout; memcpy(sc__req.cmd, cmd, cmdlen); sc__req.cmdlen = cmdlen; sc__req.databuf = data; sc__req.datalen = datalen; sc__req.datalen_used = ((direction==SC_WRITE) ? datalen : 0); sc__req.senselen = SENSEBUFLEN; sc__req.senselen_used = 0; if (ioctl(s->fd, SCIOCCOMMAND, (char *)&sc__req) < 0) { s->sense.status = -1; s->sense.len = 0; return -1; } if (sc__req.retsts || sc__req.senselen_used) { s->sense.status = sc__req.retsts; s->sense.len = sc__req.senselen_used; memcpy((u_char *)&s->sense.data, sc__req.sense, sc__req.senselen_used); } return ((sc__req.retsts!=0 || (sc__req.senselen_used > 3 && (sc__req.sense[2] & 0x0f))) ? -1 : (direction==SC_READ ? sc__req.datalen_used : 0));}intsc_set_timeout(SCSI *s, u_long timeout){ s->timeout = timeout; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -