From owner-freebsd-fs@FreeBSD.ORG Thu Sep 30 04:09:26 2004 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C49A716A4CE for ; Thu, 30 Sep 2004 04:09:26 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1F25643D49 for ; Thu, 30 Sep 2004 04:09:26 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.1/8.12.10) with ESMTP id i8U49ILG032974; Thu, 30 Sep 2004 00:09:18 -0400 (EDT) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.1/8.12.10/Submit) id i8U49Io9032973; Thu, 30 Sep 2004 00:09:18 -0400 (EDT) (envelope-from das@FreeBSD.ORG) Date: Thu, 30 Sep 2004 00:09:18 -0400 From: David Schultz To: Nehal Message-ID: <20040930040918.GA32845@VARK.MIT.EDU> Mail-Followup-To: Nehal , freebsd-fs@FreeBSD.ORG References: <20040929101403.000027aa@nehal> <20040929204233.GB30629@VARK.MIT.EDU> <20040929154328.00001444@nehal> <20040929230929.GA31474@VARK.MIT.EDU> <20040929194916.00000f43@nehal> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040929194916.00000f43@nehal> cc: freebsd-fs@FreeBSD.ORG Subject: Re: data blocks question X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Sep 2004 04:09:26 -0000 On Wed, Sep 29, 2004, Nehal wrote: > On Wed, 29 Sep 2004 19:09:29 -0400 > David Schultz wrote: > > > On Wed, Sep 29, 2004, Nehal wrote: > > > On Wed, 29 Sep 2004 16:42:33 -0400 > > > David Schultz wrote: > > > > > > > On Wed, Sep 29, 2004, Nehal wrote: > > > > > on my ufs2 partition, there is a file that has a size of > > > > > 65536, and has 2 direct blocks only. the block size of the > > > > > fs is 16k and fragment block size is 2k. > > > > > > > > > > how can this be possible? wouldn't 2 direct blocks mean > > > > > that the maximum size is 2x16k = 32k? or am i not > > > > > understanding something correctly? > > > > > > > > > > i've made a copy of the file, and the new file has 4 > > > > > direct blocks. > > > > > > > > > > it is a binary file, and i can read it fine (ie, cat it). > > > > > i've done fsck on the filesystem and it found no problem. > > > > > > > > Yes, UFS supports sparse files. That is, you can have a > > > > file with parts you haven't written to, and the blocks for > > > > those parts won't be allocated. The cp utility doesn't know > > > > about this, though, so copies will have the ``holes'' filled > > > > with zeroes. > > > > > > > > > > how would i determine the offset and length of these 'holes' > > > for sparse files? > > > > It's an implementation detail, so you're not supposed to need to > > know most of the time. You can use fsdb to find out. > > > i would like to know how it is implemented. is there somewhere in > the freebsd source that i can find this info? src/sys/fs/ufs/ffs/ffs_{balloc,inode}.c would probably be most helpful. The code is complicated, but the approach to this problem isn't: When a file is extended via ftruncate(), don't allocate new blocks. Instead, do that lazily as portions of the file are written. On reads, pretend that unallocated blocks are filled with all zeroes.