如何计算可用的设备存储?

时间:2015-12-03 17:11:52

标签: android storage osmdroid

我正在使用 OSMDroid 并尝试计算设备上有多少空间用于离线磁贴存储。 该设备是三星SM-T530NU 。它显示以下信息:

Storage

Total space
Total device capacity
16.000GB

Owner
System memory
The minimum amount of storage space required to run the system.
4.05GB

Used space
The amount of storage space currently being used.
7.86GB

Cached data
0.93GB

Miscellaneous files
The amount of memory used to store miscellaneous files.
1.81GB

Other users
John Doe
121MB

Available space
The amount of storage space currently available
1.35GB

因此,如果我计算未使用的总金额:

16GB - (7.86GB + 0.93GB + 1.81GB + .121GB)= 16GB - 10.721 = 5.279GB

然而可用空间列为1.35GB。 其他3.929GB在哪里?

2 个答案:

答案 0 :(得分:1)

你可以尝试这段代码可以帮到你!!

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;
System.out.println("Megs :"+megAvailable);

答案 1 :(得分:1)

存储设备制造商使用十进制系统(基数为10)测量容量,因此1千兆字节(GB)的计算精确为1,000,000,000字节。

存储容量通过B(字节)的前缀来衡量,以表示特定的数量,即K(Kilobyte),M(兆字节),G(技嘉),T(太字节)等。由于所有计算机都基于在二进制系统中,这些前缀代表基数2的数量。每个级别的增量为2到10次幂或1,024。

公共前缀如下:

  • Kilobyte(KB)= 1,024 Bytes
  • MegaByte(MB)= 1,024 Kilobytes或1,048,576 Bytes
  • 技嘉(GB)= 1,024兆字节或1,073,741,824字节
  • 太字节(TB)= 1,024千兆字节或1,099,511,627,776字节

使用此十进制系统测量设备中的存储容量。 基于此,对于驱动器制造商声称的每千兆字节,他们过度报告磁盘空间量为73,741,824字节 或大约70.3 MB的磁盘空间。

因此,如果制造商宣传80 GB(800亿字节)的硬盘,实际磁盘空间大约为74.5 GB,比他们宣传的大约低7%。

Total space
Total device capacity
16.000GB -> 16,000,000,000/1024/1024 = approximately 15,259MB

Owner
System memory
The minimum amount of storage space required to run the system.
4.05GB -> 4,050,000,000/1024/1024 = approximately 3,862MB

Used space
The amount of storage space currently being used.
7.86GB -> 7,860,000,000/1024/1024 = approximately 7,496MB

Cached data
0.93GB -> 930,000,000/1024/1024 = approximately 887MB

Miscellaneous files
The amount of memory used to store miscellaneous files.
1.81GB -> 1,810,000,000/1024/1024 = approximately 1,726MB

Other users
John Doe
121MB -> 121,000,000/1024/1024 =  approximately 115,4MB

Available space
The amount of storage space currently available
1.35GB -> 1,350,000,000/1024/1024 =  approximately 1,287MB

因此,如果我计算未使用的总金额: 15,259MB - (3,862MB + 7,496MB + 887MB + 1,726MB + 115,4MB)=约1,173MB

现在剩下的值可能听起来不是很大,但仍然有一个近似误差。

我的建议是看一下分区

$ adb shell cat /proc/partitions
major minor  #blocks  name

 253        0     486272 zram0
 179        0   15388672 mmcblk0
 179        1      65536 mmcblk0p1
 179        2        512 mmcblk0p2
 179        3       1024 mmcblk0p3
 179        4        512 mmcblk0p4
 179        5       2048 mmcblk0p5
 179        6        512 mmcblk0p6
 179        7       1024 mmcblk0p7
 179        8        512 mmcblk0p8
 179        9       2048 mmcblk0p9
 179       10       4096 mmcblk0p10
 179       11       4096 mmcblk0p11
 179       12        512 mmcblk0p12
 179       13        512 mmcblk0p13
 179       14       4096 mmcblk0p14
 179       15        512 mmcblk0p15
 179       16        512 mmcblk0p16
 179       17        512 mmcblk0p17
 179       18        512 mmcblk0p18
 179       19        512 mmcblk0p19
 179       20        512 mmcblk0p20
 179       21       1024 mmcblk0p21
 179       22        512 mmcblk0p22
 179       23       6656 mmcblk0p23
 179       24       6144 mmcblk0p24
 179       25        512 mmcblk0p25
 179       26        512 mmcblk0p26
 179       27       1536 mmcblk0p27
 179       28       1536 mmcblk0p28
 179       29       6144 mmcblk0p29
 179       30       6144 mmcblk0p30
 179       31      10240 mmcblk0p31
 259        0       8192 mmcblk0p32
 259        1      24576 mmcblk0p33
 259        2      24576 mmcblk0p34
 259        3      16384 mmcblk0p35
 259        4      16384 mmcblk0p36
 259        5      16384 mmcblk0p37
 259        6      57344 mmcblk0p38
 259        7      32768 mmcblk0p39
 259        8    3801088 mmcblk0p40
 259        9     512000 mmcblk0p41
 259       10     921600 mmcblk0p42
 259       11    9814016 mmcblk0p43
 259       12       4079 mmcblk0p44
 179       32       4096 mmcblk0rpmb

eMMC( mmcblk0 )尺寸 15388672 (1K块)或约15028MB或14.67GB

$ adb shell "ls -la /dev/block/bootdevice/by-name/"
total 0
drwxr-xr-x 2 root root  920 2015-12-31 22:31 .
drwxr-xr-x 4 root root 1000 2015-12-31 22:31 ..
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 DDR -> /dev/block/mmcblk0p13
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 OP -> /dev/block/mmcblk0p42
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 aboot -> /dev/block/mmcblk0p5
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 abootbak -> /dev/block/mmcblk0p9
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 boot -> /dev/block/mmcblk0p35
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 cache -> /dev/block/mmcblk0p41
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 config -> /dev/block/mmcblk0p22
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 devinfo -> /dev/block/mmcblk0p21
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 drm -> /dev/block/mmcblk0p29
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 eksst -> /dev/block/mmcblk0p19
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 encrypt -> /dev/block/mmcblk0p18
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 factory -> /dev/block/mmcblk0p38
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 fota -> /dev/block/mmcblk0p24
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 fsc -> /dev/block/mmcblk0p15
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 fsg -> /dev/block/mmcblk0p14
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 grow -> /dev/block/mmcblk0p44
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 keystore -> /dev/block/mmcblk0p17
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 laf -> /dev/block/mmcblk0p33
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 lafbak -> /dev/block/mmcblk0p34
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 misc -> /dev/block/mmcblk0p31
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 modem -> /dev/block/mmcblk0p1
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 modemst1 -> /dev/block/mmcblk0p10
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 modemst2 -> /dev/block/mmcblk0p11
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 mpt -> /dev/block/mmcblk0p39
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 persist -> /dev/block/mmcblk0p32
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 raw_resources -> /dev/block/mmcblk0p27
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 raw_resourcesbak -> /dev/block/mmcblk0p28
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 rct -> /dev/block/mmcblk0p25
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 recovery -> /dev/block/mmcblk0p36
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 recoverybak -> /dev/block/mmcblk0p37
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 rpm -> /dev/block/mmcblk0p4
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 rpmbak -> /dev/block/mmcblk0p8
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 sbl1 -> /dev/block/mmcblk0p2
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 sbl1bak -> /dev/block/mmcblk0p6
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 sec -> /dev/block/mmcblk0p16
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 sns -> /dev/block/mmcblk0p30
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 spare1 -> /dev/block/mmcblk0p23
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 spare2 -> /dev/block/mmcblk0p26
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 spare3 -> /dev/block/mmcblk0p20
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 ssd -> /dev/block/mmcblk0p12
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 system -> /dev/block/mmcblk0p40
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 tz -> /dev/block/mmcblk0p3
lrwxrwxrwx 1 root root   20 2015-12-31 22:31 tzbak -> /dev/block/mmcblk0p7
lrwxrwxrwx 1 root root   21 2015-12-31 22:31 userdata -> /dev/block/mmcblk0p43

但请记住,14.67Gb是磁盘大小而不是文件系统容量

命令df代表“磁盘文件系统”。使用-h选项(df -h),它以“人类可读”的形式显示磁盘空间

$ adb shell df -h
Filesystem                             Size  Used Avail Use% Mounted on
tmpfs                                  950M  1.1M  949M   1% /dev
tmpfs                                  950M     0  950M   0% /mnt
/dev/block/bootdevice/by-name/system   3.5G  3.3G  141M  97% /system
/dev/block/bootdevice/by-name/cache    484M  576K  474M   1% /cache
/dev/block/bootdevice/by-name/userdata 9.1G  570M  8.5G   7% /data
/dev/block/bootdevice/by-name/persist  3.8M  152K  3.5M   5% /persist
/dev/block/bootdevice/by-name/modem     64M   55M  9.4M  86% /firmware
/dev/block/bootdevice/by-name/sns      1.8M   44K  1.7M   3% /sns
/dev/block/bootdevice/by-name/drm      1.8M  356K  1.4M  20% /persist-lg
/dev/block/bootdevice/by-name/mpt       27M  4.2M   23M  17% /mpt
/dev/block/bootdevice/by-name/OP       872M  488M  368M  58% /OP
tmpfs                                  950M     0  950M   0% /storage
/dev/fuse                              9.1G  570M  8.5G   7% /storage/emulated

设备具有8.5G用户数据可用空间,如上例所示 请注意,userdata分区大小为9814016(mmcblk0p43),文件系统大小为9610592(9.1G)

的引用: