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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: assignlock.c,v 1.6 1997/01/27 00:36:14 ldp Exp $
  4.     $Log: assignlock.c,v $
  5.     Revision 1.6  1997/01/27 00:36:14  ldp
  6.     Polish
  7.  
  8.     Revision 1.5  1996/12/09 13:53:21  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.4  1996/10/24 15:50:24  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.3  1996/08/13 13:52:44  digulla
  17.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  18.     Replaced AROS_LA by AROS_LHA
  19.  
  20.     Revision 1.2  1996/08/01 17:40:47  digulla
  21.     Added standard header for all files
  22.  
  23.     Desc:
  24.     Lang: english
  25. */
  26. #include <exec/memory.h>
  27. #include <proto/exec.h>
  28. #include <dos/filesystem.h>
  29. #include "dos_intern.h"
  30.  
  31. /*****************************************************************************
  32.  
  33.     NAME */
  34. #include <proto/dos.h>
  35.  
  36.     AROS_LH2(BOOL, AssignLock,
  37.  
  38. /*  SYNOPSIS */
  39.     AROS_LHA(STRPTR, name, D1),
  40.     AROS_LHA(BPTR,   lock, D2),
  41.  
  42. /*  LOCATION */
  43.     struct DosLibrary *, DOSBase, 102, Dos)
  44.  
  45. /*  FUNCTION
  46.     Create an assign from a given name to a lock. Replaces any older
  47.     assignments from that name, 0 cancels the assign completely. Do not
  48.     use or free the lock after calling this function - it becomes
  49.     the assign and will be freed by the system if the assign is removed.
  50.  
  51.     INPUTS
  52.     name - NUL terminated name of the assign.
  53.     lock - Lock to assigned directory.
  54.  
  55.     RESULT
  56.     !=0 success, 0 on failure. IoErr() gives additional information
  57.     in that case. The lock is freed on failure and must not be used
  58.     in that case too.
  59.  
  60.     NOTES
  61.  
  62.     EXAMPLE
  63.  
  64.     BUGS
  65.  
  66.     SEE ALSO
  67.  
  68.     INTERNALS
  69.  
  70.     HISTORY
  71.     29-10-95    digulla automatically created from
  72.                 dos_lib.fd and clib/dos_protos.h
  73.  
  74. *****************************************************************************/
  75. {
  76.     AROS_LIBFUNC_INIT
  77.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  78.  
  79.     BOOL success=1;
  80.     struct DosList *dl, *newdl=NULL;
  81.     struct Process *me=(struct Process *)FindTask(NULL);
  82.     struct IOFileSys io,*iofs=&io;
  83.     struct FileHandle *fh=(struct FileHandle *)BADDR(lock);
  84.  
  85.     if(lock)
  86.     {
  87.     newdl=MakeDosEntry(name,DLT_DIRECTORY);
  88.     if(newdl==NULL)
  89.     {
  90.         UnLock(lock);
  91.         me->pr_Result2=ERROR_NO_FREE_STORE;
  92.         return 0;
  93.     }else
  94.     {
  95.         newdl->dol_Unit  =fh->fh_Unit;
  96.         newdl->dol_Device=fh->fh_Device;
  97.         FreeDosObject(DOS_FILEHANDLE,fh);
  98.     }
  99.     }
  100.  
  101.     dl=LockDosList(LDF_DEVICES|LDF_ASSIGNS|LDF_WRITE);
  102.  
  103.     dl=FindDosEntry(dl,name,LDF_DEVICES|LDF_ASSIGNS);
  104.     if(dl==NULL)
  105.     {
  106.     if(newdl!=NULL)
  107.         AddDosEntry(newdl);
  108.     }else if(dl->dol_Type==DLT_DEVICE)
  109.     {
  110.     dl=newdl;
  111.     me->pr_Result2=ERROR_OBJECT_EXISTS;
  112.     success=0;
  113.     }else
  114.     {
  115.     RemDosEntry(dl);
  116.     if(newdl!=NULL)
  117.         AddDosEntry(newdl);
  118.     }
  119.  
  120.     if(dl!=NULL)
  121.     {
  122.     /* Prepare I/O request. */
  123.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  124.     iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  125.     iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  126.     iofs->IOFS.io_Device =dl->dol_Device;
  127.     iofs->IOFS.io_Unit   =dl->dol_Unit;
  128.     iofs->IOFS.io_Command=FSA_CLOSE;
  129.     iofs->IOFS.io_Flags  =0;
  130.  
  131.     /* Send the request. No errors possible. */
  132.     (void)DoIO(&iofs->IOFS);
  133.  
  134.     FreeDosEntry(dl);
  135.     }
  136.  
  137.     UnLockDosList(LDF_DEVICES|LDF_ASSIGNS|LDF_WRITE);
  138.  
  139.     return success;
  140.     AROS_LIBFUNC_EXIT
  141. } /* AssignLock */
  142.