home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!gatech!concert!sas!mozart.unx.sas.com!jamie
- From: jamie@cdevil.unx.sas.com (James Cooper)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Is there a disk in the drive ?
- Keywords: disk
- Message-ID: <C0p9w8.27s@unx.sas.com>
- Date: 11 Jan 93 17:28:56 GMT
- References: <C0ou7J.Kyu@ens-lyon.fr>
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Organization: SAS Institute Inc.
- Lines: 58
- Originator: jamie@cdevil.unx.sas.com
- Nntp-Posting-Host: cdevil.unx.sas.com
-
-
- In article <C0ou7J.Kyu@ens-lyon.fr>, obaby@ens-lyon.fr (Olivier Baby) writes:
- >Hi,
- >
- >I am currently writing a C program which needs to test if there is a disk in the disk drive.
- >Does anyone know how to make such a test ?
-
- Sure. Use the dos.libray Info() call, then check the id_DiskType field of the
- InfoData structure. If it is ID_NO_DISK_PRESENT, there's no disk in the drive.
-
- Sample code:
-
- #include <dos/dos.h> /* For 1.3: <libraries/dos.h> */
-
- int existsDisk(char *drivename)
- {
- BPTR lock;
- struct InfoData idata; /* MUST be longword aligned!!! */
- /* Better would be to use AllocDosObject() if
- running under 2.0+ */
- int exists; /* Does it exist? */
- void *OldWindow /* Store current spot Requesters pop up. */
- struct Process *myproc; /* Pointer to current process. */
-
- myproc = (struct Process *)FindTask(NULL);
- myproc->pr_WindowPtr = (void *)-1;
-
- exists = 0; /* Assume it doesn't. */
-
- if ((lock = Lock(drivename, ACCESS_READ)) != NULL)
- {
- if (Info(lock, &idata) != NULL)
- {
- exists = (idata.id_DiskType != ID_NO_DISK_PRESENT);
- }
- UnLock(lock);
- }
- myproc->pr_WindowPtr = OldWindow;
-
- return(exists); /* Returns 1 if valid disk in drive,
- 0 if no disk, or disk is unreadable
- (might be unformatted, might be
- MS-DOS disk, etc., etc.)
- */
- }
-
- WARNING: This will only work on valid, already formatted AmigaDOS disks. If
- you truly want to know whether or not there is a disk in the drive, you will
- have to go down to sending an ACTION_DISK_INFO packet to the appropriate unit of
- the trackdisk.device.
-
- --
- ---------------
- Jim Cooper
- (jamie@unx.sas.com) bix: jcooper
-
- Any opinions expressed herein are mine (Mine, all mine! Ha, ha, ha!),
- and not necessarily those of my employer.
-