FOPEN Routine in MPE and UNIX
Both MPE and UNIX have routines named FOPEN
and FCLOSE which open and close files.
The MPE versions are more complex, since the MPE file
system is more complex (it has record types and sizes,
user labels, etc.). On UNIX a file is just a stream of bytes.
In fact, MPE has superseded FOPEN with the even more complex
HPFOPEN routine.
Foptions Means File-Type-Options
The Foptions value is a 16-bit unsigned integer made up
of 1, 2 and 3-bit fields. The 1-bit fields have value 1
to enable the option. Most fields default to the 0 value.
Remember that MPE
numbers bit fields
as (startbit:bitcount) and leftmost bit is 0:
Text version.
(1:1) | (2:3) | (5:1) | (6:1) | (7:1) | (8:2) | (10:3) | (13:1) | (14:2)
|
Byte stream
| File type?
| No :File
| Tape label
| CCTL
| Record format
| Def. desig
| ASCII/ Binary
| Domain
|
New!! | 0=std | | | | 0=fix | 0=file | | 0=new
|
| 1=ksam | | | | 1=var | 1=$stdlist | | 1=old
|
| 2=rio | | | | 2=undef | 2=$newpass | | 2=temp
|
| 3=ksam/xl | | | | 3=spool | 3=$oldpass | | 3=either
|
| 4=cir | | | | | 4=$stdin |
|
| 5=nm spoofle | | | | | 5=$stdinx |
|
| 6=msg | | | | | 6=$null |
|
| 7=ksam64 | | | | | |
|
Aoptions Means Access-Type Options
The Aoptions value is a 16-bit unsigned integer made up
of 1 to 4-bit fields. The 1-bit fields have value 1
to enable the option. Most fields default to the 0 value.
Remember that MPE
numbers bit fields
as (startbit:bitcount) and leftmost bit is 0:
Text version.
(2:1) | (3:1) | (4:1) | (5:2) | (7:1) | (8:2) | (10:1) | (11:1) | (12:4)
|
Glob open
| File Copy
| Nowait I/O
| Multi Access
| Nobuf
| Excl acc
| Locking
| Multi record
| Access type
|
| | | 0=none | | 0=default | | | 0=read
|
| | | 1=intra-job | | 1=exclusive | | | 1=write
|
| | | 2=inter-job | | 2=excl+read | | | 2=write/save
|
| | | 3=share | | | | | 3=append
|
| | | | | | | | 4=inout
|
| | | | | | | | 5=update
|
| | | | | | | | 6=execute
|
| | | | | | | | 9=readdir
|
HPFOPEN Gives You Mapped Access and More
When HP needed new parameters and options for opening files,
they added a new intrinsic to MPE: HPFOPEN. It accepts a
variable number of
pairs of parameters, the first of which is an Itemnum
and the second is the Item_Value
.
Text version.
HPFOPEN (filenum, | {32-bit integer by reference}
|
status, | {32-bit integer by reference}
|
itemnum, | {32-bit integer by value}
|
itemval, | {type varies, by reference}
|
... | {up to 41 pairs}
|
); |
|
A few important things to remember:
the status
is actually decoded as
two 16-bit values, Itemnum 2
the file name must
have an opening "quote" that also appears at the end,
you can open a new file and save it at the same time, and
you can open a file with mapped access
.
FCLOSE Intrinsic On MPE
FCLOSE does at least five distinct functions:
- Closes a file.
- Attempts to change the domain (save, temp, delete).
- Changes the security on the file.
- Releases unused disc space.
- Truncates the file limit to the current EOF.
FCLOSE(filenum {16-bit integer value }
,disposition {0=as is, 1=save, 2= temp}
{3=temp, no rewind, 4=delete}
{5=convert perm to temp NEW!!}
{.(11:2)=1 truncates, 2=trims}
,securitycode {1=tight, creator only}
);
FCONTROL versus fcntl
The MPE FCONTROL intrinsic and the UNIX fcntl function both
provide control over open files, but are otherwise dissimilar.
The terminal control functions of FCONTROL, such as control code 12
to turn Echo on, are not part of fcntl; see stty, termio,
and ioctl instead.
The file lock functions of fctnl are provided by the FLOCK and
FUNLOCK intrinsics of MPE, if at all.
The undocumented control codes 31 and 30 of FCONTROL (Vplus Block mode On
and Off) are incorporated into the blmode functions of HP-UX.