3 * wmfsm (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 <libdockapp/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 LENMP 5 /*max 10, number char for mountpoint */
105 /*modes for drawing*/
110 void ParseCMDLine(int argc
, char *argv
[]);
111 void pressEvent(XButtonEvent
* xev
);
112 void readFileSystems(void);
113 void excludeFileSystems(void);
114 void print_usage(void);
126 int delay
= DELAY_10
;
127 char appearance
[256] = "";
129 int xpos
[] = { 66, 71, 76, 81, 86, 91, /* A B C D E F */
130 66, 71, 76, 81, 86, 91, /* G H I J K L */
131 66, 71, 76, 81, 86, 91, /* M N O P Q R */
132 66, 71, 76, 81, 86, 91, /* S T U V W X */
133 66, 71, 76, 81, 86, 91, /* Y Z / _ - . */
141 int ypos
[] = { 4, 4, 4, 4, 4, 4,
143 14, 14, 14, 14, 14, 14,
144 19, 19, 19, 19, 19, 19,
145 24, 24, 24, 24, 24, 24,
158 main(int argc
, char *argv
[])
166 int c
, on
[9] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
167 struct statfs buffer
;
171 * Parse any command line arguments.
173 myName
= strdup(argv
[0]);
174 ParseCMDLine(argc
, argv
);
176 if (appearance
[0] == 0) {
177 pixmap
= wmfsm_master_xpm
;
179 if (XpmReadFileToData(appearance
, &pixmap
) != XpmSuccess
) {
180 fprintf(stderr
, "warning: could not read appearance file; using default.\n");
181 pixmap
= wmfsm_master_xpm
;
187 openXwindow(argc
, argv
, pixmap
, wmfsm_mask_bits
, wmfsm_mask_width
, wmfsm_mask_height
);
193 if (gethostname(hostname
, 100) != 0) {
194 perror("gethostname");
198 if (sysinfo(SI_HOSTNAME
, hostname
, 100) < 0) {
199 perror("sysinfo(SI_HOSTNAME)");
209 * Process any pending X events.
211 while (XPending(display
)) {
212 XNextEvent(display
, &event
);
213 switch (event
.type
) {
218 pressEvent(&event
.xbutton
);
219 mode
= (mode
+ 1) % 2;
227 for (i
= 0; i
< numberfs
; i
++) {
228 if (STATFS(mp
[i
], &buffer
) != -1) {
229 per
[i
] = 100 - (int) ((float) buffer
.f_bfree
/ (float) buffer
.f_blocks
* 100.0);
238 copyXPMArea(5, 69, 54, 54, 5, 5);
240 * void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
244 for (i
= 0, dy
= 0; i
< numberfs
; i
++) {
245 for (j
= 0, dx
= 0; j
< LENMP
&& (unsigned int)j
< strlen(mp
[i
]); j
++) {
246 k
= j
+ (strlen(mp
[i
]) > LENMP
? strlen(mp
[i
]) - LENMP
: 0);
271 copyXPMArea(xpos
[c
- 97], ypos
[c
- 97], 5, 5, 6 + dx
, 5 + dy
);
274 c
= (int) ((float) per
[i
] * 0.52 + 66.0);
275 k
= (10 - LENMP
) * 5 + 2;
276 k
= (float) per
[i
] / 100.0 * k
;
278 k
= k
< LENMP
* 5 + 1 ? LENMP
* 5 + 1 : k
;
280 c
= c
> 117 ? 117 : c
;
282 if ((int) per
[i
] >= blinkper
)
290 for (j
= LENMP
* 5; j
< k
; j
++) {
291 if (mode
== FIRE
&& on
[i
])
292 copyXPMArea(66 + (float) (j
- LENMP
* 5) * 52.0 / (float) ((10 - LENMP
) * 5), 29, 1, 5, 6 + j
, 5 + dy
);
293 else if (mode
== NORMAL
&& on
[i
])
294 copyXPMArea(c
, 29, 1, 5, 6 + j
, 5 + dy
);
299 else { /*one fs in two lines */
300 for (i
= 0, dy
= 0; i
< numberfs
; i
++) {
301 for (j
= 0, dx
= 0; j
< 10 && (unsigned int)j
< strlen(mp
[i
]); j
++) {
302 c
= (int) mp
[i
][j
+ (strlen(mp
[i
]) > 10 ? strlen(mp
[i
]) - 10 : 0)];
326 copyXPMArea(xpos
[c
- 97], ypos
[c
- 97], 5, 5, 6 + dx
, 5 + dy
);
330 c
= (int) ((float) per
[i
] * 0.52 + 66.0);
331 k
= (float) per
[i
] / 100.0 * 52;
334 c
= c
> 117 ? 117 : c
;
336 if ((int) per
[i
] >= blinkper
)
344 for (j
= 0; j
< k
; j
++) {
345 if (mode
== FIRE
&& on
[i
])
346 copyXPMArea(66 + (float) (j
) * 52.0 / 50.0, 29, 1, 5, 6 + j
, 5 + dy
);
347 else if (mode
== NORMAL
&& on
[i
])
348 copyXPMArea(c
, 29, 1, 5, 6 + j
, 5 + dy
);
354 for (j
= 0, dx
= 0, dy
= 47; j
< 10 && (unsigned int)j
< strlen(hostname
); j
++) {
355 c
= (int) hostname
[j
];
385 copyXPMArea(xpos
[c
- 97], ypos
[c
- 97], 5, 5, 6 + dx
, 6 + dy
);
392 * Wait for next update
408 ParseCMDLine(int argc
, char *argv
[])
412 static struct option long_options
[] = {
413 {"fire", no_argument
, 0, 'f'},
414 {"normal", no_argument
, 0, 'n'},
415 {"blink", no_argument
, &blink
, 1},
416 {"noblink", no_argument
, &blink
, 0},
417 {"delay", required_argument
, 0, 'd'},
418 {"appearance", required_argument
, 0, 'a'},
419 {"help", no_argument
, 0, 'h'},
420 {"version", no_argument
, 0, 'v'},
424 c
= getopt_long(argc
, argv
, "a:bd:fhnv", long_options
, &option_index
);
428 case 0: /* If blink or noblink was toggled */
431 strcpy(appearance
, optarg
);
437 delay
= atoi(optarg
);
449 printf("wmfsm version: %s\n", PACKAGE_VERSION
);
465 printf("usage: wmfsm \n");
466 printf("\t--normal, -n\t\tDraw bars in normal mode.\n");
467 printf("\t--fire, -f\t\tDraw bars in fire mode.\n");
468 printf("\t--[no]blink\t\tBlinks if a filesystem is 95 percent full.\n");
469 printf("\t-display <Display>\tUse alternate X display.\n");
470 printf("\t--delay <number>, -d\tUse a delay that is not the default.\n");
471 printf("\t--appearance <file>, -a\tSelect an appearance file.\n");
472 printf("\t-h\t\t\tDisplay help screen.\n");
476 pressEvent(XButtonEvent
* xev
)
488 for (i
= 0; i
< 100; i
++)
494 /* Look for the goods between #if defined(__OpenBSD__) -- tschroed */
495 #if defined(__OpenBSD__) || defined(__FreeBSD__)
497 struct statfs sfs
[MAXMOUNT
];
500 /* OpenBSD has no /etc/mtab, we use getfsstat instead -- tschroed */
501 if ((fscount
= getfsstat(sfs
, sizeof(sfs
), 0)) == -1) {
505 for (numberfs
= 0; numberfs
< fscount
; numberfs
++)
506 /* We won't watch RO mounts. */
507 if (sfs
[numberfs
].f_flags
& MNT_RDONLY
) {
512 mp
[numberfs
] = strdup(sfs
[numberfs
].f_mntonname
);
513 #else /* __OpenBSD__ || __FreeBSD__ */
516 char mountPoint
[255], dummy
[255], fstype
[255], options
[512];
519 /* Solaris uses /etc/mnttab */
520 fp
= fopen("/etc/mnttab", "r");
522 fprintf(stderr
, "%s:Can't open /etc/mnttab for reading\n", myName
);
526 fp
= fopen("/etc/mtab", "r");
528 fprintf(stderr
, "%s:Can't open /etc/mtab for reading\n", myName
);
534 while (!feof(fp
) && numberfs
< 100) {
536 /* only five entries per row in /etc/mnttab */
537 if (fscanf(fp
, "%s %s %s %s %s\n", dummy
, mountPoint
, fstype
, options
, dummy
) < 5)
538 fprintf(stderr
, "%s:/etc/mnttab not in expected format\n", myName
);
540 if (fscanf(fp
, "%s %s %s %s %s %s\n", dummy
, mountPoint
, fstype
, options
, dummy
, dummy
) < 6)
541 fprintf(stderr
, "%s:/etc/mtab not in expected format\n", myName
);
545 #if defined IRIX64 || defined(SunOS)
546 strcmp(fstype
, "hwgfs") && strcmp(fstype
, "autofs") && strcmp(fstype
, "proc") && strcmp(fstype
, "fd") && !strstr(options
, "ignore")
548 strcmp(fstype
, "proc") && strcmp(fstype
, "tmpfs") && strcmp(fstype
, "devfs") && strcmp(fstype
, "ramfs") && strcmp(fstype
, "sysfs") && strcmp(fstype
, "devpts") && strcmp(fstype
, "usbfs")
553 if (mp
[numberfs
]) free(mp
[numberfs
]);
554 mp
[numberfs
++] = strdup(mountPoint
);
557 #endif /* __OpenBSD__ || __FreeBSD__ */
560 excludeFileSystems();
566 char confFileName
[255];
567 char workString
[255];
569 int i
, j
, exnumberfs
= 0;
570 int excluded
, finalnumberfs
= 0;
571 char *mount_points
[100];
576 home
= getenv("HOME");
578 fprintf(stderr
, "error: HOME must be defined\n");
581 if (strlen(home
) > 244) {
583 "error: HOME may not be longer than 244 characters\n");
586 strncpy(confFileName
, home
, 245);
587 strcat(confFileName
, "/.wmfsmrc");
588 confFile
= fopen(confFileName
, "r");
590 while (!feof(confFile
)) {
591 if (fgets(workString
, 255, confFile
)) {
592 if(strstr(workString
, "\n")){
593 /* This is probably dangerous, but easy */
594 *(strstr(workString
, "\n")) = '\0';
596 if (!strcmp(workString
, "[include]")) {
599 else if (!strcmp(workString
, "[exclude]")) {
603 mount_points
[exnumberfs
] = strdup(workString
);
610 printf("wmfsm: Please specify either to include or exclude filesystems.\n");
616 numberfs
= numberfs
> 9 ? 9 : numberfs
;
620 numberfs
= numberfs
> 9 ? 9 : numberfs
;
624 for (i
= 0; i
< numberfs
; i
++) {
625 for (j
= 0, excluded
= 0; j
< exnumberfs
; j
++) {
626 if (!strcmp(mp
[i
], mount_points
[j
]) && !include
) {
628 } else if (!strcmp(mp
[i
], mount_points
[j
]) && include
) {
632 if ((!excluded
&& !include
) || (included
&& include
)) {
633 if (finalnumberfs
== i
) {
636 if (mp
[finalnumberfs
]) free(mp
[finalnumberfs
]);
637 mp
[finalnumberfs
++] = strdup(mp
[i
]);
640 included
= excluded
= 0;
642 numberfs
= finalnumberfs
> 9 ? 9 : finalnumberfs
;
645 for (j
= 0; j
< exnumberfs
; j
++)
646 if (mount_points
[j
]) {
647 free(mount_points
[j
]);