All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jim C. Brown" <jma5@umd.edu>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Re: qemu disk on vfat
Date: Tue, 16 May 2006 13:21:16 -0400	[thread overview]
Message-ID: <20060516172116.GA15611@jbrown.mylinuxbox.org> (raw)
In-Reply-To: <20060508235024.GA18407@jbrown.mylinuxbox.org>

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

On Mon, May 08, 2006 at 08:36:15PM -0500, Anthony Liguori wrote:
> Jim C. Brown wrote:
> >Aactually, the bug is in vfat not in qemu-img.
> >
>
> Not really.  POSIX doesn't mandate that ftruncate() increase a file
> size.  This is a Linux-ism and is only valid for filesystems that
> support holes (which vfat doesn't).
>
> Regards,
>
> Anthony Liguori
>

Ok, so in that case this is something qemu-img should handle on its own then.
(Since we're not likely to see a "fix" in either glibc or the kernel for this,
and it has the potential to be a portability issue.)

On Mon, May 08, 2006 at 07:50:24PM -0400, Jim C. Brown wrote:
> qemu-img correctly uses ftruncate() which is suppose to make the file sparse
> if the underlying filesystem supports it, but it should fall back to adding zeros
> to the end of the file. On vfat you aren't able to seek past the end of a file
> period, so this doesn't work.

Turns out I was wrong about this too.

http://www.mail-archive.com/bug-tar@gnu.org/msg00556.html

Here is a patch that silently handles the Linux/vfat case using lseek().

-- 
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.

[-- Attachment #2: block.patch --]
[-- Type: text/plain, Size: 809 bytes --]

--- block.c	Tue May 16 13:06:15 2006
+++ block.c	Tue May 16 13:07:51 2006
@@ -753,6 +753,20 @@
     close(s->fd);
 }
 
+int qemu_ftruncate(int fd, off_t length)
+/* ftruncate() isn't guarranteed to grow a file, according to POSIX. **
+** This is. */
+{
+    int res = ftruncate(fd, length);
+    if (res && (errno == EPERM))
+    {
+        if ((lseek( fd, length - 1, SEEK_SET) == (off_t)-1) ||
+       	    (write(fd, "\0", 1) == -1))
+       return -1;
+    }
+    return res;
+}
+
 static int raw_create(const char *filename, int64_t total_size,
                       const char *backing_file, int flags)
 {
@@ -765,7 +779,7 @@
               0644);
     if (fd < 0)
         return -EIO;
-    ftruncate(fd, total_size * 512);
+    qemu_ftruncate(fd, total_size * 512);
     close(fd);
     return 0;
 }

  parent reply	other threads:[~2006-05-16 17:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-08 10:04 [Qemu-devel] qemu disk on vfat Yann Le Doaré
2006-05-07  8:44 ` André Braga
2006-05-08 10:41   ` Yann Le Doaré
2006-05-07 15:50     ` [Qemu-devel] " Alex
2006-05-07 11:00 ` [Qemu-devel] " NyOS
2006-05-07 13:47   ` Jernej Simončič
2006-05-08 19:44   ` Yann Le Doaré
2006-05-08 14:57     ` Jan Marten Simons
2006-05-09 21:05       ` Yann Le Doaré
2006-05-07 11:21 ` Johannes Schindelin
2006-05-08 21:12 ` [Qemu-devel] " Anthony Liguori
2006-05-09 23:41   ` Yann Le Doaré
2006-05-08 22:05     ` Michael McConnell
2006-05-08 22:48       ` Jim C. Brown
2006-05-08 23:10         ` Jim C. Brown
2006-05-08 23:50           ` Jim C. Brown
2006-05-09  1:36             ` Anthony Liguori
2006-05-09  2:11               ` Paul Brook
2006-05-16 17:21             ` Jim C. Brown [this message]
2006-05-08 22:23     ` Ian C. Blenke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060516172116.GA15611@jbrown.mylinuxbox.org \
    --to=jma5@umd.edu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.