home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / lock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  3.1 KB  |  126 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: lock.c,v 1.5 1997/01/27 00:36:24 ldp Exp $
  4.     $Log: lock.c,v $
  5.     Revision 1.5  1997/01/27 00:36:24  ldp
  6.     Polish
  7.  
  8.     Revision 1.4  1996/12/09 13:53:33  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.3  1996/10/24 15:50:32  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.2  1996/09/21 14:14:23  digulla
  17.     Hand DOSBase to DoName()
  18.  
  19.     Revision 1.1  1996/09/11 12:54:46  digulla
  20.     A couple of new DOS functions from M. Fleischer
  21.  
  22.     Desc:
  23.     Lang: english
  24. */
  25. #include <proto/exec.h>
  26. #include <utility/tagitem.h>
  27. #include <dos/dosextens.h>
  28. #include <dos/filesystem.h>
  29. #include <proto/dos.h>
  30. #include "dos_intern.h"
  31.  
  32. /*****************************************************************************
  33.  
  34.     NAME */
  35. #include <proto/dos.h>
  36.  
  37.     AROS_LH2(BPTR, Lock,
  38.  
  39. /*  SYNOPSIS */
  40.     AROS_LHA(STRPTR, name,       D1),
  41.     AROS_LHA(LONG,   accessMode, D2),
  42.  
  43. /*  LOCATION */
  44.     struct DosLibrary *, DOSBase, 14, Dos)
  45.  
  46. /*  FUNCTION
  47.     Gets a lock on a file or directory. There may be more than one
  48.     shared lock on a file but only one if it is an exclusive one.
  49.     Locked files or directories may not be deleted.
  50.  
  51.     INPUTS
  52.     name       - NUL terminated name of the file or directory.
  53.     accessMode - One of SHARED_LOCK
  54.                 EXCLUSIVE_LOCK
  55.  
  56.     RESULT
  57.     Handle to the file or directory or 0 if the object couldn't be locked.
  58.     IoErr() gives additional information in that case.
  59.  
  60.     NOTES
  61.     The lock structure returned by this function is different
  62.     from that of AmigaOS (in fact it is identical to a filehandle).
  63.     Do not try to read any internal fields.
  64.  
  65.     EXAMPLE
  66.  
  67.     BUGS
  68.  
  69.     SEE ALSO
  70.  
  71.     INTERNALS
  72.  
  73.     HISTORY
  74.     29-10-95    digulla automatically created from
  75.                 dos_lib.fd and clib/dos_protos.h
  76.  
  77. *****************************************************************************/
  78.  
  79. {
  80.     AROS_LIBFUNC_INIT
  81.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  82.  
  83.     struct FileHandle *ret;
  84.  
  85.     /* Get pointer to process structure */
  86.     struct Process *me=(struct Process *)FindTask(NULL);
  87.  
  88.     /* Create filehandle */
  89.     ret=(struct FileHandle *)AllocDosObject(DOS_FILEHANDLE,NULL);
  90.     if(ret!=NULL)
  91.     {
  92.     /* Get pointer to I/O request. Use stackspace for now. */
  93.     struct IOFileSys io,*iofs=&io;
  94.  
  95.     /* Prepare I/O request. */
  96.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  97.     iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  98.     iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  99.     iofs->IOFS.io_Flags=0;
  100.     iofs->IOFS.io_Command=FSA_OPEN;
  101.     /* io_Args[0] is the name which is set by DoName(). */
  102.     switch(accessMode)
  103.     {
  104.         case EXCLUSIVE_LOCK:
  105.         iofs->io_Args[1]=FMF_LOCK|FMF_READ;
  106.         break;
  107.         case SHARED_LOCK:
  108.         iofs->io_Args[1]=FMF_READ;
  109.         break;
  110.         default:
  111.         iofs->io_Args[1]=accessMode;
  112.         break;
  113.     }
  114.     if(!DoName(iofs,name,DOSBase))
  115.     {
  116.         ret->fh_Device=iofs->IOFS.io_Device;
  117.         ret->fh_Unit  =iofs->IOFS.io_Unit;
  118.         return MKBADDR(ret);
  119.     }
  120.     FreeDosObject(DOS_FILEHANDLE,ret);
  121.     }else
  122.     me->pr_Result2=ERROR_NO_FREE_STORE;
  123.     return 0;
  124.     AROS_LIBFUNC_EXIT
  125. } /* Lock */
  126.