@echo off
rem 11-03-2004 JvW Derived from DFSUNFD, check ONE partition      (6.04)
echo.
echo Get information on ONE partition, PID %1 %2

if exist _write_._ok del _write_._ok > NUL
echo test > _write_._ok
if exist _write_._ok goto writeok
echo.
echo ERROR: The current directory is write-protected or the disk is full
echo.
echo        Please change the current directory to a disk or diskette
echo        with more than 100Kb of available space ...
echo.
goto end
:writeok
if exist _write_._ok del _write_._ok > NUL

if "%0"=="CPRTTEST"     echo on
if "%0"=="cprttest"     echo on

if "%OS2_SHELL%"=="" goto notos2
set dfsexe=dfsos2.exe
set cmdext=CMD
goto dfsee
:notos2
if "%OS%"==""        goto notnt
if "%OS%"=="DOS"     goto notnt
if "%OS%"=="MSDOS"   goto notnt
if "%OS%"=="DRDOS"   goto notnt
if "%OS%"=="IBMDOS"  goto notnt
if "%OS%"=="OPENDOS" goto notnt
set dfsexe=dfswin.exe
set cmdext=BAT
goto dfsee
:notnt
set dfsexe=dfsdos.exe
set cmdext=BAT
:dfsee

if "%1" == ""    goto usage
if "%1" == "?"   goto usage
if "%1" == "/?"  goto usage
if "%1" == "-?"  goto usage

echo Checking PID number %1, and filesystem  ...
%dfsexe% -b -q query PValid %1
if not errorlevel 1 goto pidok
echo.
echo ERROR: The specified partition number PID: %1  does not exist
goto end

:pidok
if "%2" == "" goto gettype
set ptype=%2
goto check

:gettype
%dfsexe% -b -B- query PInfo %1
if errorlevel 79 goto typebad
if errorlevel 78 goto typentfs
if errorlevel 77 goto typebad
rem rrorlevel 76 goto typelinux
if errorlevel 75 goto typebad
if errorlevel 74 goto typejfs
if errorlevel 73 goto typebad
if errorlevel 72 goto typehpfs
if errorlevel 71 goto typebad
if errorlevel 70 goto typefat
rem rrorlevel 69 goto typeext2
:typebad
echo.
echo The type for the specified partition is not supported with %0 (yet)
goto end

:typefat
set ptype=FAT
goto check

:typentfs
set ptype=NTFS
goto check

:typehpfs
set ptype=HPFS
goto check

:typejfs
set ptype=JFS
goto check

:typelinux
:typeext2
set ptype=EXT2
goto check

:check
echo Checking filesystem %ptype% in partition %1 ...
if exist dfsc%ptype%.p%1 del  dfsc%ptype%.p%1

%dfsexe% -b -q query RValid
if not errorlevel 1 goto work
echo.
echo NOTE: Your DFSee version is not properly registred, this will cause
echo       some extra delays and reminder messages to be displayed  ...
echo.

:work
set runcmd=-RO -Quit -batch -quiet -7bit run -Error:ignore do%ptype%.dfs

%dfsexe% -l:dfsc%ptype%.p%1 %runcmd% %1

:showerrors
if errorlevel 235 goto failure
if errorlevel 234 goto noscript
if errorlevel 001 goto failure
goto end

:noscript
echo.
echo ERROR: The required DFSee script 'do%ptype%.dfs' was not found.
echo Either '%ptype%' is NOT supported, or the script is missing.
echo Check if it is in the current directory, the same directory
echo as the execuatable %dfsexe% or a directory on the PATH.
goto end

:failure
echo.
echo WARNING: Execution of the script seems to have failed.
echo.
echo Check if %dfsexe% and the script file 'do%ptype%.dfs' can be
echo found in the current directory, or a directory on the PATH.

:usage
echo A careful analysis of the generated info can lead to %dfsexe%
echo commands like FIXBOOT to repair missing or damaged FS structures.
echo.
echo Usage: %0  partition-id  [filesystem]
echo.
echo    partition-id   =  The DFSee number (PID) for the partition to check
echo                      This can be taken from a DFSee 'part' display where
echo                      it is displayed in the most left column of the table.
echo.
echo    filesystem     =  The type of the filesystem to be checked, one of:
echo.
echo         FAT       =  For any FAT16 or FAT32 partition
echo         NTFS      =  For the Windows NTFS filesystem
echo         HPFS      =  For the OS/2 and eCS HPFS or HPFS386 filesystem
echo         JFS       =  For the OS/2 and eCS Journalled filesystem
echo.
echo                      When the filesystem is not specified, it will be
echo                      queried using DFSee itself from the Format column
echo                      This may fail however for damaged partitions ...
echo.
echo Examples:
echo    %0 3           To check any filesystem in the third partition
echo    %0 1  ntfs     To check an NTFS filesystem in the first partition
echo    %0 5  hpfs     To check an HPFS filesystem in partition 05
:end
