[comp.sys.amiga] The zero lock

rmeyers@tle.dec.com (Randy Meyers 381-2743 ZKO2-3/N30) (05/04/88)

A couple of weeks ago there was a discussion in .tech on the special
lock 0.  Several people were badly confused as to what a lock with a
value of zero means, and what operations are valid using this lock.

AmigaDOS supports a special lock who's value is zero.  The CLI
created when the Amiga is booted and Workbench processes all start
out with a current directory lock of zero.  This special lock is a
lock not on any particular file or volume: it is a lock on the device
DF0:.

Since the zero lock is a lock on the device DF0:, any volume mounted in
DF0: when the lock is used will be the volume referenced.  For example,
if the initial CLI never issues a CD command, a DIR command will take
the directory of whatever floppy mounted in DF0: when the DIR command is
given.  This feature can be very useful when browsing through several
floppies.

Not many people know the meaning of the zero lock because it is somewhat
poorly documented in "The AmigaDOS Manual."  The describes the zero lock
as "referring to the root of the initial filing system."  This has caused
some people to think that the zero lock is a lock on the boot floppy
instead of the device DF0:.  For example, Robert Peck's "Programmer's
Guide to the Amiga" mistakenly claims that the zero lock is lock that
can be used to determine the volume name of the boot volume and that
"No matter how many disk swaps you perform, along with ASSIGN statements,
the system still remembers which disk volume name was used for the
original boot."  This is wrong on both counts.  The system completely
forgets which volume was the original boot volume if all the assignments
(like SYS:, DEVS:, LIBS:, etc.) are changed, and the zero lock (and
Peck's example program) always refers to the volume mounted in DF0:.

A good part of the confusion about the zero lock is because most of the
documentation about the zero lock does not occur in the section of the
AmigaDOS on calling AmigaDOS functions, instead it occurs in the section
on AmigaDOS data structures and sending packets to handlers.

The zero lock is a legitimate argument for any AmigaDOS function that
takes a lock as an argument.  All of the AmigaDOS functions do the
right thing when passed a zero lock.  At no time do they cause a system
crash, or even an error return from the function call.

Here is the list of AmigaDOS functions that take a lock as an argument
and what the function does when passed a zero lock:

CurrentDir	Set the current directory to DF0:.  Any reference to
		a file in the current directory will get a file in
		whatever volume is currently mounted in DF0:.  If no
		floppy is mounted in DF0:, the system will display a
		requester, "No disk present in unit 0."  At that point
		you can either place a floppy in DF0: or abort the
		operation.

DupLock		Will return zero as the duplicated lock.  This behavior
		is required by the documentation on sending packets to
		handlers.  (The value of IoErr is not changed by
		DupLock(0)!  If it was zero before the call, it will be
		zero after.)

Examine		Returns information about the volume currently mounted
		in DF0:.

ExNext 		Returns information about the files in the volume currently
		mounted in DF0:.

Info		Returns information about the volume currently mounted
		in DF0:.

ParentDir	Returns zero (DF0: is its own parent).  IoErr is cleared.

UnLock		Takes no action (the zero lock remains an active lock
		after being unlocked).  This behavior is documented in
		the section on sending packets to handlers.  (The value
		of IoErr is not changed by UnLock(0)!  If it was zero
		before the call, it will be zero after.)

As you can see, the zero lock is a perfectly good lock.  The only thing
that you cannot do with it is convert it to a pointer to a struct FileLock
by shifting it left by two.

There is a chance that Kickstart 1.3 could change the meaning of the
zero lock.  The autoboot feature might change the meaning of the "root
of the current filing system" to be the boot device.  Perhaps, C/A
can comment?

All of this contains a lesson for anyone writing a AmigaDOS handler.  If
your device supports locks, it should correctly support zero locks as well.

----------------------------------------
Randy Meyers, not representing Digital Equipment Corporation
	USENET:	{decwrl|decvax|decuac}!tle.dec.com!rmeyers
	ARPA:	rmeyers%tle.dec.com@decwrl.dec.com

neil@amiga.UUCP (Neil Katin) (05/05/88)

In article <8805032135.AA26451@decwrl.dec.com> rmeyers@tle.dec.com (Randy Meyers 381-2743 ZKO2-3/N30) writes:
>A couple of weeks ago there was a discussion in .tech on the special
>lock 0.  Several people were badly confused as to what a lock with a
>value of zero means, and what operations are valid using this lock.
>
>AmigaDOS supports a special lock who's value is zero.  The CLI
>created when the Amiga is booted and Workbench processes all start
>out with a current directory lock of zero.  This special lock is a
>lock not on any particular file or volume: it is a lock on the device
>DF0:.

A good article, with one point that's wrong (or at least not strictly true).
A lock of zero refers to the disk handler pointed to by your process's
pr_FileSystemTask.  This is (by default) the boot disk, but can be
changed.

It is DF0: on most amiga's because most amigas were booted from df0:

	Neil Katin

spencer@eris (Randal m. Spencer [RmS]) (05/11/88)

Recently on *comp.sys.amiga* neil@spam.UUCP (Neil Katin) wrote:

...In article <8805032135.AA26451@decwrl.dec.com> rmeyers@tle.dec.com (Randy Meyers 381-2743 ZKO2-3/N30) writes:
...>AmigaDOS supports a special lock who's value is zero.
...
...A good article, with one point that's wrong (or at least not strictly true).
...A lock of zero refers to the disk handler pointed to by your process's
...pr_FileSystemTask.  This is (by default) the boot disk, but can be
...changed.
...
...It is DF0: on most amiga's because most amigas were booted from df0:
...
...	Neil Katin

Wait, This can't be right.  I boot from RAD: and my Zero lock points to DF0:
still.  Infact this came up at the developers conference and I remember 
hearing that the C/A people were not to thrilled with the idea of the Zero
lock always meaning the boot device (since that don't work now) and they
thought instead there would be a logical boot: assign to point to the 
boot device, and that Zero lock would just always point to df0:.

If anyone knows different I would love to hear...

 Randy  (finally back from sight seeing in D.C.)  Spencer

ps.  Thanks to all who made that such a wonderful developers conference!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Randy Spencer      P.O. Box 4542   Berkeley  CA  94704        (415)222-7595 
spencer@mica.berkeley.edu        I N F I N I T Y         BBS: (415)222-9416
..ucbvax!mica!spencer            s o f t w a r e                  AAA-WH1M
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-