linux磁盤大小獲取和文件大小獲取
一、獲取磁盤大小(給入的是文件夾絕對路徑);
check_disk_available(QString path)
{
struct statfs diskinfo;
unsigned long long size;
unsigned long long blocksize;
statfs(path.toUtf8().data(),&diskinfo);
blocksize=diskinfo.f_bsize;
size=diskinfo.f_bavail*blocksize;
size=size>>20;
if(size<2000)
{
return -1;
}
return 1;
}
statfs定義:
struct statfs {
long f_type; /* 文件系統類型 */
long f_bsize; /* 經過優化的傳輸塊大小,單位B*/
long f_blocks; /* 文件系統數據塊總數 */
long f_bfree; /* 可用塊數 */
long f_bavail; /* 非超級用戶可獲取的塊數 */
long f_files; /* 文件結點總數 */
long f_ffree; /* 可用文件結點數 */
fsid_t f_fsid; /* 文件系統標識 */
long f_namelen; /* 文件名的最大長度 */
};
二、文件大小獲?。?/div>
int getfilesize(char *filename)
{
int filesize=0;
struct stat mystat;
stat(filename,&mystat);
filesize=mystat.st_size;
return filesize;
}
- struct stat
- {
- dev_t st_dev; /* ID of device containing file -文件所在設備的ID*/
- ino_t st_ino; /* inode number -inode節點號*/
- mode_t st_mode; /* protection -保護模式?*/
- nlink_t st_nlink; /* number of hard links -鏈向此文件的連接數(硬連接)*/
- uid_t st_uid; /* user ID of owner -user id*/
- gid_t st_gid; /* group ID of owner - group id*/
- dev_t st_rdev; /* device ID (if special file) -設備號,針對設備文件*/
- off_t st_size; /* total size, in bytes -文件大小,字節為單位*/
- blksize_t st_blksize; /* blocksize for filesystem I/O -系統塊的大小*/
- blkcnt_t st_blocks; /* number of blocks allocated -文件所占塊數*/
- time_t st_atime; /* time of last access -最近存取時間*/
- time_t st_mtime; /* time of last modification -最近修改時間*/
- time_t st_ctime; /* time of last status change - */
- };
浙公網安備 33010602011771號