1 /*
2  *  Interface to OpenAFS
3  *
4  *  Contributed 1998,2003 by Wolfgang Friebel <friebel@ifh.de>
5  */
6 
7 #if defined( __hpux)
8 #define IGNORE_STDS_H
9 #endif
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <errno.h>
13 #include <sys/ioctl.h>
14 
15 #define MAXSIZE 2048
16 #define MAXDNAME 2048
17 
18 #include <afs/afsint.h>
19 #include <afs/venus.h>
20 #include <resolv.h>
21 
22 #ifdef SunOS4
23 #define _VICEIOCTL(id)  ((unsigned int ) _IOW(V, id, struct ViceIoctl))
24 #endif
25 
26 
27 /*
28  *  Check if AFS is installed
29  */
30 
afs_check(void)31 int afs_check(void)
32 {
33   struct  ViceIoctl vi;
34   int32_t code;
35   char space[MAXSIZE];
36 
37   vi.in_size = 0;
38   vi.out_size = MAXSIZE;
39   vi.out = (caddr_t) space;
40   code = pioctl(NULL, VIOC_GET_WS_CELL, &vi, 0);
41   return  ! code;
42 }
43 
44 
45 /*
46  *  report quota
47  */
48 
afs_getquota(char * path,int * maxQuota,int * blocksUsed)49 int afs_getquota(char *path, int *maxQuota, int *blocksUsed)
50 {
51     struct ViceIoctl a_params;
52     struct VolumeStatus *vs;
53 
54     a_params.in_size  = 0;
55     a_params.out_size = MAXSIZE;
56     a_params.in       = NULL;
57     a_params.out      = malloc(MAXSIZE);
58 
59     if (a_params.out == NULL) {
60 	errno = ENOMEM;
61 	return -1;
62     }
63 
64     if (pioctl(path, VIOCGETVOLSTAT,&a_params,1) == -1) {
65 	free(a_params.out);
66 	return -1;
67     }
68 
69     vs = (struct VolumeStatus *) a_params.out;
70 
71     *maxQuota   = vs->MaxQuota;
72     *blocksUsed = vs->BlocksInUse;
73 
74     free(a_params.out);
75     return 0;
76 }
77 
78 /*
79  * Usage: fs sq <path> <max quota in kbytes>
80  */
81 
afs_setqlim(char * path,int maxQuota)82 int afs_setqlim(char *path, int maxQuota)
83 {
84     struct ViceIoctl a_params;
85     struct VolumeStatus *vs;
86     int insize;
87 
88     a_params.in_size  = 0;
89     a_params.out_size = MAXSIZE;
90     a_params.in       = NULL;
91     a_params.out      = malloc(MAXSIZE);
92 
93     if (a_params.out == NULL) {
94 	errno = ENOMEM;
95 	return -1;
96     }
97 
98     /* Read the old volume status */
99     if(pioctl(path,VIOCGETVOLSTAT,&a_params,1) == -1) {
100 	free(a_params.out);
101 	return -1;
102     }
103 
104     insize = sizeof(struct VolumeStatus) + strlen(path) + 2;
105 
106     a_params.in_size  = ((MAXSIZE < insize) ? MAXSIZE : insize);
107     a_params.out_size = 0;
108     a_params.in       = a_params.out;
109     a_params.out      = NULL;
110 
111     vs = (struct VolumeStatus *) a_params.in;
112     vs->MaxQuota = maxQuota;
113 
114     if(pioctl(path,VIOCSETVOLSTAT,&a_params,1) == -1) {
115 	free(a_params.in);
116 	return -1;
117     }
118 
119     free(a_params.in);
120     return 0;
121 }
122 
123 #ifdef __hpux
sigvec(int sig,struct sigvec * vec,struct sigvec * ovec)124 int sigvec( int sig, struct sigvec *vec, struct sigvec *ovec )
125 {
126   return sigvector(sig, vec, ovec);
127 }
128 #endif
129 
130 #ifdef STAND_ALONE
main(int argc,char ** argv)131 int main(int argc, char **argv)
132 {
133     int usage, limit;
134 
135     if (afs_check()) {
136       if (afs_getquota("/afs/ifh.de/user/z/zorner", &limit, &usage) == 0) {
137         printf("limit=%d  usage=%d\n", limit, usage);
138       }
139       else
140         perror("Not an AFS filesystem");
141     }
142     else {
143       printf("No AFS available\n");
144     }
145 }
146 #endif
147 
148 /*
149  *  Compiler options for standalone compilation
150  */
151 
152 /*
153 AIX:
154 cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb -lroken -lld
155 
156 IRIX:
157 cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb   \
158               -Wl,-rpath -Wl,/products/security/athena/lib
159 
160 Linux:
161 cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb  \
162               -Wl,-rpath -Wl,/products/security/athena/lib
163 
164 HP-UX:
165 cc -Ae afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb
166 
167 Solaris: (Workshop compiler)
168 cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb  \
169               -Wl,-R -Wl,/products/security/athena/lib
170 
171 SunOS:
172 acc afsquota.c -U__STDC__ -DSunOS4 \
173                -L/products/security/athena/lib -lkafs -ldes -lkrb
174 */
175