$NetBSD: patch-af,v 1.1.1.1 2002/05/02 13:28:16 bouyer Exp $

--- changer-src/scsi-chio.c.orig	Thu Jun 17 20:33:19 1999
+++ changer-src/scsi-chio.c	Tue Apr 30 14:33:22 2002
@@ -59,16 +59,26 @@
  */
 int GetCurrentSlot(int fd, int drive)
 {
-    struct changer_element_status  ces;
+#if defined(OCHIOGSTATUS)
+struct ochanger_element_status_request cesr;
+#else
+struct changer_element_status  ces;
+#endif
     int slot;
     int i, rc;
 
     get_changer_info(fd);
+#if defined(OCHIOGSTATUS)
+    cesr.cesr_type = CHET_ST;
+    cesr.cesr_data = malloc(changer_info.cp_nslots);
 
+    rc = ioctl(fd, CHIOGSTATUS, &cesr);
+#else
     ces.ces_type = CHET_ST;
     ces.ces_data = malloc(changer_info.cp_nslots);
 
     rc = ioctl(fd, CHIOGSTATUS, &ces);
+#endif
     if (rc) {
 	dbprintf(("%s: changer status query failed: 0x%x %s\n",
 			get_pname(), rc,strerror(errno)));
@@ -76,7 +86,11 @@
     }
     for (slot = 0; slot < changer_info.cp_nslots; slot++)
     {
+#if defined(OCHIOGSTATUS)
+    	i = cesr.cesr_data[slot] & CESTATUS_FULL;
+#else
     	i = ces.ces_data[slot] & CESTATUS_FULL;
+#endif
     	dbprintf(("\tGetCurrentSlot slot %d = %d\n", slot, i));
     	if (!i)
             return(slot);
@@ -121,25 +135,41 @@
  */
 int isempty(int fd, int slot)
 {
+#if defined(OCHIOGSTATUS)
+struct ochanger_element_status_request cesr;
+#else
 struct changer_element_status  ces;
+#endif
+
 int                            i,rc;
 int type=CHET_ST;
 
     get_changer_info(fd);
 
+#if defined(OCHIOGSTATUS)
+    cesr.cesr_type = type;
+    cesr.cesr_data = malloc(changer_info.cp_nslots);
+    rc = ioctl(fd, OCHIOGSTATUS, &cesr);
+#else
     ces.ces_type = type;
     ces.ces_data = malloc(changer_info.cp_nslots);
-
     rc = ioctl(fd, CHIOGSTATUS, &ces);
+#endif
+
     if (rc) {
 	dbprintf(("%s: changer status query failed: 0x%x %s\n",
 			get_pname(), rc,strerror(errno)));
 	return -1;
     }
 
+#if defined(OCHIOGSTATUS)
+    i = cesr.cesr_data[slot] & CESTATUS_FULL;
+    free(cesr.cesr_data);
+#else
     i = ces.ces_data[slot] & CESTATUS_FULL;
-
     free(ces.ces_data);
+#endif
+
     return !i;
 }
 
@@ -148,16 +178,27 @@
  */
 int find_empty(int fd, int start, int count)
 {
+#if defined(OCHIOGSTATUS)
+struct ochanger_element_status_request cesr;
+#else
 struct changer_element_status  ces;
+#endif
+
 int                            i,rc;
 int type=CHET_ST;
 
     get_changer_info(fd);
 
+#if defined(OCHIOGSTATUS)
+    cesr.cesr_type = type;
+    cesr.cesr_data = malloc(changer_info.cp_nslots);
+    rc = ioctl(fd, OCHIOGSTATUS, &cesr);
+#else
     ces.ces_type = type;
     ces.ces_data = malloc(changer_info.cp_nslots);
+    rc = ioctl(fd, CHIOGSTATUS, &ces);
+#endif
 
-    rc = ioctl(fd,CHIOGSTATUS,&ces);
     if (rc) {
 	dbprintf(("%s: changer status query failed: 0x%x %s\n",
 			get_pname(), rc, strerror(errno)));
@@ -165,9 +206,17 @@
     }
 
     i = 0; 
+
+#if defined(OCHIOGSTATUS)
+    while ((i < changer_info.cp_nslots)&&(cesr.cesr_data[i] & CESTATUS_FULL))
+        i++;
+    free(cesr.cesr_data);
+#else
     while ((i < changer_info.cp_nslots)&&(ces.ces_data[i] & CESTATUS_FULL))
 	i++;
     free(ces.ces_data);
+#endif
+
     return i;
 }
 
@@ -176,25 +225,41 @@
  */
 int drive_loaded(int fd, int drivenum)
 {
+#if defined(OCHIOGSTATUS)
+struct ochanger_element_status_request cesr;
+#else
 struct changer_element_status  ces;
+#endif
+
 int                            i,rc;
 int type=CHET_DT;
 
     get_changer_info(fd);
 
+#if defined(OCHIOGSTATUS)
+    cesr.cesr_type = type;
+    cesr.cesr_data = malloc(changer_info.cp_ndrives);
+    rc = ioctl(fd, OCHIOGSTATUS, &cesr);
+#else
     ces.ces_type = type;
     ces.ces_data = malloc(changer_info.cp_ndrives);
-
     rc = ioctl(fd, CHIOGSTATUS, &ces);
+#endif
+
     if (rc) {
 	dbprintf(("%s: drive status query failed: 0x%x %s\n",
 			get_pname(), rc, strerror(errno)));
 	return -1;
     }
 
+#if defined(OCHIOGSTATUS)
+    i = (cesr.cesr_data[drivenum] & CESTATUS_FULL);
+    free(cesr.cesr_data);
+#else
     i = (ces.ces_data[drivenum] & CESTATUS_FULL);
-
     free(ces.ces_data);
+#endif
+
     return i;
 }
 
@@ -204,7 +269,12 @@
  */
 int unload(int fd, int drive, int slot)
 {
+#if defined(OCHIOGSTATUS)
+struct changer_move_request move;
+#else
 struct changer_move  move;
+#endif
+
 int rc;
 
     dbprintf(("unload : fd = %d, drive = %d, slot =%d\n",fd, drive, slot));
@@ -230,7 +300,12 @@
  */
 int load(int fd, int drive, int slot)
 {
+#if defined(OCHIOGSTATUS)
+struct changer_move_request move;
+#else
 struct changer_move  move;
+#endif
+
 int rc;
 
     dbprintf(("load : fd = %d, drive = %d, slot =%d\n",fd, drive, slot));
