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 9 extern "C" { 10 #endif 11 12 /* --- 13 these hooks are how the kernel accesses the device 14 --- */ 15 16 typedef fssh_status_t (*fssh_device_open_hook) (const char *name, 17 uint32_t flags, void **cookie); 18 typedef fssh_status_t (*fssh_device_close_hook) (void *cookie); 19 typedef fssh_status_t (*fssh_device_free_hook) (void *cookie); 20 typedef fssh_status_t (*fssh_device_control_hook) (void *cookie, uint32_t op, 21 void *data, fssh_size_t len); 22 typedef fssh_status_t (*fssh_device_read_hook) (void *cookie, 23 fssh_off_t position, void *data, 24 fssh_size_t *numBytes); 25 typedef fssh_status_t (*fssh_device_write_hook) (void *cookie, 26 fssh_off_t position, const void *data, 27 fssh_size_t *numBytes); 28 typedef fssh_status_t (*fssh_device_select_hook) (void *cookie, uint8_t event, 29 uint32_t ref, fssh_selectsync *sync); 30 typedef fssh_status_t (*fssh_device_deselect_hook) (void *cookie, uint8_t event, 31 fssh_selectsync *sync); 32 typedef 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); 35 typedef 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 46 typedef 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 59 fssh_status_t fssh_init_hardware(void); 60 const char **fssh_publish_devices(void); 61 fssh_device_hooks *fssh_find_device(const char *name); 62 fssh_status_t fssh_init_driver(void); 63 void fssh_uninit_driver(void); 64 65 extern int32_t fssh_api_version; 66 67 enum { 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 124 FSSH_B_GET_PATH_FOR_DEVICE, /* get the absolute path of the device */ 125 126 FSSH_B_GET_NEXT_OPEN_DEVICE = 1000, /* iterate through open devices */ 127 FSSH_B_ADD_FIXED_DRIVER, /* private */ 128 FSSH_B_REMOVE_FIXED_DRIVER, /* private */ 129 130 FSSH_B_AUDIO_DRIVER_BASE = 8000, /* base for codes in audio_driver.h */ 131 FSSH_B_MIDI_DRIVER_BASE = 8100, /* base for codes in midi_driver.h */ 132 FSSH_B_JOYSTICK_DRIVER_BASE = 8200, /* base for codes in joystick.h */ 133 FSSH_B_GRAPHIC_DRIVER_BASE = 8300, /* base for codes in graphic_driver.h */ 134 135 FSSH_B_DEVICE_OP_CODES_END = 9999 /* end of Be-defined contol id's */ 136 }; 137 138 /* --- 139 geometry structure for the B_GET_GEOMETRY opcode 140 --- */ 141 142 typedef struct { 143 uint32_t bytes_per_sector; /* sector size in bytes */ 144 uint32_t sectors_per_track; /* # sectors per track */ 145 uint32_t cylinder_count; /* # cylinders */ 146 uint32_t head_count; /* # heads */ 147 uint8_t device_type; /* type */ 148 bool removable; /* non-zero if removable */ 149 bool read_only; /* non-zero if read only */ 150 bool write_once; /* non-zero if write-once */ 151 } fssh_device_geometry; 152 153 154 /* --- 155 Be-defined device types returned by B_GET_GEOMETRY. Use these if it makes 156 sense for your device. 157 --- */ 158 159 enum { 160 FSSH_B_DISK = 0, /* Hard disks, floppy disks, etc. */ 161 FSSH_B_TAPE, /* Tape drives */ 162 FSSH_B_PRINTER, /* Printers */ 163 FSSH_B_CPU, /* CPU devices */ 164 FSSH_B_WORM, /* Write-once, read-many devices */ 165 FSSH_B_CD, /* CD ROMS */ 166 FSSH_B_SCANNER, /* Scanners */ 167 FSSH_B_OPTICAL, /* Optical devices */ 168 FSSH_B_JUKEBOX, /* Jukeboxes */ 169 FSSH_B_NETWORK /* Network devices */ 170 }; 171 172 173 /* --- 174 partition_info structure used by B_GET_PARTITION_INFO and B_SET_PARTITION 175 --- */ 176 177 typedef struct { 178 fssh_off_t offset; /* offset (in bytes) */ 179 fssh_off_t size; /* size (in bytes) */ 180 int32_t logical_block_size; /* logical block size of partition */ 181 int32_t session; /* id of session */ 182 int32_t partition; /* id of partition */ 183 char device[256]; /* path to the physical device */ 184 } fssh_partition_info; 185 186 /* --- 187 driver_path structure returned by the B_GET_DRIVER_FOR_DEVICE 188 --- */ 189 190 typedef char fssh_driver_path[256]; 191 192 193 /* --- 194 open_device_iterator structure used by the B_GET_NEXT_OPEN_DEVICE opcode 195 --- */ 196 197 typedef struct { 198 uint32_t cookie; /* must be set to 0 before iterating */ 199 char device[256]; /* device path */ 200 } fssh_open_device_iterator; 201 202 203 /* --- 204 icon structure for the B_GET_ICON opcode 205 --- */ 206 207 typedef struct { 208 int32_t icon_size; /* icon size requested */ 209 void *icon_data; /* where to put 'em (usually BBitmap->Bits()) */ 210 } fssh_device_icon; 211 212 213 #ifdef __cplusplus 214 } 215 #endif 216 217 #endif /* _FSSH_DRIVERS_DRIVERS_H */ 218