Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Jun 2012 16:34:50 -0400
From:      Mike Meyer <mwm@mired.org>
To:        freebsd-hackers@freebsd.org
Subject:   Re: BIO_DELETE equivalent for file on FFS filesystem
Message-ID:  <20120616163450.2d0fa3c7@bhuda.mired.org>
In-Reply-To: <CADLo83-dZD5C2Fk3ZTH9z=pXHn8BtYzZQqUBG6HCkHZKe1=P8Q@mail.gmail.com>
References:  <alpine.BSF.2.00.1205261704590.70782@wojtek.tensor.gdynia.pl> <4FD94240.6060806@delphij.net> <alpine.BSF.2.00.1206140647080.72545@wojtek.tensor.gdynia.pl> <CADLo83-T%2B4W2aUKc=-CEUrOqwCq5aqipt-fK=BBboQVNJ3qcWQ@mail.gmail.com> <CAGMYy3sWPMCnttUtJhJCFTtPtgfWWUO1tgK%2BRYOE3QQpg=%2Bw1A@mail.gmail.com> <CADLo83-dZD5C2Fk3ZTH9z=pXHn8BtYzZQqUBG6HCkHZKe1=P8Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 16 Jun 2012 21:04:26 +0100
Chris Rees <utisoft@gmail.com> wrote:

> On Jun 16, 2012 8:37 PM, "Xin LI" <delphij@gmail.com> wrote:
> >
> > On Sat, Jun 16, 2012 at 12:01 PM, Chris Rees <utisoft@gmail.com> wrote:
> > > On Jun 14, 2012 5:49 AM, "Wojciech Puchar" <
> wojtek@wojtek.tensor.gdynia.pl>
> > > wrote:
> > >>>>
> > >>>> file to take 900MB or... can i call some system function to "punch"
> > >>>> holes?
> > >>>
> > >>>
> > >>> I think you can only truncate the file at this time, pretty much like
> > >>> brk() works for memory.
> > >>
> > >>
> > >>
> > >> BAD. suppose i keep windoze VM image on filesystem which takes 10GB but
> > > uses 5GB.
> > >>
> > >> i could write simple program to find out what blocks are unused and
> > > then...do nothing.
> > >>
> > >
> > > What if you cp it?
> >
> > That would be a dd(1) unless we teach cp(1) how to do sparse.  I think
> > what he wanted is to tell the OS "I don't need block XX - YY anymore"
> > and the OS creates a sparse hole, which is not available at this time.
> 
> Sorry, I must have misread.  I take it cp would take a file with holes and
> only copy the data part? i.e. take a 10G file of which 5G is a hole, you'd
> end up with a 5G file?

No, cp just does read()s. Reading data from a hole returns a block
full of zeros. A quick test (after writing a program to create the
file) shows this:

bhuda% df -h .
Filesystem    Size    Used   Avail Capacity  Mounted on
/dev/md0      123M    1.2M    112M     1%    /tmp
bhuda% ls -lh holey.test
-rwxr-xr-x  1 mwm  wheel   953M Jun 16 16:22 holey.test

Ok, I've got a file that's 953M on an FS with 1.2 meg used. It's got
holes.

bhuda% cp holey.test foobar
/tmp: write failed, filesystem is full
cp: foobar: No space left on device

And doing a cp fails. Use dd conv=sparse to get the effect you want.

    <mike
-- 
Mike Meyer <mwm@mired.org>		http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120616163450.2d0fa3c7>