linux文件分区 簇大小,Linux下st_blksize与Windows下簇大小的对应

声明:此调查结果如有错误,敬请指正。谢谢^_^

Linux下文件对应的属性

struct stat {

mode_t     st_mode;        //文件对应的模式,文件、目录等

ino_t         st_ino;            //inode节点号

dev_t        st_dev;           //设备号码

dev_t        st_rdev;          //特殊设备号码

nlink_t       st_nlink;         //文件的连接数

uid_t         st_uid;            //文件所有者

gid_t         st_gid;            //文件所有者对应的组

off_t          st_size;          //普通文件对应的文件字节数

time_t       st_atime;        //文件最后被访问的时间

time_t       st_mtime;       //文件内容最后被修改的时间

time_t       st_ctime;        //文件状态改变时间

blksize_t   st_blksize;     //文件内容对应原块大小

blkcnt_t     st_blocks;      //文件内容对应的块数量

}

Windows下对应于上述st_blksize的值为“一个簇的大小 = 一个簇的扇区数 * 一个扇区的字节数”。

Windows下,如果用GetDiskFreeSpace函数来取得磁盘信息

GetDiskFreeSpace(

lpRootPathName: PChar;                           //磁盘根路径

var lpSectorsPerCluster: DWORD;             //一个簇内的扇区数

var lpBytesPerSector: DWORD;                 //一个扇区的字节数

var lpNumberOfFreeClusters: DWORD;     //剩余簇数

var lpTotalNumberOfClusters: DWORD     //总簇数

): BOOL;

则 一个簇的大小 = lpSectorsPerCluster * lpBytesPerSector

测试:

void testGetDiskfree() {

DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;

unsigned __int64 i64TotalBytes, i64FreeBytes;

float fResult= GetDiskFreeSpace("F://work//", &dwSectPerClust,

&dwBytesPerSect, &dwFreeClusters,

&dwTotalClusters);

if (fResult) {

/* force 64-bit math */

i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust

* dwBytesPerSect;

i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust

* dwBytesPerSect;

}

printf("一个簇的字节数:%lu/n", dwBytesPerSect * dwSectPerClust);

printf("剩余空间:%I64d(GB)/n", i64FreeBytes/1024/1024/1024);

printf("总空间:%I64d(GB)/n", i64TotalBytes/1024/1024/1024);

}

-----------------------

理由1:

Linux下最小的存储文件的单位是"块"

Dos下最小的存储文件的单位是"籁"

-----------------------

理由2:

(参考 -

The problem with this is that there are four distinct units that you must be keeping in mind. To make things even worse, two of these units bear the same name. These are the different units:

1. Hardware block size, "sector size"

2. Filesystem block size, "block size"

3. Kernel buffer cache block size, "block size"

4. Partition table block size, "cylinder size"

To differentiate between the filesystem block size and the buffer cache block size, I will follow FAT terminology and use "cluster size" for the filesystem block size.

The sector size is the units that the hardware deals with. This ranges between different hardware types, but most PC-style hardware (floppies, IDE disks, etc.) use 512 byte sectors.

The cluster size is the allocation unit that the filesystem uses, and is what causes fragmentation - I'm sure you know about that. On a moderately sized ext3 filesystem, this is usually 4096 bytes, but you can check that with dumpe2fs. Remember that these are also usually called "blocks", only that I refer to them as clusters here.

The cluster size is what gets returned in st_blksize in the stat buffer, in order for programs to be able to calculate the actual disk usage of a file.

The block size is the size of the buffers that the kernel uses internally when it caches sectors that have been read from storage devices (hence the name "block device"). Since this is the most primitive form of storage in the kernel, all filesystem cluster sizes must be multiples of this. This block size is also what is almost always referred to by userspace programs. For example, when you run "du" without the -h or -H options, it will return how many of these blocks a file takes up. df will also report sizes in these blocks, the "Blocks" column in the fdisk -l output is of this type, and so on. It is what is most commonly referred to as a "block". Two disk sectors fit into each block.

The cylinder size is

only used in the partition table and by the BIOS (and the BIOS isn't used by Linux).

"df" only operates on filesystems, so, no, it can't be used without a filesystem - without a filesystem, the data that it would return doesn't exist. "du" operates on individual files.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值