kopenafs-20060802
[openafs.git] / src / sys / glue.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  *
9  * This file contains any necessary C glue to allow programs to communicate
10  * with the AFS kernel module.  The necessary lower-level glue is defined in
11  * syscall.s.
12  */
13
14 #include <afsconfig.h>
15 #include <afs/param.h>
16
17 RCSID
18     ("$Header$");
19
20 #include <afs/afs_args.h>
21 #include <sys/file.h>
22 #include <sys/ioctl.h>
23 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
24 #include <unistd.h>
25 #else
26 #include <stdio.h>
27 #endif
28 #ifdef AFS_SUN5_ENV
29 #include <fcntl.h>
30 #endif
31 #include "afssyscalls.h"
32
33 #ifdef AFS_LINUX20_ENV
34 int proc_afs_syscall(long syscall, long param1, long param2, long param3, 
35                      long param4, int *rval) {
36   struct afsprocdata syscall_data;
37   int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
38   if(fd < 0)
39       fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
40   if(fd < 0)
41     return -1;
42
43   syscall_data.syscall = syscall;
44   syscall_data.param1 = param1;
45   syscall_data.param2 = param2;
46   syscall_data.param3 = param3;
47   syscall_data.param4 = param4;
48
49   *rval = ioctl(fd, VIOC_SYSCALL, &syscall_data);
50
51   close(fd);
52
53   return 0;
54 }
55 #endif
56
57 #if defined(AFS_DARWIN80_ENV)
58 int ioctl_afs_syscall(long syscall, long param1, long param2, long param3, 
59                      long param4, long param5, long param6, int *rval) {
60   struct afssysargs syscall_data;
61   int code;
62   int fd = open(SYSCALL_DEV_FNAME, O_RDWR);
63   if(fd < 0)
64     return -1;
65
66   syscall_data.syscall = syscall;
67   syscall_data.param1 = param1;
68   syscall_data.param2 = param2;
69   syscall_data.param3 = param3;
70   syscall_data.param4 = param4;
71   syscall_data.param5 = param5;
72   syscall_data.param6 = param6;
73
74   code = ioctl(fd, VIOC_SYSCALL, &syscall_data);
75
76   close(fd);
77   if (code)
78      return code;
79   *rval=syscall_data.retval;
80   return 0;
81 }
82 #endif