9#include "module_debug.h"
18#define MAX_CONNECTIONS 20
19static struct bdm_mounts g_mount[MAX_CONNECTIONS];
21static bdm_cb g_cb = NULL;
22static int bdm_event = -1;
23static int bdm_thread_id = -1;
26#define BDM_EVENT_CB_MOUNT 0x01
27#define BDM_EVENT_CB_UMOUNT 0x02
28#define BDM_EVENT_MOUNT 0x04
30void bdm_RegisterCallback(bdm_cb cb)
34 M_DEBUG(
"%s\n", __func__);
42 for (i = 0; i < MAX_CONNECTIONS; ++i) {
43 if ((g_mount[i].bd != NULL) && (g_mount[i].fs != NULL)) {
44 SetEventFlag(bdm_event, BDM_EVENT_CB_MOUNT);
54 M_PRINTF(
"connecting device %s%dp%d id=0x%x\n", bd->name, bd->devNr, bd->parNr, bd->parId);
56 for (i = 0; i < MAX_CONNECTIONS; ++i) {
57 if (g_mount[i].bd == NULL) {
60 g_mount[i].cbd = (bd->parNr == 0) ? bd_cache_create(bd) : NULL;
62 SetEventFlag(bdm_event, BDM_EVENT_MOUNT);
72 M_PRINTF(
"disconnecting device %s%dp%d id=0x%x\n", bd->name, bd->devNr, bd->parNr, bd->parId);
74 for (i = 0; i < MAX_CONNECTIONS; ++i) {
75 if (g_mount[i].bd == bd) {
76 if (g_mount[i].fs != NULL) {
78 g_mount[i].fs->disconnect_bd(g_mount[i].cbd != NULL ? g_mount[i].cbd : g_mount[i].bd);
79 M_PRINTF(
"%s%dp%d unmounted from %s\n", bd->name, bd->devNr, bd->parNr, g_mount[i].fs->name);
83 if (g_mount[i].cbd != NULL) {
84 bd_cache_destroy(g_mount[i].cbd);
85 g_mount[i].cbd = NULL;
91 SetEventFlag(bdm_event, BDM_EVENT_CB_UMOUNT);
100 M_PRINTF(
"connecting fs %s\n", fs->name);
102 for (i = 0; i < MAX_CONNECTIONS; ++i) {
103 if (g_fs[i] == NULL) {
110 SetEventFlag(bdm_event, BDM_EVENT_MOUNT);
117 M_PRINTF(
"disconnecting fs %s\n", fs->name);
120 for (i = 0; i < MAX_CONNECTIONS; ++i) {
121 if (g_mount[i].fs == fs) {
122 g_mount[i].fs = NULL;
124 SetEventFlag(bdm_event, BDM_EVENT_CB_UMOUNT);
129 for (i = 0; i < MAX_CONNECTIONS; ++i) {
141 M_DEBUG(
"%s\n", __func__);
144 for (i = 0; (
unsigned int)i <
count && i < MAX_CONNECTIONS; i++)
145 pbd[i] = g_mount[i].bd;
148static void bdm_try_mount(
struct bdm_mounts *mount)
152 M_DEBUG(
"%s(%s%dp%d)\n", __func__, mount->bd->name, mount->bd->devNr, mount->bd->parNr);
154 for (i = 0; i < MAX_CONNECTIONS; ++i) {
155 if (g_fs[i] != NULL) {
156 if (g_fs[i]->connect_bd(mount->cbd != NULL ? mount->cbd : mount->bd) == 0) {
157 M_PRINTF(
"%s%dp%d mounted to %s\n", mount->bd->name, mount->bd->devNr, mount->bd->parNr, g_fs[i]->name);
160 SetEventFlag(bdm_event, BDM_EVENT_CB_MOUNT);
167static void bdm_thread(
void *arg)
174 M_PRINTF(
"BDM event thread running\n");
177 WaitEventFlag(bdm_event, BDM_EVENT_CB_MOUNT | BDM_EVENT_CB_UMOUNT | BDM_EVENT_MOUNT, WEF_OR | WEF_CLEAR, &EFBits);
179 if (EFBits & BDM_EVENT_MOUNT) {
181 for (i = 0; i < MAX_CONNECTIONS; ++i) {
182 if ((g_mount[i].bd != NULL) && (g_mount[i].fs == NULL))
183 bdm_try_mount(&g_mount[i]);
187 if (EFBits & BDM_EVENT_CB_MOUNT) {
193 if (EFBits & BDM_EVENT_CB_UMOUNT) {
207 M_DEBUG(
"%s\n", __func__);
209 for (i = 0; i < MAX_CONNECTIONS; ++i) {
210 g_mount[i].bd = NULL;
211 g_mount[i].cbd = NULL;
212 g_mount[i].fs = NULL;
216 EventFlagData.attr = 0;
217 EventFlagData.option = 0;
218 EventFlagData.bits = 0;
219 result = bdm_event = CreateEventFlag(&EventFlagData);
221 M_DEBUG(
"ERROR: CreateEventFlag %d\n", result);
225 ThreadData.attr = TH_C;
226 ThreadData.thread = bdm_thread;
227 ThreadData.option = 0;
228 ThreadData.priority = 0x30;
229 ThreadData.stacksize = 0x1000;
230 result = bdm_thread_id = CreateThread(&ThreadData);
232 M_DEBUG(
"ERROR: CreateThread %d\n", result);
233 DeleteEventFlag(bdm_event);
237 result = StartThread(bdm_thread_id, NULL);
239 M_DEBUG(
"ERROR: StartThread %d\n", result);
240 DeleteThread(bdm_thread_id);
241 DeleteEventFlag(bdm_event);
u32 count
start sector of fragmented bd/file