WARNOCK@clemson.CSNET (Todd Warnock) (11/28/86)
Exactly what is the "MAXIMUM RECORD SIZE for a file ???? I need to know the length of the longest record in a given file... The lexical function F$FILE("''filename'","MRS") SEEMS like it should return what I need, however it only works CORRECTLY some of the time... Why is this ? It seems to work correctly on savesets, although I cannot be sure that it ONLY works on them... Surely the correct information can be obtained from an image via some system service, but I've been unable to locate one... Any help would be appreciated... Thanks. Todd Warnock Clemson University WARNOCK@CLEMSON.CSNET
LEICHTER-JERRY@YALE.ARPA (12/01/86)
Exactly what is the "MAXIMUM RECORD SIZE for a file ???? I need to know the length of the longest record in a given file... The lexical function F$FILE("''filename'","MRS") SEEMS like it should return what I need, however it only works CORRECTLY some of the time... Why is this? Perhaps because you haven't understood the documentation? (See below) It seems to work correctly on savesets, although I cannot be sure that it ONLY works on them... Surely the correct information can be obtained from an image via some system service, but I've been unable to locate one... There are two fields that have to do with the length of "longest" records in a file: MRS (also known as MRZ in the file header, by the way) and LRL. MRS, the Maximum Record Size, is a value YOU specify for a file. For fixed- length files, it is the actual length of each record. For variable-length files, it is a user-imposed maximum size that any record is allowed to be. RMS will reject an attempt to write a record larger than MRS to a file. MRS has NOTHING to do with the length of any record actually in the file. MRS may be 0 to indicate that the user wishes to place no limit on record size; only inherent RMS limits then apply. LRL, on the other hand, is the "Longest Record Length": It is the length of the longest record ever actually written to the file. WARNING: It is not necessarily the length of the longest record CURRENTLY in the file; the longest record could since have been deleted. In general, take LRL as an upper bound: Unless something very unusual has been done to the file, no record will actually be larger than LRL. LRL may be 0; this means that RMS doesn't know, for some reason, what upper bound it can safely give you. The exact ways in which LRL can get to be 0 isn't clear. Doing block I/O writes to a record-structured file probably sets LRL to 0, but I'm not certain if this is always the case. I don't know off-hand if LRL is set for fixed-length files; it may be 0, or it may equal MRS. Empirically, typical variable-length, carriage-return carriage control files will have a valid LRL value and MRS=0. STREAM_LF files will typically have a non-zero MRS and LRL=0. (Such files often come from VAX C programs, and this pattern is probably the result of the VAX C library's use of block I/O for stream files.) BTW, a DIR/FULL talks about the size of the "maximum record". This appears to be LRL, NOT MRS; but exactly WHAT it is isn't clear - applied to some vari- able-length, carriage-return files in my directory, it shows what appear to be legitimate LRL values; applied to some STREAM_LF files produced by C, it shows 512, which is larger than any record in the file. C may be stuffing that val- ue into LRL - it IS writable - or DIRECTORY may be acting clever. If the goal is to allocate a buffer that is guaranteed to contain the largest record in the file, a fairly safe approach is to use max(MRS,LRL,1024). Note that this COULD be quite large, since MRS can be up to 32767 or so (depending on the exact file type). Of course, if MRS=LRL=0, this just reduces to a guess that 1024 is "probably enough". I suppose something like: LRL if LRL is non-zero, else max(1024,MRS) might even be better. There was a bug in the VAX C I/O routines, at least in V4.4 or so, in which a variable-length, carriage-return file opened for append was opened with a buffer size taken from LRL. As a result, you could never append to the file a record longer than the longest one already there. (C programs wouldn't get an errors as a result since the C I/O routines would simply split the long record up into smaller pieces. You'd see the result as spurious RETURN's when you looked at the file.) So, a LOT of people seem to be confused about LRL vs. MRS and exactly when to use which. (I'll bet I'm confused, too, and that there's an error in the above SOMEWHERE.) :-) -- Jerry -------