1 | /* Copyright 1999 by the Massachusetts Institute of Technology. |
---|
2 | * |
---|
3 | * Permission to use, copy, modify, and distribute this |
---|
4 | * software and its documentation for any purpose and without |
---|
5 | * fee is hereby granted, provided that the above copyright |
---|
6 | * notice appear in all copies and that both that copyright |
---|
7 | * notice and this permission notice appear in supporting |
---|
8 | * documentation, and that the name of M.I.T. not be used in |
---|
9 | * advertising or publicity pertaining to distribution of the |
---|
10 | * software without specific, written prior permission. |
---|
11 | * M.I.T. makes no representations about the suitability of |
---|
12 | * this software for any purpose. It is provided "as is" |
---|
13 | * without express or implied warranty. |
---|
14 | */ |
---|
15 | |
---|
16 | /* This contains the AFS quota-checking routines. */ |
---|
17 | |
---|
18 | static const char rcsid[] = "$Id: afs.c,v 1.17 2004-12-16 17:19:21 zacheiss Exp $"; |
---|
19 | |
---|
20 | #include <sys/types.h> |
---|
21 | #include <sys/ioctl.h> |
---|
22 | #include <netinet/in.h> |
---|
23 | #include <errno.h> |
---|
24 | #include <stdio.h> |
---|
25 | #include <string.h> |
---|
26 | #include <unistd.h> |
---|
27 | |
---|
28 | #include <afs/param.h> |
---|
29 | #include <afs/vice.h> |
---|
30 | #include <afs/venus.h> |
---|
31 | #include <afs/afsint.h> |
---|
32 | |
---|
33 | #include "quota.h" |
---|
34 | |
---|
35 | #define MAXSIZE 2048 |
---|
36 | |
---|
37 | int get_afs_quota(struct quota_fs *fs, uid_t uid, int verbose) |
---|
38 | { |
---|
39 | static struct VolumeStatus *vs; |
---|
40 | struct ViceIoctl ibuf; |
---|
41 | int code; |
---|
42 | uid_t euid = geteuid(); |
---|
43 | |
---|
44 | ibuf.out_size = MAXSIZE; |
---|
45 | ibuf.in_size = 0; |
---|
46 | ibuf.out = malloc(MAXSIZE); |
---|
47 | seteuid(getuid()); |
---|
48 | code = pioctl(fs->device, VIOCGETVOLSTAT, &ibuf, 1); |
---|
49 | seteuid(euid); |
---|
50 | if (code) |
---|
51 | { |
---|
52 | if (verbose || ((errno != EACCES) && (errno != EPERM))) |
---|
53 | { |
---|
54 | fprintf(stderr, "Error getting AFS quota: "); |
---|
55 | perror(fs->device); |
---|
56 | } |
---|
57 | free(ibuf.out); |
---|
58 | return -1; |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | fs->have_quota = fs->have_blocks = 1; |
---|
63 | fs->have_files = 0; |
---|
64 | memset(&fs->dqb, 0, sizeof(fs->dqb)); |
---|
65 | |
---|
66 | vs = (VolumeStatus *) ibuf.out; |
---|
67 | |
---|
68 | /* Need to multiply by 2 to get 512 byte blocks instead of 1k */ |
---|
69 | fs->dqb.dqb_curblocks = vs->BlocksInUse * 2; |
---|
70 | fs->dqb.dqb_bsoftlimit = fs->dqb.dqb_bhardlimit = vs->MaxQuota * 2; |
---|
71 | |
---|
72 | if (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota * 9 / 10)) |
---|
73 | fs->warn_blocks = 1; |
---|
74 | free(ibuf.out); |
---|
75 | return 0; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void print_afs_warning(struct quota_fs *fs) |
---|
80 | { |
---|
81 | if (fs->dqb.dqb_curblocks > fs->dqb.dqb_bhardlimit) |
---|
82 | { |
---|
83 | printf("Over disk quota on %s, remove %dK.\n", fs->mount, |
---|
84 | (fs->dqb.dqb_curblocks - fs->dqb.dqb_bhardlimit) / 2); |
---|
85 | } |
---|
86 | else if (fs->dqb.dqb_curblocks > (fs->dqb.dqb_bhardlimit * 9 / 10)) |
---|
87 | { |
---|
88 | printf("%d%% of the disk quota on %s has been used.\n", |
---|
89 | (int)((fs->dqb.dqb_curblocks * 100.0 / |
---|
90 | fs->dqb.dqb_bhardlimit) + 0.5), |
---|
91 | fs->mount); |
---|
92 | } |
---|
93 | } |
---|