---
title: "lookupItem(named:in:packer:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/kerneloffloadediohandler/lookupitem(named:in:packer:context:replyhandler:)"
---

# lookupItem(named:in:packer:context:replyHandler:)

Looks up an item within a directory and maps its disk space.

## Declaration

```swift
func lookupItem(named name: FSFileName, in directory: FSItem, packer: FSExtentPacker, context: FSContext, replyHandler reply: @escaping @Sendable (FSLookupItemKOIOResult?, (any Error)?) -> Void)
```

```swift
func lookupItem(named name: FSFileName, in directory: FSItem, packer: FSExtentPacker, context: FSContext) async throws -> FSLookupItemKOIOResult
```

## Parameters

- `name`: The name of the file to look up.
- `directory`: The directory in which to look up the 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.

## Discussion

Discussion ::::: Swift :::::::::: reply: A block or closure to indicate success or failure. If lookup succeeds, pass an instance of FSLookupItemKOIOResult containing the found FSItem together with its FSFileName (as saved within the file system) and its FSItem.Attributes, along with a nil error. If lookup fails, pass the relevant error as the second parameter; FSKit ignores the FSLookupItemKOIOResult 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 lookup succeeds, pass an instance of FSLookupItemKOIOResult containing the found FSItem together with its FSFileName (as saved within the file system) and its FSItem.Attributes, along with a nil error. If lookup fails, pass the relevant error as the second parameter; FSKit ignores the FSLookupItemKOIOResult 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:). Only perform this technique opportunistically. In particular, don’t perform additional I/O to fetch extent data.

## See Also

### Working with items

- [createFile(named:in:attributes:packer:context:replyHandler:)](fskit/fsvolume/kerneloffloadediohandler/createfile(named:in:attributes:packer:context:replyhandler:).md)
- [FSItem.SetAttributesRequest](fskit/fsitem/setattributesrequest.md)
- [FSCreateFileKOIOResult](fskit/fscreatefilekoioresult.md)
- [FSLookupItemKOIOResult](fskit/fslookupitemkoioresult.md)
- [preallocateSpace(for:at:length:flags:packer:context:replyHandler:)](fskit/fsvolume/kerneloffloadediohandler/preallocatespace(for:at:length:flags:packer:context:replyhandler:).md)
- [FSVolume.PreallocateFlags](fskit/fsvolume/preallocateflags.md)
- [FSPreallocateKOIOResult](fskit/fspreallocatekoioresult.md)
