A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 121 lines 4.5 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2014 by Amaury Pouly 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21#ifndef __RB_SCSI_H__ 22#define __RB_SCSI_H__ 23 24#ifdef __cplusplus 25extern "C" { 26#endif 27 28struct rb_scsi_device_t; 29typedef struct rb_scsi_device_t *rb_scsi_device_t; 30 31typedef void (*rb_scsi_printf_t)(void *user, const char *fmt, ...); 32 33/* flags for rb_scsi_open */ 34#define RB_SCSI_READ_ONLY (1 << 0) 35#define RB_SCSI_DEBUG (1 << 1) 36 37/* transfer direction */ 38#define RB_SCSI_NONE 0 39#define RB_SCSI_READ 1 40#define RB_SCSI_WRITE 2 41 42/* most common status */ 43#define RB_SCSI_GOOD 0 44#define RB_SCSI_CHECK_CONDITION 2 45#define RB_SCSI_COMMAND_TERMINATED 0x22 46 47/* return codes */ 48#define RB_SCSI_OK 0 /* Everything worked */ 49#define RB_SCSI_STATUS 1 /* Device returned an error in status */ 50#define RB_SCSI_SENSE 2 /* Device returned sense data */ 51#define RB_SCSI_OS_ERROR 3 /* Transfer failed, got OS error */ 52#define RB_SCSI_ERROR 4 /* Transfer failed, got transfer/host error */ 53 54/* structure for raw transfers */ 55struct rb_scsi_raw_cmd_t 56{ 57 int dir; /* direction: none, read or write */ 58 int cdb_len; /* command buffer length */ 59 void *cdb; /* command buffer */ 60 int buf_len; /* data buffer length (will be overwritten with actual count) */ 61 void *buf; /* buffer */ 62 int sense_len; /* sense buffer length (will be overwritten with actual count) */ 63 void *sense; /* sense buffer */ 64 int tmo; /* timeout (in seconds) */ 65 int status; /* status returned by device (STATUS) or errno (OS_ERROR) or other error (ERROR) */ 66}; 67 68/* open a device, returns a handle or NULL on error 69 * the caller can optionally provide an error printing function 70 * 71 * Linux: 72 * Path must be the block device, typically /dev/sdX and the program 73 * must have the permission to open it in read/write mode. 74 * 75 * Windows: 76 * If the path starts with '\', it will be use as-is. This allows to use 77 * paths such as \\.\PhysicalDriveX or \\.\ScsiX 78 * Alternatively, the code will try to map a logical drive (such as 'C:') to 79 * the correspoding physical drive. 80 * In any case, on recent windows, the program needs to be started with 81 * Administrator privileges. 82 */ 83rb_scsi_device_t rb_scsi_open(const char *path, unsigned flags, void *user, 84 rb_scsi_printf_t printf); 85/* performs a raw transfer, returns !=0 on error */ 86int rb_scsi_raw_xfer(rb_scsi_device_t dev, struct rb_scsi_raw_cmd_t *raw); 87/* decode sense and print information if debug flag is set */ 88void rb_scsi_decode_sense(rb_scsi_device_t dev, void *sense, int sense_len); 89/* close a device */ 90void rb_scsi_close(rb_scsi_device_t dev); 91 92/* SCSI device reported by rb_scsi_list() */ 93struct rb_scsi_devent_t 94{ 95 /* device path to the raw SCSI device, typically: 96 * - Linux: /dev/sgX 97 * - Windows: C: 98 * This path can be used directly with scsi_rb_open(), and is guaranteed to 99 * be valid. */ 100 char *scsi_path; 101 /* device path to the corresponding block device, if it exists, typically: 102 * - Linux: /dev/sdX 103 * - Windows: C: 104 * If this path is not-NULL, then it can used directly with scsi_rb_open() */ 105 char *block_path; 106 /* various information about the device, can be NULL on error */ 107 char *vendor; 108 char *model; 109 char *rev; 110}; 111/* try to list all SCSI devices, returns a list of devices or NULL on error 112 * the list is terminated by an entry with scsi_path=NULL */ 113struct rb_scsi_devent_t *rb_scsi_list(void); 114/* free the list returned by rb_scsi_list */ 115void rb_scsi_free_list(struct rb_scsi_devent_t *list); 116 117#ifdef __cplusplus 118} 119#endif 120 121#endif /* __RB_SCSI_H__ */