Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!slxsys!jonb From: jonb@specialix.co.uk (Jon Brawn) Newsgroups: comp.unix.internals Subject: Re: How do you find the symbolic links to files. Message-ID: <1990Dec5.183223.28304@specialix.co.uk> Date: 5 Dec 90 18:32:23 GMT References: <25146@adm.brl.mil> <1990Dec5.052124.28435@erg.sri.com> <10960:Dec507:07:4190@kramden.acf.nyu.edu> Organization: Specialix International, London Lines: 117 brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >In article <1990Dec5.052124.28435@erg.sri.com> zwicky@erg.sri.com (Elizabeth Zwicky) writes: >> Unfortunately, you >> have to get pretty intimate with the disk to tell that the 20 meg of >> nulls aren't there >Hardly. You just look at the file size. Other than the file size, there >is no way a portable program can tell the difference between a hole and >an allocated block of zeros. If an archiver knows the block size and >sees that a file has N holes, it can just squish the first N holes it >finds, and write explicit zeros in the remaining zero-filled blocks. Umm? really? I wrote this program: #include #include #include #include /* ** This program was written on SCO Unix System V release 3.2.something. */ char buffer[1024]; main() { int fd; /* file desctiptor */ int block; /* a block number */ long offset; /* offset at which to write above block */ struct stat statb; /* stat structure used to read the file size */ /* ** set the buffer to a known data pattern: */ memset(buffer,42,sizeof(buffer)); /* ** create a new file */ if ( (fd = creat("hole_file",0666))==-1 ) { perror("cant creat hole_file"); exit(1); } /* ** write ten (sparse) blocks to it */ for ( block=0; block<10; block++ ) { /* ** blocks are at 10K intervals in the file */ offset = block * 10240; /* ** seek... */ if ( lseek(fd,offset,0) != offset ) { perror("cant seek into hole_file"); exit(1); } /* ** ...write */ if ( write(fd,buffer,sizeof(buffer)) != sizeof(buffer) ) { perror("cant write hole_file"); exit(1); } } /* ** close the file */ if ( close(fd) == -1 ) { perror("trouble closeing hole_file"); } /* ** ask the OS how big the file is */ if ( stat("hole_file",&statb)==-1 ) { perror("cant stat hole_file"); exit(1); } printf("stat information for hole_file:\n"); printf("st_size %d\n",statb.st_size); system("ls -ils hole_file"); } And ran it, producing this output: stat information for hole_file: st_size 93184 16314 184 -rw-rw---- 1 jonb soft 93184 Dec 5 18:23 hole_file inode size mode num user group size date time name (blocks) links name name (bytes) The size of the file is indeed 9*10240+1024. Now, please demonstrate to your audience where the holes can be detected? >---Dan Jonb -- ``Let the myth be expelled. I stand here before you. Can you not see me? Do you not hear my voice?''