<!--
{
  "availability" : [
    "macOS: 15.4.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolumeKernelOffloadedIOOperations/createFile(name:in:attributes:packer:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeKernelOffloadedIOOperations(im)createFileNamed:inDirectory:attributes:packer:replyHandler:"
  },
  "title" : "createFile(name:in:attributes:packer:replyHandler:)"
}
-->

# createFile(name:in:attributes:packer:replyHandler:)

Creates a new file item and map its disk space.

```
func createFile(name: FSFileName, in directory: FSItem, attributes: FSItem.SetAttributesRequest, packer: FSExtentPacker, replyHandler reply: @escaping @Sendable (FSItem?, FSFileName?, (any Error)?) -> Void)
```

## Parameters

`name`

The new file’s name.

`directory`

The directory in which to create the file.

`attributes`

Attributes to apply to the new file.

`packer`

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

`reply`

A block or closure to indicate success or failure. If creation succeeds, pass the newly created [`FSItem`](/documentation/FSKit/FSItem) and its [`FSFileName`](/documentation/FSKit/FSFileName), along with a `nil` error. If creation fails, pass the relevant error as the third parameter; FSKit ignores any [`FSItem`](/documentation/FSKit/FSItem) or [`FSFileName`](/documentation/FSKit/FSFileName) in this case. For an `async` Swift implementation, there’s no reply handler; instead, return a tuple of the [`FSItem`](/documentation/FSKit/FSItem) and its [`FSFileName`](/documentation/FSKit/FSFileName) or throw an error.

## Discussion

This method allows the module to opportunistically supply extents, avoiding future calls to `blockmapFile(_:offset:length:flags:operationID:packer:)`.
Only perform this technique opportunistically.
In particular, don’t perform additional I/O to fetch extent data.

Packing extents in this method requires that `attributes` defines a size greater than 0.

An implementation that doesn’t supply the extents can ignore the packer and call the corresponding method in the [`FSVolume.Operations`](/documentation/FSKit/FSVolume/Operations) protocol, `FSVolume/Operations/createItem(named:type:inDirectory:attributes:)`.

---

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)