---
title: "preallocateSpace(for:at:length:flags:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/preallocatehandler/preallocatespace(for:at:length:flags:context:replyhandler:)"
---

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

Preallocates disk space for the given item.

## Declaration

```swift
func preallocateSpace(for item: FSItem, at offset: off_t, length: Int, flags: FSVolume.PreallocateFlags, context: FSContext, replyHandler reply: @escaping @Sendable (FSPreallocateResult?, (any Error)?) -> Void)
```

```swift
func preallocateSpace(for item: FSItem, at offset: off_t, length: Int, flags: FSVolume.PreallocateFlags, context: FSContext) async throws -> FSPreallocateResult
```

## Parameters

- `item`: 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.
- `context`: An object that enables context-aware file system decisions throughout the operation.
- `reply`: A block or closure to indicate success or failure. If preallocation succeeds, pass an instance of doc://FSKit/documentation/FSKit/FSPreallocateResult containing the amount of bytes allocated, the updated doc://FSKit/documentation/FSKit/FSItem/Attributes of the file and the volume’s updated free space, along with a nil error. If preallocation fails, pass the relevant error as the second parameter; FSKit ignores the doc://FSKit/documentation/FSKit/FSPreallocateResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

## See Also

### Preallocating space

- [FSVolume.PreallocateFlags](fskit/fsvolume/preallocateflags.md)
- [FSPreallocateResult](fskit/fspreallocateresult.md)
