1 /* ************************************************************************* *
2    xfsm - (C) Copyright 1993-1999 Robert Gasch (Robert_Gasch@peoplesoft.com)
3 	  http://www.peoplesoft.com/peoplepages/g/robert_gasch/src/
4 
5    Permission to use, copy, modify and distribute this software for any
6    purpose and without fee is hereby granted, provided that this copyright
7    notice appear in all copies as well as supporting documentation. All
8    work developed as a consequence of the use of this program should duly
9    acknowledge such use.
10 
11    No representations are made about the suitability of this software for
12    any purpose. This software is provided "as is" without express or implied
13    warranty.
14 
15    See the GNU General Public Licence for more information.
16  * ************************************************************************* */
17 
18 
19 #include "xfsm.h"
20 #ifdef ULTRIX
21 /* *** This defines the gt_names string which means that we have to *** */
22 /* ***        include it here to avoid multiple definitions         *** */
23 #include <sys/fs_types.h>
24 #endif
25 
26 
27 extern Display			*mydisplay;
28 extern char*			myname;
29 extern char*			title;
30 extern XrmDatabase		resourceDB;
31 extern WinType			main_win,
32 				fs_win[MAXFS],
33 				detail_win;
34 extern unsigned long		fg, bg,
35 				warncols[];
36 extern XSizeHints		szhint;
37 extern int 			show_use,
38 				upd_interval,
39 				NFS,
40 				detail_share_color,
41 				minimize,
42 				menu_border,
43 				show_biggest,
44 				fs_border,
45 				percent,
46 				absolute,
47 				available,
48 				bell,
49 				popup,
50 				fs_level[],
51 				fs_warn[],
52 				verbose,
53 				sort,
54 				gray,
55 				override_ignore,
56 				rootdf,
57 				idx[],
58 				root;
59 extern double			b_blocks,
60 				b_bsize,
61 				b_disk;
62 extern unsigned long		turns;
63 extern float			fs_perc[],
64 				res_space,
65 				warnvals[],
66 				warn_val;
67 extern StringInfo		strinfo[];
68 extern struct statfs 		stats[];
69 
70 
71 
72 
73 static MyString ignore_names[MAXFS],	/* *** file systems to be ignored *** */
74 		select_names[MAXFS],	/* *** file systems to be selected*** */
75 #ifndef SCO
76 		ignore_type[MAXFS],	/* *** FS types to ignore *** */
77 		only_type,		/* *** show only this type *** */
78 #endif /* !SCO */
79 		ignore_pattern[MAXFS],	/* *** FSN patterns to be ignored *** */
80 		select_pattern[MAXFS];	/* *** FSN patterns to be selected*** */
81 static int	lname,
82 		ignore_n_count=0,
83 		ignore_p_count=0,
84 		select_n_count=0,
85 		select_p_count=0,
86 #ifndef SCO
87 		ignore_t_count=0,
88 		only_t=FALSE,
89 #endif /* !SCO */
90 		percent_width,
91 		old_detail_letter_x=0;
92 #ifdef AIX
93 static char	vmount_buf[BUFFERSIZE];
94 #endif
95 
96 
97 
98 
99 /* ************************************************************************ */
100 /* ************** set the window's width in relative mode ***************** */
101 /* ************************************************************************ */
fix_fs_win_width(i)102 void fix_fs_win_width (i)
103 int i;
104 {
105 	double  bsize=stats[i].f_bsize;
106 
107 #ifdef SCO
108 	bsize=512;
109 #endif
110 	if (!absolute)
111 		{
112 		fs_win[i].width=(int)(fs_win[i].width*
113 			(((double)stats[i].f_blocks)*bsize)/b_disk);
114 		if (fs_win[i].width < 1)
115 			fs_win[i].width=1;
116 		}
117 }
118 
119 
120 
121 
122 /* *********************************************************************** */
123 /* ******************** write out the detailed info ********************** */
124 /* *********************************************************************** */
write_detail(i)125 void write_detail (i)
126 int i;
127 {
128 	int 	c=3,
129 		longest,
130 		rhs,
131 		lhs = XTextWidth(detail_win.font_info, "Blocks Available ",
132 			sizeof ("Blocks Available ")),
133 		dflt_rhs = XTextWidth(detail_win.font_info,DETAIL_LETTER_STRING,
134 			sizeof (DETAIL_LETTER_STRING));
135 	char 	s[30];
136 	long	bsize=stats[i].f_bsize,
137 		blocks=stats[i].f_blocks,
138 #ifndef SCO
139 		bavail=stats[i].f_bavail,
140 #endif
141 		bfree=stats[i].f_bfree,
142 		calc_bsize=bsize;
143 #ifdef ULTRIX
144 		/* *** ULTRIX always returns the number of 1K blocks *** */
145 		calc_bsize=1024;
146 #endif /* ULTRIX */
147 #ifdef SCO
148 		/* *** SCO always returns the number of 512 byte blocks *** */
149 		calc_bsize=512;
150 #endif /* SCO */
151 #ifdef FreeBSD
152 		/* *** FreeBSD has fsize which is the physical block size *** */
153 		/* *** and bsize which is the optimal transfer block size *** */
154 		/* *** and which depends on the filesystem parameter.     *** */
155 		calc_bsize=stats[i].f_bsize;
156 #endif /* FreeBSD */
157 
158 	/* *** take the longer of the two 'problematic' strings *** */
159 	if (strlen (MntOpt) > strlen (DevName))
160 		rhs = XTextWidth(detail_win.font_info, MntOpt,
161 			longest = strlen (MntOpt));
162 	else
163 		rhs = XTextWidth(detail_win.font_info, DevName,
164 			longest = strlen (DevName));
165 	/* *** resize the detail window accordingly *** */
166 	if (longest > DETAIL_LETTER_X)
167 	   {
168 	    if (longest != old_detail_letter_x)
169 		{
170 		detail_win.width = rhs + lhs + OFF_X*2;
171 		szhint.min_width = detail_win.width;
172                 szhint.max_width = detail_win.width;
173 		szhint.min_height = szhint.max_height = detail_win.height;
174 		szhint.flags = PMinSize | PMaxSize | PSize;
175 		XSetNormalHints (mydisplay, detail_win.win, &szhint);
176 		XResizeWindow (mydisplay, detail_win.win,
177 			detail_win.width, DETAIL_Y);
178 		}
179 	   }
180 	else
181 	if (detail_win.width > dflt_rhs + lhs + OFF_X*2)
182 		/* *** window os too big - shrink it *** */
183 		{
184 		detail_win.width = dflt_rhs + lhs + OFF_X;
185 		szhint.min_width = detail_win.width;
186 		szhint.max_width = detail_win.width;
187 		szhint.min_height = szhint.max_height = detail_win.height;
188 		szhint.flags = PMinSize | PMaxSize | PSize;
189 		XSetNormalHints (mydisplay, detail_win.win, &szhint);
190 		XResizeWindow (mydisplay, detail_win.win,
191 			detail_win.width, DETAIL_Y);
192 		}
193 	old_detail_letter_x = longest;
194 
195 	XClearWindow (mydisplay, detail_win.win);
196 	/* *** write the detailed info *** */
197 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
198 		((detail_win.width / 2) - (XTextWidth(detail_win.font_info,
199 		FsName, strlen(FsName)) / 2)), OFF_Y+MENU_HEIGHT(detail_win),
200 		FsName, strlen(FsName));
201 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
202 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Device Name",
203 		strlen ("Device Name"));
204 	sprintf (s, "%s", DevName);
205 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
206 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen(s));
207 
208 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
209 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Total Size",
210 		strlen ("Total Size"));
211 	if (blocks == -1 || calc_bsize == -1)
212 		sprintf (s, "Undefined");
213 	else
214 		sprintf (s, "%.2f MB", (double)
215 		/* *** use this computational order to avoid overflows *** */
216 			((double)(calc_bsize)/(double)(MB))*(double)(blocks));
217 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
218 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
219 
220 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
221 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Space Free",
222 		strlen ("Space Free"));
223 	if (bfree == -1 || calc_bsize == -1)
224 		sprintf (s, "Undefined");
225 	else
226 		sprintf (s, "%.2f MB", (double)
227 		/* *** use this computational order to avoid overflows *** */
228 			((double)(calc_bsize)/(double)(MB))*(double)(bfree));
229 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
230 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
231 
232 #ifndef SCO
233 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
234 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Space Available",
235 		strlen ("Space Available"));
236 	if (bavail == -1 || calc_bsize == -1)
237 		sprintf (s, "Undefined");
238 	else
239 		sprintf (s, "%.2f MB", (double)
240 		/* *** use this computational order to avoid overflows *** */
241 			((double)(calc_bsize)/(double)(MB))*(double)(bavail));
242 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
243 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
244 #endif
245 
246 #ifndef OSF1
247 # ifndef SCO
248 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
249 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Mount Type",
250 		strlen ("Mount Type"));
251 	sprintf (s, "%s", MntTyp);
252 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
253 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
254 # endif /* !SCO */
255 
256 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
257 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Mount Options",
258 		strlen ("Mount Options"));
259 	sprintf (s, "%s", MntOpt);
260 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
261 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
262 #endif /* !OSF1 */
263 
264 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
265 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Block Size",
266 		strlen ("Block Size"));
267 #ifdef FreeBSD
268 	sprintf (s, "%ld", calc_bsize);
269 #else
270 	sprintf (s, "%ld", bsize);
271 #endif /* FreeBSD */
272 	CHECKNA;
273 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
274 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
275 
276 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
277 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Blocks",
278 		strlen ("Blocks"));
279 	sprintf (s, "%ld", blocks);
280 	CHECKNA;
281 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
282 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
283 
284 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
285 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Blocks Free",
286 		strlen ("Blocks Free"));
287 	sprintf (s, "%ld", bfree);
288 	CHECKNA;
289 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
290 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
291 
292 #ifndef SCO
293 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
294 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Blocks Available",
295 		strlen ("Blocks Available"));
296 	sprintf (s, "%ld", bavail);
297 	CHECKNA;
298 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
299 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
300 #endif
301 
302 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
303 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c,
304 #ifdef ULTRIX
305 		"Gnodes", strlen ("Gnodes"));
306 #else
307 		"File Inodes", strlen ("File Inodes"));
308 #endif
309 
310 #ifdef SGI
311 	sprintf (s, "%lld", stats[i].f_files);
312 #else
313 	sprintf (s, "%d", stats[i].f_files);
314 #endif
315 	CHECKNA;
316 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
317 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
318 
319 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
320 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c,
321 #ifdef ULTRIX
322 		"Free Gnodes", strlen ("Free Gnodes"));
323 #else
324 		"Free Inodes", strlen ("Free Inodes"));
325 #endif
326 
327 #ifdef SGI
328 	sprintf (s, "%lld", stats[i].f_ffree);
329 #else
330 	sprintf (s, "%d", stats[i].f_ffree);
331 #endif
332 	CHECKNA;
333 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
334 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
335 
336 #if defined (SVR4) || defined (SOLARIS) || defined (AUX) || defined (SGI) || \
337     defined (DGUX)
338 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
339 		OFF_X, OFF_Y+MENU_HEIGHT(detail_win)*c, "Inodes Available",
340 		strlen ("Inodes Available"));
341 # ifdef AUX
342 	sprintf (s, "%ld", stats[i].f_bavail);
343 # else
344 #  ifdef SGI
345 	sprintf (s, "%lld", stats[i].f_favail);
346 #  else
347 	sprintf (s, "%ld", stats[i].f_favail);
348 # endif /* SGI */
349 # endif /* AUX */
350 	CHECKNA;
351 	XDrawImageString (mydisplay, detail_win.win, detail_win.gc,
352 		OFF_X+lhs, OFF_Y+MENU_HEIGHT(detail_win)*c++, s, strlen (s));
353 #endif /* SVR4 || SOLARIS || AUX || SGI || DGUX */
354 }
355 
356 
357 
358 /* ************************************************************************ */
359 /* ************ get_fs get the file systems which are mounted ************* */
360 /* ************************************************************************ */
get_fs()361 void get_fs ()
362 {
363 	int		x,y, removed, min, t, fs_returned=0;
364 #if defined (SVR4) || defined (SOLARIS) || defined (SCO) || \
365     defined (SUNOS) || defined (LINUX) || defined (HPUX) || \
366     defined (CONVEXOS) || defined (MACH) || defined (DYNIX) || \
367     defined (AUX) || defined (SGI)|| defined (DGUX)
368 	FILE		*fp;
369 #endif
370 #ifdef ULTRIX
371 	int		which_fs=0;
372 #endif
373 #ifdef AIX
374 	int		i=0, retcode;
375 #endif
376 #ifdef SCO
377 	MyString	buffer;
378 #endif
379 
380 /* *** The struct names here are overloaded in main.h. The reason   *** */
381 /* *** we still have porting exceptions here are that the functions *** */
382 /* *** we call have different parameter types we have to adhere to. *** */
383 #if defined (SUNOS) || defined (LINUX) || defined (DYNIX) || \
384     defined (HPUX) || defined (AIX) || defined (CONVEXOS) || \
385     defined (AUX) || defined (SGI) || defined (DGUX)
386 	struct mntent 	*mnt_info;
387 # else
388 # if defined (SVR4) || defined (SOLARIS) || defined (ULTRIX) || defined (MACH)
389 	struct mntent 	mnt_info;
390 #  else
391 #  if defined (OSF1) || defined (FreeBSD) || defined (BSDI)
392 	struct statfs	*mnt_info;
393 	int		i, nstatfs;
394 #  endif /* OSF1 || FreeBSD || BSDI */
395 # endif /* SVR4 || SOLARIS || ULTRIX || MACH || DGUX */
396 #endif /* SUNOS || LINUX || DYNIX || HPUX || AIX || CONVEXOS || AUX || SGI */
397 
398 
399 	NFS=0;
400 	/* *** here we open the file containing FS info     *** */
401 	/* *** AIX && ULTRIX do not have to do this as we   *** */
402 	/* *** acces the mount data directly though memory  *** */
403 #if defined (SUNOS) || defined (LINUX) || defined (HPUX) || \
404     defined (CONVEXOS) || defined (MACH) || defined (DYNIX) || \
405     defined (AUX) || defined (SGI) || defined (DGUX)
406 	if ((fp=setmntent(MOUNT_FILE,"r"))==NULL)
407 		{
408 		perror("Can't open setmntent ... Exiting");
409 		exit(1);
410 		}
411 # else
412 # if defined (SVR4) || defined (SOLARIS)
413 	if ((fp=fopen(MOUNT_FILE,"r"))==NULL)
414 		{
415 		perror("Can't open /etc/mnttab ... Exiting");
416 		exit(1);
417 		}
418 #  else
419 #  ifdef OSF1
420 	nstatfs = getfsstat((struct statfs *)0, 0, MNT_NOWAIT);
421 	if (nstatfs < 0)
422 		{
423 		perror("Can't getfsstat(0) ... Exiting");
424 		exit(1);
425 		}
426 	mnt_info = (struct statfs *)malloc(nstatfs * sizeof (struct statfs));
427 	if (mnt_info == (struct statfs *)0)
428 		{
429 		perror("Can't malloc() ... Exiting");
430 		exit(1);
431 		}
432 	nstatfs = getfsstat(mnt_info,nstatfs*sizeof(struct statfs),MNT_NOWAIT);
433 	if (nstatfs < 0)
434 		{
435 		perror("Can't getfsstat() ... Exiting");
436 		exit(1);
437 		}
438 #   else
439 #   if defined (FreeBSD) || defined (BSDI)
440 	nstatfs = getmntinfo(&mnt_info,MNT_NOWAIT);
441 	if (nstatfs < 0)
442 		{
443 		perror("Can't getmntinfo() ... Exiting");
444 		exit(1);
445 		}
446 #    else
447 #    ifdef SCO
448 	/* *** execute command *** */
449 	if ((fp = popen ("/etc/mount", "r")) == NULL)
450 		{
451 		perror ("Can't do popen to /etc/mount command ... Exiting\n");
452 		exit (1);
453 		};
454 #    endif /* SCO */
455 #   endif /* FreeBSD || BSDI */
456 #  endif /* OSF1 */
457 # endif /* SVR4 || SOLARIS */
458 #endif /* SUNOS || LINUX || HPUX || CONVEXOS || MACH || DYNIX || AUX || SGI ||
459 	  DGUX */
460 
461 
462 	/* *** read the contents of the file *** */
463 #if defined (SUNOS) || defined (LINUX) || defined (HPUX) || \
464     defined (CONVEXOS) || defined (MACH) || defined(DYNIX) || \
465     defined (AUX) || defined (SGI) || defined (DGUX)
466 	while ((mnt_info=getmntent(fp)) && NFS < MAXFS)
467 # else
468 # if defined (SVR4) || defined (SOLARIS)
469 	while (!(getmntent (fp, &mnt_info)) && NFS < MAXFS)
470 #  else
471 #  if defined (OSF1) || defined (FreeBSD) || defined(BSDI)
472 	i=0;
473 	while (i < nstatfs && NFS < MAXFS)
474 #   else
475 #   ifdef AIX
476 	/* *** this is clumsy, but it get's things done    *** */
477 	/* *** correctly in the existing program structure *** */
478 	retcode=mntctl(MCTL_QUERY, sizeof(vmount_buf), vmount_buf);
479 	if (retcode==0)
480 		{
481 		fprintf (stderr, "Buffer too small; needs to be %d long\n\
482 Please change the definition of BUFFERSIZE in main.h to an appropriate value\n",
483 			*((int *) vmount_buf));
484 		exit(1);
485 		}
486 	/* *** assign the first strcture and start the loop *** */
487 	mnt_info=(struct vmount *)vmount_buf;
488 	while (i<retcode && NFS < MAXFS)
489 #    else
490 #    ifdef ULTRIX
491 	while (getmnt (&which_fs, &mnt_info, sizeof (struct mntent),
492 			 NOSTAT_MANY, "no_path") > 0)
493 #     else
494 #     ifdef SCO
495 	while ((fgets (buffer, STRLENGTH , fp)) != NULL)
496 #     endif /* SCO */
497 #    endif /* ULTRIX */
498 #   endif /* AIX */
499 #  endif /* OSF1 || FreeBSD || BSDI */
500 # endif /* SVR4 || SOLARIS */
501 #endif /* SUNOS || LINUX || HPUX || CONVEXOS || MACH || AUX || SGI || DGUX */
502 
503 
504 		{
505 		/* *** here the actual while loop starts *** */
506 #if defined (SUNOS) || defined (LINUX) || defined (DYNIX) || \
507     defined (HPUX) || defined (CONVEXOS) || defined (MACH) || \
508     defined (AUX) || defined (SGI) || defined (DGUX)
509 		strcpy (strinfo[NFS].fs_name, mnt_info->mnt_dir);
510 		strcpy (strinfo[NFS].dev_name, mnt_info->mnt_fsname);
511 		strcpy (strinfo[NFS].mnt_typ, mnt_info->mnt_type);
512 		strcpy (strinfo[NFS].mnt_opt, mnt_info->mnt_opts);
513 # else
514 # if defined (SVR4) || defined (SOLARIS)
515 		strcpy (strinfo[NFS].fs_name, mnt_info.mnt_dir);
516 		strcpy (strinfo[NFS].dev_name, mnt_info.mnt_fsname);
517 		strcpy (strinfo[NFS].mnt_typ, mnt_info.mnt_type);
518 		strcpy (strinfo[NFS].mnt_opt, mnt_info.mnt_opts);
519 #  else
520 #  if defined (OSF1) || defined (FreeBSD) || defined (BSDI)
521 		strcpy (strinfo[NFS].fs_name, mnt_info[i].f_mntonname);
522 		strcpy (strinfo[NFS].dev_name, mnt_info[i].f_mntfromname);
523 		i++;
524 #   else
525 #   ifdef AIX
526 		strcpy (strinfo[NFS].fs_name, vmt2dataptr(mnt_info,VMT_STUB));
527 		strcpy (strinfo[NFS].dev_name,vmt2dataptr(mnt_info,VMT_OBJECT));
528 		/* *** of course IBM had to make things difficult *** */
529 		switch (mnt_info -> vmt_gfstype)
530 			{
531 			case MNT_AIX: strcpy (strinfo[NFS].mnt_typ, "aix");
532 					break;
533 			case MNT_NFS: strcpy (strinfo[NFS].mnt_typ, "nfs");
534 					break;
535 			case MNT_JFS: strcpy (strinfo[NFS].mnt_typ, "jfs");
536 					break;
537 			case MNT_CDROM: strcpy (strinfo[NFS].mnt_typ, "cdrom");
538 					break;
539 			default: strcpy (strinfo[NFS].mnt_typ, "user defined");
540 					break;
541 			}
542 		strcpy (strinfo[NFS].mnt_opt, "");
543 		if (mnt_info -> vmt_flags & MNT_READONLY)
544 			strcat (strinfo[NFS].mnt_opt, "ro, ");
545 		if (mnt_info -> vmt_flags & MNT_REMOVABLE)
546 			strcat (strinfo[NFS].mnt_opt, "removable, ");
547 		if (mnt_info -> vmt_flags & MNT_DEVICE)
548 			strcat (strinfo[NFS].mnt_opt, "device, ");
549 		if (mnt_info -> vmt_flags & MNT_REMOTE)
550 			strcat (strinfo[NFS].mnt_opt, "remote, ");
551 		if (mnt_info -> vmt_flags & MNT_UNMOUNTING)
552 			strcat (strinfo[NFS].mnt_opt, "unmounting, ");
553 		if (mnt_info -> vmt_flags & MNT_SYSV_MOUNT)
554 			strcat (strinfo[NFS].mnt_opt, "sysv mount, ");
555 		if (mnt_info -> vmt_flags & MNT_NOSUID)
556 			strcat (strinfo[NFS].mnt_opt, "no suid, ");
557 		if (mnt_info -> vmt_flags & MNT_NODEV)
558 			strcat (strinfo[NFS].mnt_opt, "no device access, ");
559 		/* *** safety in case none of the above apply *** */
560 		if (!strcmp (strinfo[NFS].mnt_opt, ""))
561 			strcpy (strinfo[NFS].mnt_opt, "rw");
562 		/* *** remove trailing comma *** */
563 		if (strinfo[NFS].mnt_opt[strlen(strinfo[NFS].mnt_opt)-2] == ',')
564 		    strinfo[NFS].mnt_opt[strlen(strinfo[NFS].mnt_opt)-2] = '\0';
565 		i++;
566 		mnt_info=(struct vmount *)((char *)
567 			mnt_info+mnt_info->vmt_length);
568 #    else
569 #    ifdef ULTRIX
570 		strcpy (strinfo[NFS].fs_name, mnt_info.mnt_dir);
571 		strcpy (strinfo[NFS].dev_name, mnt_info.mnt_fsname);
572 		strcpy (strinfo[NFS].mnt_typ, gt_names[mnt_info.mnt_type]);
573 		/* *** IBM & ULTRIX developers should go bowling together *** */
574 		/* ***      then again, it almost looks like they have    *** */
575 		strcpy (strinfo[NFS].mnt_opt, "");
576 		if (mnt_info.mnt_opts & M_RONLY)
577 			strcat (strinfo[NFS].mnt_opt, "ro, ");
578 		if (mnt_info.mnt_opts & M_QUOTA)
579 			strcat (strinfo[NFS].mnt_opt, "quota, ");
580 		if (mnt_info.mnt_opts & M_LOCAL)
581 			strcat (strinfo[NFS].mnt_opt, "local, ");
582 		if (mnt_info.mnt_opts & M_NOSUID)
583 			strcat (strinfo[NFS].mnt_opt, "nosuid, ");
584 		if (mnt_info.mnt_opts & M_NODEV)
585 			strcat (strinfo[NFS].mnt_opt, "nodev, ");
586 		if (mnt_info.mnt_opts & M_FORCE)
587 			strcat (strinfo[NFS].mnt_opt, "force, ");
588 		if (mnt_info.mnt_opts & M_SYNC)
589 			strcat (strinfo[NFS].mnt_opt, "sync ,");
590 		if (mnt_info.mnt_opts & M_NOCACHE)
591 			strcat (strinfo[NFS].mnt_opt, "nocache, ");
592 		if (mnt_info.mnt_opts & M_EXPORTED)
593 			strcat (strinfo[NFS].mnt_opt, "exported, " );
594 		if (mnt_info.mnt_opts & M_EXRONLY)
595 			strcat (strinfo[NFS].mnt_opt, "exported ro, ");
596 		if (mnt_info.mnt_opts & M_NOEXEC)
597 			strcat (strinfo[NFS].mnt_opt, "noexec, ");
598 		/* *** safety in case none of the above apply *** */
599 		if (!strcmp (strinfo[NFS].mnt_opt, ""))
600 			strcpy (strinfo[NFS].mnt_opt, "rw");
601 		/* *** remove trailing comma *** */
602 		if (strinfo[NFS].mnt_opt[strlen (strinfo[NFS].mnt_opt)-2]==',')
603 			strinfo[NFS].mnt_opt[
604 				strlen (strinfo[NFS].mnt_opt)-2] = '\0';
605 #     else
606 #     ifdef SCO
607 		sscanf (buffer, "%s%*s%s%s", strinfo[NFS].fs_name,
608 			strinfo[NFS].dev_name, strinfo[NFS].mnt_opt);
609 #     endif /* SCO */
610 #    endif /* ULTRIX */
611 #   endif /* AIX */
612 #  endif /* OSF1 */
613 # endif /* SVR4 || SOLARIS */
614 #endif /* SUNOS || LINUX || DYNIX || HPUX || ULTRIX || CONVEXOS || MACH ||
615           AUX || SGI || DGUX */
616 
617 
618 		/* *** see if this is one of the file *** */
619 		/* *** systems that we want to remove *** */
620 		removed=FALSE;
621 #if !defined (MACH) && !defined (AIX) && !defined (OSF1) && \
622     !defined (SCO) && !defined (FreeBSD) && !defined (BSDI)
623 		/* *** AIX does not need it as we use mntctl         *** */
624 		/* *** OSF1 neither as it uses getfsstat             *** */
625 # ifdef ULTRIX
626 		if (mnt_info.mnt_type == fs_ignore)
627 			removed=TRUE;
628 # else
629 #  if defined (SOLARIS) || defined (SVR4)
630 		if (strstr(mnt_info.mnt_opts, fs_ignore))
631 			removed=TRUE;
632 #  else
633 #   if defined (SGI)
634 		if (strstr(mnt_info->mnt_opts, fs_ignore))
635 			removed=TRUE;
636 #   else
637 #    if defined (DGUX)
638 		if (hasmntopt(mnt_info,fs_ignore) != NULL)
639 			removed=TRUE;
640 #     else
641 		/* *** generic comparison *** */
642 		if (!override_ignore)
643 			if (!strcmp(mnt_info->mnt_type, fs_ignore))
644 				{
645 				removed=TRUE;
646 				if (verbose && !turns)
647 					printf ("%s marked MNTTYPE_IGNORE ... overriding ignore ...",
648 						strinfo[NFS].fs_name);
649 				}
650 
651 #    endif /* DGUX */
652 #   endif /* SGI */
653 #  endif /* SOLARIS || SVR4 */
654 # endif /* ULTRIX */
655 #endif /* !MACH && !AIX && !OSF1 && !SCO && !FreeBSD && !BSDI */
656 
657 		/* *** see if the user has any options which affect *** */
658 		/* *** which file systems we show *** */
659 #ifndef SCO
660 		if (only_t)
661 			if (strcmp (strinfo[NFS].mnt_typ, only_type))
662 				removed=TRUE;
663 #endif /* !SCO */
664 		if (!removed)
665 		   for (x=0; x<ignore_n_count; x++)
666 			/* *** we found a match *** */
667 			if (!strcmp (strinfo[NFS].fs_name, ignore_names[x]))
668 				{
669 				removed=TRUE;
670 				x=ignore_n_count;
671 				}
672 		if (!removed)
673 		   for (x=0; x<ignore_p_count; x++)
674 			/* *** we found a match *** */
675 			if(strstr(strinfo[NFS].fs_name,ignore_pattern[x])!=NULL)
676 				{
677 				removed=TRUE;
678 				x=ignore_p_count;
679 				}
680 #ifndef SCO
681 		if (!removed)
682 		   for (x=0; x<ignore_t_count; x++)
683 			/* *** we found a match *** */
684 			if (!strcmp (strinfo[NFS].mnt_typ, ignore_type[x]))
685 				{
686 				removed=TRUE;
687 				x=ignore_t_count;
688 				}
689 #endif /* !SCO */
690 
691 		/* *** FS was not targeted by -d, -D, -it or -ot option *** */
692 		if (!removed && (select_n_count > 0))
693 			{
694 			removed=TRUE;
695 			for (x=0; x<select_n_count; x++)
696 				/* *** we found a match *** */
697 				if (!strcmp (strinfo[NFS].fs_name,
698 				    	     select_names[x]))
699 					{
700 					removed=FALSE;
701 					x=select_n_count;
702 					}
703 			}
704 		if (!removed && (select_p_count > 0))
705 			{
706 			removed=TRUE;
707 			for (x=0; x<select_p_count; x++)
708 				/* *** we found a match *** */
709 				if (strstr (strinfo[NFS].fs_name,
710 					    select_pattern[x])!=NULL)
711 					{
712 					removed=FALSE;
713 					x=select_p_count;
714 					}
715 			}
716 
717 		if (!removed)
718 			NFS++;
719 		fs_returned++;
720 		/* *** end of while loop *** */
721 		}
722 
723 	/* ***         close the file           *** */
724 	/* *** ULTRIX: didn't open a file so    *** */
725 	/* *** we also don't have to close it   *** */
726 	/* *** AIX and OSF1: Same as AIX        *** */
727 	/* *** although we free the buffer      *** */
728 #if defined (SUNOS) || defined (LINUX) || defined (HPUX) || \
729     defined (CONVEXOS) || defined (MACH) || defined (AUX) || defined (SGI) || \
730     defined (DGUX)
731 	endmntent(fp);
732 # else
733 # if defined (SVR4) || defined (SOLARIS) || defined (SCO)
734 	fclose (fp);
735 #  else
736 #  ifdef AIX
737 	free (vmount_buf);
738 #   else
739 #   ifdef OSF1
740 	free (mnt_info);
741 #   endif /* OSF1 */
742 #  endif /* AIX */
743 # endif /* SVR4 || SOLARIS */
744 #endif /* SUNOS || LINUX || HPUX || CONVEXOS || MACH || DYNIX || AUX || SGI ||
745 	  DGUX */
746 
747 	if (NFS==MAXFS)
748 		{
749 		printf ("Maximum number of file systems (%d) exceeded...",
750 			MAXFS);
751 		printf ("Ignoring Rest\n");
752 		}
753 	/* *** did we get any valid file sytems back *** */
754 	if (NFS < 1)
755 		{
756 		if (fs_returned > 0)
757 			fprintf (stderr,
758 				"Mount returned %d file systems\nAfter \
759 processing command line none are left ... exiting\n", fs_returned);
760 		else
761 			fprintf (stderr,
762 				"Mount returned no valid file systems ... \
763 Exiting\n");
764 		exit (1);
765 		}
766 
767 	if (sort)
768 		/* *** perform simple selection sort *** */
769 		for (x=0; x<NFS; x++)
770 			{
771 			min=x;
772 			for (y=x+1; y<NFS; y++)
773 				if ((strcmp (strinfo[idx[min]].fs_name,
774 					     strinfo[idx[y]].fs_name)) > 0)
775 					min=y;
776 			if (min != x)
777 				{
778 				printf ("switching %d, %d\n", min, x);
779 				t=idx[min];
780 				idx[min]=idx[x];
781 				idx[x]=t;
782 				}
783 			}
784 }
785 
786 
787 
788 /* *********************************************************************** */
789 /* ********************** get the file system stats ********************** */
790 /* *********************************************************************** */
get_fs_stat()791 void get_fs_stat()
792 {
793 	static time_t	last_mod_time=0;
794 	int 		i, j, t, x, old_lname=lname, updated=FALSE, shortcut=TRUE;
795 	double		blocks,
796 			bfree,
797 #ifndef SCO
798 			bavail,
799 #endif
800 			bsize,
801 			orig_blocks;
802 	struct stat	stat_info;
803 
804 #if !defined (AIX) && !defined (ULTRIX) && !defined (OSF1) && \
805 	!defined (FreeBSD) && !defined (BSDI)
806 	/* *** This does not work under AIX as just about everything  *** */
807 	/* *** is stored in the ODM datbase. Some *&$%*&*$&% design!  *** */
808 	/* *** ULTRIX and OSF1 on the other hand seem to keep it all  *** */
809 	/* ***    in memory. See my comment about the AIX design.     *** */
810 	/* *** Anyhow, here we check if MOUNT_FILE has been modified. *** */
811 	/* ***  If not, no file systems have been (dis)mounted and    *** */
812 	/* ***   we don't have to call get_fs(). This is much cheaper *** */
813 	/* ***        than calling get_fs() everytime we update.      *** */
814 	if (!(stat (MOUNT_FILE, &stat_info)))
815 		{
816 		if (stat_info.st_mtime > last_mod_time)
817 			{
818 			last_mod_time = stat_info.st_mtime;
819 			b_blocks=0;
820 			b_bsize=0;
821 			b_disk=0;
822 			lname=0;
823 			updated=TRUE;
824 			/* *** get mounted file systems *** */
825 			get_fs ();
826 			}
827 		}
828 	else
829 		{
830 		fprintf(stderr,"Can't get stat of %s ... Exiting\n", MOUNT_FILE);
831 		exit (1);
832 		}
833 #else
834 	/* *** get mounted file systems unconditionally *** */
835 	/* *** we can't check with stat() to save time *** */
836 	lname=0;
837 	updated=TRUE;
838 	shortcut=FALSE;
839 	get_fs ();
840 #endif /* !AIX && !ULTRIX && !OSF1 && !FreeBSD && !BSDI */
841 
842 	if (!turns)
843 		{
844 		updated=TRUE;
845 		lname=0;
846 		}
847 
848  	/* *** read file system status *** */
849 	for (i=0; i<NFS; i++)
850 		{
851 #if defined (SUNOS) || defined (LINUX) || defined (AIX) || defined (HPUX) || \
852     defined (ULTRIX) || defined (CONVEXOS) || defined (MACH) || \
853     defined (OSF1) || defined (FreeBSD) || defined (AUX)
854 #undef statfs
855 		t=statfs (FsName, &stats[i]);
856 # else
857 # if defined (SVR4) || defined (SOLARIS) || defined (SGI) || defined (DGUX)
858 		t=statvfs (FsName, &stats[i]);
859 #  else
860 #  if defined (DYNIX) || defined (SCO)
861 		t=statfs (FsName, &stats[i], sizeof(struct statfs), 0);
862 #  endif /* DYNIX || SCO */
863 # endif /* SVR4 || SOLARIS || SGI || DGUX */
864 #endif /* SUNOS || LINUX || AIX || HPUX || ULTRIX || CONVEXOS || MACH || \
865           OSF1 || FreeBSD || AUX || BSDI */
866 
867 	/* *** see if the return code is an error *** */
868 	if (t == -1)
869 		{
870 		fs_perc[i]=NOGOOD;
871 		fprintf (stderr, "Can't get superblock describing %s ...\n",
872 			FsName);
873 		}
874 	else
875 		{
876 #ifdef DEBUG
877 		printf ("Got status on %s\n", FsName);
878 #endif
879 
880 		blocks=stats[i].f_blocks;
881 		bfree=stats[i].f_bfree;
882 #ifdef SCO
883 		bsize=512;
884 #else
885 		bsize=stats[i].f_bsize;
886 #endif
887 #ifndef SCO
888 		bavail=stats[i].f_bavail;
889 #endif
890 
891 		/* *** find largest file system and block size *** */
892 		if (blocks > b_blocks)
893 			b_blocks=blocks;
894 
895 		if (bsize > b_bsize)
896 			b_bsize=bsize;
897 
898 		if (bsize*blocks > b_disk)
899 			b_disk=bsize*blocks;
900 
901 		/* *** find largest file system name if we called get_fs *** */
902 		if (minimize == MNL)
903 			{
904 			int l = XTextWidth(main_win.font_info, FsName,
905 				strlen(FsName)+4);
906 
907 			if (l > lname)
908 				lname = l;
909 			}
910 
911 		/* *** throw out file systems of size 0 *** */
912 		if (blocks == 0)
913 			{
914 			if (verbose && turns && shortcut)
915 			 printf ("File system %s is of size 0 - ignoring it!\n",
916 				FsName);
917 			for (x=i; x<NFS; x++)
918 				{
919 				strcpy (strinfo[x].fs_name,
920 					strinfo[x+1].fs_name);
921 				strcpy (strinfo[x].dev_name,
922 					strinfo[x+1].dev_name);
923 #ifndef SCO
924 				strcpy (strinfo[x].mnt_typ,
925 					strinfo[x+1].mnt_typ);
926 #endif /* SCO */
927 				strcpy (strinfo[x].mnt_opt,
928 					strinfo[x+1].mnt_opt);
929 				stats[x]=stats[x+1];
930 				}
931 			i--;
932 			NFS--;
933 			}
934 		else
935 			{
936 			/* *** figure out percentage of free blocks *** */
937 			if (root)
938 			   {
939 	   		   if (show_use)
940 				{
941 				if (rootdf)
942 	   				fs_perc[i]=(float) ((blocks-bfree)/(blocks-bfree+bavail));
943 				else
944 	   				fs_perc[i]=(float) ((blocks-bfree)/blocks);
945 #ifdef DEBUG
946 	   			printf ("A: Total: %f \t Free: %f == %2f%%\n",
947 					blocks, bfree, fs_perc[i]);
948 #endif
949 				}
950 	   		   else
951 				{
952 				if (rootdf)
953 	   				fs_perc[i]=(float) (bfree/(blocks-bfree+bavail));
954 				else
955 	   				fs_perc[i]=(float) (bfree/blocks);
956 #ifdef DEBUG
957 	   			printf ("B: Total: %f \t Free: %f == %2f%%\n",
958 					blocks, bfree, fs_perc[i]);
959 #endif
960 				}
961 			   }
962 #ifndef SCO
963 			/* *** SCO doesn't know bavail - can't use this *** */
964 			else
965 			   {
966 			   /* *** account for the reserved     *** */
967 			   /* *** space and decrease the       *** */
968 			   /* *** number of blocks accordingly *** */
969 			   orig_blocks=blocks;
970 			   blocks *= (1-res_space);
971 	   		   if (show_use)
972 				{
973 				/* *** msdos doesn't know reserved space *** */
974 				if (strstr (strinfo[i].mnt_typ, "msdos"))
975 					fs_perc[i]=(float)((orig_blocks-bavail)/
976 						orig_blocks);
977 				else
978 					fs_perc[i]=(float)
979 						((blocks-bavail)/blocks);
980 # ifdef DEBUG
981 	   			printf ("C: Total: %f \t Avail: %f == %.2f%%\n",
982 					blocks, bavail, fs_perc[i]);
983 # endif
984 				}
985 	   		  else
986 				{
987 				/* *** msdos doesn't know reserved space *** */
988 				if (strstr (strinfo[i].mnt_typ, "msdos"))
989 	   				fs_perc[i]=(float) (bavail/orig_blocks);
990 				else
991 	   				fs_perc[i]=(float) (bavail/blocks);
992 # ifdef DEBUG
993 	   			printf ("D: Total: %f \t Avail: %f == %.2f%%\n",
994 					blocks, bavail, fs_perc[i]);
995 # endif
996 				}
997 			   }
998 #endif /* !SCO */
999 			}
1000 		}
1001 	}
1002 	/* *** No file systems left *** */
1003 	if (NFS < 1)
1004 		{
1005 		fprintf(stderr,"No File systems left ... Exiting\n");
1006 		exit (0);
1007 		}
1008 
1009 	/* *** Update bar levels *** */
1010 	for (i=0; i<NFS; i++)
1011 		{
1012 		for (j=3; j>=0; j--)
1013 			{
1014 			if (warnvals[j] > -1 && fs_perc[i] >= warnvals[j])
1015 				{
1016 #ifdef DEBUG
1017 				printf("LEVEL: fs_perc[%d] = %f\n",i,fs_perc[i]);
1018 				printf("LEVEL: old level   = %d\n",fs_level[i]);
1019 				printf("LEVEL: new level   = %d\n",j);
1020 #endif
1021                    		if (fs_level[i] < j)
1022 					{
1023 #ifdef DEBUG
1024 					printf("LEVEL: warning set for %d\n",i);
1025 #endif
1026 					fs_warn[i] = TRUE;
1027 					}
1028 				fs_level[i] = j;
1029 				break;
1030                 		}
1031 			}
1032 		}
1033 
1034 
1035 	/* *** calculate the new main window width *** */
1036 	if ((!minimize || minimize == MNL) && updated && old_lname != lname)
1037 		{
1038 		main_win.width = OFF_X + OFF_X + lname + percent_width;
1039 
1040 		if (main_win.width < MIN_WIN_X)
1041 			main_win.width=MIN_WIN_X;
1042 		if (turns)
1043 			{
1044 			XResizeWindow (mydisplay, main_win.win, main_win.width,
1045 				main_win.height);
1046 			fix_menu_pos (main_win.width);
1047 			}
1048 		for (i=0; i<NFS; i++)
1049 			{
1050 			fs_win[i].width=main_win.width-OFF_X*2;
1051 			/* *** don't do this the first time *** */
1052 			if (turns)
1053 				fix_fs_win_width (i);
1054 			if (turns)
1055 				{
1056 				XResizeWindow (mydisplay, fs_win[i].win,
1057 					fs_win[i].width, fs_win[i].height);
1058 				if (fs_perc[i]!=NOGOOD)
1059 					redraw_fs_win (i);
1060 				}
1061 			}
1062 		}
1063 	turns++;
1064 }
1065 
1066 
1067 
1068 
1069 /* ***************************************************************** */
1070 /* ****************** Process the program arguments **************** */
1071 /* ***************************************************************** */
process_databases(argc,argv,commandlineDB)1072 void process_databases (argc, argv, commandlineDB)
1073 int argc;
1074 char **argv;
1075 XrmDatabase commandlineDB;
1076 {
1077 	char name[MAXPATHLEN];
1078 	char msg[255];
1079 	int i;
1080 
1081 	strcpy (msg, "");
1082 	/* *** Load the local app-defaults file. *** */
1083 	if (getenv ("XAPPLRESDIR"))
1084 		{
1085 		strcpy(name, getenv ("XAPPLRESDIR"));
1086 		strcat(name, "/");
1087 		strcat(name, CLASS_NAME);
1088 		resourceDB = XrmGetFileDatabase(name);
1089 		if (resourceDB)
1090 			sprintf (msg,
1091 				"Read Resource definitions in %s ...", name);
1092 		}
1093 
1094 
1095 	/* *** check if we really found something *** */
1096 	/* *** if not, check in APP_DEFAULTS_DIR *** */
1097 	if (!resourceDB)
1098 		{
1099 		strcpy(name, APP_DEFAULTS_DIR);
1100 		strcat(name, "/");
1101 		strcat(name, CLASS_NAME);
1102 		resourceDB = XrmGetFileDatabase(name);
1103 		if (resourceDB)
1104 			sprintf(msg, "Read Resource definitions in %s ...",
1105 				name);
1106 		}
1107 
1108 	/* *** Load in any definitions supplied in the X server. *** */
1109 	if (XResourceManagerString(mydisplay) != NULL)
1110 		XrmMergeDatabases(XrmGetStringDatabase(XResourceManagerString
1111 			(mydisplay)), &resourceDB);
1112 
1113 	/* *** Merge in the command line arguments. *** */
1114 	XrmMergeDatabases(commandlineDB, &resourceDB);
1115 
1116 	/* *** See if the help flag was set. *** */
1117 	if (getBoolResource(resourceDB, catlist(myname, ".help", (char*)NULL),
1118 		"Xfsm.Help", False))
1119 			do_help();
1120 
1121 	/* *** See if the verbose flag was set. *** */
1122 	if ((verbose = getBoolResource(resourceDB,
1123 		catlist(myname, ".verbose", (char*) NULL),
1124 		"Xfsm.Verbose", False)))
1125 		{
1126 		PRINT_COPYRIGHT;
1127 		puts ("-v flag caught - verbose mode enabled...");
1128 		if (resourceDB && strlen (msg))
1129 			puts (msg);
1130 		}
1131 
1132 	/* *** this one has to go befor the -fg evaluation   *** */
1133 	/* *** as otherwise the default supplied to the      *** */
1134 	/* *** evaluation function will override our setting *** */
1135 	if (!(gray = getBoolResource(resourceDB,
1136 		catlist(myname, ".gray", (char*) NULL), "Xfsm.Gray", True)))
1137 		if (verbose)
1138 			puts("-b flag caught - will draw bars black.");
1139 
1140 	/* *** assign foreground and backgound colors *** */
1141  	fg = getColorResource(resourceDB, catlist(myname,
1142 		".foreground", (char*) NULL), "Xfsm.Foreground",
1143 		BlackPixel (mydisplay, DefaultScreen (mydisplay)));
1144 	if (fg != BlackPixel (mydisplay, DefaultScreen (mydisplay)))
1145 		{
1146 		if (verbose)
1147 			printf ("-fg flag caught - foreground set and \
1148 gray fill disabled.\n");
1149 		gray=FALSE;
1150 		}
1151 
1152 	bg = getColorResource(resourceDB, catlist(myname,
1153 		".background", (char*) NULL), "Xfsm.Background",
1154 		WhitePixel (mydisplay, DefaultScreen (mydisplay)));
1155 	if (bg != WhitePixel (mydisplay, DefaultScreen (mydisplay)))
1156 		if (verbose)
1157 			printf ("-bg flag caught - background set\n");
1158 
1159 #ifndef SCO
1160 	if ((root = getBoolResource(resourceDB,
1161 		catlist(myname, ".root", (char*) NULL), "Xfsm.Root", False)))
1162 		{
1163 		if (verbose)
1164 			puts("-r flag caught - will give statistics for root.");
1165 		}
1166 
1167 	if ((rootdf = getBoolResource(resourceDB,
1168 		catlist(myname, ".rootdf", (char*) NULL), "Xfsm.Rootdf", False)))
1169 		{
1170 		if (verbose)
1171 			puts("-rootdf flag caught - will calculate df % values with root mode.");
1172 		}
1173 #endif
1174 
1175 	if ((minimize = getIntResource(resourceDB,
1176 		catlist(myname, ".minimize", (char*) NULL),
1177 		"Xfsm.Minimize", False)))
1178 		{
1179 		if (verbose)
1180 			{
1181 			if (minimize == MNL)
1182 				puts("-mnl flag caught - will minimize \
1183 window with regard to FS name length.");
1184 			else
1185 				puts("-m flag caught - will minimize \
1186 window size.");
1187 			}
1188 		}
1189 
1190 	if ((menu_border = getBoolResource(resourceDB,
1191 		catlist(myname, ".menuborder", (char*)NULL),
1192 		"Xfsm.Menuborder", False)))
1193 		if (verbose)
1194 			puts("-mb flag caught - will draw menu border.");
1195 
1196 	if ((fs_border = getBoolResource(resourceDB,
1197 		catlist(myname, ".fs_border", (char*)NULL),
1198 		"Xfsm.Fs_border", True)));
1199 	else
1200 		if (verbose)
1201 			puts("-fsb flag caught - will not draw file system \
1202 border.");
1203 
1204 	if (!(percent = getBoolResource(resourceDB,
1205 		catlist(myname, ".percent", (char*) NULL),
1206 		"Xfsm.Percent", True)))
1207 		{
1208 		available=FALSE;
1209 		if (verbose)
1210 			puts("-p flag caught - will turn percent display off.");
1211 		}
1212 
1213 	if ((available = getBoolResource(resourceDB,
1214 		catlist(myname, ".available", (char*) NULL),
1215 		"Xfsm.Available", False)))
1216 			{
1217 			percent=FALSE;
1218 			if (verbose)
1219 				puts("-A flag caught - will show available \
1220 space in MBs");
1221 			}
1222 
1223 	if ((override_ignore = getBoolResource(resourceDB,
1224 		catlist(myname, ".override_ignore", (char*) NULL),
1225 		"Xfsm.OverrideIgnore", False)))
1226 		if (verbose)
1227 			puts("-oi flag caught - will keep file systems \
1228 marked 'ignore'.");
1229 
1230 	if ((absolute = getBoolResource(resourceDB,
1231 		catlist(myname, ".absolute", (char*) NULL),
1232 		"Xfsm.Absolute", False)))
1233 		if (verbose)
1234 			puts("-a flag caught - will display sizes relative \
1235 to absolute FS size.");
1236 
1237 	if (!(show_use = getBoolResource(resourceDB,
1238 		catlist(myname, ".used", (char*) NULL), "Xfsm.Used", True)))
1239 		if (verbose)
1240 			puts("-f flag caught - will show space free rather \
1241 than space used.");
1242 
1243 	if ((show_biggest = getBoolResource(resourceDB,
1244 		catlist(myname, ".showbiggest", (char*) NULL),
1245 		"Xfsm.ShowBiggest", False)))
1246 		if (verbose)
1247 			puts("-sb flag caught - will show biggest file \
1248 system size.");
1249 
1250 	if ((bell = getBoolResource(resourceDB,
1251 		catlist(myname, ".bell", (char*) NULL), "Xfsm.Bell", False)))
1252 		if (verbose)
1253 			puts("-e flag caught - will extend warning to \
1254 include a beep.");
1255 
1256 	if ((sort = getBoolResource(resourceDB,
1257 		catlist(myname, ".sort", (char*) NULL),
1258 		"Xfsm.Sort", False)))
1259 		if (verbose)
1260 			puts ("-sort flag caught - will sort by name ...");
1261 
1262 	if ((detail_share_color = getBoolResource(resourceDB,
1263 		catlist(myname, ".detailWin.share", (char*) NULL),
1264 		"Xfsm.detailWin.Share", False)))
1265 		if (verbose)
1266 		puts ("Detail window will have the same color as the \
1267 file system it is displaying.");
1268 
1269 
1270 	if ((res_space = (float) getIntResource(resourceDB,
1271 		catlist(myname, ".reserved_space", (char*)NULL),
1272 		"Xfsm.Reserved_space", RES_SPACE_DFLT)) != RES_SPACE_DFLT)
1273 		{
1274 		if (res_space < 0 || res_space > 100)
1275 			{
1276 			printf("Illegal value specified for resreved space ... \
1277 resetting to default (%d%%)\n", RES_SPACE_DFLT);
1278 			res_space=10;
1279 			}
1280 		else
1281 			if (verbose)
1282 				printf ("-rs flag caught - setting reserved \
1283 space level to %f %%.\n", res_space);
1284 		}
1285 	res_space /= 100.0;
1286 
1287 	if ((popup = getBoolResource(resourceDB,
1288                 catlist(myname, ".popup", (char*) NULL),
1289                 "Xfsm.Popup", False)))
1290                 if (verbose)
1291 			printf ("-pu flag caught - setting popup\n");
1292 
1293 	if ((warn_val = (float) getIntResource(resourceDB,
1294 		catlist(myname, ".warnval", (char*)NULL),
1295 		"Xfsm.Warnval", 0)) != 0.0)
1296 		{
1297 		if (warn_val < 1.0 || warn_val > 99.0)
1298 			{
1299 			puts("Illegal value supplied for warning threshold ... \
1300 resetting.");
1301 			warn_val = 0.0;
1302 			}
1303 		else
1304 			{
1305 			if (verbose)
1306 				printf ("-w flag caught - setting warning \
1307 threshold to %f %%.\n", warn_val);
1308 			warn_val /= 100.0;
1309 			}
1310 		}
1311 	if ((warnvals[1] = (float) getIntResource(resourceDB,
1312 		catlist(myname, ".warn1val", (char*)NULL),
1313 		"Xfsm.Warn1val", -1)) != -1)
1314 		{
1315 		if (warnvals[1] < 0 || warnvals[1] > 100)
1316 			{
1317 			fprintf (stderr,
1318 				"Illegal warning level 1 (%f) specifed ...\
1319 exiting\n", warnvals[1]);
1320 			exit (1);
1321 			}
1322 		else
1323 			{
1324 			if (verbose)
1325 				printf ("-wl1 flag caught and gray fill disabled \n\t- setting warning \
1326 level 1 to %f %%.\n", warnvals[1]);
1327 			gray=FALSE;
1328 			warnvals[1] /= 100;
1329 			}
1330 		}
1331 	if ((warnvals[2] = (float) getIntResource(resourceDB,
1332 		catlist(myname, ".warn2val", (char*)NULL),
1333 		"Xfsm.Warn2val", -1)) != -1)
1334 		{
1335 		if (warnvals[2] <= warnvals[1] || warnvals[2] > 100)
1336 			{
1337 			fprintf (stderr,
1338 				"Illegal warning level 2 (%f) specifed ...\
1339 exiting\n", warnvals[2]);
1340 			exit (1);
1341 			}
1342 		else
1343 			{
1344 			if (verbose)
1345 				printf ("-wl2 flag caught and gray fill disabled \n\t- setting warning \
1346 level 2 to %f %%.\n", warnvals[2]);
1347 			gray=FALSE;
1348 			warnvals[2] /= 100;
1349 			}
1350 		}
1351 	if ((warnvals[3] = (float) getIntResource(resourceDB,
1352 		catlist(myname, ".warn3val", (char*)NULL),
1353 		"Xfsm.Warn3val", -1)) != -1)
1354 		{
1355 		if (warnvals[3] <= warnvals[2] || warnvals[3] > 100)
1356 			{
1357 			fprintf (stderr,
1358 				"Illegal warning level 3 (%f) specifed ...\
1359 exiting\n", warnvals[3]);
1360 			exit (1);
1361 			}
1362 		else
1363 			{
1364 			if (verbose)
1365 				printf ("-wl3 flag caught and gray fill disabled \n\t- setting warning \
1366 level 3 to %f %%.\n", warnvals[3]);
1367 			gray=FALSE;
1368 			warnvals[3] /= 100;
1369 			}
1370 		}
1371 
1372 	 if ((warncols[0] = getColorResource(resourceDB, catlist(myname,
1373 		".warn0col", (char*)NULL), "Xfsm.Warn0col", fg)) != fg)
1374 		{
1375 		if (verbose)
1376 			printf ("-wl0c flag caught & gray fill disabled - default color \
1377 set to %d ...\n", (int)warncols[0]);
1378 		gray=FALSE;
1379                 }
1380 
1381 	if ((warncols[1] = getColorResource(resourceDB, catlist(myname,
1382 		".warn1col", (char*)NULL), "Xfsm.Warn1col", warncols[0])) != warncols[0])
1383 		{
1384 		if (verbose)
1385 			printf ("-wl1c flag caught - warning level 1 color \
1386 set to %d ...\n", (int)warncols[1]);
1387 		}
1388 	if ((warncols[2] = getColorResource(resourceDB, catlist(myname,
1389 		".warn2col",(char*)NULL),"Xfsm.Warn2col",warncols[1]))!=warncols[1])
1390 		{
1391 		if (verbose)
1392 			printf ("-wl2c flag caught - warning level 2 color \
1393 set to %d ...\n", (int)warncols[2]);
1394 		}
1395 	if ((warncols[3] = getColorResource(resourceDB, catlist(myname,
1396 		".warn3col",(char*)NULL),"Xfsm.Warn3col",warncols[2]))!=warncols[2])
1397 		{
1398 		if (verbose)
1399 			printf ("-wl3c flag caught - warning level 3 color \
1400 set to %d ...\n", (int)warncols[3]);
1401 		}
1402 
1403 	if ((upd_interval = getIntResource(resourceDB,
1404 		catlist(myname, ".updInterval", (char*)NULL),
1405 		"Xfsm.UpdInterval", 60)) != 60)
1406 		{
1407 		if (upd_interval < 1)
1408 			{
1409 			fprintf (stderr, "Supplied interval (%d) too small \
1410 (minimum = 1).\n", upd_interval);
1411 			exit (1);
1412 			}
1413 		if (verbose)
1414 			printf ("-i flag caught - update interval changed \
1415 to %d sec.\n", upd_interval);
1416 		}
1417 
1418 	for (i = 1; i < argc; i++)
1419 #ifndef SCO
1420 	   if (!strcmp (argv[i], "-ot"))
1421 		{
1422 		if (!only_t)
1423 			{
1424 			if (ignore_t_count)
1425 				{
1426 				fprintf (stderr, "-it and -ot conflict ... \
1427 will ignore any -it settings\n");
1428 				ignore_t_count=0;
1429 				}
1430 			strcpy (only_type, argv[i+1]);
1431 			only_t=TRUE;
1432 			i++;
1433 			}
1434 		else
1435 			fprintf (stderr,
1436 				"-ot flag already set ... will ignore %s\n",
1437 				argv[i+1]);
1438 		}
1439 	   else
1440 #endif /* !SCO */
1441 	   if (!strcmp (argv[i], "-d"))
1442 		/* *** does it begin with an "-" *** */
1443 		while (i < (argc - 1) && argv[i + 1][0] != '-')
1444 			{
1445 			if (ignore_n_count < MAXFS)
1446 				{
1447 				if (verbose)
1448 				    printf ("Will ignore %s ...\n", argv[i+1]);
1449 				strcpy (ignore_names[ignore_n_count++],
1450 					argv[i + 1]);
1451 				}
1452 			else
1453 				fprintf (stderr,
1454 					"Exceeded number of ignore file \
1455 systems ... %s ignored.\n", argv[i+1]);
1456 			i++;
1457 			}
1458 	   else
1459  	   if (!strcmp (argv[i], "-D"))
1460 		/* *** does it begin with an "-" *** */
1461 		while (i < (argc - 1) && argv[i + 1][0] != '-')
1462 			{
1463 			/* *** check all file systems for arg *** */
1464 			if (ignore_p_count < MAXFS)
1465 				{
1466 				if (verbose)
1467 					printf ("Will ignore patterns \
1468 matching %s ...\n", argv[i + 1]);
1469 				strcpy (ignore_pattern[ignore_p_count++],
1470 					argv[i + 1]);
1471 				}
1472 			else
1473 				fprintf (stderr,
1474 					"Exceeded number of ignore patterns \
1475 ... %s ignored\n", argv[i + 1]);
1476 			i++;
1477 			}
1478 	else
1479 	if (!strcmp (argv[i], "-s"))
1480 		/* *** does it begin with an "-" *** */
1481 		while (i < (argc - 1) && argv[i + 1][0] != '-')
1482 			{
1483 			if (select_n_count < MAXFS)
1484 				{
1485 				if (verbose)
1486 				    printf ("Will select %s ...\n", argv[i+1]);
1487 				strcpy (select_names[select_n_count++],
1488 					argv[i + 1]);
1489 				}
1490 			else
1491 				fprintf (stderr,
1492 					"Exceeded number of selected file \
1493 systems ... %s ignored.\n", argv[i+1]);
1494 			i++;
1495 			}
1496 	else
1497 	if (!strcmp (argv[i], "-S"))
1498 		/* *** does it begin with an "-" *** */
1499 		while (i < (argc - 1) && argv[i + 1][0] != '-')
1500 			{
1501 			/* *** check all file systems for arg *** */
1502 			if (select_p_count < MAXFS)
1503 				{
1504 				if (verbose)
1505 					printf ("Will select patterns \
1506 matching %s ...\n", argv[i + 1]);
1507 				strcpy (select_pattern[select_p_count++],
1508 					argv[i + 1]);
1509 				}
1510 			else
1511 				fprintf (stderr,
1512 					"Exceeded number of select patterns \
1513 ... %s ignored\n", argv[i + 1]);
1514 			i++;
1515 			}
1516 #ifndef SCO
1517 	else
1518 	if (!strcmp (argv[i], "-it"))
1519 		{
1520 		/* *** does it begin with an "-" *** */
1521 		while (i < (argc - 1) && argv[i + 1][0] != '-')
1522 			{
1523 			if (only_t)
1524 				{
1525 				fprintf (stderr, "-it and -ot conflict ... \
1526 will ignore any -it settings\n");
1527 				break;
1528 				}
1529 			/* *** check all file systems for arg *** */
1530 			if (ignore_t_count < MAXFS)
1531 				{
1532 				if (verbose)
1533 					printf ("Will ignore types %s ...\n",
1534 						argv[i + 1]);
1535 				strcpy (ignore_type[ignore_t_count++],
1536 					argv[i + 1]);
1537 				}
1538 			else
1539 				fprintf (stderr,
1540 					"Exceeded number of ignore patterns \
1541 ... %s ignored\n", argv[i + 1]);
1542 			i++;
1543 			}
1544 		}
1545 #endif /* !SCO */
1546 
1547 	   else
1548 	   printf ("Argument %s not recognized as an option ... ignored\n",
1549 		argv[i]);
1550 
1551 }
1552 
1553 
do_help()1554 void do_help ()
1555 {
1556 	printf ("\n\
1557                         X   X  FFFFF  SSSSS  M     M\n\
1558                          X X   F      S      M M M M\n\
1559                           X    FFFFF  SSSSS  M  M  M\n\
1560                          X X   F          S  M     M\n\
1561                         X   X  F      SSSSS  M     M\n\
1562 \n\
1563 displays a list of bar graphs for the file systems of the host you are on.\n\
1564 Clicking on a file system gives you detailed information - clicking in the\n\
1565 detail window or clicking in it again closes the detail window. Use %c or the\n\
1566 right mouse button to toggle between absolute and relative display modes.\n\
1567 The following options are supported:\n",
1568 TOGGLE_KEY);
1569 
1570 printf ("\n\
1571         +rv                     reverse video (use to override xrdb entry)\n\
1572         +synchronous            syncronous mode (use to override xrdb entry)\n\
1573         -?                      help\n\
1574 	-A			show available space in MBs\n\
1575         -a                      absolute display mode\n\
1576         -background <arg>       backgound color \n\
1577         -b                      black bars (disable gray fill)\n\
1578         -bg <arg>               same as -background\n\
1579         -bordercolor <arg>      border color\n\
1580 	-d <arg1 ... argn>	ignore these file systems\n\
1581 	-D <arg1 ... argn>	ignore file systems matching these patterns\n\
1582 	-detailgeometry         Geometry of detail window. Only X and Y are\n\
1583 					honored\n\
1584 	-e 			extend warning to include bell\n\
1585 	-f			show free space rather than space used\n\
1586 	-fg			same as -foreground\n\
1587         -font <arg>             font\n\
1588         -foreground <arg>       forground color (also file system bar color)\n\
1589         -geometry <arg>         geometry (will override extreme window sizes\n\
1590                                         to apply reasonable settings)\n\
1591         -help                   help\n\
1592         -i <arg>                interval at which stats are updated\n\
1593 					default = 60s\n\
1594 	-iconic                 iconic\n");
1595 #ifndef SCO
1596 printf ("\
1597 	-it <arg1 ... argn>	ignore file systems of this type\n");
1598 #endif /* !SCO */
1599 printf ("\
1600         -m                      minimize window size\n\
1601         -mb                     draw menu borders\n\
1602         -mnl                    minimize window size so that the longest file\n\
1603                                         system name fits\n\
1604         -name <arg>             run xfsm under this name\n");
1605 #ifndef SCO
1606 printf ("\
1607 	-ot <arg>		show only file systems of this type\n");
1608 #endif /* !SCO */
1609 printf ("\
1610 	-oi			-oi (override ignore) to keep file systems\n\
1611 					which are marked 'ignore'\n\
1612 	-p                      don't display percentages\n");
1613 #ifndef SCO
1614 printf ("\
1615         -r                      display space with respect to root\n\
1616 	-rootdf			calculate df %% when running in root (-r) mode\n");
1617 #endif /* !SCO */
1618 printf ("\
1619 	-rs <arg>		specify the amount of space reserved for root\n\
1620 					default = %d%% \n\
1621         -rv                     reverse video\n\
1622 	-s <arg1 ... argn>	select only these file systems\n\
1623 	-S <arg1 ... argn>	select only file systems matching these patterns\n\
1624 	-sb			show biggest file system size in lower right\n\
1625 	-sort			sort file systems according to name\n\
1626         -synchronous            synchronous mode\n\
1627 	-t 			tile to show in main window\n\
1628         -v                      verbose\n\
1629         -w <arg>                display warning pix when usage reaches <arg>%%\n\
1630 	-wl0			default color for file systems\n\
1631 	-wl1			first warning level\n\
1632 	-wl1c			first warning level color\n\
1633 	-wl2			second warning level\n\
1634 	-wl2c			second warning level color\n\
1635 	-wl3			third warning level\n\
1636 	-wl3c			third warning level color\n\
1637         -xrm                    set an entry in the resource database for\n\
1638                                         this execution only\n\
1639         help                    get this description\n", RES_SPACE_DFLT);
1640 
1641 
1642 	PRINT_KNOWN_BUGS;
1643 	PRINT_COPYRIGHT;
1644 	exit (0);
1645 }
1646 
1647