更新:这个FALLOC_FL_PUNCH_HOLE
最初不支持3.0.0-17
,我想我需要修补它。
我知道linux有这个hole
功能,我想知道是否可以在现有文件中打一个洞。
具体来说,我创建了一个名为hole_test
通过这些代码:
18 #include <stdlib.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <errno.h>
24
25 int main(int argc, char **argv)
26 {
27 int fd;
28 char a[7]="happy!";
30 fd = open("hole_test", O_CREAT|O_RDWR, 0666);
31 if(fd == -1)
32 printf("error, %s\n", (char *)strerror(errno));
35 // fallocate(fd, 0x02, 0,0);
36 // pwrite(fd, a, sizeof(a), 0);
37 // pwrite(fd, a, sizeof(b), 65536);
38 close(fd);
39 return 0;
40 }
首先,我用户L36
L37
创建一个文件。这stat hole_test
表明:
File: `hole_test'
Size: 65540 Blocks: 16 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1052101 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ bxshi) Gid: ( 1000/ bxshi)
Access: 2012-04-03 23:02:35.227664608 +0800
Modify: 2012-04-03 23:02:35.227664608 +0800
Change: 2012-04-03 23:02:35.227664608 +0800
然后我用L35
并评论L36
L37
在我的文件中打一个洞。(0x02 等于FALLOC_FL_PUNCH_HOLE
,我没有找到它的定义位置,所以只需使用它的值)
然后,通过stat hole_test
, the Blocks
仍然是16岁。
File: `hole_test'
Size: 65540 Blocks: 16 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1052101 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ bxshi) Gid: ( 1000/ bxshi)
Access: 2012-04-03 23:02:35.227664608 +0800
Modify: 2012-04-03 23:02:35.227664608 +0800
Change: 2012-04-03 23:02:35.227664608 +0800
我想知道我是否可以在这方面打出新的漏洞hole_test
文件删除现有数据?
我怎样才能钻一个洞hole_test
在偏移量 0 到 7 处,这样我认为Blocks
可能会变成8,我写的字符串就会消失。
希望大家知道我说的话并给我一些建议。