Date: Thu, 18 Jun 1998 17:51:25 -0700 (PDT) From: Thomas Dean <tomdean@ix.netcom.com> To: mi@video-collage.com Cc: questions@FreeBSD.ORG Subject: Re: file size confusion Message-ID: <199806190051.RAA01766@ix.netcom.com> In-Reply-To: <199806182133.RAA16419@xxx.video-collage.com> (message from Mikhail Teterin on Thu, 18 Jun 1998 17:33:24 -0400 (EDT))
next in thread | previous in thread | raw e-mail | index | archive | help
Try: /* xx.c - tomdean Make a large file, much more than the disk can hold. Look at the effects of 'ls -ls', etc. */ #include <stdio.h> #include <fcntl.h> #define HM 100000000 main() { short count; int fd; if ((fd=open("bigfile",O_CREAT | O_WRONLY,0700)) == 1) { perror("Open failed."); exit(1); } for (count=0; count <= 10; count++) { printf(","); if (write(fd,"data",5) == -1) { perror("write failed"); exit(1); } if (lseek(fd,HM,1) == -1) { perror("seek failed"); exit(1); } } close(fd); printf("\n"); } and look at 'ls -ls'. 352 -rwx------ 1 tomdean users 1000000055 Jun 18 17:16 bigfile The file system only puts what you actually write on the disk. The remainder is mapped by the file system to appear as if it is there, but, since there is no data in that area of the file, it is not actually written to disk. A structure that maps the file is allocated for every file. If the file is small, a direct mapping scheme is used. For larger files, indirect mapping is used. The mapping structure is allocated, but, most of the pointers are null, since there is no data in most of the file. This is a sparse file. /var/log/wtmp is another sparse file, created by the system. Does this make sense? tomdean To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806190051.RAA01766>