home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18513 < prev    next >
Encoding:
Text File  |  1993-01-11  |  2.5 KB  |  73 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!gatech!concert!sas!mozart.unx.sas.com!jamie
  2. From: jamie@cdevil.unx.sas.com (James Cooper)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Is there a disk in the drive ?
  5. Keywords: disk
  6. Message-ID: <C0p9w8.27s@unx.sas.com>
  7. Date: 11 Jan 93 17:28:56 GMT
  8. References: <C0ou7J.Kyu@ens-lyon.fr>
  9. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  10. Organization: SAS Institute Inc.
  11. Lines: 58
  12. Originator: jamie@cdevil.unx.sas.com
  13. Nntp-Posting-Host: cdevil.unx.sas.com
  14.  
  15.  
  16. In article <C0ou7J.Kyu@ens-lyon.fr>, obaby@ens-lyon.fr (Olivier Baby) writes:
  17. >Hi,
  18. >
  19. >I am currently writing a C program which needs to test if there is a disk in the disk drive.
  20. >Does anyone know how to make such a test ?
  21.  
  22. Sure.  Use the dos.libray Info() call, then check the id_DiskType field of the
  23. InfoData structure.  If it is ID_NO_DISK_PRESENT, there's no disk in the drive.
  24.  
  25. Sample code:
  26.  
  27. #include <dos/dos.h>            /* For 1.3: <libraries/dos.h> */
  28.  
  29. int existsDisk(char *drivename)
  30. {
  31.    BPTR lock;
  32.    struct InfoData idata;       /* MUST be longword aligned!!! */
  33.                                 /* Better would be to use AllocDosObject() if
  34.                                    running under 2.0+ */
  35.    int exists;                  /* Does it exist? */
  36.    void *OldWindow              /* Store current spot Requesters pop up. */
  37.    struct Process *myproc;      /* Pointer to current process. */
  38.  
  39.    myproc = (struct Process *)FindTask(NULL);
  40.    myproc->pr_WindowPtr = (void *)-1;
  41.  
  42.    exists = 0;                  /* Assume it doesn't. */
  43.  
  44.    if ((lock = Lock(drivename, ACCESS_READ)) != NULL) 
  45.    {
  46.       if (Info(lock, &idata) != NULL)
  47.       {
  48.          exists = (idata.id_DiskType != ID_NO_DISK_PRESENT);
  49.       }
  50.       UnLock(lock);
  51.    }
  52.    myproc->pr_WindowPtr = OldWindow;
  53.  
  54.    return(exists);              /* Returns 1 if valid disk in drive,
  55.                                            0 if no disk, or disk is unreadable
  56.                                            (might be unformatted, might be
  57.                                             MS-DOS disk, etc., etc.)
  58.                                  */
  59. }
  60.  
  61. WARNING:  This will only work on valid, already formatted AmigaDOS disks.  If
  62. you truly want to know whether or not there is a disk in the drive, you will
  63. have to go down to sending an ACTION_DISK_INFO packet to the appropriate unit of
  64. the trackdisk.device.
  65.  
  66. -- 
  67. ---------------
  68. Jim Cooper
  69. (jamie@unx.sas.com)                             bix: jcooper
  70.  
  71. Any opinions expressed herein are mine (Mine, all mine!  Ha, ha, ha!),
  72. and not necessarily those of my employer.
  73.