source: trunk/athena/bin/quota/afs.c @ 13620

Revision 13620, 2.5 KB checked in by danw, 25 years ago (diff)
warnsify
Line 
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
18static const char rcsid[] = "$Id: afs.c,v 1.16 1999-09-22 22:19:03 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 <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
35int get_afs_quota(struct quota_fs *fs, uid_t uid, int verbose)
36{
37  static struct VolumeStatus vs;
38  struct ViceIoctl ibuf;
39  int code;
40  uid_t euid = geteuid();
41
42  ibuf.out_size = sizeof(struct VolumeStatus);
43  ibuf.in_size = 0;
44  ibuf.out = (caddr_t)&vs;
45  seteuid(getuid());
46  code = pioctl(fs->device, VIOCGETVOLSTAT, &ibuf, 1);
47  seteuid(euid);
48  if (code)
49    {
50      if (verbose || ((errno != EACCES) && (errno != EPERM)))
51        {
52          fprintf(stderr, "Error getting AFS quota: ");
53          perror(fs->device);
54        }
55      return -1;
56    }
57  else
58    {
59      fs->have_quota = fs->have_blocks = 1;
60      fs->have_files = 0;
61      memset(&fs->dqb, 0, sizeof(fs->dqb));
62
63      /* Need to multiply by 2 to get 512 byte blocks instead of 1k */
64      fs->dqb.dqb_curblocks = vs.BlocksInUse * 2;
65      fs->dqb.dqb_bsoftlimit = fs->dqb.dqb_bhardlimit = vs.MaxQuota * 2;
66
67      if (vs.MaxQuota && (vs.BlocksInUse >= vs.MaxQuota * 9 / 10))
68        fs->warn_blocks = 1;
69      return 0;
70    }
71}
72
73void print_afs_warning(struct quota_fs *fs)
74{
75  if (fs->dqb.dqb_curblocks > fs->dqb.dqb_bhardlimit)
76    {
77      printf("Over disk quota on %s, remove %dK.\n", fs->mount,
78             (fs->dqb.dqb_curblocks - fs->dqb.dqb_bhardlimit) / 2);
79    }
80  else if (fs->dqb.dqb_curblocks > (fs->dqb.dqb_bhardlimit * 9 / 10))
81    {
82      printf("%d%% of the disk quota on %s has been used.\n",
83             (int)((fs->dqb.dqb_curblocks * 100.0 /
84                    fs->dqb.dqb_bhardlimit) + 0.5),
85             fs->mount);
86    }
87}
Note: See TracBrowser for help on using the repository browser.