Files
philips-tv-speicher-voll/patches/usb-freesize/PATCH.diff

39 lines
1.5 KiB
Diff

--- a/src/org/droidtv/tv/os/storage/UsbVolumeListerImpl.java
+++ b/src/org/droidtv/tv/os/storage/UsbVolumeListerImpl.java
@@
- if ("1".equals(SystemProperties.get("sys.mtk.dmremoteservice.ready"))) {
- MountPoint mp = DeviceManager.getInstance().getMountPoint(path);
- if (mp != null) {
- volume.mRawDiskSize = mp.mTotalSize / 1024;
- volume.mFreeDiskSize = mp.mFreeSize / 1024;
- }
- }
+ boolean known = false;
+ if ("1".equals(SystemProperties.get("sys.mtk.dmremoteservice.ready"))) {
+ MountPoint mp = DeviceManager.getInstance().getMountPoint(path);
+ if (mp != null) {
+ long totalMiB = mp.mTotalSize / 1024L;
+ long freeMiB = mp.mFreeSize / 1024L;
+ if (totalMiB > 0 && freeMiB >= 0 && freeMiB <= totalMiB) {
+ volume.mRawDiskSize = totalMiB;
+ volume.mFreeDiskSize = freeMiB;
+ known = true;
+ }
+ }
+ }
+ if (!known) {
+ try {
+ StatFs fs = new StatFs(path);
+ long totalMiB = fs.getTotalBytes() / 1_048_576L;
+ long freeMiB = fs.getAvailableBytes() / 1_048_576L;
+ if (totalMiB <= 0 || freeMiB < 0 || freeMiB > totalMiB)
+ throw new IllegalStateException("invalid StatFs size");
+ volume.mRawDiskSize = totalMiB;
+ volume.mFreeDiskSize = freeMiB;
+ known = true;
+ } catch (RuntimeException e) {
+ Log.w(TAG, "volume size unknown: " + volume.mUUID, e);
+ }
+ }
+ if (!known) continue;