File: afsquota.c

package info (click to toggle)
libquota-perl 1.4.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 224 kB
  • ctags: 358
  • sloc: ansic: 803; perl: 524; makefile: 55
file content (171 lines) | stat: -rw-r--r-- 3,493 bytes parent folder | download
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
/*
 *  Interface to AFS with the arla package and Kerberos authentication
 */

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#if defined( sparc )
#include <sys/ioccom.h>
#endif

#define MAXSIZE 2048

#include <ktypes.h>
#include <kafs.h>

/* #include "../arla-0.13/appl/fs_local.h" */
struct VolumeStatus {
    int32_t   Vid;
    int32_t   ParentId;
    char      Online;
    char      InService;
    char      Blessed;
    char      NeedsSalvage;
    int32_t   Type;
    int32_t   MinQuota;
    int32_t   MaxQuota;
    int32_t   BlocksInUse;
    int32_t   PartBlocksAvail;
    int32_t   PartMaxBlocks;
};

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


/*
 *  Check if AFS is installed
 */

int afs_check(void)
{
    return k_hasafs();
}


/*
 *  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 (k_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(k_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(k_pioctl(path,VIOCSETVOLSTAT,&a_params,1) == -1) {
	free(a_params.in);
	return -1;
    }

    free(a_params.in);
    return 0;
}

#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
*/