3 REM Check the free space available on a writable DVD
\r
4 REM Should always exit with 0 status, otherwise it indicates a serious error.
\r
5 REM (wrong number of arguments, Python exception...)
\r
7 REM called: dvd-handler <dvd-device-name> operation args
\r
9 REM operations used by Bacula:
\r
11 REM free (no arguments)
\r
12 REM Scan the device and report the available space. It returns:
\r
13 REM Prints on the first output line the free space available in
\r
15 REM If an error occurs, prints a negative number (-errno), followed,
\r
16 REM on the second line, by an error message.
\r
18 REM write op filename
\r
19 REM Write a part file to disk.
\r
20 REM This operation needs two additional arguments.
\r
21 REM The first (op) indicates to
\r
23 REM 1 -- first write to a blank disk
\r
24 REM 2 -- blank or truncate a disk
\r
26 REM The second is the filename to write
\r
28 REM operations available but not used by Bacula:
\r
30 REM test Scan the device and report the information found.
\r
31 REM This operation needs no further arguments.
\r
32 REM prepare Prepare a DVD+/-RW for being used by Bacula.
\r
33 REM Note: This is only useful if you already have some
\r
34 REM non-Bacula data on a medium, and you want to use
\r
35 REM it with Bacula. Don't run this on blank media, it
\r
39 REM $Id: dvd-handler.in,v 1.11 2006/08/30 16:19:30 kerns Exp $
\r
42 setlocal ENABLEDELAYEDEXPANSION
\r
43 SET PATH=%PATH%;@bin_dir_cmd@
\r
44 REM Configurable values:
\r
46 SET dvdrwmediainfo=dvd+rw-mediainfo.exe
\r
47 SET growcmd=growisofs.exe
\r
48 SET dvdrwformat=dvd+rw-format.exe
\r
52 REM Comment the following line if you want the tray to be reloaded
\r
53 REM when writing ends.
\r
54 SET growcmd=%growcmd% -use-the-force-luke^^^^^=notray
\r
56 REM end of configurable values
\r
58 IF "%1" == "" GOTO :usage
\r
59 IF "%2" == "" GOTO :usage
\r
66 ECHO No Error reported.
\r
67 ) ELSE IF "%2" == "prepare" (
\r
69 ECHO Medium prepared successfully.
\r
70 ) ELSE IF "%2" == "test" (
\r
71 IF %freespace_collected% EQU 0 CALL :collect_freespace
\r
72 IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype
\r
73 ECHO Class disk, initialized with device %device%
\r
74 ECHO type = '!disktype!' mode='!diskmode!' status = '!diskstatus!'
\r
75 ECHO next_session = !next_session! capacity = !capacity!
\r
76 ECHO Hardware device is '!hardwaredevice!'
\r
77 ECHO growcmd = '!growcmd!'
\r
78 ECHO growparams = '!growparams!'
\r
80 SET empty_disk=false
\r
82 IF !ERRORLEVEL! EQU 1 SET empty_disk=true
\r
83 SET rewritable=false
\r
85 IF !ERRORLEVEL! EQU 1 SET rewritable=true
\r
86 SET plus_RW_disk=false
\r
88 IF !ERRORLEVEL! EQU 1 SET plus_RW_disk=true
\r
89 SET minus_RW_disk=false
\r
91 IF !ERRORLEVEL! EQU 1 SET minus_RW_disk=true
\r
92 SET restricted_overwrite_disk=false
\r
93 CALL :is_restricted_overwrite
\r
94 IF !ERRORLEVEL! EQU 1 SET restricted_overwrite_disk=true
\r
95 SET blank_disk=false
\r
97 IF !ERRORLEVEL! EQU 1 SET blank_disk=true
\r
98 ECHO Empty disk: !empty_disk! Blank Disk: !blank_disk! ReWritable disk: !rewritable!
\r
99 ECHO Plus RW: !plus_RW_disk! Minus RW: !minus_RW_disk! Restricted Overwrite: !restricted_overwrite_disk!
\r
101 ECHO Free space: !ERRORLEVEL!
\r
102 ) ELSE IF "%2" == "write" (
\r
103 IF "%3" == "" GOTO :usage
\r
104 IF "%4" == "" GOTO :usage
\r
106 ECHO Part file %4 successfully written to disk.
\r
108 ECHO No operation - use test, free, prepare or write.
\r
109 ECHO THIS MIGHT BE A CASE OF DEBUGGING BACULA OR AN ERROR!
\r
113 REM ##########################################################################
\r
115 REM The rest of this file is a set of subroutines that return DVD disk
\r
118 REM Status information about the device and the disk loaded is collected
\r
119 REM only when asked for (for example dvd-freespace doesn't need to know the
\r
120 REM media type, and dvd-writepart doesn't not always need to know the free
\r
123 REM The following subroutines are implemented:
\r
124 REM init we need that...
\r
125 REM is_empty Set ERRORLEVEL to TRUE if the disk is empty, blank...
\r
126 REM this needs more work, especially concerning non-RW media
\r
127 REM and blank vs. no filesystem considerations. Here, we
\r
128 REM should also look for other filesystems - probably we don't
\r
129 REM want to silently overwrite UDF or ext2 or anything not
\r
130 REM mentioned in fstab...
\r
131 REM (NB: I don't think it is a problem)
\r
132 REM is_RW Set ERRORLEVEL to TRUE if the disk is RW (DVD-RW or DVD+RW)
\r
133 REM is_plus_RW Set ERRORLEVEL to TRUE if the disk is DVD+RW
\r
134 REM is_minus_RW Set ERRORLEVEL to TRUE if the disk is DVD-RW
\r
135 REM is_blank Set ERRORLEVEL to TRUE if the disk is blank
\r
136 REM free Returns the available free space.
\r
137 REM write Writes one part file to disk, either starting a new file
\r
138 REM system on disk, or appending to it.
\r
139 REM This method should also prepare a blank disk so that a
\r
140 REM certain part of the disk is used to allow detection of a
\r
141 REM used disk by all / more disk drives.
\r
142 REM blank Blank the device
\r
144 REM ##########################################################################
\r
150 SET diskstatus=none
\r
151 SET hardwaredevice=none
\r
153 SET next_session=-1
\r
156 SET freespace_collected=0
\r
157 SET mediumtype_collected=0
\r
159 SET growcmd=%growcmd% -quiet -use-the-force-luke^^^=4gms
\r
161 SET growparams=-A "Bacula Data" -input-charset=default -iso-level 3 -pad
\r
162 SET growparams=%growparams% -p "dvd-handler / growisofs" -sysid "BACULADATA" -R
\r
168 FOR /f "delims== tokens=1*" %%i in ( '%growcmd% -F %device%' ) DO (
\r
169 IF "%%i" == "next_session" (
\r
170 SET next_session=%%j
\r
171 ) ELSE IF "%%i" == "capacity" (
\r
173 ) ELSE IF "%%j" == "" (
\r
174 SET result=!result! %%i
\r
176 SET RESULT=!result! %%i=%%j
\r
179 SET status=%ERRORLEVEL%
\r
180 IF %STATUS% NEQ 0 (
\r
181 SET /a STATUS=STATUS ^& 0x7F
\r
182 IF !STATUS! EQU 112 (
\r
183 REM Kludge to force dvd-handler to return a free space of 0
\r
186 freespace_collected = 1
\r
189 ECHO growisofs returned with an error !STATUS!. Please check you are using a patched version of dvd+rw-tools.
\r
194 IF %next_session% EQU 0 IF %capacity% EQU 0 (
\r
195 ECHO Cannot get next_session and capacity from growisofs.
\r
196 ECHO Returned: %result:|=^|%
\r
199 SET freespace_collected=1
\r
202 :collect_mediumtype
\r
203 SET hardwaredevice=
\r
208 FOR /f "delims=: tokens=1,2 usebackq" %%i in ( `"%dvdrwmediainfo%" %device%` ) DO (
\r
209 IF "%%i" == "INQUIRY" FOR /f "tokens=*" %%k in ( "%%j" ) DO SET hardwaredevice=%%k
\r
210 IF "%%i" == " Mounted Media" FOR /f "tokens=1,2* delims=, " %%k in ( "%%j" ) DO (
\r
214 IF "%%i" == " Disc status" FOR /f "tokens=*" %%k in ( "%%j" ) DO SET diskstatus=%%k
\r
217 IF NOT DEFINED disktype (
\r
218 ECHO Media type not found in %dvdrwmediainfo% output
\r
222 IF "%disktype%" == "DVD-RW" IF NOT DEFINED diskmode (
\r
223 ECHO Media mode not found for DVD-RW in %dvdrwmediainfo% output
\r
227 IF NOT DEFINED diskstatus (
\r
228 ECHO Disc status not found in %dvdrwmediainfo% output
\r
232 SET mediumtype_collected=1
\r
236 IF %freespace_collected% EQU 0 CALL :collect_freespace
\r
237 IF %next_session% EQU 0 ( EXIT /b 1 ) ELSE EXIT /b 0
\r
240 IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype
\r
241 IF %disktype% == "DVD-RW" EXIT /b 1
\r
242 IF %disktype% == "DVD+RW" EXIT /b 1
\r
243 IF %disktype% == "DVD-RAM" EXIT /b 1
\r
247 IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype
\r
248 IF "%disktype%" == "DVD+RW" EXIT /b 1
\r
252 IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype
\r
253 IF "%disktype%" == "DVD-RW" EXIT /b 1
\r
256 :is_restricted_overwrite
\r
257 IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype
\r
258 IF "%diskmode%" == "Restricted Overwrite" EXIT /b 1
\r
262 IF %mediumtype_collected% EQU 0 CALL :collect_mediumtype
\r
263 IF "%diskstatus%" == "blank" EXIT /b 1
\r
267 IF %freespace_collected% EQU 0 CALL :collect_freespace
\r
268 FOR /f %%i in ( 'expr64 "capacity - next_session - margin"' ) DO SET fr=%%i
\r
269 expr64 /q "fr < 0" && ( EXIT /b 0 ) || EXIT /b %fr%
\r
271 REM %1 - newvol, %2 - partfile
\r
273 REM Blank DVD+RW when there is no data on it
\r
275 SET tmpvar=%ERRORLEVEL%
\r
277 SET /a tmpvar=tmpvar + ERRORLEVEL
\r
278 IF %1 EQU 1 IF %tmpvar% EQU 2 (
\r
279 ECHO DVD+RW looks brand-new, blank it to fix some DVD-writers bugs.
\r
281 ECHO Done, now writing the part file.
\r
284 IF %ERRORLEVEL% NEQ 0 IF %1 NEQ 0 (
\r
285 CALL :is_restricted_overwrite
\r
286 IF !ERRORLEVEL! EQU 0 (
\r
287 ECHO DVD-RW is in %diskmode% mode, reformating it to Restricted Overwrite
\r
288 CALL :reformat_minus_RW
\r
289 ECHO Done, now writing the part file.
\r
293 REM Ignore any existing iso9660 filesystem - used for truncate
\r
295 SET cmd_opts= -use-the-force-luke^^^=tty -Z
\r
302 ECHO Running %growcmd% %growparams% %cmd_opts% %device% %2
\r
303 %growcmd% %growparams% %cmd_opts% %device% %2
\r
304 IF %ERRORLEVEL% NEQ 0 (
\r
305 ECHO Exited with status !ERRORLEVEL!
\r
312 IF %ERRORLEVEL% EQU 0 (
\r
313 ECHO I won't prepare a non-rewritable medium
\r
317 REM Blank DVD+RW when there is no data on it
\r
319 SET result=%ERRORLEVEL%
\r
321 SET /a result=result + ERRORLEVEL
\r
322 IF %result% EQU 2 (
\r
323 ECHO DVD+RW looks brand-new, blank it to fix some DVD-writers bugs.
\r
329 IF %ERRORLEVEL% EQU 1 (
\r
330 CALL :is_restricted_overwrite
\r
331 IF !ERRORLEVEL! EQU 0 (
\r
332 ECHO DVD-RW is in %diskmode% mode, reformating it to Restricted Overwrite
\r
333 CALL :reformat_minus_RW
\r
341 ECHO Running %growcmd% -Z %device% =/dev/zero
\r
342 %growcmd% -Z %device% =/dev/zero
\r
343 IF %ERRORLEVEL% NEQ 0 (
\r
344 ECHO Exited with status !ERRORLEVEL!
\r
350 ECHO Running %dvdrwformat% -force %device%
\r
351 %dvdrwformat% -force %device%
\r
352 IF %ERRORLEVEL% NEQ 0 (
\r
353 ECHO Exited with status !ERRORLEVEL!
\r
358 REM class disk ends here.
\r
361 ECHO Wrong number of arguments.
\r
365 ECHO dvd-handler DVD-DRIVE test
\r
366 ECHO dvd-handler DVD-DRIVE free
\r
367 ECHO dvd-handler DVD-DRIVE write APPEND FILE
\r
368 ECHO dvd-handler DVD-DRIVE blank
\r
370 ECHO where DVD-DRIVE is the drive letter of the DVD burner like D:
\r
373 ECHO test Scan the device and report the information found.
\r
374 ECHO This operation needs no further arguments.
\r
375 ECHO free Scan the device and report the available space.
\r
376 ECHO write Write a part file to disk.
\r
377 ECHO This operation needs two additional arguments.
\r
378 ECHO The first indicates to append (0), restart the
\r
379 ECHO disk (1) or restart existing disk (2). The second
\r
380 ECHO is the file to write.
\r
381 ECHO prepare Prepare a DVD+/-RW for being used by Bacula.
\r
382 ECHO Note: This is only useful if you already have some
\r
383 ECHO non-Bacula data on a medium, and you want to use
\r
384 ECHO it with Bacula. Don't run this on blank media, it
\r