A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 Frank Gevaerts
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
22#include <stdbool.h>
23#include <string.h>
24
25#include "config.h"
26#include "fs_defines.h"
27#include "storage.h"
28
29#define NUM_SECTORS 16384
30
31static unsigned char ramdisk[SECTOR_SIZE * NUM_SECTORS];
32
33static long last_disk_activity = -1;
34
35int ramdisk_read_sectors(IF_MD(int drive,)
36 sector_t start,
37 int count,
38 void* buf)
39{
40#ifdef HAVE_MULTIDRIVE
41 (void)drive; /* unused for now */
42#endif
43 if(start+count>NUM_SECTORS)
44 {
45 return -1;
46 }
47 memcpy(buf,&ramdisk[start*SECTOR_SIZE],count*SECTOR_SIZE);
48 return 0;
49}
50
51int ramdisk_write_sectors(IF_MD(int drive,)
52 sector_t start,
53 int count,
54 const void* buf)
55{
56#ifdef HAVE_MULTIDRIVE
57 (void)drive; /* unused for now */
58#endif
59 if(start+count>NUM_SECTORS)
60 {
61 return -1;
62 }
63 memcpy(&ramdisk[start*SECTOR_SIZE],buf,count*SECTOR_SIZE);
64 return 0;
65}
66
67int ramdisk_init(void)
68{
69 return 0;
70}
71
72long ramdisk_last_disk_activity(void)
73{
74 return last_disk_activity;
75}
76
77void ramdisk_sleep(void)
78{
79}
80
81void ramdisk_spin(void)
82{
83}
84
85void ramdisk_sleepnow(void)
86{
87}
88
89void ramdisk_enable(bool on)
90{
91 (void)on;
92}
93
94bool ramdisk_disk_is_active(void)
95{
96 return true;
97}
98
99int ramdisk_soft_reset(void)
100{
101 return 0;
102}
103
104int ramdisk_spinup_time(void)
105{
106 return 0;
107}
108
109void ramdisk_spindown(int seconds)
110{
111 (void)seconds;
112}
113#ifdef STORAGE_GET_INFO
114void ramdisk_get_info(IF_MD(int drive,) struct storage_info *info)
115{
116#ifdef HAVE_MULTIDRIVE
117 (void)drive; /* unused for now */
118#endif
119 /* firmware version */
120 info->revision="0.00";
121
122 /* vendor field, need better name? */
123 info->vendor="Rockbox";
124 /* model field, need better name? */
125 info->product="Ramdisk";
126
127 /* blocks count */
128 info->num_sectors=NUM_SECTORS;
129 info->sector_size=SECTOR_SIZE;
130}
131#endif
132
133#ifdef CONFIG_STORAGE_MULTI
134int ramdisk_num_drives(int first_drive)
135{
136 /* We don't care which logical drive number(s) we have been assigned */
137 (void)first_drive;
138
139 return 1;
140}
141#endif
142
143#ifdef HAVE_HOTSWAP
144bool ramdisk_removable(IF_MD(int drive))
145{
146#ifdef HAVE_MULTIDRIVE
147 (void)drive; /* unused for now */
148#endif
149
150 return false;
151}
152
153bool ramdisk_present(IF_MD(int drive))
154{
155#ifdef HAVE_MULTIDRIVE
156 (void)drive; /* unused for now */
157#endif
158
159 return true;
160}
161#endif
162
163int ramdisk_event(long id, intptr_t data)
164{
165 return storage_event_default_handler(id, data, last_disk_activity,
166 STORAGE_RAMDISK);
167}