8c1a2e
diff -up cdrkit-1.1.11/wodim/drv_mmc.c.format cdrkit-1.1.11/wodim/drv_mmc.c
8c1a2e
--- cdrkit-1.1.11/wodim/drv_mmc.c.format	2011-05-18 16:49:14.591822130 +0200
8c1a2e
+++ cdrkit-1.1.11/wodim/drv_mmc.c	2011-05-18 16:49:14.596822130 +0200
8c1a2e
@@ -1507,6 +1507,11 @@ getdisktype_mdvd(SCSI *usalp, cdr_t *dp)
8c1a2e
 	dstat_t	*dsp = dp->cdr_dstat;
8c1a2e
 
8c1a2e
 	struct track_info track_info;
8c1a2e
+
8c1a2e
+	extern char *buf;
8c1a2e
+	struct disk_info *dip;
8c1a2e
+	int profile;
8c1a2e
+
8c1a2e
     if(lverbose)
8c1a2e
         printf("HINT: use dvd+rw-mediainfo from dvd+rw-tools for information extraction.\n");
8c1a2e
 	/* if(getdisktype_mmc(usalp, dp)<0)
8c1a2e
@@ -1521,6 +1526,18 @@ getdisktype_mdvd(SCSI *usalp, cdr_t *dp)
8c1a2e
 	dsp->ds_disktype&= ~DT_CD;
8c1a2e
 	dsp->ds_disktype|= DT_DVD;
8c1a2e
 
8c1a2e
+	profile = get_curprofile(usalp);
8c1a2e
+	if (profile == 0x1A) {
8c1a2e
+		dip = (struct disk_info *)buf;
8c1a2e
+		if (get_diskinfo(usalp, dip) < 0)
8c1a2e
+			return (-1);
8c1a2e
+		if (dip->disk_status == DS_EMPTY) {	/* Unformatted	    */
8c1a2e
+			dsp->ds_flags |= DSF_NEED_FORMAT;
8c1a2e
+			if(lverbose)
8c1a2e
+				printf("The medium is empty, it will be auto formatted.\n");
8c1a2e
+		}
8c1a2e
+	}
8c1a2e
+	
8c1a2e
 	return (ret);
8c1a2e
 
8c1a2e
 }
8c1a2e
diff -up cdrkit-1.1.11/wodim/scsi_cdr.c.format cdrkit-1.1.11/wodim/scsi_cdr.c
8c1a2e
--- cdrkit-1.1.11/wodim/scsi_cdr.c.format	2011-05-18 16:49:14.601822130 +0200
8c1a2e
+++ cdrkit-1.1.11/wodim/scsi_cdr.c	2011-05-18 16:49:14.600822130 +0200
8c1a2e
@@ -1328,7 +1328,7 @@ scsi_format(SCSI *usalp, caddr_t addr, i
8c1a2e
 	}
8c1a2e
 	sleep(10);
8c1a2e
 	printf("\rFormating in progress: 100.00 %% done.        \n");
8c1a2e
-	if (pid) exit (0);
8c1a2e
+	if (pid > 0) exit (0);
8c1a2e
 	return ret;
8c1a2e
 }
8c1a2e
 
8c1a2e
diff -up cdrkit-1.1.11/wodim/wodim.c.format cdrkit-1.1.11/wodim/wodim.c
8c1a2e
--- cdrkit-1.1.11/wodim/wodim.c.format	2011-05-18 16:49:14.584822130 +0200
8c1a2e
+++ cdrkit-1.1.11/wodim/wodim.c	2011-05-18 17:21:59.510821630 +0200
8c1a2e
@@ -946,6 +946,40 @@ int main(int argc, char *argv[])
8c1a2e
 		print_toc(usalp, dp);
8c1a2e
 		comexit(0);
8c1a2e
 	}
8c1a2e
+	
8c1a2e
+	if ((flags & F_FORMAT) || (dp->cdr_dstat->ds_flags & DSF_NEED_FORMAT)) {
8c1a2e
+		printf("wodim: media format asked\n");
8c1a2e
+		/*
8c1a2e
+		* Do not abort if OPC failes. Just give it a chance
8c1a2e
+		* for better laser power calibration than without OPC.
8c1a2e
+		*
8c1a2e
+		* Ricoh drives return with a vendor unique sense code.
8c1a2e
+		* This is most likely because they refuse to do OPC
8c1a2e
+		* on a non blank media.
8c1a2e
+		*/
8c1a2e
+		usalp->silent++;
8c1a2e
+		do_opc(usalp, dp, flags);
8c1a2e
+		usalp->silent--;
8c1a2e
+		wait_unit_ready(usalp, 120);
8c1a2e
+		if (gettimeofday(&starttime, (struct timezone *)0) < 0)
8c1a2e
+			errmsg("Cannot get start time\n");
8c1a2e
+		
8c1a2e
+		if ((*dp->cdr_format)(usalp, dp, formattype) < 0) {
8c1a2e
+			errmsgno(EX_BAD, "Cannot format disk, aborting.\n");
8c1a2e
+			comexit(EX_BAD);
8c1a2e
+		}
8c1a2e
+		if (gettimeofday(&fixtime, (struct timezone *)0) < 0)
8c1a2e
+			errmsg("Cannot get format time\n");
8c1a2e
+		if (lverbose)
8c1a2e
+			prtimediff("Formatting time: ", &starttime, &fixtime);
8c1a2e
+
8c1a2e
+		if (!wait_unit_ready(usalp, 240) || tracks == 0) {
8c1a2e
+			comexit(0);
8c1a2e
+		}
8c1a2e
+		if (gettimeofday(&starttime, (struct timezone *)0) < 0)
8c1a2e
+			errmsg("Cannot get start time\n");
8c1a2e
+	}
8c1a2e
+	
8c1a2e
 #ifdef	XXX
8c1a2e
 	if ((*dp->cdr_check_session)() < 0) {
8c1a2e
 		comexit(EX_BAD);
8c1a2e
@@ -1230,38 +1264,6 @@ int main(int argc, char *argv[])
8c1a2e
 			comexit(0);
8c1a2e
 		}
8c1a2e
 	}
8c1a2e
-	if (flags & F_FORMAT) {
8c1a2e
-		printf("wodim: media format asked\n");
8c1a2e
-		/*
8c1a2e
-		* Do not abort if OPC failes. Just give it a chance
8c1a2e
-		* for better laser power calibration than without OPC.
8c1a2e
-		*
8c1a2e
-		* Ricoh drives return with a vendor unique sense code.
8c1a2e
-		* This is most likely because they refuse to do OPC
8c1a2e
-		* on a non blank media.
8c1a2e
-		*/
8c1a2e
-		usalp->silent++;
8c1a2e
-		do_opc(usalp, dp, flags);
8c1a2e
-		usalp->silent--;
8c1a2e
-		wait_unit_ready(usalp, 120);
8c1a2e
-		if (gettimeofday(&starttime, (struct timezone *)0) < 0)
8c1a2e
-			errmsg("Cannot get start time\n");
8c1a2e
-
8c1a2e
-		if ((*dp->cdr_format)(usalp, dp, formattype) < 0) {
8c1a2e
-			errmsgno(EX_BAD, "Cannot format disk, aborting.\n");
8c1a2e
-			comexit(EX_BAD);
8c1a2e
-		}
8c1a2e
-		if (gettimeofday(&fixtime, (struct timezone *)0) < 0)
8c1a2e
-			errmsg("Cannot get format time\n");
8c1a2e
-		if (lverbose)
8c1a2e
-			prtimediff("Formatting time: ", &starttime, &fixtime);
8c1a2e
-
8c1a2e
-		if (!wait_unit_ready(usalp, 240) || tracks == 0) {
8c1a2e
-			comexit(0);
8c1a2e
-		}
8c1a2e
-		if (gettimeofday(&starttime, (struct timezone *)0) < 0)
8c1a2e
-			errmsg("Cannot get start time\n");
8c1a2e
-	}
8c1a2e
 	/*
8c1a2e
 	* Reset start time so we will not see blanking time and
8c1a2e
 	* writing time counted together.