6.3 Extending Files Using Specific Allocation

Extend an NLM application file by selecting the volume segments and/or blocks to be allocated:

  1. Determine if space is available.

    Call DFSReturnVolumeMappingInformation to obtain the volume size, allocation unit size, sector size, number of free blocks, number of blocks available in deleted files, number of blocks not available in deleted files, and so forth. If adequate space for the file extension is not available, go to Step 5.

  2. Determine the current allocation for the file.

    Call DFSReturnFileMappingInformation to determine the file’s current mapping, including volume segments and blocks allocated. This information is required to determine where to extend a file.

    A file may not be extended by specifying file block addresses which already exist. This means that an extend request to allocate file space for a hole in a sparse file must not specify a number or contiguous blocks which exceed the size of the hole.

  3. Determine the available blocks on a volume.

    Call DFSReturnVolumeBlockInformation to obtain a bit map of available blocks on the desired volume. Determine from the bitmap a contiguous range of blocks large enough to extend the file as needed.

    As a result of multitasking, the bitmap of available blocks is valid only at the moment it is obtained, and may have changed by the time an application NLM requests a specific range of blocks to be allocated for a file (possibly requiring this step to be repeated multiple times).

    Call DFSExpandFile to specify the range of contiguous available blocks selected from the preceding bitmap. Specifying more than a single block causes the requested contiguous blocks to be allocated from the same volume segment. A good return code indicates that the requested function is completed.

  4. Extend the file.

    If enough contiguous space to expand the file the requested number of blocks is not available, applications may be required to make several calls specifying smaller request sizes, or fail the request.

    If the return code indicates that the above operation was not successful, proceed to Step 5. Some other module may have allocated the requested blocks, so the calling application must be prepared to retry the operation several times.

  5. Free up volume space.

    Call DFSFreeLimboVolumeSpace to specify the volume number and the requested number of blocks to be freed. This causes one or more deleted files to be purged from the volume in the order of the time of deletion. Go back to Step 1.