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