[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 | |
---|
[21184] | 18 | static const char rcsid[] = "$Id: afs.c,v 1.17 2004-12-16 17:19:21 zacheiss Exp $"; |
---|
[12786] | 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> |
---|
[13620] | 25 | #include <string.h> |
---|
[12786] | 26 | #include <unistd.h> |
---|
[5342] | 27 | |
---|
| 28 | #include <afs/param.h> |
---|
[6829] | 29 | #include <afs/vice.h> |
---|
[5342] | 30 | #include <afs/venus.h> |
---|
| 31 | #include <afs/afsint.h> |
---|
| 32 | |
---|
[12786] | 33 | #include "quota.h" |
---|
[5949] | 34 | |
---|
[21184] | 35 | #define MAXSIZE 2048 |
---|
| 36 | |
---|
[12786] | 37 | int get_afs_quota(struct quota_fs *fs, uid_t uid, int verbose) |
---|
[5342] | 38 | { |
---|
[21184] | 39 | static struct VolumeStatus *vs; |
---|
[12786] | 40 | struct ViceIoctl ibuf; |
---|
| 41 | int code; |
---|
| 42 | uid_t euid = geteuid(); |
---|
[5342] | 43 | |
---|
[21184] | 44 | ibuf.out_size = MAXSIZE; |
---|
[12786] | 45 | ibuf.in_size = 0; |
---|
[21184] | 46 | ibuf.out = malloc(MAXSIZE); |
---|
[12786] | 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); |
---|
[5347] | 56 | } |
---|
[21184] | 57 | free(ibuf.out); |
---|
[12786] | 58 | return -1; |
---|
[5343] | 59 | } |
---|
[12786] | 60 | else |
---|
| 61 | { |
---|
| 62 | fs->have_quota = fs->have_blocks = 1; |
---|
| 63 | fs->have_files = 0; |
---|
| 64 | memset(&fs->dqb, 0, sizeof(fs->dqb)); |
---|
[5949] | 65 | |
---|
[21184] | 66 | vs = (VolumeStatus *) ibuf.out; |
---|
| 67 | |
---|
[12786] | 68 | /* Need to multiply by 2 to get 512 byte blocks instead of 1k */ |
---|
[21184] | 69 | fs->dqb.dqb_curblocks = vs->BlocksInUse * 2; |
---|
| 70 | fs->dqb.dqb_bsoftlimit = fs->dqb.dqb_bhardlimit = vs->MaxQuota * 2; |
---|
[5949] | 71 | |
---|
[21184] | 72 | if (vs->MaxQuota && (vs->BlocksInUse >= vs->MaxQuota * 9 / 10)) |
---|
[12786] | 73 | fs->warn_blocks = 1; |
---|
[21184] | 74 | free(ibuf.out); |
---|
[12786] | 75 | return 0; |
---|
[5342] | 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
[12786] | 79 | void print_afs_warning(struct quota_fs *fs) |
---|
[5342] | 80 | { |
---|
[12786] | 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); |
---|
[5477] | 85 | } |
---|
[12786] | 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); |
---|
[6171] | 92 | } |
---|
[5477] | 93 | } |
---|