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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: namefromlock.c,v 1.9 1997/01/27 00:36:26 ldp Exp $
  4.     $Log: namefromlock.c,v $
  5.     Revision 1.9  1997/01/27 00:36:26  ldp
  6.     Polish
  7.  
  8.     Revision 1.8  1996/12/09 13:53:35  aros
  9.     Added empty templates for all missing functions
  10.  
  11.     Moved #include's into first column
  12.  
  13.     Revision 1.7  1996/11/08 11:27:54  aros
  14.     All OS function use now Amiga types
  15.  
  16.     Moved intuition-driver protos to intuition_intern.h
  17.  
  18.     Revision 1.6  1996/10/24 15:50:33  aros
  19.     Use the official AROS macros over the __AROS versions.
  20.  
  21.     Revision 1.5  1996/09/13 17:50:07  digulla
  22.     Use IPTR
  23.  
  24.     Revision 1.4  1996/08/13 13:52:49  digulla
  25.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  26.     Replaced AROS_LA by AROS_LHA
  27.  
  28.     Revision 1.3  1996/08/12 14:20:38  digulla
  29.     Added aliases
  30.  
  31.     Revision 1.2  1996/08/01 17:40:55  digulla
  32.     Added standard header for all files
  33.  
  34.     Desc:
  35.     Lang: english
  36. */
  37. #include <proto/exec.h>
  38. #include <dos/exall.h>
  39. #include <dos/filesystem.h>
  40. #include "dos_intern.h"
  41.  
  42. /*****************************************************************************
  43.  
  44.     NAME */
  45. #include <proto/dos.h>
  46.  
  47.     AROS_LH3(BOOL, NameFromLock,
  48.  
  49. /*  SYNOPSIS */
  50.     AROS_LHA(BPTR,   lock,   D1),
  51.     AROS_LHA(STRPTR, buffer, D2),
  52.     AROS_LHA(LONG,   length, D3),
  53.  
  54. /*  LOCATION */
  55.     struct DosLibrary *, DOSBase, 67, Dos)
  56.  
  57. /*  FUNCTION
  58.     Get the full path name associated with a lock to a file or
  59.     directory into a user supplied buffer.
  60.  
  61.     INPUTS
  62.     lock   - Lock to file or directory.
  63.     buffer - Buffer to fill. Contains a NUL terminated string if
  64.          all went well.
  65.     length - Size of the buffer in bytes.
  66.  
  67.     RESULT
  68.     !=0 if all went well, 0 in case of an error. IoErr() will
  69.     give additional information in that case.
  70.  
  71.     NOTES
  72.  
  73.     EXAMPLE
  74.  
  75.     BUGS
  76.  
  77.     SEE ALSO
  78.  
  79.     INTERNALS
  80.  
  81.     HISTORY
  82.     29-10-95    digulla automatically created from
  83.                 dos_lib.fd and clib/dos_protos.h
  84.  
  85. *****************************************************************************/
  86.  
  87. /*****************************************************************************
  88.  
  89.     NAME
  90. #include <clib/dos_protos.h>
  91.  
  92.     AROS_LH3(LONG, NameFromFH,
  93.  
  94.     SYNOPSIS
  95.     AROS_LHA(BPTR  , fh, D1),
  96.     AROS_LHA(STRPTR, buffer, D2),
  97.     AROS_LHA(LONG  , len, D3),
  98.  
  99.     LOCATION
  100.     struct DosLibrary *, DOSBase, 68, Dos)
  101.  
  102.     FUNCTION
  103.     Get the full path name associated with file-handle into a
  104.     user supplied buffer.
  105.  
  106.     INPUTS
  107.     fh     - File-handle to file or directory.
  108.     buffer - Buffer to fill. Contains a NUL terminated string if
  109.          all went well.
  110.     length - Size of the buffer in bytes.
  111.  
  112.     RESULT
  113.     !=0 if all went well, 0 in case of an error. IoErr() will
  114.     give additional information in that case.
  115.  
  116.     NOTES
  117.  
  118.     EXAMPLE
  119.  
  120.     BUGS
  121.  
  122.     SEE ALSO
  123.  
  124.     INTERNALS
  125.  
  126.     HISTORY
  127.     29-10-95    digulla automatically created from
  128.                 dos_lib.fd and clib/dos_protos.h
  129.  
  130. *****************************************************************************/
  131. /*AROS alias NameFromFH NameFromLock */
  132. {
  133.     AROS_LIBFUNC_INIT
  134.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  135.  
  136.     STRPTR s1, s2, name;
  137.     struct Unit *curlock, *oldlock=NULL;
  138.     struct ExAllData *ead=(struct ExAllData *)buffer;
  139.     LONG error;
  140.  
  141.     /* Get pointer to filehandle */
  142.     struct FileHandle *fh=(struct FileHandle *)BADDR(lock);
  143.  
  144.     /* Get pointer to process structure */
  145.     struct Process *me=(struct Process *)FindTask(NULL);
  146.  
  147.     /* Get pointer to I/O request. Use stackspace for now. */
  148.     struct IOFileSys io,*iofs=&io;
  149.  
  150.     /* Prepare I/O request. */
  151.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  152.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  153.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  154.     iofs->IOFS.io_Device= fh==NULL?DOSBase->dl_NulHandler:fh->fh_Device;
  155.  
  156.     /* Construct the name from top to bottom */
  157.     name=buffer+length;
  158.     *--name=0;
  159.     curlock= fh==NULL?DOSBase->dl_NulLock:fh->fh_Unit;
  160.     /* Loop over path */
  161.     do
  162.     {
  163.     /* Read name of current lock (into the user supplied buffer) */
  164.     iofs->IOFS.io_Unit=curlock;
  165.     iofs->IOFS.io_Command=FSA_EXAMINE;
  166.     iofs->io_Args[0]=(IPTR)buffer;
  167.     iofs->io_Args[1]=name-buffer;
  168.     iofs->io_Args[2]=ED_TYPE;
  169.     DoIO(&iofs->IOFS);
  170.     error=iofs->io_DosError;
  171.  
  172.     /* Move name to the top of the buffer. */
  173.     if(!error)
  174.     {
  175.         s1=s2=ead->ed_Name;
  176.         while(*s2++)
  177.         ;
  178.         if(ead->ed_Type==ST_ROOT)
  179.         *--name=':';
  180.         else if(oldlock!=NULL)
  181.         *--name='/';
  182.         s2--;
  183.         while(s2>s1)
  184.         *--name=*--s2;
  185.     }
  186.  
  187.     /* Read the parent's lock (if there is a parent) */
  188.     if(!error&&ead->ed_Type!=ST_ROOT)
  189.     {
  190.         iofs->IOFS.io_Command=FSA_OPEN;
  191.         iofs->io_Args[0]=(IPTR)"/";
  192.         iofs->io_Args[1]=0;
  193.         DoIO(&iofs->IOFS);
  194.         curlock=iofs->IOFS.io_Unit;
  195.         error=iofs->io_DosError;
  196.     }
  197.  
  198.     /* Free the old lock if it was allocated by NameFromLock(). */
  199.     if(oldlock!=NULL)
  200.     {
  201.         iofs->IOFS.io_Unit=oldlock;
  202.         iofs->IOFS.io_Command=FSA_CLOSE;
  203.         DoIO(&iofs->IOFS);
  204.     }
  205.     oldlock=curlock;
  206.     }while(!error&&ead->ed_Type!=ST_ROOT);
  207.  
  208.     /* Move the name from the top to the bottom of the buffer. */
  209.     while((*buffer++=*name++)!=0)
  210.     ;
  211.     /* All done. */
  212.     me->pr_Result2=error;
  213.     return !error;
  214.     AROS_LIBFUNC_EXIT
  215. } /* NameFromLock */
  216.