1#ifndef _FSSH_DRIVERS_DRIVERS_H
2#define _FSSH_DRIVERS_DRIVERS_H
3
4#include "fssh_defs.h"
5#include "fssh_fs_interface.h"
6
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12/* ---
13	these hooks are how the kernel accesses the device
14--- */
15
16typedef fssh_status_t (*fssh_device_open_hook) (const char *name,
17								uint32_t flags, void **cookie);
18typedef fssh_status_t (*fssh_device_close_hook) (void *cookie);
19typedef fssh_status_t (*fssh_device_free_hook) (void *cookie);
20typedef fssh_status_t (*fssh_device_control_hook) (void *cookie, uint32_t op,
21								void *data, fssh_size_t len);
22typedef fssh_status_t  (*fssh_device_read_hook) (void *cookie,
23								fssh_off_t position, void *data,
24								fssh_size_t *numBytes);
25typedef fssh_status_t  (*fssh_device_write_hook) (void *cookie,
26								fssh_off_t position, const void *data,
27								fssh_size_t *numBytes);
28typedef fssh_status_t (*fssh_device_select_hook) (void *cookie, uint8_t event,
29								uint32_t ref, fssh_selectsync *sync);
30typedef fssh_status_t (*fssh_device_deselect_hook) (void *cookie, uint8_t event,
31								fssh_selectsync *sync);
32typedef fssh_status_t (*fssh_device_read_pages_hook)(void *cookie,
33								fssh_off_t position, const fssh_iovec *vec,
34								fssh_size_t count, fssh_size_t *_numBytes);
35typedef fssh_status_t (*fssh_device_write_pages_hook) (void *cookie,
36								fssh_off_t position, const fssh_iovec *vec,
37								fssh_size_t count, fssh_size_t *_numBytes);
38
39#define	FSSH_B_CUR_DRIVER_API_VERSION	2
40
41/* ---
42	the device_hooks structure is a descriptor for the device, giving its
43	entry points.
44--- */
45
46typedef struct {
47	fssh_device_open_hook			open;			/* called to open the device */
48	fssh_device_close_hook			close;			/* called to close the device */
49	fssh_device_free_hook			free;			/* called to free the cookie */
50	fssh_device_control_hook		control;		/* called to control the device */
51	fssh_device_read_hook			read;			/* reads from the device */
52	fssh_device_write_hook			write;			/* writes to the device */
53	fssh_device_select_hook			select;			/* start select */
54	fssh_device_deselect_hook		deselect;		/* stop select */
55	fssh_device_read_pages_hook		read_pages;		/* scatter-gather physical read from the device */
56	fssh_device_write_pages_hook	write_pages;	/* scatter-gather physical write to the device */
57} fssh_device_hooks;
58
59fssh_status_t		fssh_init_hardware(void);
60const char		  **fssh_publish_devices(void);
61fssh_device_hooks	*fssh_find_device(const char *name);
62fssh_status_t		fssh_init_driver(void);
63void				fssh_uninit_driver(void);
64
65extern int32_t	fssh_api_version;
66
67enum {
68	FSSH_B_GET_DEVICE_SIZE = 1,			/* get # bytes */
69										/*   returns size_t in *data */
70
71	FSSH_B_SET_DEVICE_SIZE,				/* set # bytes */
72										/*   passed size_t in *data */
73
74	FSSH_B_SET_NONBLOCKING_IO,			/* set to non-blocking i/o */
75
76	FSSH_B_SET_BLOCKING_IO,				/* set to blocking i/o */
77
78	FSSH_B_GET_READ_STATUS,				/* check if can read w/o blocking */
79										/*   returns bool in *data */
80
81	FSSH_B_GET_WRITE_STATUS,			/* check if can write w/o blocking */
82										/*   returns bool in *data */
83
84	FSSH_B_GET_GEOMETRY,				/* get info about device geometry */
85										/*   returns struct geometry in *data */
86
87	FSSH_B_GET_DRIVER_FOR_DEVICE,		/* get the path of the executable serving that device */
88
89	FSSH_B_GET_PARTITION_INFO,			/* get info about a device partition */
90										/*   returns struct partition_info in *data */
91
92	FSSH_B_SET_PARTITION,				/* create a user-defined partition */
93
94	FSSH_B_FORMAT_DEVICE,				/* low-level device format */
95
96	FSSH_B_EJECT_DEVICE,				/* eject the media if supported */
97
98	FSSH_B_GET_ICON,					/* return device icon (see struct below) */
99
100	FSSH_B_GET_BIOS_GEOMETRY,			/* get info about device geometry */
101										/* as reported by the bios */
102										/*   returns struct geometry in *data */
103
104	FSSH_B_GET_MEDIA_STATUS,			/* get status of media. */
105										/* return fssh_status_t in *data: */
106										/* B_NO_ERROR: media ready */
107										/* B_DEV_NO_MEDIA: no media */
108										/* B_DEV_NOT_READY: device not ready */
109										/* B_DEV_MEDIA_CHANGED: media changed */
110										/*  since open or last B_GET_MEDIA_STATUS */
111										/* B_DEV_MEDIA_CHANGE_REQUESTED: user */
112										/*  pressed button on drive */
113										/* B_DEV_DOOR_OPEN: door open */
114
115	FSSH_B_LOAD_MEDIA,					/* load the media if supported */
116
117	FSSH_B_GET_BIOS_DRIVE_ID,			/* get bios id for this device */
118
119	FSSH_B_SET_UNINTERRUPTABLE_IO,		/* prevent cntl-C from interrupting i/o */
120	FSSH_B_SET_INTERRUPTABLE_IO,		/* allow cntl-C to interrupt i/o */
121
122	FSSH_B_FLUSH_DRIVE_CACHE,			/* flush drive cache */
123	FSSH_B_GET_PATH_FOR_DEVICE,			/* get the absolute path of the device */
124	FSSH_B_GET_ICON_NAME,				/* get an icon name identifier */
125	FSSH_B_GET_VECTOR_ICON,				/* retrieves the device's vector icon */
126	FSSH_B_GET_DEVICE_NAME,				/* get name, string buffer */
127	FSSH_B_TRIM_DEVICE,					/* trims blocks, see fs_trim_data */
128
129	FSSH_B_GET_NEXT_OPEN_DEVICE = 1000,	/* iterate through open devices */
130	FSSH_B_ADD_FIXED_DRIVER,			/* private */
131	FSSH_B_REMOVE_FIXED_DRIVER,			/* private */
132
133	FSSH_B_AUDIO_DRIVER_BASE = 8000,	/* base for codes in audio_driver.h */
134	FSSH_B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
135	FSSH_B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
136	FSSH_B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
137
138	FSSH_B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined contol id's */
139};
140
141/* ---
142	geometry structure for the B_GET_GEOMETRY opcode
143--- */
144
145typedef struct {
146	uint32_t	bytes_per_sector;		/* sector size in bytes */
147	uint32_t	sectors_per_track;		/* # sectors per track */
148	uint32_t	cylinder_count;			/* # cylinders */
149	uint32_t	head_count;				/* # heads */
150	uint8_t		device_type;			/* type */
151	bool		removable;				/* non-zero if removable */
152	bool		read_only;				/* non-zero if read only */
153	bool		write_once;				/* non-zero if write-once */
154} fssh_device_geometry;
155
156
157/* ---
158	Be-defined device types returned by B_GET_GEOMETRY.  Use these if it makes
159	sense for your device.
160--- */
161
162enum {
163	FSSH_B_DISK = 0,					/* Hard disks, floppy disks, etc. */
164	FSSH_B_TAPE,						/* Tape drives */
165	FSSH_B_PRINTER,						/* Printers */
166	FSSH_B_CPU,							/* CPU devices */
167	FSSH_B_WORM,						/* Write-once, read-many devices */
168	FSSH_B_CD,							/* CD ROMS */
169	FSSH_B_SCANNER,						/* Scanners */
170	FSSH_B_OPTICAL,						/* Optical devices */
171	FSSH_B_JUKEBOX,						/* Jukeboxes */
172	FSSH_B_NETWORK						/* Network devices */
173};
174
175
176/* ---
177	partition_info structure used by B_GET_PARTITION_INFO and B_SET_PARTITION
178--- */
179
180typedef struct {
181	fssh_off_t	offset;					/* offset (in bytes) */
182	fssh_off_t	size;					/* size (in bytes) */
183	int32_t		logical_block_size;		/* logical block size of partition */
184	int32_t		session;				/* id of session */
185	int32_t		partition;				/* id of partition */
186	char		device[256];			/* path to the physical device */
187} fssh_partition_info;
188
189/* ---
190	driver_path structure returned by the B_GET_DRIVER_FOR_DEVICE
191--- */
192
193typedef char	fssh_driver_path[256];
194
195
196/* ---
197	open_device_iterator structure used by the B_GET_NEXT_OPEN_DEVICE opcode
198--- */
199
200typedef struct {
201	uint32_t	cookie;			/* must be set to 0 before iterating */
202	char		device[256];	/* device path */
203} fssh_open_device_iterator;
204
205
206/* ---
207	icon structure for the B_GET_ICON opcode
208--- */
209
210typedef struct {
211	int32_t	icon_size;			/* icon size requested */
212	void	*icon_data;			/* where to put 'em (usually BBitmap->Bits()) */
213} fssh_device_icon;
214
215
216/* B_TRIM_DEVICE data structure */
217typedef struct {
218	uint32_t	range_count;
219	uint64_t	trimmed_size;			/* filled on return */
220	struct range {
221		uint64_t	offset;				/* offset (in bytes) */
222		uint64_t	size;
223	} ranges[1];
224} fssh_fs_trim_data;
225
226
227#ifdef __cplusplus
228}
229#endif
230
231#endif /* _FSSH_DRIVERS_DRIVERS_H */
232