3 * wmfsm-0.33 (C) 1999 Stefan Eilemann (Stefan.Eilemann@dlr.de)
5 * - Shows file system usage ala mfsm
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program (see the file COPYING); if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301, USA
27 * Changes: #include "../ChangeLog"
45 #include "../wmgeneral/wmgeneral.h"
46 #include "wmfsm_master.xpm"
47 #include "wmfsm_mask.xbm"
55 #include <sys/systeminfo.h>
61 #ifdef HAVE_SYS_STATFS_H
62 #include <sys/statfs.h>
64 #ifdef HAVE_SYS_MOUNT_H
65 #include <sys/mount.h>
67 #ifdef HAVE_SYS_PARAM_H
68 #include <sys/param.h>
70 #ifdef HAVE_SYS_TYPES_H
71 #include <sys/types.h>
74 #ifdef STATFS_2_ARGUMENTS
75 # define STATFS(a,b) statfs(a,b)
76 #elif defined STATFS_4_ARGUMENTS
77 # define STATFS(a,b) statfs(a,b,sizeof(struct statfs),0)
79 # define STATFS(a,b) statfs(a,b) /* Maybe configure got messed up */
84 # include <sys/types.h>
85 # define STATFS(a,b) statfs(a,b,sizeof(struct statfs),0)
87 # define STATFS(a,b) statfs(a,b)
89 # define STATFS(a,b) statfs(a,b,sizeof(struct statfs),0)
90 #elif defined(__OpenBSD__) || defined(__FreeBSD__)
91 # define STATFS(a,b) statfs(a,b)
92 # include <sys/param.h>
99 * Delay between refreshes (in microseconds), uses the 10*DELAY_10
100 * coz irix has max of 100000L :(.
102 #define DELAY_10 99999L
103 #define WMFSM_VERSION "0.33"
104 #define LENMP 5 /*max 10, number char for mountpoint */
106 /*modes for drawing*/
111 void ParseCMDLine(int argc
, char *argv
[]);
112 void pressEvent(XButtonEvent
* xev
);
113 void readFileSystems(void);
114 void excludeFileSystems(void);
115 void print_usage(void);
127 int delay
= DELAY_10
;
128 char appearance
[256] = "";
130 int xpos
[] = { 66, 71, 76, 81, 86, 91, /* A B C D E F */
131 66, 71, 76, 81, 86, 91, /* G H I J K L */
132 66, 71, 76, 81, 86, 91, /* M N O P Q R */
133 66, 71, 76, 81, 86, 91, /* S T U V W X */
134 66, 71, 76, 81, 86, 91, /* Y Z / _ - . */
142 int ypos
[] = { 4, 4, 4, 4, 4, 4,
144 14, 14, 14, 14, 14, 14,
145 19, 19, 19, 19, 19, 19,
146 24, 24, 24, 24, 24, 24,
159 main(int argc
, char *argv
[])
167 int c
, on
[9] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
168 struct statfs buffer
;
172 * Parse any command line arguments.
174 myName
= strdup(argv
[0]);
175 ParseCMDLine(argc
, argv
);
177 if (appearance
[0] == 0) {
178 pixmap
= wmfsm_master_xpm
;
180 if (XpmReadFileToData(appearance
, &pixmap
) != XpmSuccess
) {
181 fprintf(stderr
, "warning: could not read appearance file; using default.\n");
182 pixmap
= wmfsm_master_xpm
;
188 openXwindow(argc
, argv
, pixmap
, wmfsm_mask_bits
, wmfsm_mask_width
, wmfsm_mask_height
);
194 if (gethostname(hostname
, 100) != 0) {
195 perror("gethostname");
199 if (sysinfo(SI_HOSTNAME
, hostname
, 100) < 0) {
200 perror("sysinfo(SI_HOSTNAME)");
210 * Process any pending X events.
212 while (XPending(display
)) {
213 XNextEvent(display
, &event
);
214 switch (event
.type
) {
219 pressEvent(&event
.xbutton
);
220 mode
= (mode
+ 1) % 2;
228 for (i
= 0; i
< numberfs
; i
++) {
229 if (STATFS(mp
[i
], &buffer
) != -1) {
230 per
[i
] = 100 - (int) ((float) buffer
.f_bfree
/ (float) buffer
.f_blocks
* 100.0);
239 copyXPMArea(5, 69, 54, 54, 5, 5);
241 * void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
245 for (i
= 0, dy
= 0; i
< numberfs
; i
++) {
246 for (j
= 0, dx
= 0; j
< LENMP
&& (unsigned int)j
< strlen(mp
[i
]); j
++) {
247 k
= j
+ (strlen(mp
[i
]) > LENMP
? strlen(mp
[i
]) - LENMP
: 0);
272 copyXPMArea(xpos
[c
- 97], ypos
[c
- 97], 5, 5, 6 + dx
, 5 + dy
);
275 c
= (int) ((float) per
[i
] * 0.52 + 66.0);
276 k
= (10 - LENMP
) * 5 + 2;
277 k
= (float) per
[i
] / 100.0 * k
;
279 k
= k
< LENMP
* 5 + 1 ? LENMP
* 5 + 1 : k
;
281 c
= c
> 117 ? 117 : c
;
283 if ((int) per
[i
] >= blinkper
)
291 for (j
= LENMP
* 5; j
< k
; j
++) {
292 if (mode
== FIRE
&& on
[i
])
293 copyXPMArea(66 + (float) (j
- LENMP
* 5) * 52.0 / (float) ((10 - LENMP
) * 5), 29, 1, 5, 6 + j
, 5 + dy
);
294 else if (mode
== NORMAL
&& on
[i
])
295 copyXPMArea(c
, 29, 1, 5, 6 + j
, 5 + dy
);
300 else { /*one fs in two lines */
301 for (i
= 0, dy
= 0; i
< numberfs
; i
++) {
302 for (j
= 0, dx
= 0; j
< 10 && (unsigned int)j
< strlen(mp
[i
]); j
++) {
303 c
= (int) mp
[i
][j
+ (strlen(mp
[i
]) > 10 ? strlen(mp
[i
]) - 10 : 0)];
327 copyXPMArea(xpos
[c
- 97], ypos
[c
- 97], 5, 5, 6 + dx
, 5 + dy
);
331 c
= (int) ((float) per
[i
] * 0.52 + 66.0);
332 k
= (float) per
[i
] / 100.0 * 52;
335 c
= c
> 117 ? 117 : c
;
337 if ((int) per
[i
] >= blinkper
)
345 for (j
= 0; j
< k
; j
++) {
346 if (mode
== FIRE
&& on
[i
])
347 copyXPMArea(66 + (float) (j
) * 52.0 / 50.0, 29, 1, 5, 6 + j
, 5 + dy
);
348 else if (mode
== NORMAL
&& on
[i
])
349 copyXPMArea(c
, 29, 1, 5, 6 + j
, 5 + dy
);
355 for (j
= 0, dx
= 0, dy
= 47; j
< 10 && (unsigned int)j
< strlen(hostname
); j
++) {
356 c
= (int) hostname
[j
];
386 copyXPMArea(xpos
[c
- 97], ypos
[c
- 97], 5, 5, 6 + dx
, 6 + dy
);
393 * Wait for next update
409 ParseCMDLine(int argc
, char *argv
[])
413 static struct option long_options
[] = {
414 {"fire", no_argument
, 0, 'f'},
415 {"normal", no_argument
, 0, 'n'},
416 {"blink", no_argument
, &blink
, 1},
417 {"noblink", no_argument
, &blink
, 0},
418 {"delay", required_argument
, 0, 'd'},
419 {"appearance", required_argument
, 0, 'a'},
420 {"help", no_argument
, 0, 'h'},
424 c
= getopt_long(argc
, argv
, "a:bd:fhn", long_options
, &option_index
);
428 case 0: /* If blink or noblink was toggled */
431 strcpy(appearance
, optarg
);
437 delay
= atoi(optarg
);
462 printf("\nwmfsm version: %s\n", WMFSM_VERSION
);
463 printf("\nusage: wmfsm \n");
464 printf("\t--normal, -n\t\tDraw bars in normal mode.\n");
465 printf("\t--fire, -f\t\t\tDraw bars in fire mode.\n");
466 printf("\t--[no]blink\t\tBlinks if a filesystem is 95 percent full.\n");
467 printf("\t-display <Display>\tUse alternate X display.\n");
468 printf("\t--delay <number>, -d\tUse a delay that is not the default.\n");
469 printf("\t--appearance <file>, -a\tSelect an appearance file.\n");
470 printf("\t-h\t\t\tDisplay help screen.\n");
474 pressEvent(XButtonEvent
* xev
)
486 for (i
= 0; i
< 100; i
++)
492 /* Look for the goods between #if defined(__OpenBSD__) -- tschroed */
493 #if defined(__OpenBSD__) || defined(__FreeBSD__)
495 struct statfs sfs
[MAXMOUNT
];
498 /* OpenBSD has no /etc/mtab, we use getfsstat instead -- tschroed */
499 if ((fscount
= getfsstat(sfs
, sizeof(sfs
), 0)) == -1) {
503 for (numberfs
= 0; numberfs
< fscount
; numberfs
++)
504 /* We won't watch RO mounts. */
505 if (sfs
[numberfs
].f_flags
& MNT_RDONLY
) {
510 mp
[numberfs
] = strdup(sfs
[numberfs
].f_mntonname
);
511 #else /* __OpenBSD__ || __FreeBSD__ */
514 char mountPoint
[255], dummy
[255], fstype
[255], options
[255];
517 /* Solaris uses /etc/mnttab */
518 fp
= fopen("/etc/mnttab", "r");
520 fprintf(stderr
, "%s:Can't open /etc/mnttab for reading\n", myName
);
524 fp
= fopen("/etc/mtab", "r");
526 fprintf(stderr
, "%s:Can't open /etc/mtab for reading\n", myName
);
532 while (!feof(fp
) && numberfs
< 100) {
534 /* only five entries per row in /etc/mnttab */
535 if (fscanf(fp
, "%s %s %s %s %s\n", dummy
, mountPoint
, fstype
, options
, dummy
) < 5)
536 fprintf(stderr
, "%s:/etc/mnttab not in expected format\n", myName
);
538 if (fscanf(fp
, "%s %s %s %s %s %s\n", dummy
, mountPoint
, fstype
, options
, dummy
, dummy
) < 6)
539 fprintf(stderr
, "%s:/etc/mtab not in expected format\n", myName
);
543 #if defined IRIX64 || defined(SunOS)
544 strcmp(fstype
, "hwgfs") && strcmp(fstype
, "autofs") && strcmp(fstype
, "proc") && strcmp(fstype
, "fd") && !strstr(options
, "ignore")
546 strcmp(fstype
, "proc") && strcmp(fstype
, "tmpfs") && strcmp(fstype
, "devfs") && strcmp(fstype
, "ramfs") && strcmp(fstype
, "sysfs") && strcmp(fstype
, "devpts") && strcmp(fstype
, "usbfs")
551 if (mp
[numberfs
]) free(mp
[numberfs
]);
552 mp
[numberfs
++] = strdup(mountPoint
);
555 #endif /* __OpenBSD__ || __FreeBSD__ */
558 excludeFileSystems();
564 char confFileName
[255];
565 char workString
[255];
566 int i
, j
, exnumberfs
= 0;
567 int excluded
, finalnumberfs
= 0;
568 char *mount_points
[100];
573 strncpy(confFileName
, (char *) getenv("HOME"), 245);
574 strcat(confFileName
, "/.wmfsmrc");
575 confFile
= fopen(confFileName
, "r");
577 while (!feof(confFile
)) {
578 if (fgets(workString
, 255, confFile
)) {
579 if(strstr(workString
, "\n")){
580 /* This is probably dangerous, but easy */
581 *(strstr(workString
, "\n")) = '\0';
583 if (!strcmp(workString
, "[include]")) {
586 else if (!strcmp(workString
, "[exclude]")) {
590 mount_points
[exnumberfs
] = strdup(workString
);
597 printf("wmfsm: Please specify either to include or exclude filesystems.\n");
603 numberfs
= numberfs
> 9 ? 9 : numberfs
;
607 numberfs
= numberfs
> 9 ? 9 : numberfs
;
611 for (i
= 0; i
< numberfs
; i
++) {
612 for (j
= 0, excluded
= 0; j
< exnumberfs
; j
++) {
613 if (!strcmp(mp
[i
], mount_points
[j
]) && !include
) {
615 } else if (!strcmp(mp
[i
], mount_points
[j
]) && include
) {
619 if ((!excluded
&& !include
) || (included
&& include
)) {
620 if (finalnumberfs
== i
) {
623 if (mp
[finalnumberfs
]) free(mp
[finalnumberfs
]);
624 mp
[finalnumberfs
++] = strdup(mp
[i
]);
627 included
= excluded
= 0;
629 numberfs
= finalnumberfs
> 9 ? 9 : finalnumberfs
;
632 for (j
= 0; j
< exnumberfs
; j
++)
633 if (mount_points
[j
]) {
634 free(mount_points
[j
]);