File: afsquota.c

package info (click to toggle)
libquota-perl 1.6.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 308 kB
  • ctags: 406
  • sloc: ansic: 888; perl: 768; makefile: 50; sh: 22
file content (174 lines) | stat: -rw-r--r-- 3,493 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 *  Interface to OpenAFS
 *
 *  Contributed 1998,2003 by Wolfgang Friebel <friebel@ifh.de>
 */

#if defined( __hpux)
#define IGNORE_STDS_H
#endif
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>

#define MAXSIZE 2048
#define MAXDNAME 2048

#include <afs/afsint.h>
#include <afs/venus.h>
#include <resolv.h>

#ifdef SunOS4
#define _VICEIOCTL(id)  ((unsigned int ) _IOW(V, id, struct ViceIoctl))
#endif


/*
 *  Check if AFS is installed
 */

int afs_check(void)
{
  struct  ViceIoctl vi;
  int32_t code;
  char space[MAXSIZE];
 
  vi.in_size = 0;
  vi.out_size = MAXSIZE;
  vi.out = (caddr_t) space;
  code = pioctl(NULL, VIOC_GET_WS_CELL, &vi, 0);
  return  ! code;
}


/*
 *  report quota
 */

int afs_getquota(char *path, int *maxQuota, int *blocksUsed)
{
    struct ViceIoctl a_params;
    struct VolumeStatus *vs;

    a_params.in_size  = 0;
    a_params.out_size = MAXSIZE;
    a_params.in       = NULL;
    a_params.out      = malloc(MAXSIZE);

    if (a_params.out == NULL) {
	errno = ENOMEM;
	return -1;
    }

    if (pioctl(path, VIOCGETVOLSTAT,&a_params,1) == -1) {
	free(a_params.out);
	return -1;
    }
  
    vs = (struct VolumeStatus *) a_params.out;

    *maxQuota   = vs->MaxQuota;
    *blocksUsed = vs->BlocksInUse;

    free(a_params.out);
    return 0;
}

/*
 * Usage: fs sq <path> <max quota in kbytes>
 */

int afs_setqlim(char *path, int maxQuota)
{
    struct ViceIoctl a_params;
    struct VolumeStatus *vs;
    int insize;

    a_params.in_size  = 0;
    a_params.out_size = MAXSIZE;
    a_params.in       = NULL;
    a_params.out      = malloc(MAXSIZE);

    if (a_params.out == NULL) {
	errno = ENOMEM;
	return -1;
    }

    /* Read the old volume status */
    if(pioctl(path,VIOCGETVOLSTAT,&a_params,1) == -1) {
	free(a_params.out);
	return -1;
    }

    insize = sizeof(struct VolumeStatus) + strlen(path) + 2;

    a_params.in_size  = ((MAXSIZE < insize) ? MAXSIZE : insize);
    a_params.out_size = 0;
    a_params.in       = a_params.out;
    a_params.out      = NULL;
  
    vs = (struct VolumeStatus *) a_params.in;
    vs->MaxQuota = maxQuota;

    if(pioctl(path,VIOCSETVOLSTAT,&a_params,1) == -1) {
	free(a_params.in);
	return -1;
    }

    free(a_params.in);
    return 0;
}

#ifdef __hpux
int sigvec( int sig, struct sigvec *vec, struct sigvec *ovec )
{
  return sigvector(sig, vec, ovec);
}
#endif

#ifdef STAND_ALONE
int main(int argc, char **argv)
{
    int usage, limit;

    if (afs_check()) {
      if (afs_getquota("/afs/ifh.de/user/z/zorner", &limit, &usage) == 0) {
        printf("limit=%d  usage=%d\n", limit, usage);
      }
      else
        perror("Not an AFS filesystem");
    }
    else {
      printf("No AFS available\n");
    }
}
#endif

/*
 *  Compiler options for standalone compilation
 */

/*
AIX:
cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb -lroken -lld

IRIX:
cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb   \
              -Wl,-rpath -Wl,/products/security/athena/lib

Linux:
cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb  \
              -Wl,-rpath -Wl,/products/security/athena/lib

HP-UX:
cc -Ae afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb

Solaris: (Workshop compiler)
cc afsquota.c -L/products/security/athena/lib -lkafs -ldes -lkrb  \
              -Wl,-R -Wl,/products/security/athena/lib

SunOS:
acc afsquota.c -U__STDC__ -DSunOS4 \
               -L/products/security/athena/lib -lkafs -ldes -lkrb
*/