Periodic filesystem consistency checks are probably a good idea. Do current Android devices ever do them?


Question

Let me start out by giving you some general background information. My actual question is at the very bottom of this post.




Background, part 1: Journal replays vs. consistency checks.


Please assume that your Android device uses the ext4 filesystem for its internal storage, and the FAT32 filesystem for its removable MicroSD storage (if present).


On ext4, a "journal replay" is a partial filesystem check-and-repair operation which normally takes no more than few seconds. (Source.) The Android kernel does a journal replay whenever necessary. (Based on this source and this source.)


On ext4, a full filesystem consistency check takes longer. For an average Android device, it takes 12 seconds or so. (Based on this source.)


FAT32 is a non-journaling filesystem. So there are no journal replays. There are only consistency checks.




Background, part 2: It's probably a good idea for your OS to do periodic consistency checks. Here's why.


Microsoft program manager Kiran Bangalore writes that there are certain cases in which a filesystem can become corrupted. On a journaling filesystem such as ext4, such cases are exceedingly rare. On removable MicroSD cards, I suspect that such cases are not so rare.


The usual way to check for such corruption is to configure your OS to run a consistency-check tool every so often. Such tools include chkdsk, ScanDisk, Apple Disk Utility, fsck, and others.


Even on ext4 storage built into an Android device, periodic consistency checks are probably a good idea. The tune2fs manual page explains why:



Bad disk drives, cables, memory, and kernel bugs could all corrupt a filesystem without marking the filesystem dirty or in error. If you are using journaling on your filesystem, your filesystem will never be marked dirty, so it will not normally be checked. A filesystem error detected by the kernel [may] still force a [consistency check] on the next reboot, but it may already be too late to prevent data loss at that point.



(Note that, on Android, I think a filesystem error detected by the kernel will not lead to a consistency check on the next reboot. Android is strange that way.)




Background, part 3: Here's what other OSes do.


Windows


Windows Vista, and all later versions of Windows, include an NTFS self-healing feature. Kiran Bangalore therefore writes that, nowadays, Windows users no longer need to run periodic consistency checks anymore. He explains that the OS "will inform you when ... corruption is found".


Windows 10 Mobile


Windows 10 Mobile is probably the third-most-popular smartphone OS. I think it uses NTFS. So perhaps it also can do NTFS self-healing.


OS X


Mac OS X runs fsck_hfs -p during every boot. I don't know what this does. See the manual page.


Linux


It's true that some ext4 developers say that periodic ext4 consistency checks aren't particularly useful. But other ext4 developers say that these checks improve safety and reliability.


In practice, when a filesystem is marked in error, Linux runs a consistency check at the next reboot. At other times, modern Linux distributions don't do automatic periodic consistency checks, ever. Those who want them must schedule these checks themselves.


Android


Stock Android includes an ext4 consistency-check tool. As well, it includes a consistency-check tool which works on removable MicroSD cards of 32 GB or less (but may corrupt larger cards). Finally, your device may or may not also include fsck.exfat or exfatfsck, for running consistency checks on removable MicroSD cards of 64 GB or more.


But does the OS ever run any of these tools automatically?


iOS


The iOS filesystem is normally either HFSX or APFS, and fsck is included with the OS. I don't know whether or not iOS ever runs automatic consistency checks.




Here's my question.


Please consider the stock ROMs shipped with current Android devices.


Do such stock ROMs ever periodically run consistency checks, either on the internal storage device or (if applicable) on the removable MicroSD card?


(P.S. In cases where a device shuts down gracefully and has enough battery charge left, it's possible to run a consistency check at shutdown instead of at startup. But it takes some engineering effort to implement such functionality, and so operating system developers normally don't bother. I wonder what Android does.)


(P.P.S. I also wonder whether or not there exist any smartphones, running any OS, which do any routine periodic consistency checking. Again, please post comments below.)


Answer

Not-yet-released Android versions



There have been some recent improvements made to the Android source code.



The next maintenance release of stock Android will be either 7.2 or 8.0. In some future version of stock Android — either that maintenance release or a later release — Android will run the fsck -f -y command during every normal shutdown. This command forces a consistency check on the internal storage, no matter what. (Based on this source and this source.)



Hurrah! Considering that so few Android users ever do complete backups (e.g. Nandroid backups), I think that this may be a useful enhancement.



Unfortunately, I still don't know of any evidence that Android ever checks any removable MicroSD card.



The above answer is about stock Android. Still, I thank the CyanogenMod team and the LineageOS team for indirectly helping me to discover the above information.



Running checks yourself



The above paragraphs refer to versions of Android which haven't been released yet.



If you're running an earlier version of Android, you can run an internal-filesystem consistency check manually yourself if you so desire. You must unmount the filesystem first, so you must be in recovery mode. See here.



Checking your MicroSD card



If you have a removable MicroSD card, you should definitely check it on certain occasions, and also periodically. If you'd like more information, please see:




Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes