Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
storage.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_STORAGE_H
27#define _ULTIBO_STORAGE_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/globaltypes.h"
34#include "ultibo/globalconst.h"
35#include "ultibo/system.h"
36#include "ultibo/devices.h"
37
39#define STORAGE_NAME_PREFIX "Storage"
40
41#define STORAGE_STATUS_TIMER_INTERVAL 1000
42
44#define STORAGE_TYPE_NONE 0
45#define STORAGE_TYPE_HDD 1
46#define STORAGE_TYPE_FDD 2
47#define STORAGE_TYPE_CDROM 3
48#define STORAGE_TYPE_OPTICAL 4
49#define STORAGE_TYPE_TAPE 5
50#define STORAGE_TYPE_REMOVABLE 6
51
53#define STORAGE_STATE_EJECTED 0
54#define STORAGE_STATE_EJECTING 1
55#define STORAGE_STATE_INSERTING 2
56#define STORAGE_STATE_INSERTED 3
57
59#define STORAGE_FLAG_NONE 0x00000000
60#define STORAGE_FLAG_REMOVABLE 0x00000001
61#define STORAGE_FLAG_LBA48 0x00000002
62#define STORAGE_FLAG_NOT_READY 0x00000004
63#define STORAGE_FLAG_NO_MEDIA 0x00000008
64#define STORAGE_FLAG_READ_ONLY 0x00000010
65#define STORAGE_FLAG_WRITE_ONLY 0x00000020
66#define STORAGE_FLAG_ERASEABLE 0x00000040
67#define STORAGE_FLAG_LOCKABLE 0x00000080
68#define STORAGE_FLAG_LOCKED 0x00000100
69#define STORAGE_FLAG_EJECTABLE 0x00000200
70#define STORAGE_FLAG_CHANGABLE 0x00000400
71
73#define STORAGE_CONTROL_TEST_READY 1
74#define STORAGE_CONTROL_RESET 2
75#define STORAGE_CONTROL_TEST_MEDIA 3
76#define STORAGE_CONTROL_LOCK 4
77#define STORAGE_CONTROL_UNLOCK 5
78#define STORAGE_CONTROL_EJECT 6
79#define STORAGE_CONTROL_TEST_LOCKED 7
80#define STORAGE_CONTROL_TEST_CHANGED 8
81#define STORAGE_CONTROL_GET_VENDORID 9
82#define STORAGE_CONTROL_GET_PRODUCTID 10
83#define STORAGE_CONTROL_GET_SERIAL 11
84#define STORAGE_CONTROL_GET_REVISION 12
85#define STORAGE_CONTROL_GET_PRODUCT 13
86#define STORAGE_CONTROL_GET_MANUFACTURER 14
87
91
93typedef uint32_t STDCALL (*storage_enumerate_cb)(STORAGE_DEVICE *storage, void *data);
95typedef uint32_t STDCALL (*storage_notification_cb)(DEVICE *device, void *data, uint32_t notification);
96
98typedef uint32_t STDCALL (*storage_device_read_proc)(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer);
99typedef uint32_t STDCALL (*storage_device_write_proc)(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer);
100typedef uint32_t STDCALL (*storage_device_erase_proc)(STORAGE_DEVICE *storage, int64_t start, int64_t count);
101typedef uint32_t STDCALL (*storage_device_control_proc)(STORAGE_DEVICE *storage, int request, size_t argument1, size_t *argument2);
102
104{
105 // Device Properties
107 // Storage Properties
108 uint32_t storageid;
109 uint32_t storagestate;
114 // Driver Properties
116 uint32_t targetid;
117 uint32_t targetlun;
118 uint32_t blocksize;
119 int64_t blockcount;
120 uint32_t blockshift;
121 char *vendor;
122 char *product;
123 char *revision;
125 // Statistics Properties
126 uint64_t readcount;
127 uint64_t readerrors;
128 uint64_t writecount;
129 uint64_t writeerrors;
130 uint64_t erasecount;
131 uint64_t eraseerrors;
132 // Internal Properties
135};
136
138uint32_t STDCALL storage_device_read(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer);
139uint32_t STDCALL storage_device_write(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer);
140uint32_t STDCALL storage_device_erase(STORAGE_DEVICE *storage, int64_t start, int64_t count);
141uint32_t STDCALL storage_device_control(STORAGE_DEVICE *storage, int request, size_t argument1, size_t *argument2);
142
149uint32_t STDCALL storage_device_set_state(STORAGE_DEVICE *storage, uint32_t state);
150
157uint32_t STDCALL storage_device_start_status(STORAGE_DEVICE *storage, uint32_t interval);
158
165
171
178
183
188
193
195
205
206uint32_t STDCALL storage_device_notification(STORAGE_DEVICE *storage, storage_notification_cb callback, void *data, uint32_t notification, uint32_t flags);
207
209
214
219
220uint32_t STDCALL storage_device_type_to_string(uint32_t storagetype, char *string, uint32_t len);
221uint32_t STDCALL storage_device_state_to_string(uint32_t storagestate, char *string, uint32_t len);
222
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif // _ULTIBO_STORAGE_H
struct _DEVICE DEVICE
Definition devices.h:373
#define STDCALL
Definition globaltypes.h:45
HANDLE TIMER_HANDLE
Definition globaltypes.h:119
HANDLE MUTEX_HANDLE
Definition globaltypes.h:105
uint32_t STDCALL storage_device_write(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer)
uint32_t STDCALL(* storage_device_read_proc)(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer)
Definition storage.h:98
uint32_t STDCALL storage_device_read(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer)
uint32_t STDCALL storage_device_set_state(STORAGE_DEVICE *storage, uint32_t state)
Set the state of the specified storage and send a notification.
uint32_t STDCALL storage_device_start_status(STORAGE_DEVICE *storage, uint32_t interval)
Start status monitoring on the specified storage for insert/eject notifications.
uint32_t STDCALL storage_device_register(STORAGE_DEVICE *storage)
Register a new Storage in the Storage table.
STORAGE_DEVICE *STDCALL storage_device_create_ex(uint32_t size)
Create a new Storage entry.
uint32_t STDCALL(* storage_device_erase_proc)(STORAGE_DEVICE *storage, int64_t start, int64_t count)
Definition storage.h:100
uint32_t STDCALL(* storage_device_write_proc)(STORAGE_DEVICE *storage, int64_t start, int64_t count, void *buffer)
Definition storage.h:99
STORAGE_DEVICE *STDCALL storage_device_find(uint32_t storageid)
uint32_t STDCALL storage_device_notification(STORAGE_DEVICE *storage, storage_notification_cb callback, void *data, uint32_t notification, uint32_t flags)
uint32_t STDCALL storage_device_stop_status(STORAGE_DEVICE *storage)
Stop status monitoring on the specified storage for insert/eject notifications.
STORAGE_DEVICE *STDCALL storage_device_create(void)
Create a new Storage entry.
uint32_t STDCALL storage_device_state_to_string(uint32_t storagestate, char *string, uint32_t len)
uint32_t STDCALL(* storage_notification_cb)(DEVICE *device, void *data, uint32_t notification)
Definition storage.h:95
uint32_t STDCALL storage_device_state_to_notification(uint32_t state)
Convert a Storage state value into the notification code for device notifications.
uint32_t STDCALL storage_device_deregister(STORAGE_DEVICE *storage)
Deregister a Storage from the Storage table.
uint32_t STDCALL storage_device_type_to_string(uint32_t storagetype, char *string, uint32_t len)
STORAGE_DEVICE *STDCALL storage_device_check(STORAGE_DEVICE *storage)
Check if the supplied Storage is in the storage table.
STORAGE_DEVICE *STDCALL storage_device_find_by_name(const char *name)
uint32_t STDCALL storage_device_erase(STORAGE_DEVICE *storage, int64_t start, int64_t count)
uint32_t STDCALL(* storage_device_control_proc)(STORAGE_DEVICE *storage, int request, size_t argument1, size_t *argument2)
Definition storage.h:101
uint32_t STDCALL storage_device_enumerate(storage_enumerate_cb callback, void *data)
STORAGE_DEVICE *STDCALL storage_device_find_by_device(DEVICE *device)
Find a Storage device by the matching DeviceData property.
uint32_t STDCALL storage_device_destroy(STORAGE_DEVICE *storage)
Destroy an existing Storage entry.
uint32_t STDCALL storage_device_control(STORAGE_DEVICE *storage, int request, size_t argument1, size_t *argument2)
STORAGE_DEVICE *STDCALL storage_device_find_by_description(const char *description)
uint32_t STDCALL(* storage_enumerate_cb)(STORAGE_DEVICE *storage, void *data)
Definition storage.h:93
uint32_t STDCALL storage_get_count(void)
Get the current storage count.
struct _STORAGE_DEVICE STORAGE_DEVICE
Definition storage.h:90
Definition storage.h:104
uint64_t erasecount
Definition storage.h:130
storage_device_erase_proc deviceerase
A Device specific DeviceErase method implementing a standard Storage device interface.
Definition storage.h:112
MUTEX_HANDLE lock
Storage lock.
Definition storage.h:115
uint64_t readerrors
Definition storage.h:127
uint32_t blockshift
Shift Count for Blocks to Bytes conversion (eg 9 for 512 byte blocks).
Definition storage.h:120
uint64_t readcount
Definition storage.h:126
STORAGE_DEVICE * prev
Previous entry in Storage table.
Definition storage.h:133
char * product
ATA Serial No, SCSI Product.
Definition storage.h:122
uint32_t targetid
SCSI ID.
Definition storage.h:116
uint64_t writeerrors
Definition storage.h:129
uint32_t storageid
Unique Id of this Storage in the Storage table.
Definition storage.h:108
STORAGE_DEVICE * next
Next entry in Storage table.
Definition storage.h:134
DEVICE device
The Device entry for this Storage.
Definition storage.h:106
TIMER_HANDLE statustimer
Timer for status change detection.
Definition storage.h:124
int64_t blockcount
Number of Blocks.
Definition storage.h:119
uint32_t blocksize
Block Size.
Definition storage.h:118
storage_device_read_proc deviceread
A Device specific DeviceRead method implementing a standard Storage device interface.
Definition storage.h:110
storage_device_write_proc devicewrite
A Device specific DeviceWrite method implementing a standard Storage device interface.
Definition storage.h:111
uint32_t storagestate
Storage state (eg STORAGE_STATE_INSERTED).
Definition storage.h:109
storage_device_control_proc devicecontrol
A Device specific DeviceControl method implementing a standard Storage device interface.
Definition storage.h:113
uint64_t eraseerrors
Definition storage.h:131
uint32_t targetlun
LUN.
Definition storage.h:117
char * revision
Firmware Revision.
Definition storage.h:123
uint64_t writecount
Definition storage.h:128
char * vendor
ATA Model, SCSI Vendor.
Definition storage.h:121