fusee: cleanup and simplify emummc logic
This commit is contained in:
@@ -80,7 +80,7 @@ static emudev_device_t *emudev_find_device(const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int emudev_mount_device(const char *name, const device_partition_t *devpart, const char *origin_path) {
|
||||
int emudev_mount_device(const char *name, const device_partition_t *devpart, const char *origin_path, int num_parts, uint64_t part_limit) {
|
||||
emudev_device_t *device = NULL;
|
||||
|
||||
if (name[0] == '\0' || devpart == NULL) {
|
||||
@@ -120,80 +120,6 @@ int emudev_mount_device(const char *name, const device_partition_t *devpart, con
|
||||
if (devpart->emu_use_file)
|
||||
strcpy(device->origin_path, origin_path);
|
||||
|
||||
device->num_parts = 0;
|
||||
device->part_limit = 0;
|
||||
|
||||
device->devoptab.name = device->name;
|
||||
device->devoptab.deviceData = device;
|
||||
|
||||
/* Initialize immediately. */
|
||||
int rc = device->devpart.initializer(&device->devpart);
|
||||
if (rc != 0) {
|
||||
errno = rc;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Allocate memory for our intermediate sector. */
|
||||
device->tmp_sector = (uint8_t *)malloc(devpart->sector_size);
|
||||
if (device->tmp_sector == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
device->setup = true;
|
||||
device->registered = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int emudev_mount_device_multipart(const char *name, const device_partition_t *devpart, const char *origin_path, int num_parts, uint64_t part_limit) {
|
||||
emudev_device_t *device = NULL;
|
||||
|
||||
if (name[0] == '\0' || devpart == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(name) > 32) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (emudev_find_device(name) != NULL) {
|
||||
errno = EEXIST; /* Device already exists */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Invalid number of parts. */
|
||||
if (num_parts < 1) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Part limit is invalid. */
|
||||
if ((part_limit % (1ull << 30)) != 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Find an unused slot. */
|
||||
for (size_t i = 0; i < EMUDEV_MAX_DEVICES; i++) {
|
||||
if (!g_emudev_devices[i].setup) {
|
||||
device = &g_emudev_devices[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (device == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(device, 0, sizeof(emudev_device_t));
|
||||
device->devoptab = g_emudev_devoptab;
|
||||
device->devpart = *devpart;
|
||||
strcpy(device->name, name);
|
||||
strcpy(device->root_path, name);
|
||||
strcat(device->root_path, ":/");
|
||||
strcpy(device->origin_path, origin_path);
|
||||
device->num_parts = num_parts;
|
||||
device->part_limit = part_limit;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user