source: trunk/athena/bin/quota/afs.c @ 6829

Revision 6829, 2.7 KB checked in by probe, 31 years ago (diff)
Solaris port (include files)
Line 
1/*
2 * AFS quota routines
3 *
4 * $Id: afs.c,v 1.13 1993-07-25 01:25:10 probe Exp $
5 */
6
7#include <stdio.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <netinet/in.h>
11
12#include <sys/ioctl.h>
13#include <afs/param.h>
14#include <afs/vice.h>
15#include <afs/venus.h>
16#include <afs/afsint.h>
17
18#ifdef SOLARIS
19#include <sys/ioccom.h>
20#endif
21#ifdef _IBMR2
22#include <sys/id.h>
23#endif
24
25extern int uflag,gflag,fsind;
26extern char *fslist[];
27extern int heading_printed;
28
29#define user_and_groups (!uflag && !gflag)
30
31void *
32getafsquota(path, explicit)
33    char *path;
34    int explicit;
35{
36    static struct VolumeStatus vs;
37    struct ViceIoctl ibuf;
38    int code;
39
40#ifdef _IBMR2
41    setuidx(ID_EFFECTIVE, getuidx(ID_REAL));
42#else
43    setreuid(geteuid(), getuid());
44#endif
45
46    ibuf.out_size=sizeof(struct VolumeStatus);
47    ibuf.in_size=0;
48    ibuf.out=(caddr_t) &vs;
49    code = pioctl(path, VIOCGETVOLSTAT, &ibuf, 1);
50    if (code) {
51        if (explicit || ((errno != EACCES) && (errno != EPERM))) {
52            fprintf(stderr, "Error getting AFS quota: ");
53            perror(path);
54        }
55    }
56
57#ifdef _IBMR2
58    setuidx(ID_EFFECTIVE, getuidx(ID_SAVED));
59#else
60    setreuid(geteuid(), getuid());
61#endif
62
63    return(code ? (void *)0 : (void *)&vs);
64}
65
66void
67prafsquota(path,foo,heading_id,heading_name)
68    char *path;
69    void *foo;
70    int heading_id;
71    char *heading_name;
72{
73    struct VolumeStatus *vs;
74    char *cp;
75
76    vs = (struct VolumeStatus *) foo;
77    cp = path;
78    if (!user_and_groups) {
79        if (!heading_printed) simpleheading(heading_id,heading_name);
80        if (strlen(path) > 15){
81            printf("%s\n",cp);
82            cp = "";
83        }
84        printf("%-14s %5d%7d%7d%12s\n",
85               cp,
86               vs->BlocksInUse,
87               vs->MaxQuota,
88               vs->MaxQuota,
89               (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota)
90                ? "Expired" : ""));
91    } else {
92        if (!heading_printed) heading(heading_id,heading_name);
93        if (strlen(cp) > 15){
94            printf("%s\n", cp);
95            cp =  "";
96        }
97        printf("%-15s %-17s %6d %6d %6d%-2s\n",
98               cp, "volume",
99               vs->BlocksInUse,
100               vs->MaxQuota,
101               vs->MaxQuota,
102               (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota * 9 / 10)
103                ? "<<" : ""));
104    }
105}
106
107void
108afswarn(path,foo,name)
109    char *path;
110    void *foo;
111    char *name;
112{
113    struct VolumeStatus *vs;
114    char buf[1024];
115    int i;
116    uid_t uid=getuid();
117
118    vs = (struct VolumeStatus *) foo;
119
120    if (vs->MaxQuota && (vs->BlocksInUse > vs->MaxQuota)) {
121        sprintf(buf,"Over disk quota on %s, remove %dK.\n",
122                path, (vs->BlocksInUse - vs->MaxQuota));
123        putwarning(buf);
124    }
125    else if (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota * 9 / 10)) {
126        sprintf(buf,"%d%% of the disk quota on %s has been used.\n",
127                (int)((vs->BlocksInUse*100.0/vs->MaxQuota)+0.5), path);
128        putwarning(buf);
129    }
130}
Note: See TracBrowser for help on using the repository browser.