@@ -626,6 +626,45 @@ int multirom_apk_get_roms(struct multirom_status *s)
626626 return -1 ;
627627 }
628628
629+ char current_rom [256 ] = { 0 };
630+ s -> curr_rom_part = NULL ;
631+
632+ /* Read multirom.ini to find current_rom */
633+ char arg [256 ];
634+ sprintf (arg , "%s/multirom.ini" , mrom_dir ());
635+
636+ FILE * f = fopen (arg , "re" );
637+ if (f )
638+ {
639+ char line [1024 ];
640+
641+ char name [64 ];
642+ char * pch ;
643+
644+ while ((fgets (line , sizeof (line ), f )))
645+ {
646+ pch = strtok (line , "=\n" );
647+ if (!pch ) continue ;
648+ strcpy (name , pch );
649+ pch = strtok (NULL , "=\n" );
650+ if (!pch ) continue ;
651+ strcpy (arg , pch );
652+
653+ if (strstr (name , "current_rom" ))
654+ strcpy (current_rom , arg );
655+ else if (strstr (name , "curr_rom_part" ))
656+ s -> curr_rom_part = strdup (arg );
657+ }
658+
659+ printf ("current_rom='%s' curr_rom_part='%s'\n" , current_rom , (s -> curr_rom_part ? s -> curr_rom_part : "" ));
660+
661+ fclose (f );
662+ }
663+ else
664+ {
665+ printf ("Failed to open config file, setting current_rom to null!\n" );
666+ }
667+
629668 /* Get Internal ROM */
630669 char roms_path [256 ];
631670 sprintf (roms_path , "%s/roms/" INTERNAL_ROM_NAME , mrom_dir ());
@@ -702,11 +741,22 @@ int multirom_apk_get_roms(struct multirom_status *s)
702741 multirom_update_partitions (s );
703742
704743 int i ;
705- for (i = 0 ; s -> partitions && s -> partitions [i ]; ++ i ) {
706- //printf("part=%s\n", s->partitions[i]->mount_path);
744+ pthread_mutex_lock (& parts_mutex );
745+ for (i = 0 ; s -> partitions && s -> partitions [i ]; ++ i )
746+ {
707747 s -> partitions [i ]-> keep_mounted = 1 ; // don't unmount on exit, the APK will need access to the folders
708748 multirom_scan_partition_for_roms (s , s -> partitions [i ]);
709749 }
750+ pthread_mutex_unlock (& parts_mutex );
751+
752+
753+ s -> current_rom = multirom_get_rom (s , current_rom , s -> curr_rom_part );
754+ if (!s -> current_rom )
755+ {
756+ printf ("Failed to find current rom (%s, part %s)!\n" , current_rom , (s -> curr_rom_part ) ? s -> curr_rom_part : "" );
757+ free (s -> curr_rom_part );
758+ s -> curr_rom_part = NULL ;
759+ }
710760
711761 return 0 ;
712762}
0 commit comments