--- ./libscg/scsi-aix.c.orig	2011-03-29 16:34:55.299568787 +0530
+++ ./libscg/scsi-aix.c	2011-03-30 14:55:51.396398859 +0530
@@ -143,7 +143,16 @@
 	if (busno >= 0 && tgt >= 0 && tlun >= 0) {	
 
 		sprintf(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,
@@ -161,7 +170,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,
@@ -492,6 +510,19 @@
 	errno = 0;
 	ret = do_ioctl(f, &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(f, &req, sp);
+			if(errno != 46)
+				b = 10;
+		} 
+	}
+
 	if (scgp->debug) {
 		printf("ret: %d errno: %d (%s)\n", ret, errno, errmsgstr(errno));
 		printf("data_length:     %d\n", req.data_length);
@@ -503,6 +534,13 @@
 		printf("adap_q_status:   0x%X\n", req.adap_q_status);
 		printf("q_tag_msg:       0x%X\n", req.q_tag_msg);
 		printf("flags:           0X%X\n", req.flags);
+
+		switch(using) {
+			case dkiocmd: 		printf("using ioctl: dkiocmd\n");
+			case dkpassthru: 	printf("using ioctl: dkpassthru\n");
+			case idepassthru: 	printf("using ioctl: ide_passthru\n");
+			case unknown:		printf("using ioctl: Unknown\n");	
+		}
 	}
 	if (ret < 0) {
 		sp->ux_errno = geterrno();
