Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在ext3和XFS上创建具有备用数据和孔的稀疏文件_Linux_Filesystems_Block - Fatal编程技术网

Linux 在ext3和XFS上创建具有备用数据和孔的稀疏文件

Linux 在ext3和XFS上创建具有备用数据和孔的稀疏文件,linux,filesystems,block,Linux,Filesystems,Block,我创建了一个程序来创建包含备用空块和数据块的稀疏文件。 例如,block1=empty,block2=data,block3=empty #define BLOCK_SIZE 4096 void *buf; int main(int argc, char **argv) { buf=malloc(512); memset(buf,"a",512); int fd=0; int i; int sector_per_block=BLOCK_SIZE/512; int block_count=4; i

我创建了一个程序来创建包含备用空块和数据块的稀疏文件。 例如,block1=empty,block2=data,block3=empty

#define BLOCK_SIZE 4096
void *buf;
int main(int argc, char **argv)
{
buf=malloc(512);
memset(buf,"a",512);
int fd=0;
int i;
int sector_per_block=BLOCK_SIZE/512;
int block_count=4;
if(argc !=2 ){
        printf("Wrong usage\n USAGE: program absolute_path_to_write\n");
        _exit(-1);
}
fd=open(argv[1],O_RDWR | O_CREAT,0666);
if(fd <= 0){
        printf("file open failed\n");
        _exit(0);
}
while(block_count > 0){
        lseek(fd,BLOCK_SIZE,SEEK_CUR);
        block_count--;
        for(i=0;i<sector_per_block;i++)
        write(fd,buf,512);
        block_count--;
}
close(fd);
return 0;
}
#定义块大小4096
无效*buf;
int main(int argc,字符**argv)
{
buf=malloc(512);
memset(buf,“a”,512);
int-fd=0;
int i;
每个块的int扇区=块大小/512;
int block_count=4;
如果(argc!=2){
printf(“错误用法\n用法:程序绝对路径到写入\n”);
_出口(-1);
}
fd=打开(argv[1],O|u RDWR | O|u CREAT,0666);
如果(fd 0){
lseek(fd、块大小、寻道电流);
块_计数--;

对于(i=0;i稀疏文件只是一种空间优化,任何FS都可能不需要创建稀疏文件来优化文件碎片和文件访问速度。因此,您不能依赖文件在某些FS上的空闲度


因此,XFS上的12kb也是正确的。

稀疏文件只是一种空间优化,任何FS可能不会创建一个稀疏文件来优化文件碎片和文件访问速度。因此,您不能依赖于某些FS上文件的空闲度

因此,XFS上的12kb也是正确的。

这是XFS中的一个错误:

这是XFS中的一个错误:


在同一个程序中,我增加了块数,以便写入200MB的文件。ls-lh在两个FSs上都显示为200MB,而du-h在XFS上显示为187MB,在ext3上显示为100MB。在优化文件碎片和文件访问速度方面有很大的不同?尽量不要用最小大小的4kb块填充大量内容,而是增加块大小。我的意思是更改
\de精细块大小4096
#定义块大小(4096*32)
是的,增加块大小是可行的,但它不会创建一个文件,这样就有1blockhole、1blockdata、1blockhole、1blockdata……sequence.xfs的类型不是基于块的fs,而是基于块的。因此,块的大小可以大于单个块。在同一个程序中,我增加了块的数量,这样就可以写入200MB的文件。ls-lh show对于两个FSs,s 200MB,但du-h在XFS上显示为187MB,在ext3上显示为100MB。在优化文件碎片和文件访问速度方面有很大的不同?尽量不要用4kb的最小大小的块填充很多内容,而是增加一个块大小。我的意思是将
#define block_size 4096
更改为
#define block_size(4096*32)
是的,增加块大小是可行的,但它不会创建一个文件,这样就有1blockhole、1blockdata、1blockhole、1blockdata……sequence.xfs的类型不是基于块的fs,而是基于块的fs。因此,块的大小可以大于单个块。