🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #12384

Re: locks

#12384
From: Chuck McManis
Date: Wed, 26 Apr 1989 17:25
110 lines
3414 bytes
In article <0797.AA0797@caleb> jdp@caleb.UUCP (Jim Pritchett) writes:
>     Recently someone mentioned a program (PD) that lists all locks currently
>outstanding.  Could someone please Email me a copy of this program (preferably
>with source, if possible.)

I wrote one that is pretty short. It's included below ...
--Chuck

/*
 *	showlocks.c
 *
 * Written 13-Mar-88 by Chuck McManis
 * Copyright 1988 Charles McManis, All rights reserved. 
 * This file may be freely redistributed and used as long as this notice remains
 * with it.
 *
 * This program will list out all of the locks that are being held on the 
 * specified volume. You can enter either a volume name or disk device.
 *
 * The output of this program is :
 *	Lock #0 : 'Path'
 *	Lock #1 : 'Path'
 *	...
 */

#include <exec/types.h>
#include <exec/memory.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>

extern struct DosLibrary *DOSBase;
char	*GetPath();

void
main(argc,argv)

int	argc;
char	*argv[];

{
  int			i;		/* File counter			*/
  struct FileLock	*fl;
  ULONG			thislock;


  if (argc != 2) {
    printf("Usage is : ShowLocks Volumename:\n");
    exit(0);
  }

  printf("Lock Monitor, prints out outstanding locks on a given volume.\n");
  thislock = Lock(argv[1]);
  i = 0;
  for (fl = (struct FileLock *)(BADDR(thislock)); fl;
       fl = (struct FileLock *)(BADDR(fl->fl_Link))) 
      printf("    Lock #%d : '%s'\n",i++,GetPath((ULONG)(fl) >> 2));
  if (thislock) UnLock(thislock);
}


/*
 * Function GetPath()
 *
 * This function will return a pointer to a string with the path of
 * the passed lock.
 */
char *
GetPath(Lck)

ULONG	Lck;

{

  static char	LockPath[256];
  UWORD		FDATA[sizeof(struct FileInfoBlock)/2+1];
  ULONG		CurLock,NewLock;
  char		*s;
  struct FileInfoBlock	*fi;


  /* Initialize LockPath to the NULL string */
  LockPath[0]  = '\0';
  if ((Lck == 0) || (Lck == ~0L))
    return(LockPath); /* If Lock is on root (0) return */

  /* Initialize fi so that it is on a long word boundary */
  if ((long)(FDATA) & 2) fi = (struct FileInfoBlock *)(&FDATA[1]);
  else fi = (struct FileInfoBlock *)FDATA;

  CurLock = DupLock(Lck); /* Make a copy of the Lock passed */
  while (CurLock != NULL) {
    Examine(CurLock,fi);
    if ((CurLock != 0) && (fi->fib_DiskKey != 0)) {
      if (strlen(LockPath)) strins(LockPath,"/");
      strins(LockPath,fi->fib_FileName);
    }
    NewLock = ParentDir(CurLock);
    UnLock(CurLock);
    CurLock = NewLock;
  }
  /* Fix up the volume name to include a colon */
  for (s = LockPath; *s; s++) if (*s == '/') {*s = ':'; break;}
  if (!(*s)) strcat(LockPath,":"); 
  return(LockPath);
}

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"A most excellent barbarian ... Genghis Kahn!"
Technical Details
Message-ID: <101321@sun.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!oliveb!sun!pepper!cmcmanis
References: <0797.AA0797@caleb>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!oliveb!sun!pepper!cmcmanis
From: cmcmanis%pepper@Sun.COM (Chuck McManis)
Newsgroups: comp.sys.amiga.tech
Subject: Re: locks
Message-ID: <101321@sun.Eng.Sun.COM>
Date: 26 Apr 89 17:25:21 GMT
References: <0797.AA0797@caleb>
Sender: news@sun.Eng.Sun.COM
Reply-To: cmcmanis@sun.UUCP (Chuck McManis)
Organization: Sun Microsystems, Mountain View
Lines: 110