[1749] | 1 | /* |
---|
| 2 | * xquota - X window system quota display program. |
---|
| 3 | * |
---|
| 4 | * $Athena: man.c,v 1.7 89/02/15 16:06:44 kit Exp $ |
---|
| 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: man.c,v 4.7 89/02/15 20:09:34 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 | |
---|
| 38 | static void DisplayInfo(), SetQuotaDisplay(); |
---|
| 39 | |
---|
| 40 | /* Function Name: ShowQuota() |
---|
| 41 | * Description: Shows the quota to the user. |
---|
| 42 | * Arguments: none. |
---|
| 43 | * Returns: none. |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | void ShowQuota(info) |
---|
| 47 | Info * info; |
---|
| 48 | { |
---|
| 49 | struct dqblk quota_info; |
---|
| 50 | |
---|
| 51 | SetTimeOut(info); |
---|
| 52 | |
---|
| 53 | getnfsquota(info->host, info->path, info->uid, "a_info); |
---|
| 54 | |
---|
| 55 | if (info->numbers && !info->space_saver) { |
---|
| 56 | char buf[BUFSIZ]; |
---|
| 57 | sprintf(buf, "Quota: %5dK", (int) kb(quota_info.dqb_bsoftlimit)); |
---|
| 58 | SetLabel(info->quota_top, buf); |
---|
| 59 | sprintf(buf, " Used: %5dK", (int) kb(quota_info.dqb_curblocks)); |
---|
| 60 | SetLabel(info->used_top, buf); |
---|
| 61 | } |
---|
| 62 | SetGraph(info, info->graph, (int) kb(quota_info.dqb_bsoftlimit), |
---|
| 63 | (int) kb(quota_info.dqb_curblocks)); |
---|
| 64 | |
---|
| 65 | DisplayInfo(info, "a_info); |
---|
| 66 | if ( quota_info.dqb_curblocks > quota_info.dqb_bsoftlimit) |
---|
| 67 | XtPopup(info->info_popup, XtGrabNone); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /* Function Name: DisplayInfo |
---|
| 71 | * Description: Displays information. |
---|
| 72 | * Arguments: info - the info struct. |
---|
| 73 | * Returns: none. |
---|
| 74 | */ |
---|
| 75 | |
---|
| 76 | static void |
---|
| 77 | DisplayInfo(info, quota_info) |
---|
| 78 | Info * info; |
---|
| 79 | struct dqblk * quota_info; |
---|
| 80 | { |
---|
| 81 | long now; |
---|
| 82 | char buf[BUFSIZ]; |
---|
| 83 | |
---|
| 84 | SetQuotaDisplay(info->hard_widget, "Hard Limit:", |
---|
| 85 | (int) kb(quota_info->dqb_bhardlimit), |
---|
| 86 | (int) quota_info->dqb_fhardlimit); |
---|
| 87 | |
---|
| 88 | SetQuotaDisplay(info->soft_widget, "Soft Limit:", |
---|
| 89 | (int) kb(quota_info->dqb_bsoftlimit), |
---|
| 90 | (int) quota_info->dqb_fsoftlimit); |
---|
| 91 | |
---|
| 92 | SetQuotaDisplay(info->used_widget, "Current:", |
---|
| 93 | (int) kb(quota_info->dqb_curblocks), |
---|
| 94 | (int) quota_info->dqb_curfiles); |
---|
| 95 | |
---|
| 96 | (void) time(&now); |
---|
| 97 | strcpy(buf, "Last Quota Check: "); |
---|
| 98 | strncat(buf, ctime(&now), 16); |
---|
| 99 | SetLabel(info->last_widget, buf); |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Determine which message to give. If you are over both you file and |
---|
| 103 | * block quota you will only get a message about the blocks, oh well. |
---|
| 104 | */ |
---|
| 105 | |
---|
| 106 | if (quota_info->dqb_curblocks > quota_info->dqb_bsoftlimit) { |
---|
| 107 | int kbytes = (int) kb(quota_info->dqb_curblocks - |
---|
| 108 | quota_info->dqb_bsoftlimit); |
---|
| 109 | if ( (kb(quota_info->dqb_curblocks) >= |
---|
| 110 | (kb(quota_info->dqb_bhardlimit) - 5))|| |
---|
| 111 | (quota_info->dqb_btimelimit <= now) ) { |
---|
| 112 | sprintf(buf, EXCEEDED_HARD, kbytes, "kilobytes"); |
---|
| 113 | } |
---|
| 114 | else { |
---|
| 115 | sprintf(buf, EXCEEDED_SOFT, kbytes, "kilobytes", |
---|
| 116 | ctime("a_info->dqb_btimelimit)); |
---|
| 117 | } |
---|
| 118 | SetTextMessage(info->message_widget, buf); |
---|
| 119 | } |
---|
| 120 | else if ( quota_info->dqb_curfiles > quota_info->dqb_fsoftlimit ) { |
---|
| 121 | int files = quota_info->dqb_curfiles - quota_info->dqb_fsoftlimit; |
---|
| 122 | if ( (quota_info->dqb_curfiles >= (quota_info->dqb_fhardlimit - 10)) || |
---|
| 123 | (quota_info->dqb_ftimelimit <= now) ) { |
---|
| 124 | sprintf(buf, EXCEEDED_HARD, files, "files"); |
---|
| 125 | } |
---|
| 126 | else { |
---|
| 127 | sprintf(buf, EXCEEDED_SOFT, files, "files", |
---|
| 128 | ctime("a_info->dqb_ftimelimit)); |
---|
| 129 | } |
---|
| 130 | SetTextMessage(info->message_widget, buf); |
---|
| 131 | } |
---|
| 132 | else if (info->flipped) |
---|
| 133 | SetTextMessage(info->message_widget, WARNING_MESSAGE); |
---|
| 134 | else |
---|
| 135 | SetTextMessage(info->message_widget, SAFE_MESSAGE); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /* Function Name: SetQuotaDisplay |
---|
| 139 | * Description: Sets the Quota Display. |
---|
| 140 | * Arguments: w - the widget to display this in. |
---|
| 141 | * string - string to preface this with. |
---|
| 142 | * bytes - number of bytes. |
---|
| 143 | * files - number of files. |
---|
| 144 | * Returns: none |
---|
| 145 | */ |
---|
| 146 | |
---|
| 147 | static void |
---|
| 148 | SetQuotaDisplay( w, string, bytes, files ) |
---|
| 149 | Widget w; |
---|
| 150 | char * string; |
---|
| 151 | int bytes, files; |
---|
| 152 | { |
---|
| 153 | char buf[BUFSIZ]; |
---|
| 154 | |
---|
| 155 | sprintf(buf, "%12s %10d %10d", string, bytes, files); |
---|
| 156 | SetLabel(w, buf); |
---|
| 157 | } |
---|
| 158 | |
---|