source: trunk/athena/bin/xquota/handler.c @ 1760

Revision 1760, 5.2 KB checked in by kit, 35 years ago (diff)
support for users w/o quota.
Line 
1/*
2 * xquota -  X window system quota display program.
3 *
4 * $Athena: handler.c,v 1.1 89/03/05 20:58:19 kit Locked $
5 *
6 * Copyright 1989 Massachusetts Institute of Technology
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted, provided
10 * that the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of M.I.T. not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission.  M.I.T. makes no representations about the
15 * suitability of this software for any purpose.  It is provided "as is"
16 * without express or implied warranty.
17 *
18 * Author:    Chris D. Peterson, MIT Project Athena
19 * Created:   March 5, 1989
20 */
21
22#if ( !defined(lint) && !defined(SABER))
23  static char rcs_version[] = "$Athena: handler.c,v 1.1 89/03/05 20:58:19 kit Locked $";
24#endif
25
26#include <stdio.h>
27#include <sys/time.h>
28
29#include <sys/param.h>
30#include <ufs/quota.h>
31
32#include <X11/Intrinsic.h>
33
34#include "xquota.h"
35
36#define kb(n)   (howmany(dbtob(n), 1024))
37
38static void DisplayInfo(), SetQuotaDisplay();
39
40/*      Function Name: ShowQuota()
41 *      Description: Shows the quota to the user.
42 *      Arguments: none.
43 *      Returns: none.
44 */
45
46void ShowQuota(info)
47Info * info;
48{
49  struct dqblk quota_info;
50  int ret_val;
51
52  SetTimeOut(info);
53
54  ret_val = getnfsquota(info->host, info->path, info->uid, &quota_info);
55  if (ret_val == QUOTA_NONE) {
56    printf("You do not have a quota on your home file system.\n");
57    printf("Filesystem: %s:%s\n", info->host, info->path);
58    exit(1);
59  }
60
61  if (ret_val == QUOTA_PERMISSION) {
62    printf("You do not have permission to get quota information on the\n");
63    printf("filesystem: %s:%s.\n", info->host, info->path);
64    exit(1);
65  }
66
67  if (ret_val == QUOTA_ERROR) {
68    printf("Error in quota checking, trying again.\n");
69    ret_val = getnfsquota(info->host, info->path, info->uid, &quota_info);
70    if (ret_val != QUOTA_OK) {
71      printf("Quota check failed twice in a row, giving up.\n");
72      exit(1);
73    }
74  }
75
76  if (info->numbers && !info->space_saver) {
77    char buf[BUFSIZ];
78    sprintf(buf, "Quota: %5dK", (int) kb(quota_info.dqb_bsoftlimit));
79    SetLabel(info->quota_top, buf);
80    sprintf(buf, " Used: %5dK", (int) kb(quota_info.dqb_curblocks));
81    SetLabel(info->used_top, buf);
82  }
83  SetGraph(info, info->graph, (int) kb(quota_info.dqb_bsoftlimit),
84           (int) kb(quota_info.dqb_curblocks));
85
86  DisplayInfo(info, &quota_info);
87  if ( quota_info.dqb_curblocks > quota_info.dqb_bsoftlimit)
88    XtPopup(info->info_popup, XtGrabNone);
89}
90
91/*      Function Name: DisplayInfo
92 *      Description: Displays information.
93 *      Arguments: info - the info struct.
94 *      Returns: none.
95 */
96
97static void
98DisplayInfo(info, quota_info)
99Info * info;
100struct dqblk * quota_info;
101{
102  long now;
103  char buf[BUFSIZ];
104
105  SetQuotaDisplay(info->hard_widget, "Hard Limit:",
106                  (int) kb(quota_info->dqb_bhardlimit),
107                  (int) quota_info->dqb_fhardlimit);
108
109  SetQuotaDisplay(info->soft_widget, "Soft Limit:",
110                  (int) kb(quota_info->dqb_bsoftlimit),
111                  (int) quota_info->dqb_fsoftlimit);
112
113  SetQuotaDisplay(info->used_widget, "Current:",
114                  (int) kb(quota_info->dqb_curblocks),
115                  (int) quota_info->dqb_curfiles);
116
117  (void) time(&now);
118  strcpy(buf, "Last Quota Check: ");
119  strncat(buf, ctime(&now), 16);
120  SetLabel(info->last_widget, buf);
121
122/*
123 * Determine which message to give.  If you are over both you file and
124 * block quota you will only get a message about the blocks, oh well.
125 */
126 
127  if (quota_info->dqb_curblocks > quota_info->dqb_bsoftlimit) {
128    int kbytes = (int) kb(quota_info->dqb_curblocks -
129                          quota_info->dqb_bsoftlimit);
130    if ( (kb(quota_info->dqb_curblocks) >=
131                                       (kb(quota_info->dqb_bhardlimit) - 5))||
132         (quota_info->dqb_btimelimit <= now) ) {
133      sprintf(buf, EXCEEDED_HARD, kbytes, "kilobytes");
134    }
135    else {
136      sprintf(buf, EXCEEDED_SOFT, kbytes, "kilobytes",
137              ctime(&quota_info->dqb_btimelimit));
138    }
139    SetTextMessage(info->message_widget, buf);
140  }
141  else if ( quota_info->dqb_curfiles > quota_info->dqb_fsoftlimit ) {
142    int files = quota_info->dqb_curfiles - quota_info->dqb_fsoftlimit;
143    if ( (quota_info->dqb_curfiles >= (quota_info->dqb_fhardlimit - 10))  ||
144         (quota_info->dqb_ftimelimit <= now) ) {
145      sprintf(buf, EXCEEDED_HARD, files, "files");
146    }
147    else {
148      sprintf(buf, EXCEEDED_SOFT, files, "files",
149              ctime(&quota_info->dqb_ftimelimit));
150    }
151    SetTextMessage(info->message_widget, buf);
152  }
153  else if (info->flipped)
154    SetTextMessage(info->message_widget, WARNING_MESSAGE);
155  else
156    SetTextMessage(info->message_widget, SAFE_MESSAGE);
157}
158
159/*      Function Name: SetQuotaDisplay
160 *      Description: Sets the Quota Display.
161 *      Arguments: w - the widget to display this in.
162 *                 string - string to preface this with.
163 *                 bytes - number of bytes.
164 *                 files - number of files.
165 *      Returns: none
166 */
167
168static void
169SetQuotaDisplay( w, string, bytes, files )
170Widget w;
171char * string;
172int bytes, files;
173{
174  char buf[BUFSIZ];
175 
176  sprintf(buf, "%12s %10d %10d", string, bytes, files);
177  SetLabel(w, buf);
178}
179 
Note: See TracBrowser for help on using the repository browser.