<!--
{
  "availability" : [
    "macOS: 15.4.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolumeKernelOffloadedIOOperations/preallocateSpace(for:at:length:flags:packer:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeKernelOffloadedIOOperations(im)preallocateSpaceForFile:atOffset:length:flags:packer:replyHandler:"
  },
  "title" : "preallocateSpace(for:at:length:flags:packer:replyHandler:)"
}
-->

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

Preallocates and maps disk space for the given file.

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

## 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.

`reply`

A block or closure to indicate success or failure. If preallocation succeeds, pass the amount of bytes allocated and a nil error. If preallocation fails, pass the relevant error as the second parameter; FSKit ignores any byte count in this case. For an `async` Swift implementation, there’s no reply handler; simply return the allocated byte count or throw an error.

## Discussion

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

> Important: Only implement this method if your file system conforms to ``doc://FSKit/documentation/FSKit/FSVolume/PreallocateOperations``.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)