Home | History | Annotate | Download | only in user_space
      1 /*
      2  *
      3  *   Copyright (c) International Business Machines  Corp., 2001
      4  *
      5  *   This program is free software;  you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 2 of the License, or
      8  *   (at your option) any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  *   the GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program;  if not, write to the Free Software
     17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  *
     19 
     20  * This file will include user space functions that will drive
     21  * the kernel module to test various functions and kernel
     22  * calls. Each function will need to setup the tif structure
     23  * so that the in parameters and out parameters are correctly
     24  * initialized
     25  *
     26  * use tif structure for passing params between user
     27  * space and kernel space, in some tests it is really not
     28  * needed, and if nothing is needed to pass in utilize
     29  * the ki_generic function below. the tif structure makes
     30  * it easy to maintain all the tests if they have the same
     31  * process in kernel space to read in params in the kernel
     32  * module no matter what the test is
     33  *
     34  * author: Sean Ruyle
     35  * date:   06/11/2003
     36  *
     37  * tmod_ki.c
     38  */
     39 
     40 #include <stdlib.h>
     41 #include <stdio.h>
     42 #include <sys/ioctl.h>
     43 #include "../kernel_space/tmod.h"
     44 
     45 int ki_generic(int fd, int flag)
     46 {
     47 	int rc;
     48 	tmod_interface_t tif;
     49 
     50 	/*
     51 	 * build interface structure
     52 	 */
     53 	tif.in_len = 0;
     54 	tif.in_data = 0;
     55 	tif.out_len = 0;
     56 	tif.out_data = 0;
     57 	tif.out_rc = 0;
     58 
     59 	/*
     60 	 * ioctl call for flag
     61 	 */
     62 	rc = ioctl(fd, flag, &tif);
     63 	if (rc) {
     64 		printf("Ioctl error\n");
     65 		return rc;
     66 	}
     67 	if (tif.out_rc) {
     68 		printf("Specific errorr: ");
     69 		return tif.out_rc;
     70 	}
     71 
     72 	return rc;
     73 }
     74 
     75 #if 0
     76 An example of using in_data to pass in a structure:ki_write_t wif;
     77 tmod_interface_t tif;
     78 
     79 //fill out wif structure
     80 
     81 /*
     82  * build interface structure
     83  */
     84 tif.in_len = sizeof(ki_write_t);
     85 tif.in_data = (caddr_t) & wif;
     86 tif.out_len = 0;
     87 tif.out_data = 0;
     88 tif.out_rc = 0;
     89 
     90 //make ioctl call
     91 
     92 An example of using out_data to get back a structure:ki_read_t rif;
     93 tmod_interface_t tif;
     94 
     95 //fill out rif structure
     96 rif.len = p_test->data[0];
     97 rif.handle = open_handle;
     98 rif.data = (caddr_t) p_test->data[1];
     99 
    100 /*
    101  * build interface structure
    102  */
    103 tif.in_len = sizeof(ki_read_t);
    104 tif.in_data = (caddr_t) & rif;
    105 tif.out_len = 0;
    106 tif.out_data = 0;
    107 tif.out_rc = 0;
    108 
    109 //make ioctl call
    110 
    111 #endif
    112