HP OpenVMS Systems

ask the wizard
Content starts here

Accessing file attributes via $qio?

» close window

The Question is:

How i can perform analog of DCL command
in my C program, which must executed as
a detached process(i cannot use a system() call)?
Where i can found function description?
My problem is - i can't understand how to
modify FAB in easy way, because i think,
what file descriptor structure can be
accessed only for read.

The Answer is :

  The stock file record format created by C routines is stream LF.
  While system() and lib$spawn are not available to a detached process
  lacking a CLI, a lib$creprc() creation of a subprocess running the
  LOGINOUT image is permitted.  (Please see the OpenVMS FAQ for some
  related information.)
  The file-level record attributes are generally accessed via an
  IO$_ACPCONTROL call, specifying the ATR and FAT item blocks.  For
  details on this API, please see the I/O User's Reference Manual.
  In this particular case, the required ATR block would contain a
  reference to ATR$C_RECATTR code which would reference a FAT block
  where the FAT$V_RTYPE field contains FAT$C_STREAMLF.
  The following example sets the DIRECTORY bit via the IO$C_MODIFY.
  This involves using ATR$C_UCHAR rather than the ATR$C_RECATTR
  code needed to access the FAT$C_STREAMLF field, but is otherwise
  rather similar to what would need to be done to alter the record
	.title	    SETDIRBIT fixes the DIRECTORY bit
	; this program is used to turn on the "DIRECTORY" bit in the
	; file header.  The file (more correctly directory) to be
	; reset is specified by FID (file identification) and device.
	; (The FID can be retrieved from a DIRECTORY/FULL command.)
	;   a) Put the FID into the "fid" buffer, below.
	;   b) The device the FID is from must also be plugged into
	;	the "dev" descriptor, below.
	; The UCHAR field is protected -- see the I/O Abuser's Guide,
	; Part I, ACP/QIO Interface.  (SYSTEM or OWNER access to the
	; file (directory) is required.)
	; 11-Apr-1988	Stephen Hoffman, DIGITAL Equipment Corp.
	;	This was written up...  No claims to style or content:
	;	intended simply to solve a one-shot problem.  MINIMAL
	;	error checking and user-hostile!
	.library    'Sys$Library:LIB.Mlb'
	$atrdef	    ; File attribute definitions
	$fchdef	    ; File characteristics
	$fibdef	    ; File Information Block
	$iodef	    ; I/O definitions
	$ssdef	    ; System Service Definitions
	.psect	    data,wrt,noexe,long,noshr,usr
fid:	;   A file id (FID) looks like this: [NUM,SEQ,RVN]
	.word	    652		    ; file NUM
	.word	    9		    ; file SEQ
	.word	    0		    ; file RVN
	.word	    0		    ; (so we can use a MOVQ)
dev:	; And the name of the disk the file id is from...
	.ascid	    /HSC000$DUA2:/
iosb:	.blkw	    4		    ; garden variety IOSB
fchan:	.blkw	    1		    ; channel to the disk
FIBSIZE=22			    ; use the short FIB
fibbuf:	.blkb	    FIBSIZE	    ; here's the FIB itself
fib:	.long	    FIBSIZE	    ; here's the FIB descriptor
	.address    fibbuf
uchar:	.blkb	    ATR$S_UCHAR	    ; the FAT characteristics buffer
fat:	; The File Attributes itemlist follows:
	.word	    ATR$S_UCHAR	    ; length of the buffer
	.word	    ATR$C_UCHAR	    ; address of the buffer
	.address    uchar	    ; where the UCHAR field is...
	.blkq	    0		    ; zero marks the end...
	.psect	    code,nowrt,exe,long,shr,usr
	.entry	    SETDIRBIT, ^M<R2>
	; Get a channel to the device
	blbs	    r0,10$
10$:	;
	; Move the two important "bits" of trivia out to the FIB.
	moval	fibbuf,R0
	movq	fid,FIB$W_FID(R0)
	; Access the file (directory)
	$QIOW_S -
	blbc	    r0,19$
	blbs	    iosb,20$
19$:	ret
20$:	;
	; Force the DIRECTORY bit on!
	bisl2	    #FCH$M_DIRECTORY,uchar
	; Write the modified characteristics out...
	$QIOW_S -
	blbc	    r0,29$
	blbs	    iosb,30$
29$:	ret
30$:	;
	; And deaccess the file (directory)
	$QIOW_S -
	blbc	    r0,39$
	blbs	    iosb,40$
39$:	ret
40$:	;
	; Deassign the channel to the disk
	movzwl	    #SS$_NORMAL,R0
	; And bail out...

answer written or last revised on ( 19-JUL-2000 )

» close window