diff --git a/ce/interp.c b/ce/interp.c index 5e94757..a226db3 100644 --- a/ce/interp.c +++ b/ce/interp.c @@ -395,29 +395,6 @@ static void quit1(struct context* context) { static void cls(struct context* context) { cprintf(context, ANSIQ_CUR_HOME ANSIQ_SCR_CLR_ALL); } -static void mkvol(struct context* context, const char* volume, const char* str_fs_type, - const char* device) { - int fs_type; - - if (strcmp(str_fs_type, "tar") == 0) { - fs_type = FS_TARFS; - } else if (strcmp(str_fs_type, "fat16") == 0) { - fs_type = FS_FAT16; - } else if (strcmp(str_fs_type, "fat32") == 0) { - fs_type = FS_FAT32; - } else if (strcmp(str_fs_type, "iso9660") == 0) { - fs_type = FS_ISO9660; - } else { - cprintf(context, "ERROR Unknown filesystem '%s'\n", str_fs_type); - return; - } - - int ret = create_volume(volume, fs_type, device); - - if (ret < 0) - cprintf(context, "ERROR Could not create volume: %s\n", str_status[-ret]); -} - static void stall(uint64_t ms) { stall_ms(ms); } static void help(struct context* context) { @@ -432,7 +409,6 @@ static void help(struct context* context) { cprintf(context, "edit \n"); cprintf(context, "terminfo\n"); cprintf(context, "cls\n"); - cprintf(context, "mkvol \n"); cprintf(context, "procinfo\n"); cprintf(context, "quit\n"); cprintf(context, "stall \n"); @@ -504,11 +480,6 @@ static void execute_cmd(struct ast_cmd* cmd, struct context* context, bool run_b terminfo(context); } else if (strcmp(cmd->name, "cls") == 0) { cls(context); - } else if (strcmp(cmd->name, "mkvol") == 0) { - if (cmd->arg_count == 3) - mkvol(context, cmd->args[0], cmd->args[1], cmd->args[2]); - else - cprintf(context, "ERROR No volume key, filesystem type or device key provided\n"); } else if (strcmp(cmd->name, "procinfo") == 0) { procinfo(context); } else if (strcmp(cmd->name, "stall") == 0) { diff --git a/etc/init.cmd b/etc/init.cmd index d980d14..c4d4c04 100644 --- a/etc/init.cmd +++ b/etc/init.cmd @@ -3,9 +3,7 @@ echo "Terminal information: " terminfo echo "\n" -echo "Starting USB poller...\n" -sys:/usb -poll & -echo "\n" +sys:/usb -poll -d xhci & stall 2000 diff --git a/make/apps.mk b/make/apps.mk index 2ff1aa4..629fafe 100644 --- a/make/apps.mk +++ b/make/apps.mk @@ -5,7 +5,8 @@ apps := \ sdutil \ usb \ mailtest \ - devices + devices \ + volumes all_apps: @for d in $(apps); do make -C $$d platform=$(platform) all; done diff --git a/sdutil/sdutil.c b/sdutil/sdutil.c index 0c0df55..5d52915 100644 --- a/sdutil/sdutil.c +++ b/sdutil/sdutil.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/usb/usb.c b/usb/usb.c index de66a00..313b21e 100644 --- a/usb/usb.c +++ b/usb/usb.c @@ -11,68 +11,25 @@ #include static bool cmdline_poll = false; -static bool cmdline_eject = false; static char cmdline_dev[CMDLINE_OPT_VALUE_MAX]; static struct cmdline_opt cmdline_opts[] = { CMDLINE_OPT("p", "poll", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_poll), - CMDLINE_OPT("e", "eject", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_eject), CMDLINE_OPT("d", "device", CMDLINE_OPT_VALUE_STRING, false, (char*)cmdline_dev), CMDLINE_END(), }; static void usb_poll(void) { - struct device_info* infos = malloc(sizeof(struct device_info) * 1024); - memset(infos, 0, sizeof(struct device_info) * 1024); + for (;;) { + device_do(cmdline_dev, XUSBCTRL_POLL_DRIVER, NULL, NULL, NULL, NULL); - 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 < 1000; i++) { - sched(); + for (volatile int i = 0; i < 1000; i++) { + sched(); #if defined(__x86_64__) - __asm__ volatile("pause" ::: "memory"); + __asm__ volatile("pause" ::: "memory"); #endif - } } } - - 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\n", info->volume_name, str_status[ret < 0 ? -ret : ret]); - break; - } - } - - free(volume_infos); } void app_main(void) { @@ -83,7 +40,5 @@ void app_main(void) { if (cmdline_poll) { usb_poll(); - } else if (cmdline_eject) { - usb_eject(cmdline_dev); } } diff --git a/volumes/.gitignore b/volumes/.gitignore new file mode 100644 index 0000000..4ebb2c5 --- /dev/null +++ b/volumes/.gitignore @@ -0,0 +1,6 @@ +*.o +*.json +docs/ +.cache/ +*.map +volumes diff --git a/volumes/Makefile b/volumes/Makefile new file mode 100644 index 0000000..d16094b --- /dev/null +++ b/volumes/Makefile @@ -0,0 +1 @@ +include ../make/user.mk diff --git a/volumes/app.mk b/volumes/app.mk new file mode 100644 index 0000000..6ccd4f8 --- /dev/null +++ b/volumes/app.mk @@ -0,0 +1 @@ +app := volumes diff --git a/volumes/src.mk b/volumes/src.mk new file mode 100644 index 0000000..51bac21 --- /dev/null +++ b/volumes/src.mk @@ -0,0 +1,3 @@ +c += volumes.c + +o += volumes.o diff --git a/volumes/volumes.c b/volumes/volumes.c new file mode 100644 index 0000000..1054957 --- /dev/null +++ b/volumes/volumes.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool cmdline_eject = false; +static char cmdline_dev[CMDLINE_OPT_VALUE_MAX]; +static bool cmdline_list = false; +static char cmdline_volkey[CMDLINE_OPT_VALUE_MAX]; +static bool cmdline_make = false; +static char cmdline_fstype[CMDLINE_OPT_VALUE_MAX]; + +static struct cmdline_opt cmdline_opts[] = { + CMDLINE_OPT("d", "device", CMDLINE_OPT_VALUE_STRING, false, (char*)cmdline_dev), + CMDLINE_OPT("e", "eject", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_eject), + CMDLINE_OPT("l", "list", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_list), + CMDLINE_OPT("m", "make", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_make), + CMDLINE_OPT("k", "key", CMDLINE_OPT_VALUE_STRING, false, (char*)cmdline_volkey), + CMDLINE_OPT("fs", "filesystem", CMDLINE_OPT_VALUE_STRING, false, (char*)cmdline_fstype), + CMDLINE_END(), +}; + +static void eject(void) { + 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, cmdline_dev) == 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); +} + +static void list(void) { + 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); + + mprintf("%-40s %-40s\n", "VOLUME", "DEVICE"); + + for (size_t i = 0; i < count; i++) { + struct volume_info* info = &volume_infos[i]; + + mprintf("%-40s %-40s\n", info->volume_name, info->device_key); + } + + free(volume_infos); +} + +static void make(void) { + int fs_type; + + if (strcmp(cmdline_fstype, "tar") == 0) { + fs_type = FS_TARFS; + } else if (strcmp(cmdline_fstype, "fat16") == 0) { + fs_type = FS_FAT16; + } else if (strcmp(cmdline_fstype, "fat32") == 0) { + fs_type = FS_FAT32; + } else if (strcmp(cmdline_fstype, "iso9660") == 0) { + fs_type = FS_ISO9660; + } else { + mprintf("ERROR Unknown filesystem '%s'\n", cmdline_fstype); + return; + } + + int ret = create_volume(cmdline_volkey, fs_type, cmdline_dev); + + if (ret < 0) + mprintf("ERROR Could not create volume: %s\n", str_status[-ret]); +} + +void app_main(void) { + if (cmdline_parse(get_cmdline(), cmdline_opts) < 0) { + mprintf("Failed to parse commandline arguments\n"); + return; + } + + if (cmdline_eject) { + eject(); + } else if (cmdline_list) { + list(); + } else if (cmdline_make) { + make(); + } +}