Why does the use of symlinks in /system gradually erode available space?
I am working on a routine for swapping dictionaries on an e-reader (Nook Simple Touch--Android 2.1). I've got the shell commands nailed down and have constructed an app using Tasker. It all works great except that after a few dictionary changes the amount of available space in /system (where the dictionary databases are) decreases to the point that the stock dictionaries cannot be restored to their original place.
I start by moving the stock databases from their default location to a directory where all the dictionaries will be stored. One option is in /data/media and the other on the sdcard. Both appear to work fine. Once those are out of the way, symlinks are created to replace them, referring to databases in the dictionary storage directories. This is the general sequence in terms of shell commands:
adb shell ln -s "'/data/media/B&N Downloads/Dictionary/en-de.db'" /system/media/reference/basewords.db adb shell ln -s "'/data/media/B&N Downloads/Dictionary/inflect-de.db'" /system/media/reference/inflectedwords.db
or, for the /sdcard storage option:
adb shell ln -s "/sdcard/Dictionary/en-de.db" /system/media/reference/basewords.db adb shell ln -s "/sdcard/Dictionary/inflect-de.db" /system/media/reference/inflectedwords.db
These changes require a reboot to take effect.
To remove the symlinks in preparation for a different dictionary or before restoring the stock dictionary to its proper place:
adb shell rm /system/media/reference/basewords.db adb shell rm /system/media/reference/inflectedwords.db
As I say, it all works fine except for the disappearance of available space in /system to the eventual point that you cannot restore the original dictionary.
Before doing any of this stuff I typically have about 80% of /system used. There should be about 55 mb still available (that's with the stock dictionaries in place). But after several dictionary swaps I show about 89% full and down to around 30 mb available. Restoration of the stock dictionaries requires about 57 mb available space.
I've looked through /system trying to find something "new" that is taking up space but have not been able to find anything.
I've never seen this issue addressed anywhere. I'd be grateful for some input.
Thanks to the comment from alecxs and additional research in that vein, I have arrived at a solution for at least my instance.
It is stated elsewhere that removing files which are being used by running processes will cause a loss of available inodes. Although I can't claim to understand all the inode nuances, this made me look at the background processes on the e-reader. One, com.bn.nook.reader.activites, has its tendrils in the dictionary. I therefore tried:
adb shell pidof com.bn.nook.reader.activities
This returns a four-digit number which I use as:
adb shell kill [pid]
Then I proceed to do my operations with the database files, including moving, deleting, creating symlinks, deleting symlinks, restoring the original files, etc.
It all works with only the expected changes in /system available space at each juncture. No data appears to be lost by killing the background process and the reader function starts up right away when a book is accessed with the new dictionary immediately accessible, no reboot required (a bonus).
So before every change from the Dictionary Management app I just get the pid and kill the background process. Works like a charm!
Thanks again, alecxs!