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

Revision 13620, 2.5 KB checked in by danw, 25 years ago (diff)
warnsify
RevLine 
[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
[13620]18static const char rcsid[] = "$Id: afs.c,v 1.16 1999-09-22 22:19:03 danw 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
[12786]35int get_afs_quota(struct quota_fs *fs, uid_t uid, int verbose)
[5342]36{
[12786]37  static struct VolumeStatus vs;
38  struct ViceIoctl ibuf;
39  int code;
40  uid_t euid = geteuid();
[5342]41
[12786]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);
[5347]54        }
[12786]55      return -1;
[5343]56    }
[12786]57  else
58    {
59      fs->have_quota = fs->have_blocks = 1;
60      fs->have_files = 0;
61      memset(&fs->dqb, 0, sizeof(fs->dqb));
[5949]62
[12786]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;
[5949]66
[12786]67      if (vs.MaxQuota && (vs.BlocksInUse >= vs.MaxQuota * 9 / 10))
68        fs->warn_blocks = 1;
69      return 0;
[5342]70    }
71}
72
[12786]73void print_afs_warning(struct quota_fs *fs)
[5342]74{
[12786]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);
[5477]79    }
[12786]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);
[6171]86    }
[5477]87}
Note: See TracBrowser for help on using the repository browser.