--- ./libscg/scsi-aix.c.orig	2017-09-27 08:59:08 -0500
+++ ./libscg/scsi-aix.c	2017-09-27 09:03:58 -0500
@@ -175,7 +175,16 @@
 	if (busno >= 0 && tgt >= 0 && tlun >= 0) {
 
 		js_snprintf(devname, sizeof (devname), "/dev/rcd%d", tgt);
-		f = openx(devname, 0, 0, SC_DIAGNOSTIC);
+
+		/* open that only works on DVD-RAM media because it's r/w */
+		f = open(devname, 2, 0);
+		if (f < 0) {
+			/* retry open, because -R & -RW media will fail previous open 
+				This time openx with SC_DIAGNOSTIC*/
+			close(f);
+			f = openx(devname, 0, 0, SC_DIAGNOSTIC);
+		}
+
 		if (f < 0) {
 			if (scgp->errstr)
 				js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
@@ -193,7 +202,16 @@
 	}
 openbydev:
 	if (device != NULL && *device != '\0' && busno >= 0 && tgt >= 0 && tlun >= 0) {
-		f = openx(device, 0, 0, SC_DIAGNOSTIC);
+
+		/* open that only works on DVD-RAM media because it's r/w */
+ 		f = open(device, 2, 0);
+ 		if (f < 0) {
+     		/* retry open, because -R & -RW media will fail previous open
+         		This time openx with SC_DIAGNOSTIC*/
+     		close(f);
+     		f = openx(device, 0, 0, SC_DIAGNOSTIC);
+ 		}
+
 		if (f < 0) {
 			if (scgp->errstr)
 				js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
@@ -545,6 +563,20 @@
 	errno = 0;
 	ret = do_ioctl(scgp, &req, sp);
 
+	/*Added to retry Write10 cmds with errno of 46 (Drive Not Ready).
+	  There will be a couple of retry's with some sleep in between,
+	  which is needed because of the Long Write In Progress. */
+	if (errno == 46 && ret == -1 && req.scsi_cdb[0] == 0x2A) {
+	  	for(int b = 1; b < 6; b++) {
+			sleep(b*b);
+			errno = 0;
+			ret = do_ioctl(scgp, &req, sp);
+			if(errno != 46)
+				b = 10;
+		} 
+	}
+
+
 	if (scgp->debug > 0) {
 		js_fprintf((FILE *)scgp->errfile, "ret: %d errno: %d (%s)\n", ret, errno, errmsgstr(errno));
 		js_fprintf((FILE *)scgp->errfile, "data_length:     %d\n", req.data_length);
