Implement volume unmounting, collecting VFS volume info, usb Add eject command
This commit is contained in:
81
usb/usb.c
81
usb/usb.c
@@ -5,14 +5,68 @@
|
||||
#include <process.h>
|
||||
#include <process_self.h>
|
||||
#include <status.h>
|
||||
#include <str_status.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
|
||||
int device_count = get_device_info (infos, 1024);
|
||||
struct device_info info;
|
||||
bool found = false;
|
||||
|
||||
for (int dev = 0; dev < device_count; dev++) {
|
||||
info = infos[dev];
|
||||
|
||||
if (info.type == DEVICE_TYPE_USB_CTRL) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
mprintf ("Polling device %s\n", info.key);
|
||||
|
||||
for (;;) {
|
||||
device_do (info.key, XUSBCTRL_POLL_DRIVER, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (volatile int i = 0; i < 500; i++)
|
||||
sched ();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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", info->volume_name, str_status[ret < 0 ? -ret : ret]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free (volume_infos);
|
||||
}
|
||||
|
||||
void app_main (void) {
|
||||
libprocess_self_init ();
|
||||
|
||||
char commandbuf[32];
|
||||
memset (commandbuf, 0, sizeof (commandbuf));
|
||||
char devnamebuf[32];
|
||||
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");
|
||||
@@ -20,29 +74,14 @@ void app_main (void) {
|
||||
}
|
||||
|
||||
if (strcmp (commandbuf, "poll") == 0) {
|
||||
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);
|
||||
|
||||
for (int dev = 0; dev < device_count; dev++) {
|
||||
struct device_info* info = &infos[dev];
|
||||
|
||||
if (info->type != DEVICE_TYPE_USB_CTRL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mprintf ("Polling device %s\n", info->key);
|
||||
|
||||
for (;;) {
|
||||
device_do (info->key, XUSBCTRL_POLL_DRIVER, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (volatile int i = 0; i < 500; i++)
|
||||
sched ();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
free (infos);
|
||||
usb_eject (devnamebuf);
|
||||
} else {
|
||||
mprintf ("ERROR unknown command %s\n", commandbuf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user