在手机终端开发的时候,我们需要关注手机剩余空间,因为手机不像电脑一样空间宽裕,当设备空间比较少得时候需要释放空间.

用法:先引入头文件

#include <sys/param.h>

#include <sys/mount.h>

代码片段:

+ (long long) freeDiskSpaceInBytesByMB{

struct statfs buf;

long long freespace = -1;

if(statfs("/var", &buf) >= 0){

freespace = (long long)(buf.f_bsize * buf.f_bfree);

}

return freespace/1024/1024;

}

先来说说statfs这个东东,这是C语言函数,下面是官方的介绍:

#if __DARWIN_64_BIT_INO_T

struct statfs __DARWIN_STRUCT_STATFS64;

#else /* !__DARWIN_64_BIT_INO_T */

/*

* LP64 - WARNING - must be kept in sync with struct user_statfs in mount_internal.h.

*/

struct statfs {

short f_otype; /* TEMPORARY SHADOW COPY OF f_type */

short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */

long f_bsize; /* fundamental file system block size */

long f_iosize; /* optimal transfer block size */

long f_blocks; /* total data blocks in file system */

long f_bfree; /* free blocks in fs */

long f_bavail; /* free blocks avail to non-superuser */

long f_files; /* total file nodes in file system */

long f_ffree; /* free file nodes in fs */

fsid_t f_fsid; /* file system id */

uid_t f_owner; /* user that mounted the filesystem */

short f_reserved1; /* spare for later */

short f_type; /* type of filesystem */

long f_flags; /* copy of mount exported flags */

long    f_reserved2[2]; /* reserved for future use */

char f_fstypename[MFSNAMELEN]; /* fs type name */

char f_mntonname[MNAMELEN]; /* directory on which mounted */

char f_mntfromname[MNAMELEN];/* mounted filesystem */

char f_reserved3; /* For alignment */

long f_reserved4[4]; /* For future use */

};

#endif /* __DARWIN_64_BIT_INO_T */

如何获得iphone设备的剩余空间的更多相关文章

  1. /tmp/crontab.tDoyrp: 设备上没有空间 查看文件夹所在分区 磁盘剩余空间 15g的root-mail大文件

    问题诊断: 文件夹所在磁盘已满 问题确认: 查看文件夹所在磁盘剩余空间,找出空间被消耗的文件(集) 查看文件夹所在磁盘空间的所属文件(暂未解决) [root@hadoop1 /]# df -Bg /t ...

  2. ios5和ios6横竖屏支持及ipad和iphone设备的判断

    ios5和ios6横竖屏支持及ipad和iphone设备的判断 判断是ipad还是iphone设备.此定义在PayViewControllerDemo-Prefix.pch 定义如下: #define ...

  3. 系统服务监控指标--load、CPU利用率、磁盘剩余空间、磁盘I/O、内存使用情况等

    介绍 大型互联网企业的背后,依靠的是成千上万台服务器日夜不停的运转,以支撑其业务的运转.宕机对于互联网企业来说,代价是沉重的,轻则影响用户体验,重则直接影响交易,导致交易下跌,并且给企业声誉造成不可挽 ...

  4. android计算每个目录剩余空间丶总空间以及SD卡剩余空间

    ublic class MemorySpaceCheck { /** * 计算剩余空间 * @param path * @return */ public static String getAvail ...

  5. SQL Server自动化运维系列——监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  6. 关于iPhone设备不同显示尺寸适配的一些方法

    关于iPhone设备不同显示尺寸适配的一些方法   ------关于适配的理解------ 1.什么是适配? 适配是对不同硬件和系统软件的适应,硬件包括屏幕显示,处理器,内存等等(目前主要是屏幕适配, ...

  7. css实现div的高度填满剩余空间

    css实现div的高度填满剩余空间 .top{ width: 100%; height: 70px;} .bottom{background-color: #cc85d9;width: 100%;po ...

  8. sql 查询服务器硬盘剩余空间

    DECLARE @tb1 Table( drive varchar(20), [MB 可用空间] varchar(20)) INSERT INTO @tb1 Exec master.dbo.xp_fi ...

  9. android 判断sd的状态,所有文件,剩余空间的大小

    public class MainActivity extends AppCompatActivity { String TAG = MainActivity.class.getCanonicalNa ...

随机推荐

  1. Linux批量替换文件内容

    问题描述:现在需要将rack1目录下*.send文件中的"-ip="替换成“-localIp=10.0.0.1/n-ip=” 刚才那个批量文本内容替换,只能替换内存中的内容,并不会 ...

  2. MATLAB的循环结构

    循环结构有两种基本形式:while 循环和for 循环.两者之间的最大不同在于代码的重复是如何控制的.在while 循环中,代码的重复的次数是不能确定的,只要满足用户定义的条件,重复就进行下去.相对地 ...

  3. nodejs中npm工具自身升级

    npm官方地址:https://www.npmjs.com/ npm在github上的地址:https://github.com/npm/npm 目前(截止2016-03-15)npm最新版本为3.8 ...

  4. hihocoder 1163 博弈游戏·Nim游戏

    1163 : 博弈游戏·Nim游戏 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob. Alice与Bob总是在进行各种各样的 ...

  5. c#通过Dotpeek调试dll

    我想编程的兄弟们都要引用别人代码,哪怕是.framework里面的基础类库,也经常引用别人的一些dll,但是别人内部抛出一些异常的时候,又不知道到底怎么回事,如果这时候可以在别人的代码里面调试该多好呀 ...

  6. content = "IE=edge,chrome=1" 详解

    content = "IE=edge,chrome=1" 详解 < meta http-equiv = "X-UA-Compatible" content ...

  7. Could not find artifact com.sun:tools:jar:1.5.0解决方法

    可以参照在XP系统下搭建maven环境出的问题 Unable to locate the Javac Compiler in: C:\Program Files\Java\jre6\..\lib\to ...

  8. Server Error The server encountered an error and could not complete your request. 新建站点模版失败

    500 Server Error Error: Server Error The server encountered an error and could not complete your req ...

  9. 转 Java中Filter、Servlet、Listener的学习

      1.Filter的功能filter功能,它使用户可以改变一个 request和修改一个response. Filter 不是一个servlet,它不能产生一个response,它能够在一个requ ...

  10. 暑假集训(3)第一弹 -----还是畅通工程(hdu1233)

    题意梗概:N(n<100)个村子想要富起来,自然就要先修路,不过到底还是没富起来,所以陷入了一个怪圈 :资金不足->修不起路->资金不足...... 为了实现走向全民小康社会,全面实 ...