Path: utzoo!utgpu!watserv1!maytag!xenitec!tirith!ggk From: ggk@tirith.UUCP (Gregory Kritsch) Message-ID: Date: 21 Nov 20 02:47:39 Newsgroups: comp.sys.amiga.tech Subject: Re: Finding disks In-Reply-To: chris@genly.UUCP (Chris Hind Genly) References: chris@genly.UUCP (Chris Hind Genly) writes: >Once a device is found with a non-zero task entry, it can be tested to >see if it is really a disk device by trying to lock it. If you can >lock it, its a disk. If you can't it still might be a disk. If its >df0: for example and there is no disk in df0: I don't want a requester >to pop up, so I suppress them. If there's no disk, the lock operation >will fail. If the device is a disk device the lock will fail with an >error such as: ERROR_NO_DISK. This tells me the device is a disk >device. >Here is my current solution. You are free to do with the code as you wish. >static >void >FindDiskNames( > char *DiskNames[], > int DiskNamesMax >) >{ > /* Look for a device, not a volume */ > if (Device->dol_Type != 0) > continue; Hmm, so you assume that there is a device for every volume, which is not neccesarily the case. Case in point, my network file system from last year. It created only volume nodes for network volumes, the idea of trying to dynamically allocate device names scared me, and didn't seem very logical either (there was an ND0: entry used basically to find the handler, it only supported certain custom packets though). I wasn't aware at that time that it would break a good number of file requesters, as well as some Workbench replacement type programs that assumed device entries as well. > /* A disk device has a task associated with it */ > if (Device->dol_Task == 0) > continue; > /* Get the device name */ > Name = (char *)BADDR(Device->dol_Name); > Name++; > > /* Make a copy with a colon at the end */ > DiskName = smalloc(strlen(Name)+2); > strcpy(DiskName, Name); > strcat(DiskName, ":"); > > /* Disable requesters in case there's no disk present */ > Process = (struct Process *) FindTask(NULL); > OldWindow = Process->pr_WindowPtr; > Process->pr_WindowPtr = (APTR) -1; > > /* Attempt to create a lock to verify that its a disk */ > lk = Lock(DiskName, ACCESS_READ); > if (lk) UnLock(lk); > ADisk = lk != 0 > || IoErr() == ERROR_NOT_A_DOS_DISK > || IoErr() == ERROR_NO_DISK; Two thoughts here: It might be more prudent to send the packet directly to the file process, rather than go through all the mumbo jumbo converting the BSTR and adding the colon and so on. This also has the advantage of not having to play with pr_WindowPtr, since the dos requestor generator mechanism can't get in the way. Also, the test "IoErr() != ERROR_ACTION_NOT_KNOWN" might be better - all disk handlers will understand ACTION_LOCK, but almost all non-disk handlers won't understand it (and should return ERROR_ACTION_NOT_KNOWN). >/ Chris Hind Genly chris@genly.uucp uunet!hsi!genly!chris \ -- Gregory Kritsch | University of Waterloo Fido: 1:221/208.11110 [1:163/109.30] | 1A Computer Engineering OCUG: ggk@tirith.ocug.on.ca |---------------------------- UUCP: ggk@tirith.UUCP | The University doesn't get ...!watmath!xenitec!tirith!ggk | a chance to censor me!