LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] using map_user_kiobuf

[ILUG] using map_user_kiobuf

Oliver Ryan oryan at physics.nuigalway.ie
Mon Jul 23 11:54:46 IST 2001


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





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell