From 3ff37e97a0b750b59464d5dab8d250e3366dfad0 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Tue, 24 Jun 2025 21:46:08 -0700 Subject: [PATCH] intel/mda: Allow more toplevel directory names inside mda.tar files Will allow generate anv.tar with unique "first directory name" instead of always "mda/", avoiding overlaps if user untars the files. The name still must end with "mda/". Acked-by: Kenneth Graunke Acked-by: Lionel Landwerlin Part-of: --- src/intel/mda/mda.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/intel/mda/mda.c b/src/intel/mda/mda.c index 4d2170f5a49..6bec2f78180 100644 --- a/src/intel/mda/mda.c +++ b/src/intel/mda/mda.c @@ -44,6 +44,7 @@ typedef struct mesa_archive { object *objects; const char *info; + slice detected_mda_prefix; } mesa_archive; enum diff_mode { @@ -190,6 +191,7 @@ parse_mesa_archive(void *mem_ctx, const char *filename) tar_reader_entry entry = {0}; bool found_mesa_txt = false; + ma->detected_mda_prefix = (slice){}; while (tar_reader_next(&tr, &entry)) { slice fullpath; if (!slice_is_empty(entry.prefix)) { @@ -202,10 +204,16 @@ parse_mesa_archive(void *mem_ctx, const char *filename) } slice mda_mesa_txt = slice_from_cstr("mda/mesa.txt"); - if (slice_equal(fullpath, mda_mesa_txt)) { - ma->info = slice_to_cstr(ma, entry.contents); - found_mesa_txt = true; - break; + + if (slice_ends_with(fullpath, mda_mesa_txt)) { + slice_cut_result cut = slice_cut(fullpath, '/'); + if (cut.found && slice_equal_cstr(cut.after, "mesa.txt")) { + /* Cut was succesful, so can extend to include the separator. */ + ma->detected_mda_prefix = (slice){ cut.before.data, cut.before.len+1 }; + ma->info = slice_to_cstr(ma, entry.contents); + found_mesa_txt = true; + break; + } } } @@ -234,13 +242,24 @@ parse_mesa_archive(void *mem_ctx, const char *filename) if (slice_is_empty(entry.contents)) continue; - /* Already processed this before. */ - if (slice_equal_cstr(fullpath, "mda/mesa.txt")) + if (!slice_starts_with(fullpath, ma->detected_mda_prefix)) { + fprintf(stderr, "mda: ignoring unexpected file with wrong prefix: %.*s\n", SLICE_FMT(fullpath)); continue; + } - /* Normalize path: strip leading "mda/" if present */ - slice mda_prefix = slice_from_cstr("mda/"); - fullpath = slice_strip_prefix(fullpath, mda_prefix); + /* Remove the detected prefix from paths. We'll use the filename later + * on since is more visible to the user. Most of the time is going to + * be the same. + */ + { + slice_cut_result cut = slice_cut(fullpath, '/'); + assert(cut.found); + fullpath = cut.after; + } + + /* Already processed this before. */ + if (slice_equal_cstr(fullpath, "mesa.txt")) + continue; slice_cut_result first_cut = slice_cut(fullpath, '/'); if (!first_cut.found)