$OpenBSD: patch-interface_scan_devices_c,v 1.3 2002/09/16 13:35:52 lebel Exp $ --- interface/scan_devices.c.orig Mon Mar 26 07:44:01 2001 +++ interface/scan_devices.c Mon Sep 16 13:05:57 2002 @@ -19,6 +19,8 @@ #include "common_interface.h" #include "utils.h" +#ifdef __linux__ + #define MAX_DEV_LEN 20 /* Safe because strings only come from below */ /* must be absolute paths! */ static char *scsi_cdrom_prefixes[]={ @@ -50,9 +52,16 @@ static char *cdrom_devices[]={ "/dev/gscd", "/dev/optcd",NULL}; +#endif +#ifdef __OpenBSD__ +static char *cdrom_devices[]={"/dev/cdrom", "/dev/cd?c", "/dev/mcd?c", + "/dev/acd?c", NULL }; +#endif + /* Functions here look for a cdrom drive; full init of a drive type happens in interface.c */ +#if defined(__linux__) || defined(__OpenBSD__) cdrom_drive *cdda_find_a_cdrom(int messagedest,char **messages){ /* Brute force... */ @@ -71,14 +80,16 @@ cdrom_drive *cdda_find_a_cdrom(int messa /* number, then letter */ - buffer[pos-(cdrom_devices[i])]=j+48; + buffer[pos-(cdrom_devices[i])]=j+'0'; if((d=cdda_identify(buffer,messagedest,messages))) return(d); idmessage(messagedest,messages,"",NULL); - buffer[pos-(cdrom_devices[i])]=j+97; +#ifdef __linux__ + buffer[pos-(cdrom_devices[i])]=j+'a'; if((d=cdda_identify(buffer,messagedest,messages))) return(d); idmessage(messagedest,messages,"",NULL); +#endif } }else{ /* Name. Go for it. */ @@ -98,6 +109,7 @@ cdrom_drive *cdda_find_a_cdrom(int messa } return(NULL); } +#endif /* __linux__ */ cdrom_drive *cdda_identify(const char *device, int messagedest,char **messages){ struct stat st; @@ -146,6 +158,9 @@ char *test_resolve_symlink(const char *f cdrom_drive *cdda_identify_cooked(const char *dev, int messagedest, char **messages){ +#ifdef __OpenBSD__ + return cdda_identify_scsi(dev, dev, messagedest, messages); +#else cdrom_drive *d=NULL; struct stat st; int fd=-1; @@ -273,6 +288,7 @@ cdrom_drive *cdda_identify_cooked(const idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description); return(d); +#endif } struct sg_id { @@ -289,12 +305,18 @@ typedef struct scsiid{ /* Even *this* isn't as simple as it bloody well should be :-P */ /* SG has an easy interface, but SCSI overall does not */ static int get_scsi_id(int fd, scsiid *id){ +#ifdef __linux__ struct sg_id argid; +#endif +#if defined (__NetBSD__) || defined (__OpenBSD__) + struct scsi_addr argid; +#endif int busarg; /* get the host/id/lun */ if(fd==-1)return(-1); +#ifdef __linux__ if(ioctl(fd,SCSI_IOCTL_GET_IDLUN,&argid))return(-1); id->bus=argid.l2; /* for now */ id->id=argid.l1&0xff; @@ -302,6 +324,18 @@ static int get_scsi_id(int fd, scsiid *i if(ioctl(fd,SCSI_IOCTL_GET_BUS_NUMBER,&busarg)==0) id->bus=busarg; +#endif +#if defined (__NetBSD__) || defined (__OpenBSD__) +#ifdef __NetBSD__ +#define ARGID argid.addr.scsi +#else +#define ARGID argid +#endif + if(ioctl(fd,SCIOCIDENTIFY,&argid))return(-1); + id->bus=ARGID.scbus; + id->id=ARGID.target; + id->lun=ARGID.lun; +#endif return(0); } @@ -401,6 +435,7 @@ void strscat(char *a,char *b,int n){ strcat(a," "); } +#ifdef __linux__ /* At this point, we're going to punt compatability before SG2, and allow only SG2 and SG3 */ static int verify_SG_version(cdrom_drive *d,int messagedest, @@ -430,6 +465,7 @@ static int verify_SG_version(cdrom_drive idmessage(messagedest,messages,buffer,""); return(major); } +#endif cdrom_drive *cdda_identify_scsi(const char *generic_device, const char *ioctl_device, int messagedest, @@ -460,6 +496,7 @@ cdrom_drive *cdda_identify_scsi(const ch generic_device); return(NULL); } +#ifdef __linux__ if((int)(g_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ if((int)(g_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ idmessage(messagedest,messages,"\t\t%s is not a SCSI device", @@ -471,6 +508,7 @@ cdrom_drive *cdda_identify_scsi(const ch ioctl_device=temp; } } +#endif } if(ioctl_device){ if(stat(ioctl_device,&i_st)){ @@ -478,6 +516,7 @@ cdrom_drive *cdda_identify_scsi(const ch ioctl_device); return(NULL); } +#ifdef __linux__ if((int)(i_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ if((int)(i_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ idmessage(messagedest,messages,"\t\t%s is not a SCSI device", @@ -489,6 +528,7 @@ cdrom_drive *cdda_identify_scsi(const ch ioctl_device=temp; } } +#endif } /* we need to resolve any symlinks for the lookup code to work */ @@ -505,6 +545,7 @@ cdrom_drive *cdda_identify_scsi(const ch } if(!generic_device || !ioctl_device){ +#ifdef __linux__ if(generic_device){ ioctl_device= scsi_match(generic_device,scsi_cdrom_prefixes, @@ -520,6 +561,9 @@ cdrom_drive *cdda_identify_scsi(const ch if(!generic_device) goto cdda_identify_scsi_fail; } +#else + goto cdda_identify_scsi_fail; +#endif } idmessage(messagedest,messages,"\t\tgeneric device: %s",generic_device); @@ -556,6 +600,7 @@ cdrom_drive *cdda_identify_scsi(const ch type=(int)(i_st.st_rdev>>8); +#ifdef __linux__ if(type==SCSI_CDROM_MAJOR){ if (!S_ISBLK(i_st.st_mode)) { idmessage(messagedest,messages,"\t\tSCSI CDROM device %s not a " @@ -567,8 +612,10 @@ cdrom_drive *cdda_identify_scsi(const ch "major number",ioctl_device); goto cdda_identify_scsi_fail; } +#endif } +#ifdef __linux__ if((int)(g_st.st_rdev>>8)==SCSI_GENERIC_MAJOR){ if (!S_ISCHR(g_st.st_mode)) { idmessage(messagedest,messages,"\t\tGeneric SCSI device %s not a " @@ -580,6 +627,7 @@ cdrom_drive *cdda_identify_scsi(const ch "major number",generic_device); goto cdda_identify_scsi_fail; } +#endif d=calloc(1,sizeof(cdrom_drive)); @@ -590,6 +638,7 @@ cdrom_drive *cdda_identify_scsi(const ch d->bigendianp=-1; /* We don't know yet... */ d->nsectors=-1; +#ifdef __linux__ version=verify_SG_version(d,messagedest,messages); switch(version){ case -1:case 0:case 1: @@ -599,6 +648,9 @@ cdrom_drive *cdda_identify_scsi(const ch d->interface=GENERIC_SCSI; break; } +#else + d->interface=GENERIC_SCSI; +#endif /* malloc our big buffer for scsi commands */ d->sg=malloc(MAX_BIG_BUFF_SIZE); @@ -617,7 +669,16 @@ cdrom_drive *cdda_identify_scsi(const ch /* It would seem some TOSHIBA CDROMs gets things wrong */ - if (!strncmp (p + 8, "TOSHIBA", 7) && +#ifndef TYPE_DISK +#define TYPE_DISK 0 /* direct */ +#endif +#ifndef TYPE_WORM +#define TYPE_WORM 4 /* write once, read many */ +#endif +#ifndef TYPE_ROM +#define TYPE_ROM 5 /* CD-ROM */ +#endif + if (p && !strncmp (p + 8, "TOSHIBA", 7) && !strncmp (p + 16, "CD-ROM", 6) && p[0] == TYPE_DISK) { p[0] = TYPE_ROM;