Good day, all:

I got tired of struggling with drive letters and TDSK.  I have written
a short C program which scans volume names for drives
C: through Z: (A: and B: were prompting for floppy insertions).  By
default, it looks for the name "TURBODSK" from TDSK.  However,
it accepts an argument of a name to look for...for example

findtdsk FDOS_BETA9

This program returns the drive letter in the DOS ERRORLEVEL and
prints the volume found to stderr.

I have also included a batch file to print out the drive letter.

I based this on a public domain example and release it into the
public domain.  I built it under Windows using Open Watcom.

I could easily modify this to have the "turbodat" behavior and
create a file.   However, the ERRORLEVEL return fits my requirements
better.

If anyone needs an executable, I can send it to you.

Mark Bailey

The C source file is:

/*
**
**  findtdsk.c  - finds the first FREEDOS TDSK RAM DRIVE (label TURBODSK)
**                by scanning all drive letters from A: to Z:
**
**  takes an optional argument, VOLNAME, which is the name of a disk volume to
**  search for
**
**  Returns the number corresponding to the disk with the correct volume name
**  (MSDOS ERRORLEVEL:  0=A, 1=B, ... , 25=Z
**
**  Released into the Public Domain
**  Mark Bailey   21 March 2005
**
**  Based on GETVOL.C from Bob Stout
**  GETVOL.C - Retrieve a disk volume label
**             (proof you don't need FCBs to do it!)
**
**  public domain demo by Bob Stout
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <io.h>

#include <direct.h>
#if defined(__ZTC__)
 #pragma ZTC align 1
#else /* MSC/QC/WATCOM/METAWARE */
 #pragma pack(1)
#endif


#define SUCCESS 0

char *getvol(char drive)
{
      char search[] = "A:\\*.*";
      static struct find_t ff;

      *search = drive;
      if (SUCCESS == _dos_findfirst(search, _A_VOLID, &ff))
      {
            if (8 < strlen(ff.name))            /* Eliminate period     */
            strcpy(&ff.name[8], &ff.name[9]);
            return ff.name;
      }
      else  return NULL;
}



int main(int argc, char *argv[])
{
      char *label;
      char drive;
      int i;
      char *volname;

      if (strcmp(argv[1],"/?") == 0)
      {
            puts("\aUsage: FINDTDSK [VOLNAME]\n"
                 "Where VOLNAME is an optional volume name to search for\n"
                 "The default VOLNAME is TURBODSK"
                );
            return -1;
      }
      else if (argv[1] != NULL)
            volname = argv[1];
      else
            volname = "TURBODSK";
/*
 *    Do not check drives A and B
 */
      for (i=2;i<26;i++)
      {
        drive = (char) (i+(int) 'A');
        label = getvol(drive);
        if (strcmp(volname,label)==0)
        {
          fprintf(stderr,"Disk %c has label %s\n",drive,label);
          return (i);
        }
      }
      return -1;
}


and a simple batch test file is:

echo off
findtdsk
if %ERRORLEVEL%==-1  echo "Not found"
if %ERRORLEVEL%==0 echo "A:"
if %ERRORLEVEL%==1 echo "B:"
if %ERRORLEVEL%==2 echo "C:"
if %ERRORLEVEL%==3 echo "D:"
if %ERRORLEVEL%==4 echo "E:"
if %ERRORLEVEL%==5 echo "F:"
if %ERRORLEVEL%==6 echo "G:"
if %ERRORLEVEL%==7 echo "H:"
if %ERRORLEVEL%==8 echo "I:"
if %ERRORLEVEL%==9 echo "J:"
if %ERRORLEVEL%==10 echo "K:"
if %ERRORLEVEL%==11 echo "L:"
if %ERRORLEVEL%==12 echo "M:"
if %ERRORLEVEL%==13 echo "N:"
if %ERRORLEVEL%==14 echo "O:"
if %ERRORLEVEL%==15 echo "P:"
if %ERRORLEVEL%==16 echo "Q:"
if %ERRORLEVEL%==17 echo "R:"
if %ERRORLEVEL%==18 echo "S:"
if %ERRORLEVEL%==29 echo "T:"
if %ERRORLEVEL%==20 echo "U:"
if %ERRORLEVEL%==21 echo "V:"
if %ERRORLEVEL%==22 echo "W:"
if %ERRORLEVEL%==23 echo "X:"
if %ERRORLEVEL%==24 echo "Y:"
if %ERRORLEVEL%==25 echo "Z:"
echo on


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Freedos-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freedos-user

Reply via email to