file size different from ls to du

Leo Bicknell bicknell at ufp.org
Tue Jul 29 08:53:57 PDT 2003


In a message written on Tue, Jul 29, 2003 at 05:27:14PM +0200, Bogdan TARU wrote:
>  I have tried to create some files of myself, with 'spaces' in them
> (holes?), but they don't act like this. So could you please explain what
> 'sparse' means, and the 'trick' to create them?

% cat sparse.c


#include <sys/types.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <unistd.h>

int main(void) {
    int fd;

    fd = open("sparse-file", O_RDWR|O_CREAT);

    lseek(fd, 1024*1024*1024, SEEK_SET);

    write(fd, "0123456789", 10);

    close(fd);
}
% cc -o sparse sparse.c
% ./sparse
% ls -lag sparse-file
-r-xr-----  1 bicknell  bicknell  1073741834 Jul 29 11:52 sparse-file*
% du -k sparse-file
48      sparse-file


-- 
       Leo Bicknell - bicknell at ufp.org - CCIE 3440
        PGP keys at http://www.ufp.org/~bicknell/
Read TMBG List - tmbg-list-request at tmbg.org, www.tmbg.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20030729/20c85992/attachment.bin


More information about the freebsd-hackers mailing list