Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jörn
Date: Wednesday, November 28, 2007 - 9:14 pm

On Wed, 28 November 2007 20:27:11 -0700, Andreas Dilger wrote:

That could work.  There really isn't a reason for any application to
mess with physical locations when dealing with logfs.


It has the advantage of being easy to use.  My completely untested
attempt at a copy loop is just 14 lines.  Add some error handling and it
should still be quite small.

off_t data_ofs, hole_ofs;
long count;

for (data_ofs = hole_ofs = 0; ; ) {
	if (data_ofs >= hole_ofs) {
		data_ofs = llseek(in_fd, data_ofs, SEEK_DATA);
		hole_ofs = llseek(in_fd, data_ofs, SEEK_HOLE);
	}
	count = splice(in_fd, &data_ofs, out_fd, &data_ofs,
			hole_ofs - data_ofs, 0);
	if (count == 0)
		break;
	data_ofs += count;
}

And when trying to optimize away some of the system calls, my personal
preference would be to teach splice about seek_hole and seek_data and
just splice the complete file range in one go.

Jörn

-- 
"Security vulnerabilities are here to stay."
-- Scott Culp, Manager of the Microsoft Security Response Center, 2001
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Josef Bacik, (Wed Nov 28, 1:02 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Brad Boyer, (Wed Nov 28, 2:56 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Nicholas Miell, (Wed Nov 28, 3:56 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Josef Bacik, (Wed Nov 28, 4:33 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Josef Bacik, (Wed Nov 28, 4:38 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Andreas Dilger, (Wed Nov 28, 4:39 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Andreas Dilger, (Wed Nov 28, 4:49 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Nicholas Miell, (Wed Nov 28, 4:50 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Nicholas Miell, (Wed Nov 28, 5:06 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Andreas Dilger, (Wed Nov 28, 8:27 pm)
Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA, Jörn, (Wed Nov 28, 9:14 pm)