apue 里介绍了文洞(英文是hole,中文不知道怎么说,我理解为“文件的黑洞”,感觉它挺神秘的,像黑洞一样……),所以做了一个程序来产生一个有黑洞的文件,一个没有黑洞的文件。用法是
a.out filename1 filename2,filename1
代表有黑洞的文件名,filename2 代表没黑洞的文件名。注意设计程序的时候这个“黑洞”一定要给得足够大,否则看不见……
所以我的 DELTA 设置为 1000 了,一开始设置为 100,结果 ls -asl 的时候两个文件竟然是一模一样的……
#include <stdio.h>
//#include <unistd.h>
#include "apue.h"
#include "myerr.c"
//#include <pwd.h>
#include <fcntl.h>
#define BUFSIZE 11
#define DELTA 1000
int
main (int argc, char *argv[])
{
int i, fd;
char buf[BUFSIZE] = {"abcdefghij"} ;
if (argc != 3)
err_quit ("usage: a.out filename1 filename2\n") ;
// write a holed file
if ((fd = open (argv[1], O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) == -1)
err_sys ("holed file open error") ;
// printf ("%d\n", fd) ;
if (write (fd, buf, 10) != 10)
err_sys ("holed file 1 write error") ;
if (lseek (fd, 10 * DELTA, SEEK_SET) == -1)
err_sys ("holed file lseek error") ;
if (write (fd, buf, 10) != 10)
err_sys ("holed file 2 write error") ;
close (fd) ;
// write a no hole file
if ((fd = open (argv[2], O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) == -1)
err_sys ("noholed file open error") ;
if (write (fd, buf, 10) != 10)
err_sys ("noholed file 1 write error") ;
for (i = 0 ; i < DELTA ; ++i) {
if (write (fd, buf, 10) != 10)
err_sys ("noholed file 2 write error") ;
}
close (fd) ;
exit (0) ;
}
分享到:
相关推荐
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
嵌入式系统软件基础描述及各类嵌入式软件分析方法。嵌入式系统及应用-Chapter3-嵌入式软件系统基础
JAVA_JAVA课件_chapter6-File-Stream
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
Chapter3-《Ext JS高级程序设计》源代码.rar Chapter4-《Ext JS高级程序设计》源代码.rar Chapter5《Ext JS高级程序设计》源代码.rar Chapter6-《Ext JS高级程序设计》源代码.rar Chapter7-《Ext JS高级程序设计》源...
模拟集成电路的分析与设计:Chapter 3-Single-Stage Amplifiers.ppt
Chapter 3 - Dedicated Installation Chapter 4 - Multiboot Installation Chapter 5 - Post-Install Setup Chapter 6 - Startup and Booting Chapter 7 - Managing Users Chapter 8 - Networking ...
Chapter 3 - Attacking the TNS Listener and Dispatchers Chapter 4 - Attacking the Authentication Process Chapter 5 - Oracle and PL/SQL Chapter 6 - Triggers Chapter 7 - Indirect Privilege ...
配电网自动化-chapter1-2-3-4-5.ppt
操作系统概念英文课件:Chapter 10-file-system interface.pptx
操作系统概念英文课件:Chapter 11-file-system implementation.pptx
ProWPFinVB-src-Chapter02-15 ProWPFinVB-src-Chapter02-15 ProWPFinVB-src-Chapter02-15
Chapter3-1.cpp
ProWPFinVB-src-Chapter15-28ProWPFinVB-src-Chapter15-28ProWPFinVB-src-Chapter15-28
计算机网络专业课-Chapter3-The-Data-Link-LayerPPT文档.pptx