fix-includes-20060810
[openafs.git] / src / kopenafs / kopenafs.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
10 /*
11  * Glue code for the kopenafs API.  Mostly just wrappers around the functions
12  * included in the libsys code.
13  */
14
15 #include <sys/param.h>
16 #include <netinet/in.h>
17 #include <errno.h>
18 #include <stdlib.h>
19 #include <signal.h>
20
21 #include <afsconfig.h>
22 #include <afs/afssyscalls.h>
23 #include <kopenafs.h>
24
25 static volatile sig_atomic_t syscall_okay = 1;
26
27 /* Signal handler to catch failed system calls and change the okay flag. */
28 #ifdef SIGSYS
29 static RETSIGTYPE
30 sigsys_handler(int s)
31 {
32     syscall_okay = 0;
33     signal(SIGSYS, sigsys_handler);
34 }
35 #endif /* SIGSYS */
36
37 int
38 k_hasafs(void)
39 {
40     struct ViceIoctl iob;
41     int okay, saved_errno;
42     RETSIGTYPE (*saved_func)(int);
43
44     saved_errno = errno;
45
46 #ifdef SIGSYS
47     saved_func = signal(SIGSYS, sigsys_handler);
48 #endif
49
50     iob.in = NULL;
51     iob.in_size = 0;
52     iob.out = NULL;
53     iob.out_size = 0;
54     lpioctl(NULL, VIOCSETTOK, (char *) &iob, 0);
55
56 #ifdef SIGSYS
57     signal(SIGSYS, saved_func);
58 #endif
59
60     okay = 1;
61     if (!syscall_okay || errno != EINVAL)
62         okay = 0;
63     errno = saved_errno;
64     return okay;
65 }
66
67 int
68 k_setpag(void)
69 {
70     return lsetpag();
71 }
72
73 int
74 k_pioctl(char *path, int cmd, struct ViceIoctl *cmarg, int follow)
75 {
76     return lpioctl(path, cmd, (char *) cmarg, follow);
77 }
78
79 int
80 k_unlog(void)
81 {
82     struct ViceIoctl iob;
83
84     iob.in = NULL;
85     iob.in_size = 0;
86     iob.out = NULL;
87     iob.out_size = 0;
88     return lpioctl(NULL, VIOCUNLOG, (char *) &iob, 0);
89 }