summaryrefslogtreecommitdiff
path: root/firmware/common/dircache.c
AgeCommit message (Collapse)Author
2021-07-03fat: move fattime_mktime to timefuncsJames Buren
This moves the time conversion function to timefuncs since it has uses on ports that don't use the FAT driver. This function has no dependency on the FAT driver as it is so this should not cause any issues. To reflect this separation the function was renamed to dostime_mktime since it is really for DOS timestamps. The places where it was used have also been updated. Change-Id: Id98b1448d5c6fcda286846e1d2c736db682bfb52
2020-10-27dircache: Fix a NULL pointer dereferenceSolomon Peachy
if idx == 0, get_idx_dcvolp() will return NULL. Change-Id: I4eafa71bb1f77ef8c865570bf8f124cdd9326d3e
2020-08-20Revert root_redirect :(William Wilgus
This reverts commit 31fc46ded69be7438cca2ba2c2b93c1f200165a6. Change-Id: Ia78618c0e8b25ca65f7c8ae0db1cb9c9b321bad9
2020-08-20Allow mounting of any directory as the root directory.William Wilgus
Provide definitions for the macros: * RB_ROOT_VOL_HIDDEN(v) to exclude certain items from the root. * RB_ROOT_CONTENTS to return a string with the name of the directory to mount in the root. Defaults are in export/rbpaths.h It's a bit much for those that don't need the full functionality. Some conditional define can cut it back a lot to cut out things only needed if alternate root mounts are required. I'm just not bothering yet. The basic concept would be applied to all targets to keep file code from forking too much. Change-Id: I90b5c0a1c949283d3102c16734b0b6ac73901a30
2017-03-21Dircache: Improve freed name memory recallocationMichael Sevakis
There's only a need to check every MAX_TINYNAME+1 bytes and that the last character of the needed size 0xff in order to verify the size of the block since the minimum indirectly-stored string is MAX_TINYNAME+1. Change-Id: Ic789376b8575bab9266fcd54c610db0961de5d7f
2017-03-21Avoid having to wait for dircache builds if shut down too soonBoris Gjenero
When dircache scanning is happening in the background, the user can shut down the device before it is complete. Then, reset_cache() sets size to 0 before it is copied to last_size at the end of build_volumes(). When saved last_size is zero, scanning happens in the foreground during next startup. Avoid shrinking the size if the build is suspended. Change-Id: Ife133e0be0dc0dfd53a4de119f70dba014c7ee68
2017-03-12Dircache: Refine name allocation and error handling.Michael Sevakis
* 8 bits is enough to allow 260 character base names when five bytes is the minimum indirect storage size (0..255->5..260). * Don't truncate anything that's too long as that can lead to bad behavior, simply don't include the offending entry in the parent. * Set the .tinyname flag to 1 by default to indicate that the entry's name doesn't need freeing. Clear it only when allocating indirect storage. * Rename some things to help catch all instances Change-Id: Iff747b624acbb8e03ed26c24afdf0fc715fd9d99
2017-03-08Fix a couple dircache oopsies.Michael Sevakis
Moving binding from queued to resolved was messed up if it was the first queued one and there were other resolved files open at the time of resolving it. Dircache info for a directory about to be recursively scanned should be filled before opening it. Would only affect a directory if it happened to be opening while it was being initialized. Change-Id: I26ccf219c382d7caf1424b5ddddc4793e74cb390
2017-02-10Restore dircache hookup in the database ramcache.Michael Sevakis
Do a few other changes to dircache and file code flags to accomodate its demands. Change-Id: I4742a54e8cfbe4d8b9cffb75faaf920dd907cf8a
2017-02-06Make sure dircache resolves outstanding references on volume root.Michael Sevakis
If a volume root was open at the beginning of a build, its dircache reference wouldn't be resolved on an already open volume root directory because the call to do it was simply omitted. Nothing horribly bad unless a root were opened at mount time and kept open long term. Change-Id: I09de30ff8174ad1d14eeeb9539bd23fb51b9e31a
2017-01-17Do some debug and preparatory work for ramcache and playlistMichael Sevakis
The file system rework introduced incompatibility between dircache and the tagcache ramcache and playlist dircache path caching. This update makes changes to filesystem code to reintegrate all that. It also fixes a couple bugs that were found when vetting all the code. The filestream cache was being reset without regard to the stream even if it was shared in write mode (made work of .playlist_control). Better handling of unmounting gives files a better go at force-closing them without risk to disk integrity. Did some miscellaneous pedantic changes. Improved efficiency of testing a file's existence (a little) since the path parser will be shared between file code and parsing for the sake of finding dircache references, not duplicated as before. This commit doesn't reenable said items just for the sake of keeping changes separate and related. Plan for the next is to enable dircache again for the playlists (easy peasy) and reenable tagcache ramcache but *without* the dircache path caching because it's rather substantial to change in itself. The ramcache will still function without dircache. Change-Id: I7e2a9910b866251fa8333e1275f72fcfc8425d2d
2017-01-14Dircache: Fix a tiny-block reclaim bugMichael Sevakis
Logic left over from before switching from NULL-terminated to counted strings would prevent a single-byte tiny free block gap from being properly reclaimed into free string bytes. Due to rarity, not as disasterous to functionality so much as wrong. Change-Id: I68e0875b04bb0ab6cdead0fdf535144b9c1bc13e
2015-01-01Limit "struct dircache_runinfo" to file scopeThomas Jarosch
Change-Id: Ib3edef9a4568605a36bdacde174dfa6bca2d26fa
2014-08-30Rewrite filesystem code (WIP)Michael Sevakis
This patch redoes the filesystem code from the FAT driver up to the clipboard code in onplay.c. Not every aspect of this is finished therefore it is still "WIP". I don't wish to do too much at once (haha!). What is left to do is get dircache back in the sim and find an implementation for the dircache indicies in the tagcache and playlist code or do something else that has the same benefit. Leaving these out for now does not make anything unusable. All the basics are done. Phone app code should probably get vetted (and app path handling just plain rewritten as environment expansions); the SDL app and Android run well. Main things addressed: 1) Thread safety: There is none right now in the trunk code. Most of what currently works is luck when multiple threads are involved or multiple descriptors to the same file are open. 2) POSIX compliance: Many of the functions behave nothing like their counterparts on a host system. This leads to inconsistent code or very different behavior from native to hosted. One huge offender was rename(). Going point by point would fill a book. 3) Actual running RAM usage: Many targets will use less RAM and less stack space (some more RAM because I upped the number of cache buffers for large memory). There's very little memory lying fallow in rarely-used areas (see 'Key core changes' below). Also, all targets may open the same number of directory streams whereas before those with less than 8MB RAM were limited to 8, not 12 implying those targets will save slightly less. 4) Performance: The test_disk plugin shows markedly improved performance, particularly in the area of (uncached) directory scanning, due partly to more optimal directory reading and to a better sector cache algorithm. Uncached times tend to be better while there is a bit of a slowdown in dircache due to it being a bit heavier of an implementation. It's not noticeable by a human as far as I can say. Key core changes: 1) Files and directories share core code and data structures. 2) The filesystem code knows which descriptors refer to same file. This ensures that changes from one stream are appropriately reflected in every open descriptor for that file (fileobj_mgr.c). 3) File and directory cache buffers are borrowed from the main sector cache. This means that when they are not in use by a file, they are not wasted, but used for the cache. Most of the time, only a few of them are needed. It also means that adding more file and directory handles is less expensive. All one must do in ensure a large enough cache to borrow from. 4) Relative path components are supported and the namespace is unified. It does not support full relative paths to an implied current directory; what is does support is use of "." and "..". Adding the former would not be very difficult. The namespace is unified in the sense that volumes may be specified several times along with relative parts, e.g.: "/<0>/foo/../../<1>/bar" :<=> "/<1>/bar". 5) Stack usage is down due to sharing of data, static allocation and less duplication of strings on the stack. This requires more serialization than I would like but since the number of threads is limited to a low number, the tradoff in favor of the stack seems reasonable. 6) Separates and heirarchicalizes (sic) the SIM and APP filesystem code. SIM path and volume handling is just like the target. Some aspects of the APP file code get more straightforward (e.g. no path hashing is needed). Dircache: Deserves its own section. Dircache is new but pays homage to the old. The old one was not compatible and so it, since it got redone, does all the stuff it always should have done such as: 1) It may be update and used at any time during the build process. No longer has one to wait for it to finish building to do basic file management (create, remove, rename, etc.). 2) It does not need to be either fully scanned or completely disabled; it can be incomplete (i.e. overfilled, missing paths), still be of benefit and be correct. 3) Handles mounting and dismounting of individual volumes which means a full rebuild is not needed just because you pop a new SD card in the slot. Now, because it reuses its freed entry data, may rebuild only that volume. 4) Much more fundamental to the file code. When it is built, it is the keeper of the master file list whether enabled or not ("disabled" is just a state of the cache). Its must always to ready to be started and bind all streams opened prior to being enabled. 5) Maintains any short filenames in OEM format which means that it does not need to be rebuilt when changing the default codepage. Miscellaneous Compatibility: 1) Update any other code that would otherwise not work such as the hotswap mounting code in various card drivers. 2) File management: Clipboard needed updating because of the behavioral changes. Still needs a little more work on some finer points. 3) Remove now-obsolete functionality such as the mutex's "no preempt" flag (which was only for the prior FAT driver). 4) struct dirinfo uses time_t rather than raw FAT directory entry time fields. I plan to follow up on genericizing everything there (i.e. no FAT attributes). 5) unicode.c needed some redoing so that the file code does not try try to load codepages during a scan, which is actually a problem with the current code. The default codepage, if any is required, is now kept in RAM separarately (bufalloced) from codepages specified to iso_decode() (which must not be bufalloced because the conversion may be done by playback threads). Brings with it some additional reusable core code: 1) Revised file functions: Reusable code that does things such as safe path concatenation and parsing without buffer limitations or data duplication. Variants that copy or alter the input path may be based off these. To do: 1) Put dircache functionality back in the sim. Treating it internally as a different kind of file system seems the best approach at this time. 2) Restore use of dircache indexes in the playlist and database or something effectively the same. Since the cache doesn't have to be complete in order to be used, not getting a hit on the cache doesn't unambiguously say if the path exists or not. Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8 Reviewed-on: http://gerrit.rockbox.org/566 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-17Cleanup MV/MD macros a little.Michael Sevakis
When using variadic macros there's no need for IF_MD2/IF_MV2 to deal with function parameters. IF_MD/IF_MV are enough. Throw in IF_MD_DRV/ID_MV_VOL that return the parameter if MD/MV, or 0 if not. Change-Id: I7605e6039f3be19cb47110c84dcb3c5516f2c3eb
2011-11-19Update some missed pointers when moving the dircache allocationFred Bauer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31028 a1c6a512-1295-4272-9138-f99709370657
2011-11-17Simulate usb plugging on the sim better using sim_tasks.Thomas Martitz
Now all threads need to ack the connection like on real target, dircache is unloaded and playback stops accordingly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31009 a1c6a512-1295-4272-9138-f99709370657
2011-10-28Fix FS#12325 - screen corruption on early usb.Thomas Martitz
When booting with USB inserted, the dircache build can get interrupted by the usb connection, in which case the dircache buffer is freed. Due to a bug the re-creation of dircache used the old freed buffer and overwrite new allocs (causing screen corruption). Set allocated_size to 0 to make it not take the code path that assumes an existing buffer, and bring that and freeing together in the code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30845 a1c6a512-1295-4272-9138-f99709370657
2011-10-21fix sign errorFred Bauer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30812 a1c6a512-1295-4272-9138-f99709370657
2011-08-30Dircache: Allow dircache to be enabled without reboot.Thomas Martitz
Also add two dircache function, one of which does what dircache_disable() did previously as this now also frees the dircache buffer. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30393 a1c6a512-1295-4272-9138-f99709370657
2011-08-30GSoC/Buflib: Enable compaction in buflib.Thomas Martitz
This enables the ability to allocate (and free) memory dynamically without fragmentation, through compaction. This means allocations can move and fragmentation be reduced. Most changes are preparing Rockbox for this, which many times means adding a move callback which can temporarily disable movement when the corresponding code is in a critical section. For now, the audio buffer allocation has a central role, because it's the one having allocated most. This buffer is able to shrink itself, for which it needs to stop playback for a very short moment. For this, audio_buffer_available() returns the size of the audio buffer which can possibly be used by other allocations because the audio buffer can shrink. lastfm scrobbling and timestretch can now be toggled at runtime without requiring a reboot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30381 a1c6a512-1295-4272-9138-f99709370657
2011-08-30GSoC/Buflib: Add buflib memory alocator to the core.Thomas Martitz
The buflib memory allocator is handle based and can free and compact, move or resize memory on demand. This allows to effeciently allocate memory dynamically without an MMU, by avoiding fragmentation through memory compaction. This patch adds the buflib library to the core, along with convinience wrappers to omit the context parameter. Compaction is not yet enabled, but will be in a later patch. Therefore, this acts as a replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug menu. See buflib.h for some API documentation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657
2011-08-16Dircache: Fix memory leak (and recently panic).Thomas Martitz
If the dircache was interrupted during generation (e.g. through USB insertion), then the allocated buffer was leaked and a new one was allocated for the second cache generation. This causes a panic since r30308 since playback holds the control over the audiobuffer at that time. The fix is to simply check allocated_size instead of dircache_size which is reset to 0 upon cancellation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30321 a1c6a512-1295-4272-9138-f99709370657
2011-08-15Dircache: Fix bug introduced in r30308.Thomas Martitz
dircache_root wasn't initialized at all and the giving allocated_size passed to buffer_release_buffer() didn't account for alignment padding. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30318 a1c6a512-1295-4272-9138-f99709370657
2011-08-14GSoC/Buflib: Replace all direct accesses to audiobuf with buffer API functions.Thomas Martitz
Namely, introduce buffer_get_buffer() and buffer_release_buffer(). buffer_get_buffer() aquires all available and grabs a lock, attempting to call buffer_alloc() or buffer_get_buffer() while this lock is locked will cause a panicf() (doesn't actually happen, but is for debugging purpose). buffer_release_buffer() unlocks that lock and can additionally increment the audiobuf buffer to make an allocation. Pass 0 to only unlock if buffer was used temporarily only. buffer_available() is a replacement function to query audiobuflen, i.e. what's left in the buffer. Buffer init is moved up in the init chain and handles ipodvideo64mb internally. Further changes happened to mp3data.c and talk.c as to not call the above API functions, but get the buffer from callers. The caller is the audio system which has the buffer lock while mp3data.c and talk mess with the buffer. mpeg.c now implements some buffer related functions of playback.h, especially audio_get_buffer(), allowing to reduce #ifdef hell a tiny bit. audiobuf and audiobufend are local to buffer.c now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30308 a1c6a512-1295-4272-9138-f99709370657
2011-07-30Dircache: Fix 2 nasty bugs introduced with the reworks starting with r30032.Thomas Martitz
The first is an off-by-one that leads to miscalculation of the dircache size. The format string size was used but dircache size was incremented by the snprintf() result which is smaller. The other forgot to update the location of the "." and ".." strings upon compaction, so that new folders got assigned orphaned pointers for those directory entires. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30224 a1c6a512-1295-4272-9138-f99709370657
2011-07-04Initialize the d_names_start pointer correctly in dircache. This shouldMiika Pekkarinen
prevent d_names data from being overwritten (likely causing garbage in file browser and other strange symptoms). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30122 a1c6a512-1295-4272-9138-f99709370657
2011-07-01Fixed incorrect dircache reallocation during tagcache commit.Miika Pekkarinen
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30108 a1c6a512-1295-4272-9138-f99709370657
2011-06-22Fix loading dircache stat on h100. Relocating the data was broken due to ↵Thomas Martitz
struct alignment problems. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30051 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Use ALIGN_UP() macro for alignment, in a more correct way also.Thomas Martitz
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30041 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: A bit of follow-up code cleanup suggested by Amaury Pouly.Thomas Martitz
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30040 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Optimize new dircache_copy_path so that the helper (strlcat) doesn't need to ↵Thomas Martitz
walk through the entire string repeatedly. Also fix a off-by-one. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30039 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: Don't expose struct dircache_entry and pointers into the cache, ↵Thomas Martitz
use IDs instead. Only integer IDs are exposed from dircache with this. This way the cache is isolated from other modules. This is needed for my buflib gsoc project. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30038 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: Move struct maindata declaration to dircache.c and actually check ↵Thomas Martitz
for DIRCACHE_MAGIC when loading from disk. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30037 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: Change internal cache layout.Thomas Martitz
The dircache_entry structs are now allocated subsequently from the front, allowing to treat them as an array. The d_names are allocated from the back (in reverse order, growing downwards). This allows the cache to be moved around (needed for my buflib gsoc project). It is utilized when loading the cache from disk (on the h100), now the pointer to the cache begin doesn't need to be the same across reboots anymore. This should save a bit memory usage, since there's no need for aligning padding bytes after d_names anymore. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30036 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Fix dircache_size calculation bug introcuced 3 revisions ago.Thomas Martitz
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30035 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: Return the size of the result string in dircache_copy_path() so ↵Thomas Martitz
that callers don't need to call strlen on it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30034 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: Rework and simplify dircache_copy_path().Thomas Martitz
Use a recursive helper function with strlcat to build up the path backwards. This way the tree doesn't need to be walked twice and no extraneous size calculation is needed. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30033 a1c6a512-1295-4272-9138-f99709370657
2011-06-20Dircache: Remove dircache_entry::name_len.Thomas Martitz
It's reduntant, and enlarges the dircache unnecessarily. Saves 4 byte per file in the whole filesystem. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30032 a1c6a512-1295-4272-9138-f99709370657
2011-05-08Fix a bunch of 'variable set but not used' warnings reported from GCC 4.6.0.Andree Buschmann
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29841 a1c6a512-1295-4272-9138-f99709370657
2011-02-14All kernel objects in code shared amongs targets (core, plugins, codecs) ↵Michael Sevakis
should be declared SHAREDBSS_ATTR as any core could potentially touch them even though they seem only to involve threads on one core. The exception is target code for particular CPUs where proper allocation is fixed. playlist.c was a little odd too-- use one mutex for the current playlist and a separate one for created playlists (still pondering the necessity of more than one). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29305 a1c6a512-1295-4272-9138-f99709370657
2011-02-02Clean up multiple definitions of RAM size. Remove -DMEM (make) and MEM ↵Andree Buschmann
(code), use the already defined MEMORYSIZE instead. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29189 a1c6a512-1295-4272-9138-f99709370657
2010-12-06Get rid of get_user_file_path and do the path handling in wrappers for ↵Thomas Martitz
open() and friends. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28752 a1c6a512-1295-4272-9138-f99709370657
2010-09-01Ged rid of uisimulator/common/io.c for android builds.Thomas Martitz
Use host's functions for file i/o directly (open(), close() ,etc.), not the sim_* variants. Some dir functions need to be wrapped still because we need to cache the parents dir's path (host's dirent doesn't let us know). For the same reason (incompatibility) with host's dirent) detach some members from Rockbox' dirent struct and put it into an extra one, the values can be retrieved via the new dir_get_info(). Get rid of the sim_ prefix for sleep as well and change the signature to unix sleep(). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27968 a1c6a512-1295-4272-9138-f99709370657
2010-08-01Fix reds.Thomas Martitz
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27657 a1c6a512-1295-4272-9138-f99709370657
2010-08-01Rockbox as an application: add get_user_file_path().Thomas Martitz
For RaaA it evaluates user paths at runtime. For everything but codecs/plugins it will give the path under $HOME/.config/rockbox.org if write access is needed or if the file/folder in question exists there (otherwise it gives /usr/local/share/rockbox). This allows for installing themes under $HOME as well as having config.cfg and other important files there while installing the application (and default themes) under /usr/local. On the DAPs it's a no-op, returing /.rockbox directly. Not converted to use get_user_file_path() are plugins themselves, because RaaA doesn't build plugins yet. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27656 a1c6a512-1295-4272-9138-f99709370657
2010-07-26Factor out opening and removing DIRCACHE_FILE into separate functions.Thomas Martitz
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27575 a1c6a512-1295-4272-9138-f99709370657
2010-06-21Rockbox as an application: Replace many occurences of #ifdef SIMULATOR with ↵Thomas Martitz
#if (CONFIG_PLATFORM & PLATFORM_HOSTED) (or equivalently). The simulator defines PLATFORM_HOSTED, as RaaA will do (RaaA will not define SIMULATOR). The new define is to (de-)select code to compile on hosted platforms generally. Should be no functional change to targets or the simulator. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27019 a1c6a512-1295-4272-9138-f99709370657
2010-05-21dircache:Amaury Pouly
- fix check_event_queue to use queue_peek and not mess message order - change check_dircache_state to a more modest check to avoid messing up dircache state git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26228 a1c6a512-1295-4272-9138-f99709370657
2010-05-21Fix typos in commentMichael Chicoine
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26224 a1c6a512-1295-4272-9138-f99709370657