Contents

preallocateSpace(for:at:length:flags:packer:context:replyHandler:)

Preallocates and maps disk space for the given file.

Declaration

optional func preallocateSpace(for file: FSItem, at offset: off_t, length: Int, flags: FSVolume.PreallocateFlags, packer: FSExtentPacker, context: FSContext, replyHandler reply: @escaping  @Sendable (FSPreallocateKOIOResult?, (any Error)?) -> Void)
optional func preallocateSpace(for file: FSItem, at offset: off_t, length: Int, flags: FSVolume.PreallocateFlags, packer: FSExtentPacker, context: FSContext) async throws -> FSPreallocateKOIOResult

Parameters

  • file:

    The item for which to preallocate space.

  • offset:

    The offset from which to allocate.

  • length:

    The length of the space in bytes.

  • flags:

    Flags that affect the preallocation behavior.

  • packer:

    An extent packer you use to pack the file’s preallocated disk space.

  • context:

    An object that enables context-aware file system decisions throughout the operation.

Discussion

::::: Swift ::::::::::

  • reply: A block or closure to indicate success or failure. If preallocation succeeds, pass an instance of FSPreallocateKOIOResult containing the amount of bytes allocated, the updated FSItem.Attributes of the file, the volume’s update free space, along with a nil error. If preallocation fails, pass the relevant error as the second parameter; FSKit ignores the FSPreallocateKOIOResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

::::::::::::::::::::

::::: ObjC ::::::::::

  • result: A block or closure to indicate success or failure. If preallocation succeeds, pass an instance of FSPreallocateKOIOResult containing the amount of bytes allocated, the updated FSItem.Attributes of the file, the volume’s update free space, along with a nil error. If preallocation fails, pass the relevant error as the second parameter; FSKit ignores the FSPreallocateKOIOResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

::::::::::::::::::::

Discussion

This method allows the module to opportunistically supply extents, avoiding future calls to blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:).

See Also

Working with items