mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-23 09:49:34 -10:00
codex/android-native-streaming
37
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
ad2e390196 |
database_scan_test: an unknown-kind SMB scan stats its path twice now
|
||
|
|
0f72bd97d5 |
scan: reuse known path kinds for local content (#20029)
Reuse the caller's known content kind for every path. CLI scans and playlist refreshes already read it on a worker; asking again while building their configuration can stall the main thread. Keep the stat fallback when no kind is available. Reject an expected folder that is no longer a directory on the worker before playlist overwrite or validation. |
||
|
|
fa8870bc20 |
scan: preserve dots in playlist and database names
Append the playlist extension without trimming dotted suffixes. Refreshing Tiger - Game.com then keeps using its original playlist and database. |
||
|
|
83526f5f9e |
scan: bring two refresh checks up to date with merged master (#20046)
Both checks predate #19980 and #19983 meeting in master. An empty content folder in a refresh group is now skipped, not failed. Without task threads, Refresh All loads an smb:// playlist again to run it, so it stats once more than --scan-refresh; threaded, it still stats none. |
||
|
|
d99a3e2edd |
scan: Refresh All waits for a dead SMB share once
A frozen or unreachable SMB server cost the client timeout for every smb:// playlist in Refresh All, even when they all point at the same server. When a playlist's smb:// folder is not there in the loading pass, its share root is checked. If the root answers, the folder is really missing and the run goes on as before, with no more root checks. If it fails too, the share is taken as down for the rest of the run: later folders, --scan paths and refreshes on it fail with the same message and no check. With a share set in the settings, the client uses it for every URL, so every smb:// path is down. With none set, each URL names its share, so only the failed shares are down, and a root that answers later clears them, so a NAS waking from sleep recovers in the same run. |
||
|
|
5e83dce622 |
scan: '??' names only files the scan leaves unmatched
A database scan printed "??" from the lookup, before it knew what became of the file: a loose scan then added it, an expanded archive's members still had to be checked, and an m3u's discs could still match. The line is now printed where a scan counts a file unmatched, so the "??" lines and the unmatched total agree for every kind of scan. A .lutro, which matches by its extension, was counted unmatched without a line by a refresh of another database and by a group scan without a Lutro playlist; both now name it. |
||
|
|
0663a163c2 |
scan: Refresh All scans a shared folder once per group
Refresh All walked and checksummed a mixed folder once for every playlist a Fully Automatic scan of it had filled. It now reads every playlist's settings before it runs one, keeping only its name, folder and settings, and loads each playlist again when it runs, so it still holds one playlist at a time. The load turns the saved settings into text, so grouping compares strings and stats no folder on the main thread. Playlists named after an installed database, matched strictly against it alone with no DAT file, saved with no other database name and otherwise equal settings, overrides applied, share one group scan. The group runs at its first playlist's place under one line and task title naming the folder and the playlists, and the summary still counts playlists. Any other playlist, and every --scan-refresh, runs alone as before. |
||
|
|
8313950a30 |
scan: scan a folder once for a group of playlists
A Fully Automatic scan of a mixed folder fills one playlist per database, yet refreshing those playlists walks and checksums the folder once per playlist. A group scan does it once: it matches only the databases of the playlists it is given and sends each match to its database's playlist, filling one member at a time so each is sorted once. Every member is treated as its own refresh would treat it: cleared when overwriting, validated, given the scan settings whether or not it gained an entry, and saved as "<name>.lpl". A result no member takes counts as unmatched. A group scan needs a strict database scan, so it exists only with libretrodb. Its task title and --scan lines carry the label it is given. While it runs, a scan of a member's playlist is refused, and the reverse. Nothing pushes a group scan yet; Refresh All will. |
||
|
|
5074821a24 |
scan: DAT and match-none scans print the --scan lines
A DAT scan and --scan-match=none run apart from the database lookup, so --scan printed only their "++"/"==" lines and the totals. They now print the start line, a numbered line per file and a "??" for each file they count unmatched, an m3u included, as a database scan does. |
||
|
|
65f0370650 |
scan: skip a refresh whose content folder is empty
A playlist whose saved folder is an empty mount point, its drive unplugged, was refreshed and failed with "No valid content detected.", which made --scan-refresh and --scan-refresh-all exit 1. The refresh chain now skips it as it skips a folder that is gone, with a "skipped: content folder empty" line; it counts as skipped, not failed, in Refresh All Playlists' summary and in the exit status. A menu Refresh Playlist on such a folder is unchanged: it fails and leaves the playlist as it was. |
||
|
|
23af9fdedd |
scan: keep a missing entry whose folder is gone or empty
Validating a playlist dropped every entry whose file was missing, so a refresh with a drive unplugged, or with a mount point left behind empty, emptied the playlist of everything on it. A missing entry now goes only when the folder it is judged by holds something: the content folder for an entry inside it, else the folder holding the file or its archive. The extension filter applies only inside the content folder; entries outside it came from other scans. Entries are saved with their symlinks resolved, so the content folder is compared both as typed and resolved, ignoring case on Windows. The test harness builds file_path.c with RARCH_INTERNAL, as RetroArch does, so its symlink case can resolve; not on Windows, where that turns the slashes its checks look for into backslashes. |
||
|
|
7a1e7f8e5e |
database_scan_test: pass the scan's user data to task_push_dbscan
task_push_dbscan() takes a third argument, user data, and the cancelled-scan case added with the arcade set fingerprints called it with two, so the test no longer built. |
||
|
|
e9759423d6 |
scan: no set fingerprint while an archive hides a member
rar names no member it cannot unpack (solid, encrypted, an older packer), so a fingerprint taken over the members it does name would claim a set that may not be all there. Such an archive now has none and goes on to its other passes. 7z and rar also name no folder, which would look the same, so the scan's directory walk asks them to name one as zip does, ending in '/'. Nothing else sets the flag. |
||
|
|
4d320c445f |
scan: match arcade sets by a fingerprint of their member CRCs
The arcade databases key each set on the CRC of the whole TorrentZipped archive, so the same ROMs packed any other way - zstd or 7z, other names or order, a merged parent - never match. An optional set_fp1 key holds the CRC-32 of the set's ROM CRCs, de-duplicated, sorted and taken as big-endian bytes; set_fpm1 holds the same for a merged parent. The archive's one directory walk gives its fingerprint, leaving out folders, empty members and cue or gdi sheets; a member that stores no CRC leaves it without one. Each database whose cores open the archive's type and that carries the keys is looked up through an index built like the crc one. A hit writes the record's entry, as a match on the archive's own CRC does, and no archive is read whole for it. An archive of several members is looked up by its fingerprint before its size is. An archive of one member is looked up by it only after its member's CRC missed, so a first-member hit held for a cartridge database still wins. Where several records of a database share the fingerprint, as a set's split and non-merged packings can, the one whose size is the archive's is taken; where several have that size the archive's own CRC decides, and where none does, the one named like the archive, else the first. The readers read a TorrentZip set whole with no grant only while no database that opens zip carries fingerprints, so the fingerprint indexes of those databases are built before the readers start. One that cannot be built counts as carrying none: that database can match the set only by its own CRC. A database without the keys costs one walk per scan; older versions skip the keys. |
||
|
|
a859096242 |
database_scan_test: slow the unsized TorrentZip whole reads to 500 ms
"unsized TorrentZip sets: readers stop reading whole" failed twice on the four-core runner with 16 of 24 zips read whole, four rounds of the readers against three allowed: the sanitized scan ruled on the first set later than the 150 ms the readers took over each read. Forced to four readers here, the lane read 7 to 12, at the limit. A whole read now takes 500 ms, so the same delay in the scan lets fewer rounds through: 6 to 9 over six runs at four readers. The limit stays at three rounds. |
||
|
|
0b7c12251d |
Scanner: Wii U discs, WUX images and Wii U archives
Wii U content did not scan. It now takes the serial lookup by its product code: - a WUD, or a Wii U disc by another name (.iso, probed only once the other detectors find nothing, so other discs read nothing more), by the "WUP-P-XXXX" its header starts with; - a WUX, through the new formats/wux, the same octets of the disc it stands for; - a Wii U archive (.wua), by the product and company codes of its base title's meta/meta.xml, read through formats/zar. formats/wux reads WUX, the Wii U image format that keeps each distinct sector once, as the WUD it stands for. Like the other readers it does no file I/O: it asks for each range it needs. Opening reads the 32-octet header alone; the sector index is read a window at a time, only where a read needs it; a read's data lands in its own destination, one request per run of sectors the file keeps in order. formats/zar gains a directory listing, zar_dir_begin() and zar_dir_step(), each name read whole, the listing's end ZAR_END. A Wii U release's serial in the database is the product code and the maker's two characters, or the code alone for a title sold as a download; a disc does not say its maker. The code is therefore looked up as a stem, in the Wii U database alone - glob() in a libretrodb query now matches binary fields, as a serial is kept - and the release picked is the one of the maker an archive names, else a download for an archive and a disc release for a disc. The playlist names the release found. wux_test is new, zar_test lists directories, and the scan test gains a Wii U lane: a WUD, a WUX, a disc named .iso, two archives whose update is listed before the game, and another database holding the codes. |
||
|
|
1acc68146f |
Scanner: pick an Xbox release by the regions its executable names
Redump gives one serial to every release of an Xbox or Xbox 360 title, and to the extras discs that came with them, so a serial lookup found the first record - "Halo Movies (Japan)" for a North American Halo. formats/xdvdfs now reads the regions a title is for: the game region of an XBE's certificate, and the region of an XEX's security info, each only where the executable is long enough to hold it. The scanner reads the region field of the records a serial matches when it has regions to go by, and takes the first record whose regions overlap them; when none does, the first record stands in, as before. The duplicate DB_EXTRACT_* definitions in database_info.c go: the header carries them, with DB_EXTRACT_REGION added. |
||
|
|
d06c4b2ebd |
formats/zar: ZArchive reader; scan Xbox 360 games in .zar
formats/zar looks files up in a ZArchive and reads them, with no file I/O of its own. A lookup asks for a directory's entries a run at a time and for each name only as far as it can match; a read asks for a block kept as it is straight into its destination, decodes a compressed block (HAVE_RZSTD) into the destination when the read wants all of it, and otherwise into one block kept for the reads that follow. The scanner takes a .zar by the title of the default.xex it holds. |
||
|
|
37121e88e9 |
formats/xdvdfs: Xbox 360 titles; scan Xbox 360 games
The title read takes the executable an Xbox 360 disc boots,
default.xex, ahead of an Xbox one's default.xbe, and reads one on its
own as well: an XEX's execution info, an XBE's certificate or an STFS
package's header, each only as far as the title needs, after a 24-octet
head that tells them apart. The game partition is also looked for where
development images keep it, and a padded root reads as empty.
The scanner takes .xex and .xcp files by their title, and Xbox 360
discs too; a disc of a set gets its place in it ("FO-2046-1"). A .xex
that is no Xbox executable, as an Atari 8-bit one, goes on to the CRC
lookup.
|
||
|
|
5ca1dee585 |
formats/xdvdfs: Xbox disc file system; scan Xbox games
formats/xdvdfs finds an Xbox disc's game partition, at the start of a
trimmed XISO or where XGD1, XGD2 and XGD3 images keep it, looks files
up in its directory trees and reads the title of its default.xbe, with
no file I/O of its own. A lookup asks for one entry at a time, only as
much of each name as decides the search.
The scanner takes .xiso files, and .iso and .chd files no other
detector finds a serial for, through the serial lookup by the XBE's
title ("MS-004"), without the ISO size hint, which would rule out
trimmed images. Other discs read nothing more for it.
|
||
|
|
cd1a16c44b |
formats/ciso: CISO reader; scan .ciso GameCube/Wii images
formats/ciso reads a CISO file as the disc image it stands for, with no file I/O of its own: like formats/rvz, it describes each range of the file it needs as a request and the caller supplies it. A read asks for one range per run of stored blocks, straight into the read's own destination, and blocks left out are zeroed in place; the head lands in the block map's own storage and the map is built over it. Heads that are not CISO, PSP CSO included, are refused. The scanner takes .ciso files through the serial lookup, reading the disc header through the reader on a descriptor-path stream. ciso_test covers the reader and the database scan test a GameCube and a Wii image, and one whose disc starts with a block left out. |
||
|
|
e98e1da005 |
vfs smb, scan: read every smb:// URL from the configured server
The VFS reads the configured server whatever host a URL names, so a scan or refresh no longer compares the host: a playlist saved under an older server address refreshes after the SMB server setting changes, and the check takes no name lookup. A share other than the configured one is still refused. vfs_test checks URLs of other hosts, unresolvable ones included, pass on their share alone. |
||
|
|
c4fb538a89 |
scan: don't wait on an SMB server on the main thread
From the menu, the main thread stat'd an smb:// content folder up to three times before its scan task ran: for the playlist name, for whether it is a file and for the scan's folder flag. Manual Scan, Scan Directory, Scan File and a lone Refresh Playlist each did, and against a server that does not answer each stat waits out a connect with the menu frozen. The manual scan settings now keep what the caller knows the content folder to be. The menu's folder pick, Scan File and Scan Directory say whether it is a folder or a file, a refresh says its saved folder is a folder, and --scan and the chain's refreshes take it from the worker's read of the path. For an smb:// path of known kind those three places use the kind instead of a stat: the menu paths stat it none at all on the main thread, and a --scan or refresh of a reachable share is not stat'd again when its scan is pushed. The kind is kept with the settings a scan chain saves and puts back. A local path, and an smb:// one of unknown kind, stats as before. |
||
|
|
6ef3af70f8 |
scan: say why an smb:// folder failed; refuse another host or share
A scan or refresh of an smb:// folder that could not be read said "not found" or "skipped: content folder not found", whatever the cause, and logged nothing; in the menu, a scan scanned the folder path as a single file. A URL naming another host or share than the SMB settings was read from the configured server and share all the same. The scan task, the --scan path task and the playlist load of a refresh now check such a folder on the task worker before the scan starts: no SMB server set, a URL host or share other than the settings', or, when the folder cannot be read, the share's recorded connect failure (name lookup, connect, login, share). A URL refused for its host or share is never stat'd by them. The reason goes to the menu notification, one log line and the --scan line or the refresh's skip line. The item still fails, or the playlist is still skipped and left untouched, as before. A folder the server reports missing keeps the message it had. The man page states the host and share rule. |
||
|
|
47ec4f5d29 |
samples: the second scan run in one root, and a quiet cleanup
make check runs database_scan_test twice in one root. The "fs off main" lane deleted the playlists it wrote in its playlist folder but not the one outside it, so the second run's write of that playlist pushed an entry already on top, the push refused it, and the lane failed at its fixture. It deletes both now. playlist_parity_test's cleanup let cmd.exe print what rmdir could not find or remove; the cleanup is best effort, so it says nothing now. |
||
|
|
08e5b72a88 |
Scan from the command line: exit status, Manual Scan options, playlist refresh (#19977)
* file_path: stop at the end of the path after '~'
fill_pathname_expand_special() skipped two characters after a leading
'~' or ':', so a bare "~" read past its NUL and "~x" lost the x. It
now skips the prefix and a slash after it, if there is one.
* scan: hand the callback user data and what the scan did
task_push_dbscan() and task_push_manual_content_scan() take user data
for their callback, and the callback's task_data is now a
task_dbscan_result_t: how many entries the scan added, how many its
playlists already held, and how many files matched nothing. A file is
counted by what became of it, so an archive that is expanded is not
counted as unmatched, and a loose scan's unmatched files count as
added. Callers pass NULL for now.
* scan: say in the result when a scan failed
A scan that ends before it runs (bad setup, no valid content, a DAT
that will not load) or ends with a task error now sets the result's
failed flag. A database folder that is missing or unset is treated as
an empty one, so it reports the same "no database" error instead of
finishing as if it had scanned.
* scan: count the files a scan could not read
A file whose scan fails (an unreadable file, a failed lookup) was in
no count. The result now carries an errors count for them. They do
not fail the scan.
* scan: print --scan errors on stderr and totals on stdout
A command-line scan now ends with a totals line on stdout, or with the
reason it failed on stderr. A file it could not read is listed on
stderr. The ++/==/?? marks are coloured only when their stream is a
terminal, so pipes and redirected output get plain text; on Windows
redirected output keeps its marks instead of losing them to
WriteConsole.
* scan: the manual scan finder skips a finished task
A finished scan stays in the task queue while its callback runs, and
the finder that refuses a second scan for the same playlist still
matched it, so a scan pushed from that callback was refused.
* retroarch: run every --scan, then exit with what the scans did
Each --scan is collected while the command line is parsed and run in
turn once it is done, so later options and further --scan flags are
no longer dropped. A path is expanded and made absolute first; one
that does not exist, or a scan that cannot start, is reported on
stderr and the next path still runs. --scan with --cloudsync or
--command is refused.
Without --menu the exit status is 1 if any scan failed, else 0 if any
added an entry, else 2, and a content path given with the scans is
ignored, with a line on stderr. With --menu each finished scan starts
the next, as a second scan is refused while one runs.
* manual_content_scan: clear the database name a refresh did not save
A playlist with no saved database name left the name buffer
uninitialised, and the refresh compared it against every installed
database, so whatever was on the stack could pick a database the
playlist never named.
* scan: Skip Database References names the scan's one playlist
The option was meant to put the playlist's name in each entry's
db_name, even for a database match (#18641), for users who build
their own thumbnail sets. When the scan picks the playlists, db_name
also picks the playlist an entry goes to, so with the option on every
match went to one playlist named after the content folder.
It now applies only when the scan writes one playlist, and gives
that playlist's name, a loose scan's unmatched entries included. With
the target on <Automatic>, or Fully Automatic with the option left on
from a Custom scan, matches go to their databases' playlists as with
it off; the entries of a custom playlist look their thumbnails up
under its name, not the folder's.
* scan: name the scanned folder in the start line
The "Scanning content" line, in the log and in --scan's output, has
named the database folder since the manual scan and the database scan
were merged (
|
||
|
|
770391e8d5 |
scan: read an archive whole only when a database may hold its size (#19944)
* scan: read an archive's directory once for all its passes The scan fetched an archive's first member's CRC, size and extension through a helper that stops at the first entry and reports how many the header counts, and its readers did the same. One walk now reads the whole directory, in the readers as in the scan: every member's stored CRC, size and name, kept for each of the archive's passes. Its transfer state is on the heap, out of the readers' frames. The walk replaces the helper in the archive passes; the helper stays for its other users. The walk decodes the first member for a CRC where the archive stores none, a zstd stream or a RAR 5 member hashed with BLAKE2, so it is looked up as before. Later members are not decoded and keep a CRC of 0. A .bz2 is decoded to be listed at all. Folders are not members: an archive of a folder and one file has one member, that file, and is looked up by its CRC first. * zip: report a TorrentZip end comment A zip whose end-of-central-directory comment is TORRENTZIPPED- and eight hex digits was written by TorrentZip, as arcade sets are. The zip reader already reads that record to find the directory, so it now says so in the transfer state, for a caller that wants the hint. The CRC in the comment is not checked: nothing depends on it. * database_info, libretro-db: archive record sizes beside the crc index The crc index build walks each database once, off the main thread. In the same walk it now also collects the size of every record whose rom_name ends in an archive extension (zip, 7z, apk, rar, zst), kept in one sorted array keyed by size and type, so a caller can ask whether a database may hold an archive of a given type and size. A record of that type with no size, or an index built without the sizes, answers yes. The sizes count against the index budget. The stepped database scan reports one string field for this: libretrodb_scan_begin() and its callback gain a name field. A record's rom_name can also be extracted on request. * scan: look every archive member up from the directory An archive whose first member missed was read whole and, when that missed too, expanded: each member went through the databases again, by the stored CRC the directory already held. An archive of several members was read whole before any lookup, even where no database could hold it, so disc zips and console sets were read whole again. One member: its stored CRC is looked up first, as before. A hit in a database claimed only for the member's type is held, and every member's CRC is looked up next. On a miss the archive is read whole only when a database whose cores open its type may hold it by its exact size; its own CRC is then looked up there, and where that is not asked or misses, every member's. Several members: the same size question comes first. Each database whose cores open the type is then asked for the first member's CRC, and for the archive's own CRC only when the size let it be read whole, so an arcade record still wins and no database claimed only for a member's type is walked before it. Where neither matches, every member's stored CRC is looked up. A database may hold the archive when it has a record whose rom_name is of the archive's type and size, one of that type with no size, or no sizes at all. Every member is looked up with the gates and size checks the expansion uses. A hit names the archive itself only when it is the one record hit, that record is named for this archive and its database's cores open the type; other hits are written as the expansion wrote them, archive#member. The expansion stays for scans that keep unmatched files, for archives whose directory cannot be read, and where nothing hit and a member stores no CRC, which only the expansion unpacks for one. Readers read an archive whole ahead only after a whole match, twice as many after each such match up to the cap; any other verdict takes the rest back. A TorrentZip set of several members is still read whole by a reader with no grant while some database opens zip. An archive over the readers' cutoff is handed back before a grant is spent on it. This narrows "several members are read whole first" to "read whole when a database may hold it by its size". A record whose crc is an archive's own CRC but whose rom_name is not of the archive's type, or whose size is not the file's, is no longer matched; each of FBNeo's 596 sets carries its zip's size. A zip of a folder and one ROM takes the one-member order. * database_scan_test: rar archives through every pass A RAR 4 archive of stored entries, written by hand as the zips are, takes the passes zip and 7z take: a first member's hit where a core opens rar names the archive, a later member's elsewhere is held as archive#member, and the archive is read whole only while a database whose cores open rar holds a rar record of its size. * database_scan_test: define the fixture byte writers once * archive_file: clear the TorrentZip flag for every archive The flag was cleared only by the zip reader, so a transfer reused for a 7z, a rar or an archive with no backend kept what the last zip said. It is now cleared before any backend opens the archive. * scan: readers read TorrentZip sets whole while the scan asks for that Readers read every TorrentZip set of several members whole while some database opens zip, but where no database may hold a set by its size the scan drops that CRC, so a folder of sets no database holds was read whole for nothing. Each TorrentZip set the scan rules on now says whether its own CRC was asked, and the readers read the next ones whole only while it was. --------- Co-authored-by: libretroadmin <[email protected]> |
||
|
|
9d38efa2d6 |
scan: let the parallel readers open smb:// files (#19939)
* vfs: close a private SMB connection when an open, stat or opendir fails
When every pool slot is held, smb_take() connects privately for the
caller. If the open, stat or opendir then fails, smb_heal() returns
NULL when the connection is alive (a missing path, the usual case) or
cannot be replaced, and the caller stored that NULL over its context
and gave back nothing, so the connection and its socket were never
freed.
Keep the caller's context when smb_heal() returns NULL, so smb_give()
closes it. A pooled slot is given back as before.
vfs_test holds both pool slots with open files and then stats, opens
and lists a missing path; LSan reported the three connections before.
* vfs: release an SMB stream's connection when close follows a failed mend
When a stream's connection cannot be mended (the server is gone and
the reconnect is refused), or its file cannot be opened again, the
mend clears the stream's handle. Close returned early on the missing
handle, so a private stream leaked its connection, a pooled stream
kept its slot busy for the pool's life (smb_shutdown then left the
pool unfreed), and the reopen record leaked either way.
Close now checks for the connection rather than the handle and closes
the handle only when there is one. After a failed mend a private
connection is freed without a goodbye, since the server may be gone.
smb_idle_test gains a mode in which the server is stopped for good
during the pause, and local_samba_test.sh runs it, so the sanitizer
lane's LSan reports these leaks.
* cloud sync: make and drop SMB contexts under the VFS's list lock
libsmb2 keeps every context on one process-wide list with no lock of
its own, so the SMB VFS makes and drops its contexts under a lock
(
|
||
|
|
40a5f4e6ae |
scan: look archives up by their first member's CRC first (#19937)
* scan: look archives up by their first member's CRC first A zip, 7z, apk, rar, zst or bz2 was hashed whole before its first member's CRC was fetched. Cartridge databases key on ROM CRCs, so a one-ROM-per-zip set always matches by the member: the whole read, the main cost of scanning zips on a slow share, was wasted. The databases are now walked first for the member's CRC alone. Where it is stored (zip, 7z, RAR with CRC32) that costs one directory read; a zst, bz2 or BLAKE2 RAR member is decoded for it, as before. Only when that misses is the archive read whole, or a reader's whole result taken, and the databases walked again for its own CRC, which the arcade databases key on. The archive is expanded only after both miss. Each walk's size check uses its own size: the member's, then the archive's. By default the core gate looks in a database only when a core claims the file's extension. Stock cartridge cores do not list zip, so a cartridge zip was read whole and matched only once expanded. The first walk now also takes the databases claimed for the first member's extension. A hit there is held while the walk finishes the databases claimed for the archive's name: a match in one of those is written for the archive; otherwise the archive is expanded without the whole read. With "Scan Inside Archives" off nothing expands, so the first walk keeps to the archive's name. The parallel readers likewise start an archive with its first member's CRC, size and extension, and hand them to the scan. They hash archives whole only as far as the scan grants: a member-CRC miss grants one whole read ahead, each further miss in a row twice the last, up to 16 at a time, and a member-CRC match takes back what is left. A lone unknown cartridge then costs one wasted read, while an arcade folder soon has the readers 16 ahead. While the scan first walks a database's index in a member pass mid streak, the readers may keep 16 ahead, so the walk does not leave them idle. A grant goes first to the nearest archive ahead that has only its member CRC. Without a reader's whole result the scan hashes an archive it needs whole itself, in steps, like a file over the cutoff. An archive with no CRC for its first entry, such as a zip or 7z with a directory first, skipped every database, so its own CRC was never compared. It now goes straight to the whole walk, and readers always hash it whole. In first-match mode the walk's early exit leads to the whole walk too, while that has not run. The CRCs, sizes and walk are cleared at each file's start. A file that errored left them to the next, and an archive after it was looked up by the stale CRC. The serial is cleared with them: an archive matched after a file that errored in its serial lookup was written under that file's serial. Every database's member CRC is now checked before any whole CRC; each database used to check the whole CRC first. That differs only when a zip's first member matches a cartridge record and the whole zip an arcade record. The cartridge record now wins, written for the zip itself where the core gate lets the zip's name into the cartridge database, otherwise through the expansion. With "Scan Inside Archives" off nothing expands, so in that second case the arcade record still wins. * samples/tasks/database: write an rdb count over 127 as a uint A record count from 128 up is written as a msgpack uint32. The read-ahead lanes size their sets from the reader window, 64 files per reader, so they write 131 to 259 records; a fixint byte past 127 decodes as a map or a bool and the database is rejected on two- and three-core hosts. * scan: keep a refused crc index build refused A database whose crc index build is refused is flagged, and neither the size probe nor the CRC lookup starts another build for it. The index budget only shrinks, so a retry could only walk the database again to the same refusal, once per content file. The database scan test gains a cap on index builds and a lane that scans plain files with every build refused: one query walk each. * scan: look archives of several members up by either CRC An archive whose header lists more than one entry, an arcade set as a rule, is read whole first, and each database takes its own CRC or its first member's. A set whose first member is a cartridge ROM is written for its arcade record rather than expanded into the cartridge playlist, and an arcade folder walks no database claimed only for a member's extension. Readers read such an archive whole without a grant. The member pass stays for one-member archives, where a cartridge zip needs no whole read. file_archive_get_file_crc32_size_and_ext() reports the entry count the backends already take from the archive's header. A database claimed only for the member's extension joins the member pass only while it has or may get a crc index; unindexed, the lookup is a full walk the expansion repeats. A reader's member CRC survives a whole read that fails or is over the cutoff, so the scan reads only the archive itself. Lanes: an arcade set with a cartridge ROM first, an arcade folder beside a cartridge database, sets whose reader reads fail, and cartridge zips against an unindexed database. * archive: read a mapped zip's directory in place When the archive is mapped, zip_parse_file_init() finds the end of central directory record, reads the ZIP64 records and walks the central directory where they lie; only the context is allocated. Unmapped archives read them through the stream. The scan's member pass opens every zip for its directory, so this is its hot path. archive_zip64_test counts reads through the stream and checks that, mapped, a plain zip with a comment and a ZIP64 one give their first member's CRC without any. --------- Co-authored-by: LibretroAdmin <[email protected]> |
||
|
|
cf60e94e40 |
scan: RAR archives and .bz2 files matched through their members
The scanner treats .rar as an archive, and .bz2 is a compressed file the way .zst is, so a .bz2 is opened even when no core lists it; ".7Z" is an archive as ".7z" is. database_scan_test scans a 7z, a RAR, a RAR 5 with BLAKE2, a .zst, a .bz2 and a zip with a Zstandard member, each matched through its member, on both queues. |
||
|
|
71ce6182c4 |
database_scan_test: the unclaimed 3DS check holds on a second run
The playlist it checks is not written is removed before that scan and after the block, so a root an earlier run left it in does not fail the check. make check runs the scan test twice in one root to keep it so, and gives the budget test its sanitizer allowance when SANITIZER is set, as CI does. |
||
|
|
ad2e9e05d8 |
scan: parallel readers, 3DS product codes, CRCs and index builds over steps (#19920)
* samples/database: include compat/strl.h in the scan test The test calls strlcpy(), which mingw-w64 does not declare, so it did not build for Windows. * PS1 scan: PSX.EXE means no serial only as the BOOT target A root directory can list a PSX.EXE ahead of the executable SYSTEM.CNF boots: Tomb Raider (USA) lists one before SLUS_001.52. Stopping at the first PSX.EXE in the probe window sent such discs to a whole-track CRC, eight seconds for a CHD. Look for the BOOT target first, matched without regard to case so cdrom:\psx.exe counts. A disc that boots PSX.EXE, or has no SYSTEM.CNF so the BIOS boots PSX.EXE, has no serial and still falls back to its CRC (#15241); any other disc is searched for its serial with PSX.EXE directory records ignored. * 3DS scan: identify .3ds, .cci and .cxi by the NCCH product code These images took the default whole-file CRC, 0.5-4 GB a game. The product code in the NCCH header (partition 0 of a cart image, or the start of a bare NCCH) is the serial the 3DS database is keyed on, and the header is plaintext in encrypted dumps too. A code held by one record matches it outright. Revisions and regions that share a code fall back to the file's CRC to choose, and to the first record when no CRC matches; with scan_serial_and_crc on every match is confirmed by CRC, as for PSP and Dreamcast, and a file none of whose records carry its CRC goes on to the plain CRC lookup with the CRC already computed. A code no record carries, or a header without valid magic such as a CIA, keeps the CRC path, in first-match mode too. Like the CRC lookup, the serial pass visits only databases an installed core claims the extension for, unless Scan Without Core Match is on. * scan: run ITERATE steps while the shared I/O window lasts A file takes about twenty ITERATE steps, and the handler ran one per call. On the regular task queue that is one step per frame: 1000 NES zips took 335 s of pacing, 400 arcade sets 1639 s. The ITERATE states now run in a loop under the same window the BEGIN states use, which times the steps rather than counting them and grants every call at least one. The scan test's unclaimed-database lane spends the window before each check, so that it still counts steps. * scan: hash file CRCs a quantum at a time across steps A step that needed a CRC computed all of it in one handler call: a whole CHD track with LZMA decode, or a multi-gigabyte 3DS image. On the regular queue that froze a frame, and on the threaded queue it held the worker for seconds. Each CRC site now opens its span and returns, and later steps hash 256 KiB quanta while the shared I/O window lasts, at least one per call. The lookup that wanted the CRC runs when it is in, at the same entry. The one-shot CRC helpers, which nothing else called, are gone. * scan: walk each database once for its crc and serial indexes The first file to reach the serial lookup built a crc index and then a serial index for every database, a full walk each: 47 MB of Mobile - J2ME twice in one handler call, the second for an index that came out empty. The crc walk now reads serials as well. It notes whether a database has any, so the serial lookup passes over one with none, and for the serial lookup it builds the serial index in the same pass. Index contents, matches and the split of the index budget are unchanged. * scan: let a database's indexes be built a run of records at a time A database's crc and serial indexes were built by one walk and a qsort in a single call: 50-70 ms for Mobile - J2ME. libretrodb_scan_begin(), _step() and _end() walk a run of records per call, and database_info_index_job_*() builds both indexes over as many calls as it takes, each walking a run of records or merging a run of entries in a resumable merge sort. libretrodb_scan_field2() and database_info_index_new() are built on them and answer as before. * scan: build each database's indexes over steps The first file to reach a database built its indexes in one handler call: 52-68 ms on the regular queue for Mobile - J2ME, 13-17 frames' worth of the 4 ms window. The build now runs over the steps that follow the lookup that began it, a run of records walked or entries merged at a time while the window lasts, and the lookup takes the indexes when they are done. A database counts as size-checked only then. Cancelling frees a build in flight. The one-shot builders, database_info_crc_index_new(), database_info_serial_index_new(), database_info_index_new() and libretrodb_scan_field() and _field2(), lose their last caller here and go; the tests build through the job and the stepped scan. * task_queue samples: build on macOS, run on GCD in a macOS job No sample ran the GCD runner and nothing in CI built HAVE_GCD. Apple's ld has no --wrap, so on Darwin the switch and init-failure tests redirect the wrapped calls from task_queue.c by macro instead, and libdispatch comes from libSystem there. The switch test gets a GCD=1 build, and a macOS job runs every task_queue sample plain, under ASan+UBSan and TSan, threaded and, where it has a GCD=1 build, on GCD. * task_queue: a switch waits out a wake from another thread task_queue_wake() is documented as safe from any thread, but a switch between the threaded and the unthreaded queue frees the threaded runner's lock and condition variable while a waker on another thread can still be inside it. Toggling Threaded Video makes that switch at the next frame. Two seq_cst counters now keep them apart without a lock: a switch that finds a waker inside is put off to the next task_queue_check(), and a waker that finds a switch under way leaves its task to it. A wake on the thread that drives the queue cannot meet a switch and skips the counters. A switch now ends every park, and the new runner takes wakes again before it runs any task, so a parked task loses nothing to a wake dropped during the switch. A wake dropped while a switch is put off and then taken back, or for a task whose park a switch keeps because it leaves a stuck handler behind, waits for that park's horizon. The switch test holds a waker inside the queue across a switch, wakes from four threads through 1000 switches, and holds the main thread where the new runner first runs a task while that task's first pass wakes it. GCD builds leave out the threaded runner's own code, which they never used and which warned there. The switch test also checks that its realloc() wrapper ran, since on macOS that wrap is a macro rather than a link option. * scan: a scan of one file only adds to its playlist A Content Location that is a file is scanned as one file, which the Scan button, --scan=FILE and iOS "open in" already rely on. Such a scan cleared the playlist when Overwrite was on, and recorded the file, and its core, as what the playlist refreshes with, so Refresh Playlist later rescanned that file alone. Overwrite is now ignored for a file, and the playlist's scan record and default core are left as they were. Validate Existing Entries is skipped too: a file scan's extensions can differ from its folder's, so validating with them could drop entries the folder scan added. A later folder scan or Refresh still prunes. With no database and an automatic target playlist, a file is filed under its folder's name, as a scan of that folder files it, rather than in a playlist named after the file. A Content Location that is missing, as on a drive that is offline, counts as a file, so Overwrite no longer empties its playlist while the drive is away. * menu: Content Location takes a file or a folder Content Scan's Content Location now opens one browser that lists folders and files in every scan method: OK on a file picks it, <Use This Directory> picks the folder. In Automatic it lists every file, as an Automatic scan reads every file; Custom keeps listing the scan's extensions. The Scan Single File toggle, which switched the browser to files and was shown only in Custom with Search Recursively off, goes with its setting and strings, and a scan of a file no longer turns Search Recursively off behind the user's back. Import Content drops Scan Directory and Scan File, as the Scan Directory list already had, leaving Content Scan as the one way in; Scan File no longer started a scan. On Apple, File > Open and the iOS document picker opened from Content Location set the location as OK on a file does. * task_queue: hold pushes from other threads for the main thread task_queue_push() from another thread could meet a switch between the threaded and the unthreaded queue, which frees the lock and condition variable the push takes. On the unthreaded queue, with no switch at all, it put the task on a list the main thread walks without a lock. Windows pushes from the video thread under threaded video, and HID builds from libusb's thread. Such a push now goes through the switch's gate: when the gate is shut, or the unthreaded queue is up, the task goes onto a lock-free list that the next gather pushes on the main thread, and the push returns true. A push is also held while earlier ones still wait, so a thread's pushes start in the order it made them. A BLOCKING task refused there is cancelled, and its callback still runs. The switch test pushes from four threads on the unthreaded queue and through 1000 switches, checks a held BLOCKING push, and holds the main thread inside the gather that reopens the queue to show that a thread's next push does not pass its held one. * task_queue: cancel by ident and find safely from other threads task_queue_cancel_task() and task_queue_find() from another thread met the same switch and the same unlocked lists as a push did. task_queue_cancel_ident() cancels by ident from any thread: a locked walk when the threaded queue is up with nothing held, otherwise an ident left for the next gather, which applies it after its pushes, to a held push as well. A held push cancelled so retires cancelled without running, and its callback runs. A find from another thread goes through the switch's gate and reports false when it cannot walk the lists. The queue's own workers and GCD threads skip the gate, and a find on the main thread also sees held pushes. Each worker keeps its thread id in a slot of its own and clears it before it reports that it left, so a thread that reuses a joined worker's id is not taken for one. The switch test cancels and finds from other threads on both queues and across a put-off switch, and holds the main thread in the gather to show that a thread's cancel of its own held push is not lost. Once extra workers start, finds from handlers on the one worker and on an extra still skip the gate, and a find with a joined extra worker's id from inside deinit is refused. * autoconfig: make connects reported on other threads on the main thread libusb's hotplug thread and the Wii's HID poll thread report pads from their own threads, where task_queue_find() can no longer answer exactly: at a switch, or on the unthreaded queue, it reports false. Off the main thread, input_autoconfigure_connect_ex() and input_autoconfigure_disconnect() now copy the request into a main-thread task and return true. Its callback makes the call on the main thread, in the order the requests were made, so the duplicate check, the port's sequence number and the settings it reads are the main thread's. A new sample drives task_autodetect.c on the task queue with the rest stubbed, reports pads from another thread, and checks that every find runs on the main thread, that a pad reported twice queues one connect, that a disconnect handed off is made and that a cancelled request is not. * task_queue: wait, reset and deinit see pushes held for the main thread On the unthreaded queue every push from another thread is held for the next gather. A wait with nothing running returned without running it, and a reset, the exit drain's included, left it to run normally afterwards. Cancels held for the gather were never freed at deinit. The unthreaded wait now drains held pushes first, and a reset drains them into the runner before it cancels, so a held task meets a queued one's fate. Deinit applies and frees held cancels; held pushes stay held for the next runner's first gather, so no callback runs inside deinit. * task_queue: make the Threaded Tasks flag atomic Task handlers on the worker read it through task_queue_is_threaded(), and the main thread writes it when the setting changes, so changing the setting while a task ran was a data race. ThreadSanitizer shows it on a database scan whose queue is switched under it. * task_queue: a parallel task names the extra workers it needs retro_task_t gains parallel_workers, which task_init() clears. A parallel push starts the extra workers it finds missing, up to the larger of task_queue_set_parallel_workers() and the task's number, at most 8. They serve every parallel task and stay until deinit, as before, so the pool only grows; 0 keeps the frontend's number. The started count is atomic, so a push that finds enough takes no lock, and one that needs more claims the next entries under running_lock. The parallel test has a task asking for three, a later one asking for fewer, one asking for more than eight, a plain task whose number is ignored, the frontend's number holding for a task asking for fewer, and a task that leaves the number alone. * task_queue: let deinit leave extra workers behind in detachable handlers A parallel task may now also be detachable, and then runs on the extra workers like any other parallel task. Deinit gives every worker the one bound it gave the one worker, the extra workers first. One still inside a detachable handler past it is left behind to finish alone, as the one worker was, and one inside any other handler is still waited for. The primitives of an init are held by deinit and by each worker it leaves behind, and the last of them to let go frees them, so the one worker and several extras can be left behind together. A worker left behind, the one or an extra, now runs the task's cleanup once the handler returns, then frees the task, so a detachable task releases what it holds however it ends. Its callback still never runs; its cleanup, like its handler, may touch only what the task owns. The parallel test runs a detachable parallel task on an extra worker, leaves one stuck past the bound, waits for a slow one that is not detachable, and leaves the one worker and two extras behind together with a new queue running beside them. Each task left behind is cleaned up once, by its own worker, after its handler returns, and one not left behind at its retirement as before. The switch test switches to the unthreaded queue and back with extra workers live. * task_queue: on Emscripten, sleep after a pass on the one worker only On Emscripten every worker sleeps 1 ms after each handler call, a pthreads workaround from when the one worker ran every task. The extra workers run parallel tasks, which work in many short passes, and the sleep cost each of those passes 1 ms, more than the pass itself. The extra workers no longer sleep; the one worker still does. * emscripten: ask for at most 4 extra workers, and start 5 threads In the browser a pthread the pool has not started is made on demand by the main thread, and with the JS file system, where every thread's file calls go through the main thread, 8 extra workers made each of those calls about 40% dearer than 4 did. The frontend asked for cores - 3 extra workers, up to 8; on Emscripten it now asks for at most 4, and the build starts 5 pthreads up front, enough for the one worker and those 4. * scan: read small plain files on parallel reader tasks, in list order A database scan on the threaded queue pushes min(4, cores) reader tasks, none below 2, as parallel tasks that ask for that many extra workers, in HAVE_THREADS builds with lock-free atomics, except on Wii U, whose C library and FAT layer take no locks, and on Vita, where Vita3K's sceIo tables take none. With Threaded Tasks off none starts and the scan reads every file itself, stepped as before. The scan hands the plain files and archives it would CRC whole to the readers, up to 64 per reader ahead of it, each with its own copy of the path. A reader claims them in list order, opens and sizes each, leaves one over 128 MiB to the scan unread and CRCs the rest a quantum per call. The scan takes each result at its own place in the content list, so the databases see files in the same order as before, parks while the next one is still being read, and reads itself whatever a reader could not. The scan never waits for its readers. At its end, on cancel and once the queue is unthreaded, each reader leaves at its next call and hands back the file in hand. Each reader drops its reference to what they share in its cleanup, and the last reference frees it. A queue deinit leaves a reader stuck in a read behind after its 1 s bound and never calls it again; the worker left with it runs its cleanup once the read returns, which hands back the file in hand and drops the reference. The scan test covers list order, files over the cutoff, failed pushes, cancels and quits with a reader stuck in a read, and queue switches under a scan; CI runs it under TSan, without threads and with no readers. * scan: run the command-line scan with no menu on the threaded queue A command-line scan with no menu waits for the task queue to run dry, and only a scan on the threaded queue gets readers. In threaded builds that run now uses the threaded queue whatever Threaded Tasks says; the setting is not changed. * menu: Import Content offers Scan Directory and Scan File Both entries sit beside Content Scan when the database is built in. OK on a file in Scan File's browser scans that file, as the Scan action does. The load_content_filter harness checks that the entries are listed and that OK on a file starts its scan. * manual scan: Content Location holds a full file path The location can now be a file, so it is kept in a PATH_MAX_LENGTH buffer, as is the scan task's copy. A file whose path does not fit is refused in the browser instead of being joined short. The load_content_filter harness sets a location deeper than a folder buffer and checks that it is kept whole. --------- Co-authored-by: LibretroAdmin <[email protected]> |
||
|
|
bd35ea5496 |
task_database: task_push_dbscan takes the path and the callback only
The scan reads its playlist and database directories and the hidden-files setting from the settings, and treats the path the same whether it names a directory or a file, so task_push_dbscan() takes only the path and the callback. companion_core_request_scan() takes only the core and the path, and companion_core_pref_show_hidden_files() is gone with its last callers. |
||
|
|
902c7f9a57 |
task_database: pass over every refused database in one scanner step
The core-claim gate now advances past every database it refuses in a single step, so a file costs a handler call per database it can match plus a fixed few, rather than one per database in the directory. On the regular task queue the handler runs once per check, which is once a frame. database_scan_test scans four unmatched files over one claimed and 48 unclaimed databases on the regular queue and bounds the checks the scan takes by the file count. |
||
|
|
8acbe4ab8c |
core_info: resolve database claims once per scan
Which cores claim a database does not depend on the file being scanned, so the scanner now asks core info once per database when it sizes its per-database state: core_info_database_claim() returns the merged extensions of the claiming cores and whether any of them matches archive members. The per-file test is a single extension lookup in that list, with no core info lock taken, and the claims move with their database when a match promotes it to the front. database_scan_test gains a second core claiming its own database with its own extension, so claims differ per database: a claim left behind by the promotion, or a claim that ignores the database, fails it. |
||
|
|
5e4b8889af |
task_database: fix memory errors in database scans (#19544)
* task_database: fix memory errors in database scans
DATABASE_SCAN_ITERATE_NEXT handed an exhausted index to
MANUAL_SCAN_ITERATE_CONTENT, which read one entry past the end of the
content list. Since
|
||
|
|
93ccb92418 |
Audit and harden the content scanner database stack (#19279)
Audit and harden the content scanner database stack An audit of the content scanner and everything it calls - tasks/task_database.c, tasks/task_database_cue.c, database_info.c, manual_content_scan.c and the six sources under libretro-db - with fixes for what it turned up and tests that demonstrate them. .rdb files are downloaded from the buildbot, so the reader has to survive whatever is in one, and most of the parser findings are of that shape: end-of-file taken for a fabricated record and looped on forever, an output value freed before it was ever initialised, container nesting with no depth cap, a binary search that read before its own count test and recursed without shrinking, identifier slices handed to strlcpy which strlen()s its source, and an integer accumulator with nothing bounding it. Two file-scope statics in the query compiler were shared across concurrent compiles. In the scanner: a stack-buffer-overflow write building the serial query, a walk one element past the end of the info list, a 256-database ceiling that wrote past the per-database arrays, strlcpy's return value used as a length against a destination half the size of its source, an over-long content directory accepted truncated and so pointed at a different directory, a completion callback dropped entirely in builds without menu support, and an uninitialised flag written into the playlist and read back on the next scan to decide whether to overwrite it. Two archive fixes came out of testing against a real library and are included here: an LZMA property limit that rejected the lc=4 streams 7-Zip routinely writes - and since 7z holds its own header as an LZMA stream, such an archive could not be opened at all - and a lookup for an absent archive member that spun at full CPU instead of returning. The scanner asked each database the same question once per content file, and each was a full cursor walk. A crc index built in one pass answers those in under a microsecond against 10.59 ms before. Serial lookups got the same treatment and the per-database size range now comes out of the same walk rather than two further queries. Indexes cost 8 bytes per record, are capped at a share of free memory, and anything the index cannot serve falls back to the query path. Equivalence was checked rather than assumed, because the scanner takes the first match and a sixth to a quarter of the crcs shipped are duplicates: 1,225 lookups and 126 duplicate groups return the same records in the same order through both paths. The four sample directories now carry 64 checks between them, every case verified to fail without its fix, and sweep.sh runs the lot under ASan, UBSan, LeakSanitizer and TSan. Three of the defects fixed here were introduced by this work and found afterwards, all of them wrong answers with no error reported: index caches keyed by a database's position but not moved when a match promoted it, a teardown reading a list's size after freeing it, and a type check that excluded the binary encoding every shipped database uses for its serial field, which stopped disc-based systems matching entirely. Each has a regression test that fails without its fix. Not covered: the index memory share is a judgement rather than a measurement against a constrained working set. |