> For the complete documentation index, see [llms.txt](https://cbfs.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cbfs.ortusbooks.com/usage/disk-service.md).

# Disk Service

cbfs includes a Disk Service object you can use to register and interact with your disks.

The full API for the Disk Service can be found in the [Disk Service reference](/reference/reference/disk-service.md). Generated [API Docs](https://apidocs.ortussolutions.com/#/coldbox-modules/cbfs/) are also available.

## Injection DSL

The cbfs module registers a WireBox injection DSL that you can use to inject objects from the module.

| DSL                 | Description                                 |
| ------------------- | ------------------------------------------- |
| `cbfs`              | Inject the Disk Service                     |
| `cbfs:disks`        | Inject the entire disk records              |
| `cbfs:disks:{name}` | Inject a specific disk instance by `{name}` |

```javascript
// Injects the DiskService
diskService = getInstance( "cbfs" );
property name="diskService" inject="cbfs";

diskService = getInstance( "DiskService@cbfs" );
property name="diskService" inject="DiskService@cbfs";

// Injects the entire disks record structure
disks = getInstance( "cbfs:disks" );
property name="disks" inject="cbfs:disks";

// Injects a specific disk by name
tempDisk = getInstance( "cbfs:disks:{name}" );
tempDisk = getInstance( "cbfs:disks:temp" );
property name="tempDisk" inject="cbfs:disks:temp";
```

## Helper Method

The cbfs module registers a helper method called `cbfs( diskName )` that you can use in your handlers, layouts, and views to get an instance of a specific disk:

{% tabs %}
{% tab title="BoxLang" %}

```boxlang
class SomeHandler {
  function index( event, rc, prc ) {
    var storage = cbfs( "RamDisk" );
    var files = storage.allFiles();
  }
}
```

{% endtab %}

{% tab title="CFML" %}

```cfml
component {
  function index( event, rc, prc ) {
    var storage = cbfs( "RamDisk" );
    var files = storage.allFiles();
  }
}
```

{% endtab %}
{% endtabs %}

## Core Methods

### count()

Returns the count of registered disks.

### defaultDisk()

Return an instance of the default disk defined in your [configuration](/reference/reference/configuration.md).

### get( name )

Returns requested disk instance. Throws `InvalidDiskException` if the disk is not registered.

### getDiskRecord( name )

Returns struct of details for a disk.

### has( name )

Returns true if the disk has been registered with the provided name.

### names()

Returns an array of registered disk names.

### register( name, provider, properties, override )

Registers a new disk. If a disk has already been configured with the same name, then it will not be updated unless you specify `override=true`.

### shutdown()

Unregisters and shuts down all disks managed by the DiskService.

### tempDisk()

Returns the temporary disk.

### unregister( name )

Unregisters a disk. Throws `InvalidDiskException` if the disk is not registered.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cbfs.ortusbooks.com/usage/disk-service.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
