--- ../orig/dvd+rw-tools-7.0/growisofs.c	2006-09-24 10:28:53.000000000 -0700
+++ ./growisofs.c	2006-12-07 01:56:17.000000000 -0800
@@ -370,12 +370,17 @@
  *   upon Layer Break command, therefore longer timeout is required;
  * - Linux: deploy BLKFLSBUF to avoid media reloads when possible;
  * - add unit buffer utilization indicator [by request from K3b];
+ * 7.0.1: (by Nicolas Boichat, Bacula project)
+ * - Allow session to cross 4GB boundary regardless of medium type
+ *   (don't need to have a DL media)
+ * - Add a -F option (used instead of -M or -Z), which displays next_session
+ *   offset and capacity (free space = next_session - capacity).
  */
 #define PRINT_VERSION(cmd)	do {			\
     char *s=strrchr((cmd),'/');				\
     s ? s++ : (s=(cmd));				\
     printf ("* %.*sgrowisofs by <appro@fy.chalmers.se>,"\
-	    " version 7.0,\n",(int)(s-(cmd)),(cmd));	\
+	    " version 7.0.1,\n",(int)(s-(cmd)),(cmd));	\
 } while (0)
 
 #define _LARGEFILE_SOURCE 
@@ -2576,7 +2581,8 @@
 	else					arg = mkisofs_argv[0];
 
 	cmdsz--;
-	assert ((len0=strlen (arg)) < cmdsz);
+	len0 = strlen (arg);
+	assert (len0 < cmdsz);
 
 	strcpy (cmd,arg), cmd[len0++] = ' ', cmdsz -= len0;
 
@@ -2773,6 +2779,18 @@
 		else          in_device = argv[++i];
 		dev_found = 'Z';
 	    }
+	    else if (argv[i][1] == 'F')
+	    {	if (len > 2) in_device = argv[i]+2;
+		else	     in_device = argv[++i];
+		dev_found = 'F';
+		dry_run = 1; /* NEVER write anything with -F */
+	    }
+	    else if (!strncmp(opt,"-free-space",11))
+	    {	if (len > 11) in_device = opt+11;
+		else          in_device = argv[++i];
+		dev_found = 'F';
+		dry_run = 1; /* NEVER write anything with -F */
+	    }
 	    else if (!strcmp(opt,"-poor-man"))
 	    {	if (poor_man<0) poor_man = 1;
 		continue;
@@ -2898,7 +2916,7 @@
 	    else if (argv[i][1] == '?' || !strcmp(opt,"-help"))
 	    {	PRINT_VERSION (argv[0]);
 		printf ("- usage: %s [-dvd-compat] [-overburn] [-speed=1] \\\n"
-			"         -[ZM] /dev/dvd <mkisofs options>\n",argv[0]);
+			"         -[ZMF] /dev/dvd <mkisofs options>\n",argv[0]);
 		printf ("  for <mkisofs options> see 'mkisofs %s'\n",opt);
 		exit (FATAL_START(EINVAL));
 	    }
@@ -2993,7 +3011,13 @@
 		fprintf (stderr,"    you most likely want to use -Z option.\n"), 
 		exit (FATAL_START(errno));
 
-	    if (dev_found == 'M')
+	    if ((dev_found == 'M') || 
+		((dev_found == 'F') && !(mmc_profile&0x10000)) &&
+		 (saved_descriptors[0].type[0] ||
+		  saved_descriptors[0].type[1] ||
+		  saved_descriptors[0].type[2]))
+		/* -F : The medium is not blank, there is a fs on it (the_buffer[0,1 or 2] != 0),
+			so compute next_session. */
 	    {	if (memcmp (saved_descriptors[0].type,"\1CD001",6))
 	            fprintf (stderr,":-( %s doesn't look like isofs...\n",
 		    		in_device), exit(FATAL_START(EMEDIUMTYPE));
@@ -3016,8 +3040,7 @@
 			exit(FATAL_START(EINVAL));
 		}
 		else if (next_session > (0x200000-0x5000)) /* 4GB/2K-40MB/2K */
-		    if ((mmc_profile&0xFFFF)<0x20 ||
-			((mmc_profile&0xFFFF)<0x40 && !no_4gb_check))
+		    if ((mmc_profile&0xFFFF)<0x40 && !no_4gb_check)
 			fprintf (stderr,":-( next session would cross 4GB "
 					"boundary, aborting...\n"),
 			exit (FATAL_START(ENOSPC));
@@ -3060,7 +3083,7 @@
 	exit (FATAL_START(EINVAL));
 
     if (imgfd<0)
-    {	if (mkisofs_argc==1)
+    {	if ((mkisofs_argc==1) && (dev_found != 'F'))
 	    fprintf (stderr,"%s: no mkisofs options specified, "
 			    "aborting...\n",argv[0]),
 	    exit (FATAL_START(EINVAL));
@@ -3244,6 +3267,15 @@
 	}
     }
 
+    if (dev_found == 'F') {
+	off64_t capacity = 0;
+	printf("next_session=%d\n", next_session * CD_BLOCK);
+	if (ioctl_handle!=INVALID_HANDLE)
+	    capacity = get_capacity (ioctl_handle);
+	printf("capacity=%lld\n", capacity);
+	exit(0);
+    }
+
     if (imgfd>=0)
     {	quiet--;
 	if (builtin_dd (imgfd,out_fd,next_session*CD_BLOCK) < 0)
--- ../orig/dvd+rw-tools-7.0/Makefile	2006-08-27 13:07:37.000000000 -0700
+++ ./Makefile	2006-12-07 01:56:17.000000000 -0800
@@ -9,7 +9,7 @@
 
 CHAIN=growisofs dvd+rw-format dvd+rw-booktype dvd+rw-mediainfo dvd-ram-control
 clean:
-	-(rm *.o $(CHAIN) rpl8 btcflash; exit 0) < /dev/null > /dev/null 2>&1
+	-(rm *.o $(CHAIN) $(CHAIN:=.exe) rpl8 btcflash; exit 0) < /dev/null > /dev/null 2>&1
 
 VER=7.0
 DIST=dvd+rw-tools-$(VER)
--- ../orig/dvd+rw-tools-7.0/Makefile.m4	2006-09-24 10:55:19.000000000 -0700
+++ ./Makefile.m4	2006-12-07 01:59:30.000000000 -0800
@@ -1,12 +1,5 @@
 # OBS! M4 processed!
 changequote([, ])
-[
-CHAIN=growisofs dvd+rw-format dvd+rw-booktype dvd+rw-mediainfo dvd-ram-control
-
-dvd+rw-tools:	$(CHAIN)
-
-WARN=#-Wall	# developers are welcomed to build with `make WARN=-Wall'
-]
 
 # fix-up OS macro
 ifelse(substr(OS,0,7),[CYGWIN_],[define([OS],[MINGW32])])
@@ -38,11 +31,36 @@
 #
 # MINGW section
 #
+SUFFIXES+=.exe
 CC	=gcc
 CFLAGS	+=$(WARN) -mno-cygwin -O2
 CXX	=g++
 CXXFLAGS+=$(WARN) -mno-cygwin -O2 -fno-exceptions
 LINK.o	=$(LINK.cc)
+EXE	=.exe
+])
+
+ifelse(OS,XMINGW32,[
+#
+# MINGW cross-compile section
+#
+SUFFIXES+=.exe
+CC	=mingw32-gcc
+CFLAGS	+=$(WARN) -mno-cygwin -O2
+CXX	=mingw32-g++
+CXXFLAGS+=$(WARN) -mno-cygwin -O2 -fno-exceptions
+LINK.o	=$(LINK.cc)
+EXE	=.exe
+%.exe:%.o
+	$(CXX) $(CXXFLAGS) -o $@ $> $^ $(LDFLAGS) $(LDLIBS)
+
+install:	dvd+rw-tools
+	[[ -d $(prefix)/bin ]] || mkdir -p $(prefix)/bin
+	install -m 0755 $(CHAIN) $(prefix)/bin
+	[[ -d $(manprefix)/man1 ]] || mkdir -p $(manprefix)/man1
+	install -m 0644 growisofs.1 $(manprefix)/man1
+	-[[ -f rpl8 ]] && install -m 0755 rpl8 $(prefix)/bin; :
+	-[[ -f btcflash ]] && install -m 0755 btcflash $(prefix)/bin; :
 ])
 
 ifelse(OS,BSD,[
@@ -207,27 +225,33 @@
 
 # common section
 [
-growisofs:		growisofs_mmc.o growisofs.o
+CHAIN=growisofs$(EXE) dvd+rw-format$(EXE) dvd+rw-booktype$(EXE) dvd+rw-mediainfo$(EXE) dvd-ram-control$(EXE)
+
+dvd+rw-tools:	$(CHAIN)
+
+WARN=#-Wall	# developers are welcomed to build with `make WARN=-Wall'
+
+growisofs$(EXE):	growisofs_mmc.o growisofs.o
 growisofs.o:		growisofs.c mp.h
 growisofs_mmc.o:	growisofs_mmc.cpp transport.hxx
 
-dvd+rw-format:		dvd+rw-format.o
+dvd+rw-format$(EXE):	dvd+rw-format.o
 dvd+rw-format.o:	dvd+rw-format.cpp transport.hxx
 
-dvd+rw-mediainfo:	dvd+rw-mediainfo.o
+dvd+rw-mediainfo$(EXE):	dvd+rw-mediainfo.o
 dvd+rw-mediainfo.o:	dvd+rw-mediainfo.cpp transport.hxx
 
-dvd+rw-booktype:	dvd+rw-booktype.o
+dvd+rw-booktype$(EXE):	dvd+rw-booktype.o
 dvd+rw-booktype.o:	dvd+rw-booktype.cpp transport.hxx
 
-dvd-ram-control:	dvd-ram-control.o
+dvd-ram-control$(EXE):	dvd-ram-control.o
 dvd-ram-control.o:	dvd-ram-control.cpp transport.hxx
 
-rpl8:			rpl8.o
+rpl8$(EXE):		rpl8.o
 rpl8.o:			rpl8.cpp transport.hxx
 +rpl8:			rpl8
 #so that I can invoke `make +rpl8' to build rpl8...
-btcflash:		btcflash.o
+btcflash$(EXE):		btcflash.o
 btcflash.o:		btcflash.cpp transport.hxx
 +btcflash:		btcflash
 #so that I can invoke `make +btcflash' to build btcflash...
--- ../orig/dvd+rw-tools-7.0/Makefile.msc	1969-12-31 16:00:00.000000000 -0800
+++ ./Makefile.msc	2006-12-07 01:56:17.000000000 -0800
@@ -0,0 +1,48 @@
+CHAIN=growisofs.exe dvd+rw-format.exe dvd+rw-booktype.exe dvd+rw-mediainfo.exe dvd-ram-control.exe
+
+DEFINES=/D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_MBCS" 
+CFLAGS=$(DEFINES) /O2 /FD /EHsc /MD /W3 /nologo /c /Wp64 /Zi
+CPPFLAGS=$(DEFINES) /O2 /FD /EHsc /MD /W3 /nologo /c /Wp64 /Zi
+LDFLAGS=/NOLOGO /SUBSYSTEM:CONSOLE /MANIFEST
+
+all:
+
+clean:
+	-del *.obj *.manifest *.pdb *.idb $(CHAIN) > nul 2>&1
+
+install: $(CHAIN)
+	!xcopy $** $(prefix)\bin\ /y
+
+dvd+rw-tools:	$(CHAIN)
+
+growisofs.exe:		growisofs_mmc.obj growisofs.obj
+	link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
+	mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
+
+growisofs.obj:		growisofs.c mp.h
+
+growisofs_mmc.obj:	growisofs_mmc.cpp transport.hxx
+
+dvd+rw-format.exe:	dvd+rw-format.obj
+	link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
+	mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
+
+dvd+rw-format.obj:	dvd+rw-format.cpp transport.hxx
+
+dvd+rw-mediainfo.exe:	dvd+rw-mediainfo.obj
+	link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
+	mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
+
+dvd+rw-mediainfo.obj:	dvd+rw-mediainfo.cpp transport.hxx
+
+dvd+rw-booktype.exe:	dvd+rw-booktype.obj
+	link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
+	mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
+
+dvd+rw-booktype.obj:	dvd+rw-booktype.cpp transport.hxx
+
+dvd-ram-control.exe:	dvd-ram-control.obj
+	link $(LDFLAGS) /MANIFESTFILE:$@.manifest /out:$@ $** 
+	mt /nologo /outputresource:"$@;#1" -manifest $@.manifest
+
+dvd-ram-control.obj:	dvd-ram-control.cpp transport.hxx
