[lkml]   [2003]   [Nov]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: OT: why no file copy() libc/syscall ??
On Mon, Nov 10, 2003 at 08:05:11PM -0500, Albert Cahalan wrote:
> So open the file, change context, and then:
> long copy_fd_to_file(int fd, const char *name, ...)
> (if you can no longer read from the OPEN fd,
> either we override that or we just don't care
> about such mostly-fictional cases)

Actually, I think we should have a:

long copy_fd_to_fd (int src, int dst, int len)

type of systemcall.

It should do something like:

while ((nbytes = read (src, buf, BUFSIZE)) >= 0) {
if (write (dst, buf, nbytes) < 0)
return totbytes;
totbytes += nbytes;

but it allows kernel-space to optimize this whenever possible. Kernel
then becomes responsible for detecting and handling the optimizable

The kernel then becomes something

if (islocalfile (src) && issocket (dst))
/* Call the old sendfile */
return sendfile (....);

if (isCIFS (src), isCIFS(dst))
/* Tell remote host to copy the file. */
return CIFS_copy_file (....);


and then the default implementation. This is nice and expandible, and
provides a default for the case that cannot be optimized.

And if you don't want the extra code, we could enclose the different
optimizations with ifdefs.

But alas, last time Linus didn't agree with me and decided we should
do something like "sendfile", which is IMHO just a special case of
this one.

If we implement this in kernel (at first just the copy_fd_fd and the
default implementation), then we can get "cp" to use this, and then
suddenly whenever we upgrade the kernel, cp can use the newly
optimized copying mechanism. (e.g. whenever we manage to specify a
socket as the destination, cp would suddenly start to use

(It might be better to include a "buffer" argument in the interface,
freeing the implementation of allocating a buffer when an optimization
is not possible).


** ** ** +31-15-2600998 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
**** "Linux is like a wigwam - no windows, no gates, apache inside!" ****
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:58    [W:0.104 / U:4.944 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site