              <<< ISVNET::DISK$OTHER:[NOTES$LIBRARY]VMS.NOTE;1 >>>
                           -< VMS Operating System >-
================================================================================
Note 80.6                      Foreign File Header                        6 of 7
BIGBOX::BRIANP                                      122 lines  11-JUL-1990 13:52
                           -< Example macro program >-
--------------------------------------------------------------------------------
the following is the example program from the dectel database
    It works I have used it. As long as you keep your file contig you
    should have enough space in the header.
    

 Title : Example-MACRO  How To Write To The Reserved Area In A File's Header


COPYRIGHT (c) 1988 by Digital Equipment Corporation.
ALL RIGHTS RESERVED. No distribution except as provided under contract.

COMPONENT: RMS, MACRO                      OP/SYS: VMS, Version 5.0

LAST TECHNICAL REVIEW: 20-SEP-1988 15:57

SOURCE: Customer Support Center/Colorado Springs USA


OVERVIEW:

This program demonstrates how to set up and write the reserved area
within a file's header.


*** CAUTION ***

This sample program has been tested using MACRO-32  on VMS, Version
5.0.  However, we cannot guarantee its effectiveness because of the
possibility of errors in transmitting or implementing it.  It is meant
to be used as a template for writing your own program, and it may
require modification for use on your system.


PROGRAM SAMPLE:

;
; Abstract:
;
;       This program demonstrates how to set up and write the
;       reserved area of a file.
;
; Environment:
;
;       usermode.  requires access to the file.
;
; Restrictions:
;
;       The size of the reserved area is limited by 2 factors
;       The number of map pointers (file extents) and the
;       presense of an access control list.
;
;       If an ACL is present on the file and there was no previous
;       reserved area present, you cannot add the reserved field.
;       If the reserved area was present and an ACL exists, you
;       cannot enlarge it.  Both of these conditions return
;       SS$_HEADERFULL.
;
;       A file with many extents (map pointers) also limit the
;       size of the reserved area.
;
;
        $atrdef                                 ; Attributes definitions
        $dscdef                                 ; String Descriptor defs
        $iodef                                  ; IO function definitions

FAB:    $FAB    FOP=<ufo>, FAC=<get,put>        ; For accessing the file

Prompt: .ASCID  /Filename? /                    ; User prompt

Filename:                                       ; Dynamic string descriptor
        .word   0
        .byte   dsc$k_dtype_t                   ; string type
        .byte   dsc$k_class_d                   ; Dynamic
        .long   0
;
; The following builds the reserved area string.  It consists
; of a 1 word length field followed by the information to place in the
; file header.  The length portion is not written to the file, but
; it required to be present in the string passed to the file system.
;
Reserved:
        .word   reserved_string_size
Reserved_string:
        .ascii  /This is the information to place in the file/
Reserved_string_size = . - reserved

atrlist:                                        ; Attributes control list
        .word   Reserved_string_size            ; Size of information
        .word   atr$c_reserved                  ; Reserved attribute
        .address reserved                       ; Write this string
        .long   0                               ; End list
iosb:   .quad   0                               ; User IO status.

        .entry  write_reserved, ^m<>
;
; Get the file name from the user.
;
        pushab  prompt
        pushab  filename
        calls   #2, g^lib$get_input
        blbs    r0, 10$
        ret
;
; Place the file name into the FAB and open it.
; The channel to the file is returned in the FAB$L_STV field
;
10$:    cvtwb   filename, fab+fab$b_fns         ; File name length
        beql    15$                             ; Get out on a zero length
        movl    filename+4, fab+fab$l_fna       ; filename string
        $open   fab=fab                         ; Open the file
        blbs    r0, 20$                         ; Check for error
15$:    ret
20$:    $qiow_s -                               ; Close the file
                chan=fab+fab$l_stv, -           ; on this channel
                func=#IO$_DEACCESS, -
                iosb=iosb, -
                p5=#atrlist                     ; And write these attributes
        blbs    r0, 30$
        ret
30$:    movzwl  iosb, r0                        ; Return any errors.
        ret
        .end    write_reserved
