From 197d41a3e23cab35848f623c6133baccc62aacbe Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Wed, 26 Aug 2026 17:56:52 -0400 Subject: OSD stuff and Android fixes Signed-off-by: Andrew Opalach --- src/cache/backings/file.c | 2 +- src/cache/backings/file_common.h | 14 +++++++++++++- src/cache/backings/file_mapped.c | 4 +--- src/cache/handle.c | 3 ++- src/cache/handlers/cdio.c | 9 +++++++-- src/cache/handlers/http.c | 14 ++++++++++---- src/cache/handlers/http.h | 2 +- 7 files changed, 35 insertions(+), 13 deletions(-) (limited to 'src/cache') diff --git a/src/cache/backings/file.c b/src/cache/backings/file.c index 06cc600..c98c8d5 100644 --- a/src/cache/backings/file.c +++ b/src/cache/backings/file.c @@ -63,7 +63,7 @@ static void file_backing_set_size(struct cch_backing *backing, off_t size, bool struct cch_backing_file *file = (struct cch_backing_file *)backing; nn_mutex_lock(&file->mutex); file->backing.size = size; - if (expand_to_size && (size_t)size > file->file.size) { + if (expand_to_size || (size > 0 && size < file->file.size)) { nn_file_truncate(&file->file, size); } nn_mutex_unlock(&file->mutex); diff --git a/src/cache/backings/file_common.h b/src/cache/backings/file_common.h index 6650dd1..6dd4e96 100644 --- a/src/cache/backings/file_common.h +++ b/src/cache/backings/file_common.h @@ -27,7 +27,19 @@ static void file_backing_finalize(struct cch_backing *backing) static bool file_open_internal(struct cch_backing_file *file, str *path, size_t size) { s32 flags = (size != 0) ? NNWT_FILE_CREATE : NNWT_FILE_READONLY; - if (!nn_file_open(&file->file, path, flags)) return false; + if (al_str_cmp(path, &al_str_c("fd://"), 0, 5) == 0) { + str fd_str = al_str_substr(path, 5, path->length); + bool error; + s32 fd = (s32)al_str_to_long(&fd_str, 10, &error); + if (error) return false; + if (!nn_file_wrap_fd(&file->file, fd)) { + return false; + } + } else { + if (!nn_file_open(&file->file, path, flags)) { + return false; + } + } size_t filesize = file->file.size; if (!size) { file->backing.size = filesize; diff --git a/src/cache/backings/file_mapped.c b/src/cache/backings/file_mapped.c index 7657a21..24ac005 100644 --- a/src/cache/backings/file_mapped.c +++ b/src/cache/backings/file_mapped.c @@ -46,14 +46,12 @@ static void file_backing_unlock(struct cch_backing *backing) static void file_backing_set_size(struct cch_backing *backing, off_t size, bool expand_to_size) { struct cch_backing_file *file = (struct cch_backing_file *)backing; - al_assert(expand_to_size || size == 0); nn_mutex_lock(&file->mutex); file->backing.size = size; - if ((size_t)size > file->file.size) { + if (expand_to_size || (size > 0 && size < file->file.size)) { nn_file_munmap(&file->file, file->u.map); nn_file_truncate(&file->file, size); file->u.map = nn_file_mmap(&file->file); - file->file.size = size; } nn_mutex_unlock(&file->mutex); } diff --git a/src/cache/handle.c b/src/cache/handle.c index 74db306..ebc3842 100644 --- a/src/cache/handle.c +++ b/src/cache/handle.c @@ -37,6 +37,7 @@ s32 cch_handle_read(struct cch_handle *handle, u8 *buf, s32 count) al_assert(count >= 0); handle->wait.start = handle->pointer; handle->wait.end = handle->pointer + count; + log_trace("wait_for_range(%zd, %zd)", handle->wait.start, handle->wait.end); if (!handler->wait_for_range(handler, &handle->wait)) { log_trace("Wait for range (%zd-%zd) failed.", handle->wait.start, handle->wait.end); return CAMU_ERR_EOF; @@ -52,7 +53,7 @@ s32 cch_handle_read(struct cch_handle *handle, u8 *buf, s32 count) backing->read(backing, buf, handle->pointer, &available); } handle->pointer += available; - log_trace("read(%u), pointer: %zd.", count, handle->pointer); + log_trace("read(%u), avail: %zu, pointer: %zd.", count, available, handle->pointer); return (available > 0) ? (s32)available : CAMU_ERR_EOF; } diff --git a/src/cache/handlers/cdio.c b/src/cache/handlers/cdio.c index 8326868..90c5ce9 100644 --- a/src/cache/handlers/cdio.c +++ b/src/cache/handlers/cdio.c @@ -1,6 +1,7 @@ #define AL_LOG_SECTION "cache_cdio" //#define AL_LOG_ENABLE_TRACE #include +#include #include "../../codec/codec.h" @@ -51,9 +52,10 @@ static nn_thread_result NNWT_THREADCALL cd_read_thread(void *userdata) cdio_log_messages(cdio); al_assert(ret <= SECTORS_PER_STEP); off_t pointer = cdio->sector * CDIO_CD_FRAMESIZE_RAW; - size_t size; + size_t size = BYTES_PER_STEP; u8 *ptr = cdio->backing->get_ptr(cdio->backing, pointer, &size); al_assert(size >= BYTES_PER_STEP); + log_trace("cdio_read(), ret: %ld, size: %zu", ret, size); if (ret == SECTORS_PER_STEP) { al_memcpy(ptr, nn_buffer_get_ptr(&cdio->buffer, 0), BYTES_PER_STEP); } else if (ret == -10) { @@ -192,7 +194,10 @@ static bool open_cd_drive(struct cch_handler_cdio *cdio) struct cch_entry *cch_handler_cdio_create(void) { - struct cch_backing *backing = cch_backing_file_create(&al_str_c("/tmp/camu_cd_data"), 4096); + str tmpfile; + al_str_clone(&tmpfile, &nn_temp_directory); + nn_path_append(&tmpfile, &al_str_c("camu_cd_data")); + struct cch_backing *backing = cch_backing_file_create(&tmpfile, 4096); if (!backing) return NULL; struct cch_handler_cdio *cdio = al_alloc_object(struct cch_handler_cdio); cdio->backing = backing; diff --git a/src/cache/handlers/http.c b/src/cache/handlers/http.c index f57d3eb..4fe82e2 100644 --- a/src/cache/handlers/http.c +++ b/src/cache/handlers/http.c @@ -1,10 +1,12 @@ #define AL_LOG_SECTION "cache_http" +#define AL_LOG_ENABLE_TRACE #include +#include #include "../../codec/codec.h" #include "../backings/memory.h" -//#include "../backings/file.h" +#include "../backings/file.h" #include "../threaded_waits.h" #include "../wait.h" @@ -78,11 +80,14 @@ static void handler_http_maybe_spawn_worker(struct cch_handler *handler, size_t { struct cch_handler_http *http = (struct cch_handler_http *)handler; (void)index; - al_array_push(http->requests, (struct nn_http){ 0 }); - struct nn_http *request = &al_array_last(http->requests); + struct nn_http *request = al_alloc_object(struct nn_http); + al_array_push(http->requests, request); nn_http_init(request); nn_http_set_url(request, &http->url); nn_http_set_user_agent(request, &USER_AGENT); + if (index != 0) { + nn_http_set_range(request, index, 0); + } nn_http_request_stream(request, NNWT_HTTP_GET, http->loop, http_callback, http); log_debug("Spawning worker for %.*s.", al_str_x(&http->url)); } @@ -104,7 +109,7 @@ static void handler_http_free(struct cch_handler **handler) struct cch_handler_http *http = (struct cch_handler_http *)*handler; cch_threaded_waits_disable_all(&http->waits); struct nn_http *request; - al_array_foreach_ptr(http->requests, i, request) { + al_array_foreach(http->requests, i, request) { nn_http_close(request); } cch_threaded_waits_close(&http->waits); @@ -115,6 +120,7 @@ static void handler_http_free(struct cch_handler **handler) *handler = NULL; } + struct cch_entry *cch_handler_http_create(str *url, struct nn_event_loop *loop) { struct cch_backing *backing = cch_backing_memory_create(1024 * 128); diff --git a/src/cache/handlers/http.h b/src/cache/handlers/http.h index 93efdae..3e0bfca 100644 --- a/src/cache/handlers/http.h +++ b/src/cache/handlers/http.h @@ -14,7 +14,7 @@ struct cch_handler_http { struct nn_event_loop *loop; str url; off_t pointer; - array(struct nn_http) requests; + array(struct nn_http *) requests; struct cch_threaded_waits waits; }; -- cgit v1.2.3-101-g0448