[comp.sys.amiga] Help needed on AmigaDos Locks

lca@spodv4.UUCP (Lars H Carlsson) (01/09/90)

Help!

Could someone tell me if there is a way to find the Lock associated
with the filehandle created by Open (or open, fopen etc.) ??
I would like to be able to do the following:

	FILE *fp = fopen ("any_file", "any_mode");

	int lock = fp -> ...
          OR
        int lock = getlock (fileno(fp), ...

	Examine (lock, &...

Any suggestions?
(I'm using Lattice C 5.02 on a Amiga500 KickStart 1.3, WB 1.3)

Lars H Carlsson		(..!sunic!spocm2!spodv4!lca)

caw@jolnet.ORPK.IL.US (Chris Wichura) (01/10/90)

Welp, if you use FILE then you have to know the structure that Lattice
keeps the AmigaDOS filehandle for the Unix file you are working on.  Once
you know that you can look at the AmigaDOS filehandle struct and maybe
get the lock out of it.  I forget if struct FileHandle (or whatever) is
considered private only, though...
 
A much more useful function would be a way to open a file based on the
lock you have instead of having to go though some crap like use ARP's
PathName() command to build the filename off the lock so you could feed
it to Open().  Does such a beast exist and I just haven't been able to
find it is all?

-- 
Christopher A. Wichura
u12401 @ uicvm.uic.edu  (my home account)
caw @ jolnet.UUCP       (my Usenet feed)

new@udel.edu (Darren New) (01/11/90)

In article <2754@jolnet.ORPK.IL.US> caw@jolnet.UUCP (Chris Wichura) writes:
>A much more useful function would be a way to open a file based on the
>lock you have instead of having to go though some crap like use ARP's

It's in there (Ooooh I always wanted to say that).  I've got documentation
somewhere that says basically zero everything in the file handle except
set the buffer pointers to -1 and then put in the Lock and your file
is open.  Supported?  It's in official docs somewhere, so I guess so.
		  -- Darren

ccplumb@lion.waterloo.edu (Colin Plumb) (01/11/90)

There's no need to resort to such nasty tricks to open a file given a
lock.  The Open packet, if you want to delve to that level, takes a
lock and a name relative to that lock, as arguments.

If you don't want to, cd to the lock (yes, you *can* cd to a file),
open "", and cd back.  WorkBench does this all the time, so any file
system that doesn't support cd'ing to a file will break very fast indeed.
-- 
	-Colin

lca@spodv4.UUCP (Lars H Carlsson) (01/12/90)

In article <2754@jolnet.ORPK.IL.US>, caw@jolnet.ORPK.IL.US (Chris Wichura) writes:
> Welp, if you use FILE then you have to know the structure that Lattice
> keeps the AmigaDOS filehandle for the Unix file you are working on.  Once
> you know that you can look at the AmigaDOS filehandle struct and maybe
> get the lock out of it.  I forget if struct FileHandle (or whatever) is
> considered private only, though...

	I have looked through the structures for FileHandle etc. and I can't
	find any connection between the FileHandle and the Lock.

> A much more useful function would be a way to open a file based on the
> lock you have instead of having to go though some crap like use ARP's
> PathName() command to build the filename off the lock so you could feed
> it to Open().  Does such a beast exist and I just haven't been able to
> find it is all?

	What I am looking for is a way to simulate the fstat(2) system call.

	fstat (fd)
	int fd;
	{
		struct stat s;
		...
		lock = fd -> ... or getlock(fd)
		Examine (lock, &b...

		s.st_size = b.FileSize ...
		...
	
	So I really need to get the lock from filehandle (I guess??)


	Lars H Carlsson		(..!sunic!spocm2!spodv4!lca)

ridder@elvira.enet.dec.com (Hans Ridder) (01/23/90)

In article <7857@nigel.udel.EDU> new@udel.edu (Darren New) writes:
>In article <2754@jolnet.ORPK.IL.US> caw@jolnet.UUCP (Chris Wichura) writes:
>>A much more useful function would be a way to open a file based on the
>>lock you have instead of having to go though some crap like use ARP's
>
>It's in there (Ooooh I always wanted to say that).  I've got documentation
>somewhere that says basically zero everything in the file handle except
>set the buffer pointers to -1 and then put in the Lock and your file
>is open.  Supported?  It's in official docs somewhere, so I guess so.

Sorry for the long delay, but I kept forgetting to look this up when I
had the manual.

In my *ancient* (1985) AmigaDOS Technical Reference Manual, on page
3-9 it says that to do this you have to set up a DOS ActionFindInput
"packet" with the FileHandle, the Lock (on the owning directory), and
the name of the file.

The FileHandle must be intitialized to 0's, except CharPos and BufEnd
should be set to -1, and the ProcessID set to the handler process.

You then send the packet to the Handler/Filesystem and check the
result.  Of course you can now do other things while the handler runs
*asynchronously*.

All in all, not that difficult, but not simple either.  I assume
that's what you were talking about, or did you see an easier way
documented somewhere?

>		  -- Darren

-hans
========================================================================
  Hans-Gabriel Ridder			Digital Equipment Corporation
  ridder@elvira.enet.dec.com		Customer Support Center
  ...decwrl!elvira.enet!ridder		Colorado Springs, CO