Managing media capacity on a per-file basis

Learn how to manage media capacity on a per-file basis.

An application might need to manage the media capacity on a per-file basis. Following are a few methods you can use to decide if a file will fit on the media:
  1. Handle error on a close operation

    Assume an optical volume is initialized to a 95% threshold and an application writes files until the volume threshold is reached. When the threshold is reached, the application will receive message CPF1F61, No free space available on media. At this point, the volume threshold can be increased to 97% (or anything else up to 100%) by using the CHGOPTVOL command. You can then attempt to close the file.

  2. Specify QALCSIZE on the Open Stream File HFS API
    Another method to determine if a file will fit on a volume is by specifying an allocation size (QALCSIZE) on an open stream file. On an open stream file, the system can pass a value in attribute QALCSIZE. This attribute is valid when the open operation is for create or replace; otherwise, it is ignored. Specifying a value for QALCSIZE results in comparing the specified value against the space available on the volume. If the space available is less than QALCSIZE, then the system issues message CPF1F61. The space available must exceed the QALCSIZE in order for the open operation to occur. Only on the first open instance of a file honors this attribute. If specified by more than one opening of a file, the system ignores the additional attributes.
    Note: This does not actually allocate space on the optical volume at the time of the open operation. It checks the volume to see if the number of requested bytes are available.
    There are drawbacks to using this method:
    1. You need to know the size of the file you are creating at the time you make the open request.
    2. If multiple jobs are writing to the same media, there is no guarantee that by the time the data is written, the space will still be available.

    If the size of the file is known prior to the time the open request is made, and there will not be other jobs writing to that volume during the time your file is open, this is an excellent method to check media capacity before creating a file.

  3. Retrieve space available on a volume

    Another method is to have the application retrieve the space available on the volume. You can do this by using the Display Optical (DSPOPT) command through output file support. The output file can then be read to retrieve the number of bytes assumed to be available on the media.