tagp_ki.c revision bdbaec51a423e715c2b03ed9e497e9a1fba6103e
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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: Kai Zhao
35 * date:   08/25/2003
36 *
37 * tagp_ki.c
38 */
39
40#include <stdlib.h>
41#include <stdio.h>
42#include <sys/ioctl.h>
43#include "../kernel_space/tagp.h"
44
45int ki_generic(int fd, int flag) {
46        int                     rc;
47        tagp_interface_t        tif;
48
49        /*
50         * build interface structure
51         */
52        tif.in_len = 0;
53        tif.in_data = 0;
54        tif.out_len = 0;
55        tif.out_data = 0;
56        tif.out_rc = 0;
57
58        /*
59         * ioctl call for flag
60         */
61        rc = ioctl(fd, flag, &tif);
62        if(rc) {
63                printf("Ioctl error\n");
64                return rc;
65        }
66        if(tif.out_rc) {
67                printf("Specific errorr: ");
68                return tif.out_rc;
69        }
70
71        return rc;
72}
73
74
75
76
77
78#if 0
79An example of using in_data to pass in a structure:
80
81ki_write_t      wif;
82tagp_interface_t tif;
83
84
85//fill out wif structure
86
87/*
88 * build interface structure
89 */
90tif.in_len = sizeof (ki_write_t);
91tif.in_data = (caddr_t) &wif;
92tif.out_len = 0;
93tif.out_data = 0;
94tif.out_rc = 0;
95
96
97//make ioctl call
98
99An example of using out_data to get back a structure:
100
101ki_read_t       rif;
102tagp_interface_t tif;
103
104//fill out rif structure
105rif.len = p_test->data[0];
106rif.handle = open_handle;
107rif.data = (caddr_t)p_test->data[1];
108
109/*
110 * build interface structure
111 */
112tif.in_len = sizeof (ki_read_t);
113tif.in_data = (caddr_t) &rif;
114tif.out_len = 0;
115tif.out_data = 0;
116tif.out_rc = 0;
117
118
119//make ioctl call
120
121
122
123#endif
124