Updated July 2017
xcall MIAMEX, MX_EXPFIL, ch, addrecs, status
MX_EXPFIL (MIAMEX 133) expands or contracts random access (aka "contiguous") files in place by adding or removing blocks to/from the end of the file.
Parameters
ch (Num) [in]
is the channel number that the file is open (for random exclusive access). If running LOKSER, you should probably open the file for RANDOM (exclusive) before expanding it. If not running LOKSER, you are free to use some other locking scheme. Although the subroutine will not stop you from expanding a file without first gaining exclusive access, you are likely to run into synchronization conflicts with other users who have the file open. For one thing, those users will not be able to access the expanded area (until they close and reopen the file), so if you update a control record they may try to access the new area and get an illegal record number.
addrecs (Num) [in]
is the number of logical records to add (addrecs > 0) to or subtract (addrecs < 0) from the file, based on the record size passed in the file open statement. It will be converted to the appropriate number of 512 byte blocks to add or subtract. Added blocks will be filled with ]]] characters.
status (Signed Num) [out]
returns the new total number of logical records in the file if the operation is successful. 0 indicates a parameter or other configuration error trapped by the subroutine and is generally accompanied by a displayed message. <0 indicates an operating system error number, which you can retrieve the message for using MIAMEX,86,STATUS,MSG.
Comments
Under AMOS, random access files are truly contiguous, so expanding one required allocating an entirely new (larger) file and copying the contents of the original file to it. Under Windows and Unix, the disk blocks of random access files are not necessarily contiguous, thus making the kind of incremental expansion used by MX_EXPFIL possible.
Note that it is up to you to update any control records or other internal structures to correspond to the new file size. Remember to release your exclusive access after doing so.