[12786] | 1 | /* Copyright 1999 by the Massachusetts Institute of Technology. |
---|
[5949] | 2 | * |
---|
[12786] | 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. |
---|
[5342] | 14 | */ |
---|
| 15 | |
---|
[12786] | 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 | |
---|
[5949] | 20 | #include <sys/types.h> |
---|
[12786] | 21 | #include <sys/ioctl.h> |
---|
[6410] | 22 | #include <netinet/in.h> |
---|
[12786] | 23 | #include <errno.h> |
---|
| 24 | #include <stdio.h> |
---|
| 25 | #include <unistd.h> |
---|
[5342] | 26 | |
---|
| 27 | #include <afs/param.h> |
---|
[6829] | 28 | #include <afs/vice.h> |
---|
[5342] | 29 | #include <afs/venus.h> |
---|
| 30 | #include <afs/afsint.h> |
---|
| 31 | |
---|
[12786] | 32 | #include "quota.h" |
---|
[5949] | 33 | |
---|
[12786] | 34 | int get_afs_quota(struct quota_fs *fs, uid_t uid, int verbose) |
---|
[5342] | 35 | { |
---|
[12786] | 36 | static struct VolumeStatus vs; |
---|
| 37 | struct ViceIoctl ibuf; |
---|
| 38 | int code; |
---|
| 39 | uid_t euid = geteuid(); |
---|
[5342] | 40 | |
---|
[12786] | 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); |
---|
[5347] | 53 | } |
---|
[12786] | 54 | return -1; |
---|
[5343] | 55 | } |
---|
[12786] | 56 | else |
---|
| 57 | { |
---|
| 58 | fs->have_quota = fs->have_blocks = 1; |
---|
| 59 | fs->have_files = 0; |
---|
| 60 | memset(&fs->dqb, 0, sizeof(fs->dqb)); |
---|
[5949] | 61 | |
---|
[12786] | 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; |
---|
[5949] | 65 | |
---|
[12786] | 66 | if (vs.MaxQuota && (vs.BlocksInUse >= vs.MaxQuota * 9 / 10)) |
---|
| 67 | fs->warn_blocks = 1; |
---|
| 68 | return 0; |
---|
[5342] | 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
[12786] | 72 | void print_afs_warning(struct quota_fs *fs) |
---|
[5342] | 73 | { |
---|
[12786] | 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); |
---|
[5477] | 78 | } |
---|
[12786] | 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); |
---|
[6171] | 85 | } |
---|
[5477] | 86 | } |
---|