Operating System - OpenVMS
1753777 Members
7468 Online
108799 Solutions
New Discussion юеВ

Re: Find file end block in pascal

 
SOLVED
Go to solution
KenAdam
New Member

Find file end block in pascal

In 1984, I wrote some software in VAX Pascal which used fab.fab$l_alq to check the "size" of a binary file I was opening (at that time the cluster size must have been 1 block) which I then mapped to a section (provided it was no more than 130 blocks.
With new disk drives having larger clusters, I can no longer use the ALQ to get the information and I need to find out which is the end block of the user data.
I've read the fortran example, but not having used either fortran or VMS for many years, Idon;t quite see how to make it work.
Can anyone provide a simple example?
The current code is:

file_fab.fab$v_ufo := true;
open_status := $open (fab := file_fab)
$connect (rab := file_rab);
(* get channel number *)
sec_chan := file_fab.fab$l_stv;
file_size := file_fab.fab$l_alq;
IF file_size > 130 THEN
lib$signal (lin_filetoobig, 2, %stdescr f_name [f_no], file_size);

Thanks
Ken
9 REPLIES 9
Bojan Nemec
Honored Contributor

Re: Find file end block in pascal

Ken,

Welcome to the VMS forum!

You must use the File Header Characteristic XAB (XABFHC). My Pascal is very rusty so I try to explain:
Allocate an XABFHC block and initialise it. Then point to this block from the FAB block filling the fab$l_xab with the address of the XABFHC block.
After the SYS$OPEN service you have:
In the xab$l_ebk you get the end block and in xab$w_ffb the last byte of the file.

Bojan
Hein van den Heuvel
Honored Contributor

Re: Find file end block in pascal

Bojan outlines the right technique.
How come your are not 100% happy with the result (as suggested by the points)?
Please share and maybe we can help you better.

There are plenty of examples floating around of how to allocate an XAB and hook it up. Google quickly found:
http://h71000.www7.hp.com/wizard/wiz_4996.html
There a standard pascal open is used, the fab address requested, an XAB connected and $display used to ask RMS to fill in details.

It turns out that a default PASCAL open already hooks up an XABFHC, so you could perhaps pre-open and walk fab --> xabfhc --> xab$l_ebk. Then close and re-open with UFO. The overhead would be minimal, as everything will be in cache, and you'll get the standard PASCAL IO error handling for free to deal with simple File-not-found, Locking and protections problems.

http://h71000.www7.hp.com/doc/82final/6140/6140pro_012.html
FAB$L_XAB : "The XAB chain always has a File Header Characteristics (FHC) extended attribute block in order to get the longest record length (XAB$W_LRL)..."

You may also want to check out using a "USER_ACTION" pascal OPEN option to hav the RTL to a maximum of work.

hth,
Hein.

Steven Schweda
Honored Contributor

Re: Find file end block in pascal

If you like C better than Fortran, there is
some code using xab$l_ebk/xab$w_ffb in the
Info-ZIP Zip source. Look in (the seldom
used) [.VMS]VMS_IM.C.

http://www.info-zip.org/
http://www.info-zip.org/Zip.html
http://www.info-zip.org/Zip.html#Sources
[...]

Quality not guaranteed, of course.
Hein van den Heuvel
Honored Contributor
Solution

Re: Find file end block in pascal

Some more thoughts...

file_fab.fab$v_ufo := true;
open_status := $open (fab := file_fab)
$connect (rab := file_rab);
(* get channel number *)

Why do the CONNECT?
That is not needed / wrong.

>> file_size := file_fab.fab$l_alq;

Why bother picking it up from the FAB?
Just set to the max (130) and just let $CRMPSC pick it up and do the right thing?

http://h71000.www7.hp.com/doc/82FINAL/4527/4527pro_028.html
-pagcnt-
"... the specified page count is compared with the number of blocks in the section file; if they are different, the lower value is used. If you do not specify the page count or specify it as 0 (the default), the size of the section file is used."

fwiw,
Hein.
KenAdam
New Member

Re: Find file end block in pascal

Guys,
Sorry if my lack of points enthusiasm was not in line with your expectations.
As I mentioned I wrote the code in 1984, last modifed it in anyway in 1988, and have not used or seen a VAX in several years.
I was asking for a pascal example fo how to resolve the issue - I've been asked to find a solution as the original author, but I am so out of touch with the VAX stuff (I only work in Delphi these days) that I need some help with the specific code to write. The old code used the channel number as part of allocating the section (but after 20 years I don't know why I came to that conclusion).
Please be patient with an "oldie" who is struggling with half-remembered code from earlier times.
I'll follow the suggested links when I get back to the office tomorrow, and then allocate points appropriately.
Ken
Hein van den Heuvel
Honored Contributor

Re: Find file end block in pascal

Not to worry about the points themself, we have plenty of those to spare :-).
I just used those as a tell tale sign that further help might be in order.

The channel indeed must be passed to $CRMPSC to inform it about which pre-opened file to use.

I suspect that between your old code, Bojan's directions, the 'wizard' example, and an adult beverage, you can figure out how to get to XAB$L_EBK in the XABFHC.

Free advice... also check for XAB$W_FFB, to deal with EOF = byte 512 in block 1 versus byte 0 in block 2 if you catch my drift.
Or just add one to EBK :-) max it by ALQ

Or don't do any, remove all the check code and use file_size := 130.

2 decade old VMS code huh?
Well, It's like riding a bike :-)

Cheers,
Hein.
KenAdam
New Member

Re: Find file end block in pascal

Hein,
I had found that first link you googled before I posted, but for some reason I was only shown the question and the first part of the answer (not the example code), which would have got me closer, I think.
The example code I posted is in a user_action routine already.
I had the required beverage last night (when I had no access to the code), and this morning, I have access to the code, but no beverage.
Hopefully I can manage with 50% of the required assets.
I'll get back after I've had a go at solving the problem.
Thanks,
Ken
KenAdam
New Member

Re: Find file end block in pascal

The simplest answer for me was to set the size when creating the section.
Code now works, and I can forget about vaxen again for a while...
KenAdam
New Member

Re: Find file end block in pascal

Solution already noted (didn't realise that I should close and noted in one action)