CentOS7开始默认XFS文件系统, 所以之前的旧代码需要一些更改.
查询XFS文件系统Quota的几个命令
需要安装xfs的头文件:
yum install xfsprogs-devel
Sample Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <sys/types.h> #include <sys/quota.h> #include <sys/statfs.h> #include <linux/quota.h> #include <linux/magic.h> #include <xfs/xqm.h>
void set_xfs_quota (int u_id, int limit)
{
fs_disk_quota_t xfsquota;
if (quotactl(QCMD(Q_XGETQUOTA, USRQUOTA), "/dev/mapper/centos-home", u_id, (caddr_t)&xfsquota) != 0)
{ string errStr(strerror(errno));
cout << " errno("<< errno << "):" << errStr << endl;
}
xfsquota.d_fieldmask = FS_DQ_LIMIT_MASK;
xfsquota.d_blk_hardlimit = limit * 1024 * 2;
xfsquota.d_blk_softlimit = limit * 1024 * 2;
if (quotactl(QCMD(Q_XSETQLIM, USRQUOTA), "/dev/mapper/centos-home", u_id, (caddr_t)(&xfsquota)) != 0)
{ string errStr(strerror(errno));
cout << " errno("<< errno << "):" << errStr << endl; } }
|