1 | /* |
---|
2 | * AFS quota routines |
---|
3 | * |
---|
4 | * $Id: afs.c,v 1.14 1998-01-08 06:02:32 ghudson 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 | |
---|
25 | extern int uflag,gflag,fsind; |
---|
26 | extern char *fslist[]; |
---|
27 | extern int heading_printed; |
---|
28 | |
---|
29 | #define user_and_groups (!uflag && !gflag) |
---|
30 | |
---|
31 | void * |
---|
32 | getafsquota(path, explicit) |
---|
33 | char *path; |
---|
34 | int explicit; |
---|
35 | { |
---|
36 | static struct VolumeStatus vs; |
---|
37 | struct ViceIoctl ibuf; |
---|
38 | int code; |
---|
39 | uid_t euid = geteuid(); |
---|
40 | |
---|
41 | seteuid(getuid()); |
---|
42 | |
---|
43 | ibuf.out_size=sizeof(struct VolumeStatus); |
---|
44 | ibuf.in_size=0; |
---|
45 | ibuf.out=(caddr_t) &vs; |
---|
46 | code = pioctl(path, VIOCGETVOLSTAT, &ibuf, 1); |
---|
47 | if (code) { |
---|
48 | if (explicit || ((errno != EACCES) && (errno != EPERM))) { |
---|
49 | fprintf(stderr, "Error getting AFS quota: "); |
---|
50 | perror(path); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | seteuid(euid); |
---|
55 | |
---|
56 | return(code ? (void *)0 : (void *)&vs); |
---|
57 | } |
---|
58 | |
---|
59 | void |
---|
60 | prafsquota(path,foo,heading_id,heading_name) |
---|
61 | char *path; |
---|
62 | void *foo; |
---|
63 | int heading_id; |
---|
64 | char *heading_name; |
---|
65 | { |
---|
66 | struct VolumeStatus *vs; |
---|
67 | char *cp; |
---|
68 | |
---|
69 | vs = (struct VolumeStatus *) foo; |
---|
70 | cp = path; |
---|
71 | if (!user_and_groups) { |
---|
72 | if (!heading_printed) simpleheading(heading_id,heading_name); |
---|
73 | if (strlen(path) > 15){ |
---|
74 | printf("%s\n",cp); |
---|
75 | cp = ""; |
---|
76 | } |
---|
77 | printf("%-14s %5d%7d%7d%12s\n", |
---|
78 | cp, |
---|
79 | vs->BlocksInUse, |
---|
80 | vs->MaxQuota, |
---|
81 | vs->MaxQuota, |
---|
82 | (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota) |
---|
83 | ? "Expired" : "")); |
---|
84 | } else { |
---|
85 | if (!heading_printed) heading(heading_id,heading_name); |
---|
86 | if (strlen(cp) > 15){ |
---|
87 | printf("%s\n", cp); |
---|
88 | cp = ""; |
---|
89 | } |
---|
90 | printf("%-15s %-17s %6d %6d %6d%-2s\n", |
---|
91 | cp, "volume", |
---|
92 | vs->BlocksInUse, |
---|
93 | vs->MaxQuota, |
---|
94 | vs->MaxQuota, |
---|
95 | (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota * 9 / 10) |
---|
96 | ? "<<" : "")); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | void |
---|
101 | afswarn(path,foo,name) |
---|
102 | char *path; |
---|
103 | void *foo; |
---|
104 | char *name; |
---|
105 | { |
---|
106 | struct VolumeStatus *vs; |
---|
107 | char buf[1024]; |
---|
108 | int i; |
---|
109 | uid_t uid=getuid(); |
---|
110 | |
---|
111 | vs = (struct VolumeStatus *) foo; |
---|
112 | |
---|
113 | if (vs->MaxQuota && (vs->BlocksInUse > vs->MaxQuota)) { |
---|
114 | sprintf(buf,"Over disk quota on %s, remove %dK.\n", |
---|
115 | path, (vs->BlocksInUse - vs->MaxQuota)); |
---|
116 | putwarning(buf); |
---|
117 | } |
---|
118 | else if (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota * 9 / 10)) { |
---|
119 | sprintf(buf,"%d%% of the disk quota on %s has been used.\n", |
---|
120 | (int)((vs->BlocksInUse*100.0/vs->MaxQuota)+0.5), path); |
---|
121 | putwarning(buf); |
---|
122 | } |
---|
123 | } |
---|