How do you find the symbolic links to files.
Jon Brawn
jonb at specialix.co.uk
Thu Dec 6 05:32:23 AEST 1990
brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
>In article <1990Dec5.052124.28435 at erg.sri.com> zwicky at 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 <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
** 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?''
More information about the Comp.unix.internals
mailing list