首先生成一个带有空洞的文件
生辰一个不带空洞的文件:
发现二者文件的大小是一样的,但是所分配的磁盘块是不一样的。
- #include "apue.h"
-
#include <fcntl.h>
-
-
char buf1[] = "abcdefghij";
-
char buf2[] = "ABCDEFGHIJ";
-
-
int main(void )
-
{
-
int fd;
-
-
if(( fd=creat("file.hole",FILE_MODE)) < 0)
-
err_sys("creat error ");
-
/* offset now =10 */
-
if(write(fd,buf1,10) != 10)
-
err_sys("write error");
-
-
if( lseek(fd,16384,SEEK_SET ) == -1 )
-
err_sys("lseek error");
-
-
/* offset now =16384 */
-
-
if(write(fd,buf2,10) != 10)
-
err_sys("write error");
-
/* offet now =16394 */
-
exit(0);
-
}
- #include "apue.h"
-
#include <fcntl.h>
-
-
int main(void )
-
{
-
int fd;
-
-
if ((fd=creat("file.nohole",FILE_MODE)) < 0)
-
err_sys("creat error ");
-
int loop=1;
-
char *p="c";
-
for (loop =1; loop <=16394; loop++)
-
{
-
if (write(fd,p,1) != 1)
-
err_sys("write error");
-
}
-
exit(0);
-
}
- -rw-r--r-- 1 ubuntu ubuntu 16394 2011-12-27 19:50 file.hole
-
0000000 a b c d e f g h i j \0 \0 \0 \0 \0 \0
-
0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
-
*
-
0040000 A B C D E F G H I J
-
0040012
-
8 -rw-r--r-- 1 ubuntu ubuntu 16394 2011-12-27 19:50 file.hole
-
20 -rw-r--r-- 1 ubuntu ubuntu 16394 2011-12-27 20:06 file.nohole
阅读(811) | 评论(0) | 转发(0) |