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

# createFile(named:in:attributes:packer:context:replyHandler:)

Creates a new file item and map its disk space.

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

```
func createFile(named name: FSFileName, in directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest, packer: FSExtentPacker, context: FSContext) async throws -> FSCreateFileKOIOResult
```

## Parameters

`name`

The new file’s name.

`directory`

The directory in which to create the file.

`newAttributes`

Attributes to apply to the new file.

`packer`

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

`context`

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

`reply`

A block or closure to indicate success or failure. If creation succeeds, pass an instance of [`FSCreateFileKOIOResult`](/documentation/FSKit/FSCreateFileKOIOResult) containing the newly-created [`FSItem`](/documentation/FSKit/FSItem), its [`FSFileName`](/documentation/FSKit/FSFileName), its [`FSItem.Attributes`](/documentation/FSKit/FSItem/Attributes), the updated [`FSItem.Attributes`](/documentation/FSKit/FSItem/Attributes) of the parent directory, the volume’s update free space, along with a `nil` error. If creation fails, pass the relevant error as the second parameter; FSKit ignores the [`FSCreateFileKOIOResult`](/documentation/FSKit/FSCreateFileKOIOResult) 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:)`](/documentation/FSKit/FSVolume/KernelOffloadedIOHandler/blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:)).
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.Handler`](/documentation/FSKit/FSVolume/Handler) protocol, [`createItem(named:type:in:attributes:context:replyHandler:)`](/documentation/FSKit/FSVolume/Handler/createItem(named:type:in:attributes:context:replyHandler:)).

---

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)