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