Change formatting rules
This commit is contained in:
58
usb/usb.c
58
usb/usb.c
@@ -9,11 +9,11 @@
|
||||
#include <system.h>
|
||||
#include <volume_info.h>
|
||||
|
||||
static void usb_poll (void) {
|
||||
struct device_info* infos = malloc (sizeof (struct device_info) * 1024);
|
||||
memset (infos, 0, sizeof (struct device_info) * 1024);
|
||||
static void usb_poll(void) {
|
||||
struct device_info* infos = malloc(sizeof(struct device_info) * 1024);
|
||||
memset(infos, 0, sizeof(struct device_info) * 1024);
|
||||
|
||||
int device_count = get_device_info (infos, 1024);
|
||||
int device_count = get_device_info(infos, 1024);
|
||||
struct device_info info;
|
||||
bool found = false;
|
||||
|
||||
@@ -27,63 +27,63 @@ static void usb_poll (void) {
|
||||
}
|
||||
|
||||
if (found) {
|
||||
mprintf ("Polling device %s\n", info.key);
|
||||
mprintf("Polling device %s\n", info.key);
|
||||
|
||||
for (;;) {
|
||||
device_do (info.key, XUSBCTRL_POLL_DRIVER, NULL, NULL, NULL, NULL);
|
||||
device_do(info.key, XUSBCTRL_POLL_DRIVER, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (volatile int i = 0; i < 1000; i++) {
|
||||
sched ();
|
||||
sched();
|
||||
#if defined(__x86_64__)
|
||||
__asm__ volatile ("pause" ::: "memory");
|
||||
__asm__ volatile("pause" ::: "memory");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free (infos);
|
||||
free(infos);
|
||||
}
|
||||
|
||||
static void usb_eject (const char* dev_key) {
|
||||
struct volume_info* volume_infos = malloc (sizeof (*volume_infos) * 100);
|
||||
memset (volume_infos, 0, sizeof (*volume_infos) * 100);
|
||||
static void usb_eject(const char* dev_key) {
|
||||
struct volume_info* volume_infos = malloc(sizeof(*volume_infos) * 100);
|
||||
memset(volume_infos, 0, sizeof(*volume_infos) * 100);
|
||||
|
||||
size_t count = get_volume_info (volume_infos, 100);
|
||||
size_t count = get_volume_info(volume_infos, 100);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
struct volume_info* info = &volume_infos[i];
|
||||
|
||||
if (strcmp (info->device_key, dev_key) == 0) {
|
||||
int ret = volume_delete (info->volume_name);
|
||||
mprintf ("Deleted volume %s: %s\n", info->volume_name, str_status[ret < 0 ? -ret : ret]);
|
||||
if (strcmp(info->device_key, dev_key) == 0) {
|
||||
int ret = volume_delete(info->volume_name);
|
||||
mprintf("Deleted volume %s: %s\n", info->volume_name, str_status[ret < 0 ? -ret : ret]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free (volume_infos);
|
||||
free(volume_infos);
|
||||
}
|
||||
|
||||
void app_main (void) {
|
||||
void app_main(void) {
|
||||
char commandbuf[32];
|
||||
memset (commandbuf, 0, sizeof (commandbuf));
|
||||
memset(commandbuf, 0, sizeof(commandbuf));
|
||||
char devnamebuf[32];
|
||||
memset (devnamebuf, 0, sizeof (devnamebuf));
|
||||
memset(devnamebuf, 0, sizeof(devnamebuf));
|
||||
|
||||
if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) != ST_OK) {
|
||||
mprintf ("ERROR C=???. No command provided\n");
|
||||
if (env_get(process_get_pgid(), "C", (void*)commandbuf, sizeof(commandbuf)) != ST_OK) {
|
||||
mprintf("ERROR C=???. No command provided\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp (commandbuf, "poll") == 0) {
|
||||
usb_poll ();
|
||||
} else if (strcmp (commandbuf, "eject") == 0) {
|
||||
if (env_get (process_get_pgid (), "dev", (void*)devnamebuf, sizeof (devnamebuf)) != ST_OK) {
|
||||
mprintf ("ERROR No device provided\n");
|
||||
if (strcmp(commandbuf, "poll") == 0) {
|
||||
usb_poll();
|
||||
} else if (strcmp(commandbuf, "eject") == 0) {
|
||||
if (env_get(process_get_pgid(), "dev", (void*)devnamebuf, sizeof(devnamebuf)) != ST_OK) {
|
||||
mprintf("ERROR No device provided\n");
|
||||
return;
|
||||
}
|
||||
|
||||
usb_eject (devnamebuf);
|
||||
usb_eject(devnamebuf);
|
||||
} else {
|
||||
mprintf ("ERROR unknown command %s\n", commandbuf);
|
||||
mprintf("ERROR unknown command %s\n", commandbuf);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user