home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / acplook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-15  |  4.0 KB  |  138 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: acplook.c,v 1.10 1995/11/15 20:15:16 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    acplook.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    08 Dec 1984 (from test code)
  9.  * Last update:
  10.  *        15 Nov 1995, corrected err in 'SWAP' macro
  11.  *        18 Mar 1995, prototypes
  12.  *        18 Feb 1995, port to AXP (DATENT changes).
  13.  *        04 Nov 1988, added '.fexpr' data
  14.  *        22 Mar 1985, added file-id, record-length
  15.  *        27 Jan 1985, fix file-size (if negative result, assume we use
  16.  *                 the high-block).
  17.  *        20 Dec 1984, keep file-org with format (for FLIST).
  18.  *        12 Dec 1984, mask file-org from file-format
  19.  *        11 Dec 1984, fixes if privilege-violation found.
  20.  *
  21.  * Function:    This procedure uses the VMS ancillary control processor (ACP)
  22.  *        to obtain all directory information which will be useful for
  23.  *        FLIST except the filename.  When successful, a lookup using
  24.  *        ACP is up to twice as fast as the equivalent using RMS (which
  25.  *        must itself call ACP).
  26.  *
  27.  * Arguments:    z    => FILENT structure to load.  We write over default
  28.  *               values supplied by the caller.
  29.  *        filespec=> unique, null-ended filename specification string.
  30.  *        nam_    => NAM block (if a SYS$SEARCH was used before calling
  31.  *               this procedure).
  32.  *
  33.  * Returns:    The worst error status encountered in doing I/O for the lookup.
  34.  */
  35.  
  36. #include    <starlet.h>
  37. #include    <rms.h>
  38. #include    <descrip.h>
  39. #include    <iodef.h>
  40. #include    <ssdef.h>
  41. #include    <stsdef.h>
  42. #include    <string.h>
  43.  
  44. #include    "acp.h"
  45.  
  46. #include    "flist.h"
  47. #include    "dirent.h"
  48.  
  49. unsigned acplook (
  50.     FILENT    *z,
  51.     char    *filespec,        /* specifies files to lookup    */
  52.     struct    NAM    *nam_)
  53. {
  54.     unsigned status;
  55.     IOSB    iosb;
  56.     short    chnl;
  57.     int    j;
  58.     FIB    fib;
  59.     ATR    atr[14];
  60.     short    uic_vec[2];
  61.     FAT    recattr;
  62.     unsigned uchar;
  63. #define    SWAP(x)    (((x >> 16) & 0xffff) + ((x & 0xffff) << 16))
  64.  
  65.     static $DESCRIPTOR(DSC_name,"");
  66.     struct    dsc$descriptor    fibDSC;
  67.  
  68.     /* patch: if 'nam_' is zero, do local parse, search */
  69.     DSC_name.dsc$a_pointer = filespec;
  70.     DSC_name.dsc$w_length = strlen(filespec);
  71.     status = sys$assign (&DSC_name, &chnl, 0, 0);
  72.  
  73.     fibDSC.dsc$w_length = sizeof(FIB);
  74.     fibDSC.dsc$a_pointer = (char *)&fib;
  75.     memset (&fib, 0, sizeof(fib));
  76.     memcpy (fib.fib$w_fid, nam_->nam$w_fid, 6);
  77.  
  78. #define    atrSET(type,size,addr)\
  79.         atr[j].atr$w_type = type;\
  80.         atr[j].atr$w_size = size;\
  81.         atr[j++].atr$l_addr = (char *)addr
  82.  
  83.     j = 0;
  84.     atrSET(ATR$C_CREDATE, ATR$S_CREDATE, &z->fdate);
  85.     atrSET(ATR$C_REVDATE, ATR$S_REVDATE, &z->frevi);
  86.     atrSET(ATR$C_BAKDATE, ATR$S_BAKDATE, &z->fback);
  87.     atrSET(ATR$C_EXPDATE, ATR$S_EXPDATE, &z->fexpr);
  88.     atrSET(ATR$C_UIC,     ATR$S_UIC,     uic_vec);
  89.     atrSET(ATR$C_FPRO,    ATR$S_FPRO,    &z->fprot);
  90.     atrSET(ATR$C_RECATTR, ATR$S_RECATTR, &recattr);
  91.     atrSET(ATR$C_UCHAR,   ATR$S_UCHAR,   &uchar);
  92.     atr[j].atr$w_size = atr[j].atr$w_type = 0;
  93.  
  94.     z->fstat =
  95.     status = sys$qiow (0, chnl, IO$_ACCESS, &iosb, 0, 0,
  96.             &fibDSC, 0,0,0, &atr[0],0);
  97.  
  98.     if ($VMS_STATUS_SUCCESS(status))
  99.     {
  100.         /*
  101.          * Store the file-status in quasi-RMS form.  We are mostly
  102.          * interested in LOCKED, NOPRIV or NORMAL.  (The LOCKED-state
  103.          * shown by DIRECTORY corresponds to the deaccess-lock known
  104.          * to ACP; the RMS-lock-by-other-user is detected only after
  105.          * a SYS$OPEN call).
  106.          */
  107.         z->fstat = RMS$_NORMAL;
  108.         if (iosb.sts != SS$_NORMAL)    z->fstat = iosb.sts;
  109.         if (uchar & FCH$M_LOCKED)    z->fstat = RMS$_FLK;
  110.         if (iosb.sts == SS$_NOPRIV)    z->fstat = RMS$_PRV;
  111.  
  112.         if (! zNOPRIV(z))
  113.         {
  114.             z->fsize = SWAP(recattr.fat$l_efblk);
  115.             if (!recattr.fat$w_ffbyte)    z->fsize--;
  116.             z->fallc = SWAP(recattr.fat$l_hiblk);
  117.             if (z->fsize < 0)        z->fsize = z->fallc;
  118.             z->f_grp = uic_vec[1];
  119.             z->f_mbm = uic_vec[0];
  120.             memcpy (z->fidnum, nam_->nam$w_fid, sizeof(z->fidnum));
  121.  
  122.             /*
  123.              * Note: The '.f_rfm' field contains both the file-
  124.              *     organization (in bits <7:4>) and the format
  125.              *     (in bits <3:0>).
  126.              */
  127.             z->f_rfm = recattr.fat$b_rtype;
  128.             z->f_rat = recattr.fat$b_rattrib;
  129.             z->f_recl= recattr.fat$w_rsize;
  130.  
  131.             if (!isOkDate(&(z->fback)))
  132.                 makeBigDate(&(z->fback)); /* (big num) */
  133.         }
  134.     }
  135.     status = sys$dassgn (chnl);
  136.     return (z->fstat);
  137. }
  138.