---
title: roStorageHotplug
slug: develop/rostoragehotplug
docTags: 
createdAt: 2025-03-11T07:07:18.731Z
---

This object provides *roStorageAttached* messages when storage devices appear and *roStorageDetached* messages when storage devices disappear. An *roStorageAttached* event is not delivered until the filesystem is mounted. The JavaScript equivalent is Node.js `fs.watch()`. 

There is currently no way to poll for media. 

:::hint{type="info"}
See [this page](docId\:qcEvA3OCMVeT4jzT5L6PE) for more information about device storage paths.
:::

Object Creation: The *roStorageHotplug* object is created with no parameters.

```text
CreateObject("roStorageHotplug")
```

## ifStorageHotplug

### GetStorages() as Object

Returns an ordered array of strings where each string is a drive specifier where the OS will look for an autorun script. For example: `[ "USB1:/", "SD:/", "SD2:/", "SSD:/", "Flash:/" ]`. Note that note all drive specifiers may be present or even possibly present on the particular player.

### GetStorageStatus(drive As String) As roAssociativeArray

Returns the current status of a storage device ("USB:", "SD:", "SSD:", "SD2:/", "Flash:"), even if it is not mounted. This method returns an associative array containing the following:

| **Key**    | **Value Type** | **Description**                                                    |
| ---------- | -------------- | ------------------------------------------------------------------ |
| `present`  | Boolean        | Indicates whether the specified device is present.                 |
| `mounted`  | Boolean        | Indicates whether the specified device is mounted.                 |
| `corrupt`  | Boolean        | Indicates whether the specified device is believed to be corrupt.  |
| `checking` | Boolean        | Indicates whether the specified device is currently being checked. |

:::hint{type="info"}
The results of the `GetStorageStatus()` method are unreliable when called with a "USBn:" parameter, where "n" is a positive integer indicating a USB storage device when multiple USB devices are connected to the player.
:::

Example:

```text
 status = CreateObject("roStorageHotplug").GetStorageStatus("SSD:")
 if not status.mounted and not status.checking and status.present then
    ' Should ask for confirmation here
    FormatDrive("SSD:")
 end if 
```

## ifFailureReason

### GetFailureReason() As String

Returns additional diagnostic information if a method returns `False`.

## ifUserData

### SetUserData(user\_data As Object)

Sets the user data that will be returned when events are raised.

### GetUserData() As Object

Returns the user data that has previously been set via SetUserData(). It will return Invalid if no data has been set.

## ifMessagePort

### SetPort(port As roMessagePort)

Posts messages of type *roStorageAttached* and *roStorageDetached*  to the attached message port.

:::hint{type="info"}
In order to avoid race conditions at startup, you should check for any storage devices that might have existed prior to the message port being set. We recommend doing this after the object is created and the message port is set, but before instructing the script to wait for any events.
:::

## Example

```text
Sub Main()
    mp = CreateObject("roMessagePort")
    sh = CreateObject("roStorageHotplug")
    gpio = CreateObject("roControlPort", "brightsign")

    sh.SetPort(mp)
    gpio.SetPort(mp)

    finished = false
    while not finished
    ev = mp.WaitMessage(0)
    if type(ev) = "roControlDown"
        finished = true
    else if type(ev) = "roStorageAttached"
        print "ATTACHED "; ev.GetString()
    else if type(ev) = "roStorageDetached"
        print "DETACHED "; ev.GetString()
    else
        print type(ev)
        stop
    end if
    end while
End Sub 
```

