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.15 1999-03-29 19:14:14 danw 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 <unistd.h> |
---|
26 | |
---|
27 | #include <afs/param.h> |
---|
28 | #include <afs/vice.h> |
---|
29 | #include <afs/venus.h> |
---|
30 | #include <afs/afsint.h> |
---|
31 | |
---|
32 | #include "quota.h" |
---|
33 | |
---|
34 | int get_afs_quota(struct quota_fs *fs, uid_t uid, int verbose) |
---|
35 | { |
---|
36 | static struct VolumeStatus vs; |
---|
37 | struct ViceIoctl ibuf; |
---|
38 | int code; |
---|
39 | uid_t euid = geteuid(); |
---|
40 | |
---|
41 | ibuf.out_size = sizeof(struct VolumeStatus); |
---|
42 | ibuf.in_size = 0; |
---|
43 | ibuf.out = (caddr_t)&vs; |
---|
44 | seteuid(getuid()); |
---|
45 | code = pioctl(fs->device, VIOCGETVOLSTAT, &ibuf, 1); |
---|
46 | seteuid(euid); |
---|
47 | if (code) |
---|
48 | { |
---|
49 | if (verbose || ((errno != EACCES) && (errno != EPERM))) |
---|
50 | { |
---|
51 | fprintf(stderr, "Error getting AFS quota: "); |
---|
52 | perror(fs->device); |
---|
53 | } |
---|
54 | return -1; |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | fs->have_quota = fs->have_blocks = 1; |
---|
59 | fs->have_files = 0; |
---|
60 | memset(&fs->dqb, 0, sizeof(fs->dqb)); |
---|
61 | |
---|
62 | /* Need to multiply by 2 to get 512 byte blocks instead of 1k */ |
---|
63 | fs->dqb.dqb_curblocks = vs.BlocksInUse * 2; |
---|
64 | fs->dqb.dqb_bsoftlimit = fs->dqb.dqb_bhardlimit = vs.MaxQuota * 2; |
---|
65 | |
---|
66 | if (vs.MaxQuota && (vs.BlocksInUse >= vs.MaxQuota * 9 / 10)) |
---|
67 | fs->warn_blocks = 1; |
---|
68 | return 0; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | void print_afs_warning(struct quota_fs *fs) |
---|
73 | { |
---|
74 | if (fs->dqb.dqb_curblocks > fs->dqb.dqb_bhardlimit) |
---|
75 | { |
---|
76 | printf("Over disk quota on %s, remove %dK.\n", fs->mount, |
---|
77 | (fs->dqb.dqb_curblocks - fs->dqb.dqb_bhardlimit) / 2); |
---|
78 | } |
---|
79 | else if (fs->dqb.dqb_curblocks > (fs->dqb.dqb_bhardlimit * 9 / 10)) |
---|
80 | { |
---|
81 | printf("%d%% of the disk quota on %s has been used.\n", |
---|
82 | (int)((fs->dqb.dqb_curblocks * 100.0 / |
---|
83 | fs->dqb.dqb_bhardlimit) + 0.5), |
---|
84 | fs->mount); |
---|
85 | } |
---|
86 | } |
---|