linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Zheng Liu <gnehzuil.liu@gmail.com>
Cc: George Spelvin <linux@horizon.com>, linux-ext4@vger.kernel.org
Subject: Re: debugfs: dump a sparse file as a new sparse file
Date: Mon, 31 Dec 2012 21:08:41 -0500	[thread overview]
Message-ID: <20130101020841.GA9641@thunk.org> (raw)
In-Reply-To: <20121115144613.GA11706@gmail.com>

On Thu, Nov 15, 2012 at 04:46:13AM -0000, Zheng Liu wrote:
> --- a/debugfs/dump.c
> +++ b/debugfs/dump.c
> @@ -105,10 +105,11 @@ static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
>  {
>  	errcode_t retval;
>  	struct ext2_inode	inode;
> -	char 		buf[8192];
> +	char 		buf[current_fs->blocksize];

Note: this is a non-standard/non-portable GCC extension.  The best way
to fix this is to explicitly malloc the buffer and then free it before
dump_file exits.

Also, fixing the hard-coded maximum 8k block size, so these sorts of
changes should be done in a separate commit.

>  extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
> diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c
> index 1f7002c..d25ebb4 100644
> --- a/lib/ext2fs/fileio.c
> +++ b/lib/ext2fs/fileio.c
> @@ -176,23 +176,26 @@ static errcode_t sync_buffer_position(ext2_file_t file)
>   * This function loads the file's block buffer with valid data from
>   * the disk as necessary.
>   *
> - * If dontfill is true, then skip initializing the buffer since we're
> + * If flags is true, then skip initializing the buffer since we're
>   * going to be replacing its entire contents anyway.  If set, then the
>   * function basically only sets file->physblock and EXT2_FILE_BUF_VALID
>   */
>  #define DONTFILL 1

The comment "If flags is true..." should be changed to "if the
DONTFILL flag is set..."  

@@ -202,7 +205,11 @@ static errcode_t load_buffer(ext2_file_t file, int dontfill)
 			} else
 				memset(file->buf, 0, fs->blocksize);
 		}
-		file->flags |= EXT2_FILE_BUF_VALID;
+		if (flags == SEEK && ((ret_flags & BMAP_RET_UNINIT) ||
+		    file->physblock == 0))
+			valid = 0;
+		if (valid)
+			file->flags |= EXT2_FILE_BUF_VALID;


valid is initialized to 1, and then set to zero above.  So I'm not
sure what the point is having the valid variable.  Why not do
something like this:

		if (!(flags == SEEK && ((ret_flags & BMAP_RET_UNINIT) ||
				      file->physblock == 0)))
			file->flags |= EXT2_FILE_BUF_VALID;

or...
		if (((flags != SEEK) ||
		     (!(ret_flags & BMAP_RET_UNINIT) && file->physblock)))
			file->flags |= EXT2_FILE_BUF_VALID;


Also, can you add a definition of what SEEK actually means in the
context of load_buffer()?

					- Ted

  reply	other threads:[~2013-01-01  4:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-14  4:07 debugfs feature request: dump sparse files as sparse George Spelvin
2012-11-15 14:46 ` [PATCH] debugfs: dump a sparse file as a new sparse file Zheng Liu
2013-01-01  2:08   ` Theodore Ts'o [this message]
2013-01-01 12:33     ` Zheng Liu
2013-01-01 20:10     ` George Spelvin
2013-01-01 20:57       ` Theodore Ts'o
2013-01-01 21:25         ` George Spelvin
2013-01-01 22:47           ` Theodore Ts'o

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=20130101020841.GA9641@thunk.org \
    --to=tytso@mit.edu \
    --cc=gnehzuil.liu@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux@horizon.com \
    /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).