[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
using map_user_kiobuf
Hi all,
I found the following piece of code below (from
http://www.linuxarkivet.nu/mlists/linux-kernel/0011/msg05179.html) and
would like to use it but I don't understand all of it:
1. if test_kiobuf(char *buf) is a kernel module, how is it compiled and
linked with the user space program? How can buf be passed into it? Where
would init_module come into it?
2. In the user space program, what is the ioctl command number 99 stand
for? I haven't found it anywhere. What is that line (ioctl(fh, 99, buf))
doing?
That's it. Thanks in advance for any help.
Oliver.
int test_kiobuf(char* buf)
{
struct kiobuf *iobuf;
int i;
alloc_kiovec(1, &iobuf);
map_user_kiobuf(WRITE, iobuf, buf, TEST_SIZE);
for (i = 0 ; i < iobuf->length; i++)
{
int off = iobuf->offset + i;
int page = off / 4096;
unsigned char* buf = page_address(iobuf->maplist[page]);
buf[off % 4096] = (i & 0xFF); }
unmap_kiobuf(iobuf);
free_kiovec(1, &iobuf);
return 0; }
The user space programme is:
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define TEST_SIZE 1000000
int main(int argc, char *argv[])
{
int fh;
int i;
unsigned char * buf;
buf = (unsigned char *)malloc(TEST_SIZE);
fh = open("/tmp/test", O_CREAT);
if (ioctl(fh, 99, buf) != 0)
perror("ioctl failed");
else
{
for (i = 0; i < TEST_SIZE; i++)
{
if (buf[i] != (i & 0xFF))
printf("%8.8X: %2.2X %2.2X\n", i, i & 0xFF, buf[i]);
}
}
close(fh);
free(buf);
return 0; }
.
Dept. of Physics,
National University of Ireland, Galway,
Galway,
Ireland.
Tel: +353 (0)91 524411 ext. 2716
Fax: +353 (0)91 750584
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.kernelnewbies.org/