From owner-freebsd-questions Thu Jun 18 17:51:37 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA17909 for freebsd-questions-outgoing; Thu, 18 Jun 1998 17:51:37 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from ix.netcom.com (sil-wa2-07.ix.netcom.com [206.214.137.39]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA17892 for ; Thu, 18 Jun 1998 17:51:34 -0700 (PDT) (envelope-from tomdean@ix.netcom.com) Received: (from tomdean@localhost) by ix.netcom.com (8.8.8/8.8.8) id RAA01766; Thu, 18 Jun 1998 17:51:25 -0700 (PDT) (envelope-from tomdean) Date: Thu, 18 Jun 1998 17:51:25 -0700 (PDT) Message-Id: <199806190051.RAA01766@ix.netcom.com> From: Thomas Dean To: mi@video-collage.com CC: questions@FreeBSD.ORG In-reply-to: <199806182133.RAA16419@xxx.video-collage.com> (message from Mikhail Teterin on Thu, 18 Jun 1998 17:33:24 -0400 (EDT)) Subject: Re: file size confusion Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Try: /* xx.c - tomdean Make a large file, much more than the disk can hold. Look at the effects of 'ls -ls', etc. */ #include #include #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