2001-02-19 14:04:25

by Matthew Kirkwood

[permalink] [raw]
Subject: sendfile from char device?

Hi,

I'm looking for a fast way to initialise a file to zeroes
(without holes) and reckoned that sendfile from /dev/zero
would be the way to go.

But, unfortunately, sendfile (in 2.2 and 2.4) appears not
to support sendfile(2)ing a device:

$ cat foo.c
main()
{
if(sendfile(1, 0, 0, 1024) < 0)
perror("failed");
}
$ cc foo.c
$ ./a.out </etc/passwd >/dev/null
$ ./a.out </dev/zero >/tmp/test
failed: Invalid argument

I haven't played the printk game, but it looks like it may
be tripping up on the fact that devices don't support locks.
Or is it the lack of a ->readpage() method on /dev/zero?

Matthew.


2001-02-19 14:45:58

by Jeff Garzik

[permalink] [raw]
Subject: Re: sendfile from char device?

On Mon, 19 Feb 2001, Matthew Kirkwood wrote:
> I'm looking for a fast way to initialise a file to zeroes
> (without holes) and reckoned that sendfile from /dev/zero
> would be the way to go.
>
> But, unfortunately, sendfile (in 2.2 and 2.4) appears not
> to support sendfile(2)ing a device:

Correct... sendfile(2) is only for sources/destinations that can be
ripped through the page cache. I converted Lineo's BusyBox to use
sendfile, only to see it die when used on anything but a normal file or
a socket.

Jeff




2001-02-19 14:49:05

by Matthew Kirkwood

[permalink] [raw]
Subject: Re: sendfile from char device?

On Mon, 19 Feb 2001, Jeff Garzik wrote:

> > But, unfortunately, sendfile (in 2.2 and 2.4) appears not
> > to support sendfile(2)ing a device:
>
> Correct... sendfile(2) is only for sources/destinations that can be
> ripped through the page cache.

I knew that, but was surprised that /dev/zero didn't have
->readpage(). Any pointers to assist me to implement one?

Matthew.