@echo off
rem 24-04-2001 JvW Added 'pl lvm %1 related
rem 08-07-2001 JvW Added automatic check of all disks (3.42)
rem 01-08-2001 JvW Added search ALL sectors, GEO-specification and usage
rem 01-08-2001 JvW Made .BAT and .CMD identical (just rename/copy)
rem 01-10-2001 JvW Added fixsn display of important sectors
rem 01-11-2001 JvW Added diagnostic for #disks larger than 50 (possible trap)
rem 11-11-2001 JvW Added check for disk-1 being locked by other LVM/FDISK/DFSee
rem 30-11-2001 JvW Always use -R option for safe read-only mode
rem 18-04-2002 JvW Added more checks on Win-NT/DRDOS environment
rem 07-05-2002 JvW Added -7 option to force 7-bit ASCII output only
echo.
echo Get DFSee UNFDISK information

if "%0"=="UNFDTEST"     echo on
if "%0"=="unfdtest"     echo on

if "%OS%"==""        goto notnt
if "%OS%"=="DOS"     goto notnt
if "%OS%"=="MSDOS"   goto notnt
if "%OS%"=="DRDOS"   goto notnt
if "%OS%"=="IBMDOS"  goto notnt
:dfsnt
set dfsexe=dfsnt
goto dfsee
:notnt
if "%OS2_SHELL%"=="" goto notos2
:dfsnt
set dfsexe=dfs
goto dfsee
:notos2
set dfsexe=dfsmdos
:dfsee
if exist dfsunfd1.log del  dfsunfd1.log
if exist dfsunfd2.log del  dfsunfd2.log
if exist dfsunfd3.log del  dfsunfd3.log
if exist dfsunfd4.log del  dfsunfd4.log
if exist dfsunfd5.log del  dfsunfd5.log
if exist dfsunfd6.log del  dfsunfd6.log
if exist dfsunfd7.log del  dfsunfd7.log
if exist dfsunfd8.log del  dfsunfd8.log
if exist dfsunfd9.log del  dfsunfd9.log

if "%1" == "" echo (to get help on other usage just type:  '%0  ?')
echo.
if "%1" == "?"   goto usage
if "%1" == "/?"  goto usage
if "%1" == "-?"  goto usage

%dfsexe% -b -q query RValid
if not errorlevel 1 goto work
echo.
echo NOTE: Your DFSee version is not properly registred, this will
echo       require you to press [Space-bar] a few times  ...
echo.

:work
if "%2" == "*"   goto allsect
if "%2" == "a"   goto allsect
if "%2" == "A"   goto allsect
if "%2" == "All" goto allsect
if "%2" == "ALL" goto allsect
if "%2" == "all" goto allsect
if "%2" == ""    goto cbfast
if "%1" == "*" echo WARNING: specified geometry '%2' is ignored with disks *

:cbfast
echo Searching partition information on cylinder boundaries only. (fast)
set scmd=bsfind
goto scmdset
:allsect
echo Searching partition information in ALL sectors (takes a long time!)
set scmd=bsfind rebls all
:scmdset
echo.

echo.
echo Collecting UNFDISK info using %dfsexe%.exe with '%scmd%', please wait ...
if "%1" == ""                     goto alldisks
if "%1" == "*"                    goto alldisks
set geo=diskgeo
if "%scmd" == "bsfind rebls all"  goto dodisk
set geo=diskgeo %2 %3 %4
:dodisk
echo Validating specified disk-nr %1
%dfsexe% -R -b -q -7 -l:dfsunfd%1 disk %1#q
if errorlevel 1 goto baddisk
echo Collecting info for disk %1 in dfsunfd%1.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd%1 fdisk#part $*#disk %1#%geo%#%scmd%#list +s#list +b#walk %1#H 0#03f#03ec1#3f00#chs 1 0 1#pl l %1 rb#q
echo.
goto end

:alldisks
echo Detecting number of physical disks:
%dfsexe% -R -b -q -7 query Disks
if errorlevel 50 echo goto badquery
if errorlevel 10 echo Only the first 9 disks will be collected ...
if errorlevel  9 goto disk9
if errorlevel  8 goto disk8
if errorlevel  7 goto disk7
if errorlevel  6 goto disk6
if errorlevel  5 goto disk5
if errorlevel  4 goto disk4
if errorlevel  3 goto disk3
if errorlevel  2 goto disk2
if errorlevel  1 goto disk1
goto disk0

:badquery
echo The number of disks is unbelievable, information will not be collected
echo Diagnostic information will be in 'dfsunfd0.log'
echo.
%dfsexe% -R -b -l:dfsunfd0 query Disks
goto end

:disk9
echo Validating specified disk-nr 9
%dfsexe% -R -b -q -7 -l:dfsunfd9 disk 9#q
if errorlevel 1 goto locked
echo Collecting info for disk 9 in dfsunfd9.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd9 fdisk#part $*#disk 9#%scmd%#list +s#list +b#walk 9#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 9 rb#q
:disk8
echo Validating specified disk-nr 8
%dfsexe% -R -b -q -7 -l:dfsunfd8 disk 8#q
if errorlevel 1 goto locked
echo Collecting info for disk 8 in dfsunfd8.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd8 fdisk#part $*#disk 8#%scmd%#list +s#list +b#walk 8#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 8 rb#q
:disk7
echo Validating specified disk-nr 7
%dfsexe% -R -b -q -7 -l:dfsunfd7 disk 7#q
if errorlevel 1 goto locked
echo Collecting info for disk 7 in dfsunfd7.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd7 fdisk#part $*#disk 7#%scmd%#list +s#list +b#walk 7#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 7 rb#q
:disk6
echo Validating specified disk-nr 6
%dfsexe% -R -b -q -7 -l:dfsunfd6 disk 6#q
if errorlevel 1 goto locked
echo Collecting info for disk 6 in dfsunfd6.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd6 fdisk#part $*#disk 6#%scmd%#list +s#list +b#walk 6#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 6 rb#q
:disk5
echo Validating specified disk-nr 5
%dfsexe% -R -b -q -7 -l:dfsunfd5 disk 5#q
if errorlevel 1 goto locked
echo Collecting info for disk 5 in dfsunfd5.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd5 fdisk#part $*#disk 5#%scmd%#list +s#list +b#walk 5#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 5 rb#q
:disk4
echo Validating specified disk-nr 4
%dfsexe% -R -b -q -7 -l:dfsunfd4 disk 4#q
if errorlevel 1 goto locked
echo Collecting info for disk 4 in dfsunfd4.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd4 fdisk#part $*#disk 4#%scmd%#list +s#list +b#walk 4#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 4 rb#q
:disk3
echo Validating specified disk-nr 3
%dfsexe% -R -b -q -7 -l:dfsunfd3 disk 3#q
if errorlevel 1 goto locked
echo Collecting info for disk 3 in dfsunfd3.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd3 fdisk#part $*#disk 3#%scmd%#list +s#list +b#walk 3#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 3 rb#q
:disk2
echo Validating specified disk-nr 2
%dfsexe% -R -b -q -7 -l:dfsunfd2 disk 2#q
if errorlevel 1 goto locked
echo Collecting info for disk 2 in dfsunfd2.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd2 fdisk#part $*#disk 2#%scmd%#list +s#list +b#walk 2#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 2 rb#q
:disk1
echo Validating specified disk-nr 1
%dfsexe% -R -b -q -7 -l:dfsunfd1 disk 1#q
if errorlevel 1 goto locked
echo Collecting info for disk 1 in dfsunfd1.log ...
%dfsexe% -R -b -q -7 -l:dfsunfd1 fdisk#part $*       #%scmd%#list +s#list +b#walk 1#H 0#03f#03ec1#3f00#chs 1 0 1#pl l 1 rb#q
echo.
echo Resulting DFSee info logfiles:
dir dfsunfd?.log
echo.
echo email these file(s) to dfsee@fsys.demon.nl for analysis (ZIP if possible)
echo Include your DFSee registration number if you have one!
echo.
goto end

:baddisk
echo.
echo Disk number %1 does not seem to be present (or locked)
:locked
echo A disk in your system is not accesible, possibly locked.
echo This might be caused by another FDISK, LVM or DFSee program being active.
echo Please close all other FDISK related programs before running %0
echo.
goto end

:disk0
echo No physical disks detected ...
echo.
goto end

:usage
echo A careful analysis of the generated info can lead to a series of %dfsexe%
echo commands like NEWMBR and CREATE to re-create missing/lost partitions.
echo.
echo Usage:  %0  [ Disk-nr / *  [ All / Cylinders  [Heads  [Sectors ]]]]
echo.
echo Default is search all disk on cylinder boundaries only (fast mode)
echo.
echo         Disk-nr   =  search specified disk only, value  1 .. 9   * = all
echo.
echo         All       =  search all sectors, this will find any sector
echo         or '*'       but can be real slow (like 8 hours for 40Gb disk)
echo.
echo         Cylinders =  Number of cylinders or ?    value  1 .. 65535
echo         Heads     =  Number of heads             value  1 .. 255
echo         Sectors   =  Number of sectors           value  1 .. 63
echo                      Heads and Sectors use defaults when not specified.
echo                      When a '?' is used for the cylinder count, it will
echo                      be calculated based on the known disk-size
echo Examples:
echo    %0                     all disks, use standard geometry
echo    %0 * *                 all disks, every sector (slow, every geometry)
echo    %0 3                   disks 3 only, use standard geometry
echo    %0 1 1000 64 32        disks 1, geo: 1000 cyls, 64 heads, 32 sects
echo    %0 2 ? 240 63          disks 2, geo: 240 heads, 63 sectors
echo                                and calculated nr of cylinders
:end
