linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 2/2 -v2] e2image: attempt to use ftruncate64 to set i_size for raw images
Date: Fri, 17 Feb 2012 09:35:50 -0500	[thread overview]
Message-ID: <1329489350-22260-1-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1329489163-21918-2-git-send-email-tytso@mit.edu>

If ftruncate64() exists, try to use it to set i_size.  This isn't
guaranteed to work, per SuSv3, but if it doesn't work, it's guaranteed
to return an error.  So for file systems and/or operating systems that
don't support extending i_size via ftruncate64(), fall back to writing
the trailing null.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---

Oops, sent the wrong version of the patch.  My bad.

 misc/e2image.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/misc/e2image.c b/misc/e2image.c
index 3cb92fe..93359cf 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -510,8 +510,19 @@ static void output_meta_data_blocks(ext2_filsys fs, int fd)
 			}
 		}
 	}
+#ifdef HAVE_FTRUNCATE64
+	if (sparse) {
+		ext2_loff_t offset = ext2fs_llseek(fd, sparse, SEEK_CUR);
+
+		if (offset < 0)
+			lseek_error_and_exit(errno);
+		if (ftruncate64(fd, offset) < 0)
+			write_block(fd, zero_buf, -1, 1, -1);
+	}
+#else
 	if (sparse)
 		write_block(fd, zero_buf, sparse-1, 1, -1);
+#endif
 	ext2fs_free_mem(&zero_buf);
 	ext2fs_free_mem(&buf);
 }
-- 
1.7.9.107.g97f9a


  reply	other threads:[~2012-02-17 14:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16 21:35 [PATCH 1/2] e2image: truncate raw image file to correct size Phillip Susi
2012-02-16 21:35 ` [PATCH 2/2] e2image: add -a switch to include all data Phillip Susi
2012-02-16 23:17   ` Ted Ts'o
2012-02-17  0:17     ` Phillip Susi
2012-02-17  9:17       ` Lukas Czerner
2012-02-17 14:50         ` Ted Ts'o
2012-02-17 15:35           ` Lukas Czerner
2012-02-17 15:39             ` Lukas Czerner
2012-02-17 20:39             ` Ted Ts'o
2012-02-16 22:58 ` [PATCH 1/2] e2image: truncate raw image file to correct size Ted Ts'o
2012-02-16 23:10   ` Phillip Susi
2012-02-16 23:30     ` Ted Ts'o
2012-02-17  0:21       ` Phillip Susi
2012-02-17 10:04       ` Lukas Czerner
2012-02-17 14:30         ` Ted Ts'o
2012-02-17 14:32           ` [PATCH 1/2] e2image: fix logic bug which could cause a raw image not to be extended Theodore Ts'o
2012-02-17 14:32             ` [PATCH 2/2] e2image: attempt to use ftruncate64 to set i_size for raw images Theodore Ts'o
2012-02-17 14:35               ` Theodore Ts'o [this message]
2012-02-17 20:19                 ` [PATCH 2/2 -v2] " Lukas Czerner
2012-02-17 20:18             ` [PATCH 1/2] e2image: fix logic bug which could cause a raw image not to be extended Lukas Czerner
2012-02-17 14:46           ` [PATCH 1/2] e2image: truncate raw image file to correct size Phillip Susi
2012-02-17 14:31         ` Phillip Susi

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=1329489350-22260-1-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).