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 | #ifdef SOLARIS |
---|
31 | #include <sys/fs/ufs_quota.h> |
---|
32 | #else |
---|
33 | #include <ufs/quota.h> |
---|
34 | #endif |
---|
35 | |
---|
36 | #include <X11/Intrinsic.h> |
---|
37 | |
---|
38 | #include "xquota.h" |
---|
39 | |
---|
40 | #define kb(n) (howmany(dbtob(n), 1024)) |
---|
41 | |
---|
42 | static void DisplayInfo(), SetQuotaDisplay(); |
---|
43 | |
---|
44 | /* Function Name: ShowQuota() |
---|
45 | * Description: Shows the quota to the user. |
---|
46 | * Arguments: none. |
---|
47 | * Returns: none. |
---|
48 | */ |
---|
49 | |
---|
50 | void ShowQuota(info) |
---|
51 | Info * info; |
---|
52 | { |
---|
53 | struct dqblk quota_info; |
---|
54 | int ret_val; |
---|
55 | extern int homeIsAFS; |
---|
56 | int (*qfunc)(); |
---|
57 | int getnfsquota(); |
---|
58 | int getafsquota(); |
---|
59 | |
---|
60 | SetTimeOut(info); |
---|
61 | |
---|
62 | qfunc = homeIsAFS ? getafsquota : getnfsquota; |
---|
63 | ret_val = (*qfunc)(info->host, info->path, info->uid, "a_info); |
---|
64 | if (ret_val == QUOTA_NONE) { |
---|
65 | printf("You do not have a quota on your home file system.\n"); |
---|
66 | printf("Filesystem: %s:%s\n", info->host, info->path); |
---|
67 | exit(1); |
---|
68 | } |
---|
69 | |
---|
70 | if (ret_val == QUOTA_PERMISSION) { |
---|
71 | printf("You do not have permission to get quota information on the\n"); |
---|
72 | printf("filesystem: %s:%s.\n", info->host, info->path); |
---|
73 | exit(1); |
---|
74 | } |
---|
75 | |
---|
76 | if (ret_val == QUOTA_ERROR) { |
---|
77 | printf("Error in quota checking, trying again.\n"); |
---|
78 | ret_val = (*qfunc)(info->host, info->path, info->uid, "a_info); |
---|
79 | if (ret_val != QUOTA_OK) { |
---|
80 | printf("Quota check failed twice in a row, giving up.\n"); |
---|
81 | exit(1); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | if (info->numbers && !info->space_saver) { |
---|
86 | char buf[BUFSIZ]; |
---|
87 | sprintf(buf, "Quota: %5dK", (int) kb(quota_info.dqb_bsoftlimit)); |
---|
88 | SetLabel(info->quota_top, buf); |
---|
89 | sprintf(buf, " Used: %5dK", (int) kb(quota_info.dqb_curblocks)); |
---|
90 | SetLabel(info->used_top, buf); |
---|
91 | } |
---|
92 | SetGraph(info, info->graph, (int) kb(quota_info.dqb_bsoftlimit), |
---|
93 | (int) kb(quota_info.dqb_curblocks)); |
---|
94 | |
---|
95 | DisplayInfo(info, "a_info); |
---|
96 | if ( quota_info.dqb_curblocks > quota_info.dqb_bsoftlimit) |
---|
97 | XtPopup(info->info_popup, XtGrabNone); |
---|
98 | } |
---|
99 | |
---|
100 | /* Function Name: DisplayInfo |
---|
101 | * Description: Displays information. |
---|
102 | * Arguments: info - the info struct. |
---|
103 | * Returns: none. |
---|
104 | */ |
---|
105 | |
---|
106 | static void |
---|
107 | DisplayInfo(info, quota_info) |
---|
108 | Info * info; |
---|
109 | struct dqblk * quota_info; |
---|
110 | { |
---|
111 | long now; |
---|
112 | char buf[BUFSIZ]; |
---|
113 | |
---|
114 | SetQuotaDisplay(info->hard_widget, "Hard Limit:", |
---|
115 | (int) kb(quota_info->dqb_bhardlimit), |
---|
116 | (int) quota_info->dqb_fhardlimit); |
---|
117 | |
---|
118 | SetQuotaDisplay(info->soft_widget, "Soft Limit:", |
---|
119 | (int) kb(quota_info->dqb_bsoftlimit), |
---|
120 | (int) quota_info->dqb_fsoftlimit); |
---|
121 | |
---|
122 | SetQuotaDisplay(info->used_widget, "Current:", |
---|
123 | (int) kb(quota_info->dqb_curblocks), |
---|
124 | (int) quota_info->dqb_curfiles); |
---|
125 | |
---|
126 | (void) time(&now); |
---|
127 | strcpy(buf, "Last Quota Check: "); |
---|
128 | strncat(buf, ctime(&now), 16); |
---|
129 | SetLabel(info->last_widget, buf); |
---|
130 | |
---|
131 | /* |
---|
132 | * Determine which message to give. If you are over both you file and |
---|
133 | * block quota you will only get a message about the blocks, oh well. |
---|
134 | */ |
---|
135 | |
---|
136 | if (quota_info->dqb_curblocks > quota_info->dqb_bsoftlimit) { |
---|
137 | int kbytes = (int) kb(quota_info->dqb_curblocks - |
---|
138 | quota_info->dqb_bsoftlimit); |
---|
139 | if ( (kb(quota_info->dqb_curblocks) >= |
---|
140 | (kb(quota_info->dqb_bhardlimit) - 5))|| |
---|
141 | (quota_info->dqb_btimelimit <= now) ) { |
---|
142 | sprintf(buf, EXCEEDED_HARD, kbytes, "kilobytes"); |
---|
143 | } |
---|
144 | else { |
---|
145 | sprintf(buf, EXCEEDED_SOFT, kbytes, "kilobytes", |
---|
146 | ctime("a_info->dqb_btimelimit)); |
---|
147 | } |
---|
148 | SetTextMessage(info->message_widget, buf); |
---|
149 | } |
---|
150 | else if ( quota_info->dqb_curfiles > quota_info->dqb_fsoftlimit ) { |
---|
151 | int files = quota_info->dqb_curfiles - quota_info->dqb_fsoftlimit; |
---|
152 | if ( (quota_info->dqb_curfiles >= (quota_info->dqb_fhardlimit - 10)) || |
---|
153 | (quota_info->dqb_ftimelimit <= now) ) { |
---|
154 | sprintf(buf, EXCEEDED_HARD, files, "files"); |
---|
155 | } |
---|
156 | else { |
---|
157 | sprintf(buf, EXCEEDED_SOFT, files, "files", |
---|
158 | ctime("a_info->dqb_ftimelimit)); |
---|
159 | } |
---|
160 | SetTextMessage(info->message_widget, buf); |
---|
161 | } |
---|
162 | else if (info->flipped) |
---|
163 | SetTextMessage(info->message_widget, WARNING_MESSAGE); |
---|
164 | else |
---|
165 | SetTextMessage(info->message_widget, SAFE_MESSAGE); |
---|
166 | } |
---|
167 | |
---|
168 | /* Function Name: SetQuotaDisplay |
---|
169 | * Description: Sets the Quota Display. |
---|
170 | * Arguments: w - the widget to display this in. |
---|
171 | * string - string to preface this with. |
---|
172 | * bytes - number of bytes. |
---|
173 | * files - number of files. |
---|
174 | * Returns: none |
---|
175 | */ |
---|
176 | |
---|
177 | static void |
---|
178 | SetQuotaDisplay( w, string, bytes, files ) |
---|
179 | Widget w; |
---|
180 | char * string; |
---|
181 | int bytes, files; |
---|
182 | { |
---|
183 | char buf[BUFSIZ]; |
---|
184 | |
---|
185 | sprintf(buf, "%12s %10d %10d", string, bytes, files); |
---|
186 | SetLabel(w, buf); |
---|
187 | } |
---|
188 | |
---|