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 files ****** */ 20 #include <X11/Xlib.h> 21 #include <X11/Xutil.h> 22 #include <X11/Xos.h> 23 #include <X11/Xresource.h> 24 #ifndef DYNIX 25 # include <stdlib.h> 26 #endif 27 #ifdef __STDC__ 28 # include <stdarg.h> 29 #else 30 # include <varargs.h> 31 #endif 32 #include <stdio.h> 33 #include <sys/types.h> 34 #include <sys/param.h> 35 #include <sys/stat.h> 36 /* ******************************************************************* */ 37 /* *** This may seem an odd way of handling porting exceptions but *** */ 38 /* *** it concentrates most changes right here and results in code *** */ 39 /* *** which is much more legible and mainainable than if I had to *** */ 40 /* *** #ifdef all these into util.c. After almost 10 different *** */ 41 /* *** systems were supported legibility started to become a *** */ 42 /* *** problem so I opted for this approach. *** */ 43 /* ******************************************************************* */ 44 #if defined (SUNOS) || defined (LINUX) || defined (HPUX) || \ 45 defined (CONVEXOS) || defined (MACH) || defined (AUX) 46 #include <sys/vfs.h> 47 #include <mntent.h> 48 #define fs_ignore MNTTYPE_IGNORE /* ignore FS flag */ 49 # else 50 # if defined (SVR4) || defined (SOLARIS) || defined (DGUX) 51 # include <sys/statvfs.h> 52 # include <sys/mnttab.h> 53 # include <sys/mntent.h> 54 # define statfs statvfs /* FS stats structure */ 55 # if defined (SVR4) || defined (SOLARIS) 56 # define mntent mnttab /* mount structure */ 57 # define mnt_fsname mnt_special /* device name */ 58 # define mnt_dir mnt_mountp /* mount point */ 59 # define mnt_type mnt_fstype /* mount type */ 60 # define mnt_opts mnt_mntopts /* mount option */ 61 # define f_bsize f_frsize /* block size */ 62 # ifdef SOLARIS 63 # define fs_ignore MNTOPT_IGNORE /* ignore FS flag */ 64 # else 65 # define fs_ignore MNTTYPE_IGNORE /* ignore FS flag */ 66 # endif /* SOLARIS */ 67 # endif /* SVR4 || SOLARIS */ 68 # if defined (DGUX) 69 # include <mntent.h> 70 # define fs_ignore "ignore" /* ignore FS flag */ 71 # endif /* DGUX */ 72 # else 73 # ifdef DYNIX 74 # include <mntent.h> 75 # include <sys/vfs.h> 76 # include <sys/select.h> 77 # include <sys/statfs.h> 78 # define fs_ignore MNTTYPE_IGNORE /* ignore FS flag */ 79 # else 80 # ifdef AIX 81 # include <sys/statfs.h> 82 # include <sys/select.h> /* required for msleep */ 83 # include <sys/mntctl.h> 84 # include <sys/vmount.h> 85 # include <fstab.h> 86 # define mntent vmount /* mount structure */ 87 # define BUFFERSIZE 128*1024 /* 128 Kb */ 88 # else 89 # ifdef OSF1 90 # include <sys/mount.h> 91 # define f_bsize f_fsize /* block size */ 92 # define fs_ignore "xx" /* ignore FS flag */ 93 # else 94 # ifdef ULTRIX 95 # include <sys/param.h> 96 # include <sys/mount.h> 97 # define GT_UNKWN 0 /* Taken from <sys/fs_types.h> */ 98 # define mntent fs_data /* FS stucture for getmnt */ 99 # define statfs fs_data /* FS stats structure */ 100 # define mnt_dir fd_req.path /* mount path */ 101 # define mnt_fsname fd_req.devname /* device name */ 102 # define mnt_opts fd_req.flags /* mount options */ 103 # define mnt_type fd_req.fstype /* mount type */ 104 # define f_bsize fd_req.bsize /* block size */ 105 # define f_blocks fd_req.btot /* number of blocks */ 106 # define f_bfree fd_req.bfree /* free blocks */ 107 # define f_bavail fd_req.bfreen /* available blocks */ 108 # define f_files fd_req.gtot /* number of inodes (gnodes) */ 109 # define f_ffree fd_req.gfree /* free indodes (gnodes) */ 110 # define fs_ignore GT_UNKWN /* ignore FS flag */ 111 # else 112 # ifdef SCO 113 # include <sys/statfs.h> 114 # define MAXPATHLEN 1024 115 # else 116 # if defined (FreeBSD) || defined (BSDI) 117 # include <sys/mount.h> 118 # else 119 # ifdef SGI 120 # include <sys/statvfs.h> 121 # include <mntent.h> 122 # define statfs statvfs 123 # define fs_ignore MNTTYPE_IGNORE /* ignore FS flag */ 124 # endif /* SGI */ 125 # endif /* Free BSD */ 126 # endif /* SCO */ 127 # endif /* ULTRIX */ 128 # endif /* OSF1 */ 129 # endif /* AIX */ 130 # endif /* DYNIX */ 131 # endif /* SVR4 || SOLARIS || DGUX */ 132 #endif /* SUNOS || LINUX || HPUX || CONVEXOS || MACH || AUX */ 133 134 135 /* ******************************************************************* */ 136 /* *** specify which file we can check to see if the mounted file *** */ 137 /* *** system information has been updated. This is not available *** */ 138 /* *** on all systems though (AIX, Ultrix and OSF/1 keep this info *** */ 139 /* *** in a binary database) *** */ 140 /* ******************************************************************* */ 141 #if defined (SUNOS) || defined (LINUX) || defined (DYNIX) || \ 142 defined (CONVEXOS) || defined (AUX) || defined (SGI) 143 #define MOUNT_FILE "/etc/mtab" 144 # else 145 # if defined (SVR4) || defined (HPUX) || defined (MACH) || \ 146 defined (SOLARIS) || defined (SCO) || defined (DGUX) 147 # define MOUNT_FILE "/etc/mnttab" 148 # endif /* SVR4 || HPUX || MACH || SOLARIS || SCO || DGUX */ 149 #endif /* SUNOS || LINUX || DYNIX || CONVEXOS || AUX */ 150 151 152 /* ********************************************************************** */ 153 /* *** We use DETAIL_NUM to calculate the height of the detail window *** */ 154 /* ********************************************************************** */ 155 #if defined (SVR4) || defined (SOLARIS) || defined (SGI) || defined (DGUX) 156 #define DETAIL_NUM 13 157 #else 158 # if defined (SUNOS) || defined (LINUX) || defined (HPUX) || \ 159 defined (ULTRIX) || defined (CONVEXOS) || defined (AIX) || \ 160 defined (DYNIX) || defined (FreeBSD) || defined (AUX) || defined(BSDI) 161 # define DETAIL_NUM 12 162 # else 163 # ifdef OSF1 164 # define DETAIL_NUM 10 165 # else 166 # ifdef SCO 167 # define DETAIL_NUM 9 168 # endif /* SCO */ 169 # endif /* OSF1 */ 170 # endif /* SUNOS || LINUX || HPUX || ULTRIX || MACH || CONVEXOS || AIX || \ 171 DYNIX || FreeBSD || AUX || BSDI */ 172 #endif /* SVR4 || SOLARIS || SGI || DGUX */ 173 174 175 176 /* ******************************************************************** */ 177 /* ******************** general program constants ********************* */ 178 /* ******************************************************************** */ 179 #define TRUE 1 180 #define FALSE 0 181 #define STRLENGTH 255 /* length of a string */ 182 #define NOGOOD -1 /* to distinguish nogood from false */ 183 #define MAXFS 50 /* maximum number of file systems */ 184 #define QUIT_KEY 'q' /* quit key */ 185 #define UPDATE_KEY 'u' /* update key */ 186 #define TOGGLE_KEY 't' /* toggle mode key */ 187 #define CLOSE_KEY 'c' /* close detailed window key */ 188 #define MB 1048576 /* 1Mb = 1048576 Bytes */ 189 #define GB 1073741824 /* 1Gb = 1073741824 Bytes */ 190 #define MINIMIZE 1 /* minimize */ 191 #define MNL 2 /* minimize with regard to FS name */ 192 #define CLASS_NAME "Xfsm" /* How do we look for resources */ 193 #define DEFAULT_FONT "6x13" /* default font */ 194 195 #ifdef LINUX 196 # define RES_SPACE_DFLT 5 /* reserved space; ext2 = 5% */ 197 #else 198 # define RES_SPACE_DFLT 10 /* reserved space; default = 10% */ 199 #endif 200 201 /* macros used to access the strings through the use of the index */ 202 #define FsName strinfo[idx[i]].fs_name 203 #define DevName strinfo[idx[i]].dev_name 204 #define MntTyp strinfo[idx[i]].mnt_typ 205 #define MntOpt strinfo[idx[i]].mnt_opt 206 207 /* mabe the largest has changed */ 208 #define HAS_BIGGEST_CHANGED \ 209 o_b_disk!=b_disk || o_b_blocks!=b_blocks || o_b_bsize!=b_bsize 210 211 #ifndef APP_DEFAULTS_DIR 212 #define APP_DEFAULTS_DIR "/usr/X11R5/lib/X11/app-defaults/" 213 #endif 214 215 /* If something is not available we */ 216 /* use this to copy NA into the sting */ 217 #define CHECKNA if (! strcmp (s, "-1")) strcpy (s, "N.A.") 218 #define PRINT_KNOWN_BUGS printf ("\n") /* at this point there are none */ 219 220 #define PRINT_COPYRIGHT printf ("\ 221 xfsm v1.99 - (C) Copyright 1993-1999 Robert Gasch (Robert_Gasch@peoplesoft.com)\n\ 222 http://www.peoplesoft.com/peoplepages/g/robert_gasch/\n") 223 224 225 /* ****** define window constants - these are positions and sizes ****** */ 226 #define DEF_BORDER_WIDTH 4 /* Default border width. */ 227 #define WIN_X 150 228 #define WIN_Y 150 229 #define MIN_WIN_X 100 230 #define MENU_HEIGHT(w) (LETTER_HEIGHT(w)) 231 #define MIN_MENU_HEIGHT 4 232 #define LETTER_HEIGHT(w) ((w).font_info->ascent + (w).font_info->descent) 233 #define LETTER_ASCENT(w) ((w).font_info->ascent) 234 #define LETTER_SPACE(w) (LETTER_HEIGHT(w) + 5 ) 235 #define FREE_LETTER_SP(w) (LETTER_SPACE(w)-LETTER_HEIGHT(w)) 236 #define NFS_TEXT_Y (fs_win[i].y-(LETTER_SPACE(fs_win[i])-\ 237 (LETTER_HEIGHT(fs_win[i])+1))) 238 #define SM_MENU_WIDTH(w) (XTextWidth((w).font_info, (w).text, \ 239 strlen((w).text))) 240 #define MENU_ITEMS 2 241 #define MENU_SPACE(w) (MENU_HEIGHT(w)*(MENU_ITEMS+2)) 242 #define BEGIN_NFS(w) MENU_SPACE(w) 243 #define MENU_Y 10 244 #define OFF_X 10 245 #define OFF_Y 10 246 #define INTERVAL(w) ((MENU_HEIGHT(w)+FREE_LETTER_SP(w))*2) 247 #define MIN_INTERVAL(w) (MIN_MENU_HEIGHT+FREE_LETTER_SP(w)+\ 248 MENU_HEIGHT(w)) 249 #define DETAIL_LETTER_X 13 250 #define DETAIL_LETTER_STRING "XXXXXXXXXXXX " 251 #define DETAIL_X (OFF_X*2 + XTextWidth(detail_win.font_info,\ 252 "Blocks Available WWWWWWWWWWW", \ 253 sizeof("Blocks Available WWWWWWWWWWW"))) 254 #define DETAIL_Y ((MENU_HEIGHT(detail_win)*(DETAIL_NUM+3))+\ 255 (OFF_X*2)) 256 /* ****** define constants used to identify menus and windows(buttons) ****** */ 257 #define UPDATE 0 258 #define QUIT 1 259 /* ******************** define the warning bitmap size ********************** */ 260 #define warn_width 4 261 #define warn_height 10 262 #define popup_width 8 263 #define popup_height 10 264 265 266 /* ******************************************************************** */ 267 /* ********************* program data structures ********************** */ 268 /* ******************************************************************** */ 269 270 /* *** string to hold file system name *** */ 271 typedef char MyString[STRLENGTH]; 272 273 /* *** struct to hold all the string info copied form static system areas *** */ 274 typedef struct { 275 MyString fs_name, /* FS names */ 276 dev_name, /* Device Names */ 277 #ifndef SCO 278 mnt_typ, /* type of device mount */ 279 #endif /* !SCO */ 280 mnt_opt; /* option of device mount */ 281 } StringInfo, *StringInfoPtr; 282 283 /* ****** XWindow struct - this simplifies function calls ****** */ 284 typedef struct { 285 Window win; /* window ID */ 286 GC gc; /* window graphics content */ 287 XFontStruct* font_info; /* Font the window is using. */ 288 char text[40]; /* title (for menus) */ 289 int x, y, /* position */ 290 width, height, /* size */ 291 line_thick; /* line thickness of window border */ 292 unsigned long fg, bg; /* foreground and background */ 293 long event_mask, /* which events will be registered */ 294 flags; /* window flags */ 295 } WinType, *WinTypePtr; 296 297 298 /* ******************************************************************** */ 299 /* ********************** function declarations *********************** */ 300 /* ******************************************************************** */ 301 302 void do_event_loop( 303 #if NeedFunctionPrototypes 304 int argc, 305 char** argv 306 #endif 307 ); 308 void handle_NFS_change( 309 #if NeedFunctionPrototypes 310 int ppnfs, 311 int OFS 312 #endif 313 ); 314 void fix_menu_pos( 315 #if NeedFunctionPrototypes 316 int width 317 #endif 318 ); 319 void fix_fs_win_width( 320 #if NeedFunctionPrototypes 321 int i 322 #endif 323 ); 324 void set_fs_win_size( 325 #if NeedFunctionPrototypes 326 int i, 327 int ppnfs 328 #endif 329 ); 330 void get_fs( 331 #if NeedFunctionPrototypes 332 void 333 #endif 334 ); 335 void clear_fs_warn_flags( 336 #if NeedFunctionPrototypes 337 void 338 #endif 339 ); 340 void toggle_mode( 341 #if NeedFunctionPrototypes 342 void 343 #endif 344 ); 345 void redraw_main_win( 346 #if NeedFunctionPrototypes 347 void 348 #endif 349 ); 350 void write_detail( 351 #if NeedFunctionPrototypes 352 int i 353 #endif 354 ); 355 void write_available( 356 #if NeedFunctionPrototypes 357 int i 358 #endif 359 ); 360 void write_percent( 361 #if NeedFunctionPrototypes 362 int i 363 #endif 364 ); 365 void redraw_fs_win( 366 #if NeedFunctionPrototypes 367 int i 368 #endif 369 ); 370 void get_fs_stat( 371 #if NeedFunctionPrototypes 372 void 373 #endif 374 ); 375 void open_detail_win( 376 #if NeedFunctionPrototypes 377 int argc, 378 char **argv 379 #endif 380 ); 381 void create_window ( 382 #if NeedFunctionPrototypes 383 Window parent_win, 384 WinTypePtr this_win, 385 unsigned long foreg, 386 unsigned long backg 387 #endif 388 ); 389 int highlight_menu( 390 #if NeedFunctionPrototypes 391 WinType menu[], 392 int menu_num, 393 int hightlight 394 #endif 395 ); 396 int expose_win( 397 #if NeedFunctionPrototypes 398 WinType menu[], 399 int menu_num 400 #endif 401 ); 402 void destroy_menu( 403 #if NeedFunctionPrototypes 404 WinType menu[], 405 int menu_num 406 #endif 407 ); 408 int which_button_pressed( 409 #if NeedFunctionPrototypes 410 WinType menu[], 411 int menu_num 412 #endif 413 ); 414 void process_databases( 415 #if NeedFunctionPrototypes 416 int argc, 417 char** argv, 418 XrmDatabase commandlineDB 419 #endif 420 ); 421 void do_help( 422 #if NeedFunctionPrototypes 423 void 424 #endif 425 ); 426 void init_all_windows( 427 #if NeedFunctionPrototypes 428 void 429 #endif 430 ); 431 Bool getBoolResource( 432 #if NeedFunctionPrototypes 433 XrmDatabase db, 434 char* str_name, 435 char* str_class, 436 Bool deflt 437 #endif 438 ); 439 int getIntResource( 440 #if NeedFunctionPrototypes 441 XrmDatabase db, 442 char* str_name, 443 char* str_class, 444 int deflt 445 #endif 446 ); 447 unsigned long getColorResource( 448 #if NeedFunctionPrototypes 449 XrmDatabase db, 450 char* str_name, 451 char* str_class, 452 unsigned long deflt 453 #endif 454 ); 455 XFontStruct* getFontResource( 456 #if NeedFunctionPrototypes 457 XrmDatabase db, 458 char* str_name, 459 char* str_class, 460 XFontStruct* deflt 461 #endif 462 ); 463 char* catlist( 464 #if NeedFunctionPrototypes 465 char*, 466 ... 467 #endif 468 ); 469 470 #if defined (DYNIX) || defined (MACH) 471 char* strstr( 472 #if NeedFunctionPrototypes 473 const char*, 474 const char* 475 #endif 476 ); 477 #endif 478 479