bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#370792: ftruncate can fail to extend files


From: Jim Meyering
Subject: Re: Bug#370792: ftruncate can fail to extend files
Date: Sun, 25 Feb 2007 11:08:32 +0100

Peter Cordes <address@hidden> wrote:
>  Note that the ftruncate man page says ftruncate can fail (when called to
> extend a file) on filesystems like VFAT.  I don't know if vfat even supports
> sparse files, but you need to make sure the file actually ends up at the
> right length, unless you want to just return an error when someone uses cp
> --sparse to a lame filesystem.

VFAT does not support sparse files, and so cp --sparse=always
simply creates a file full of zero bytes when copying a sparse
file to such a file system.  No problem.

You can demonstrate it like this on a Linux system.
BTW, cp's use of ftruncate works fine (returns 0) there,
but even if it were to fail, there is code to handle that.

    cd /tmp                                            &&
    dd bs=1 seek=128K of=sp < /dev/null 2> /dev/null   &&
    dd if=/dev/zero of=1 bs=8192 count=50 2> /dev/null &&
    mkdir mnt && mkfs -t vfat 1 > /dev/null            &&
    mount -oloop 1 mnt && cd mnt                       &&
    cp --sparse=always /tmp/sp .                       &&
    du -sk sp

The above prints  this:

    128     sp

Run this to clean up:

    cd /tmp && umount /tmp/mnt && rm -r 1 mnt sp




reply via email to

[Prev in Thread] Current Thread [Next in Thread]