stealth@caen.engin.umich.edu (Mike Pelletier) (07/27/90)
As you may know, the spacefor.c program from the C-news source library will not compile on DECstation 3100's and their kin, due to the fact that the statfs() call uses a different style data structre than other machines. Here's the source for a fixed version that's currently running on my DECstation 3100 news server. (The patch was almost as long as the source...) Enjoy.... -Mike. ------->8 cut here 8<----------- /* Spacefor.c V1.2 Replacement for spacefor (shell script) in cnews. Change the values below as appropriate. Denny Page July 25, 1989 (denny@mcmi.uucp) BSD added by Jon Zeeff (zeeff@b-tech.ann-arbor.mi.us) DEC Ultrix added by Mike Pelletier (stealth@m-net.ann-arbor.mi.us) About how many things of $1 bytes will fit in the available space for stuff of type $2 ("incoming", "articles", "control", "outbound $3", or "archive") without cramping things too badly? */ #define HAVE_STATFS /* If you have statfs() syscall */ #define BSD /* Define on BSD sites */ #define ULTRIX /* Define on sites running DEC Ultrix */ #define BLOCKSIZE 1024 /* try 512 for Sys V and 1024 for bsd */ /* Make these the mount points */ #define DIR_INCOMING "/usr/var" #define DIR_ARTS "/usr/var" #define DIR_NEWSCTL "/usr" #define DIR_OUTGOING "/usr/var" #define DIR_ARCHIVE "/usr" #define MIN_INCOMING 400 #define MIN_ARTS 400 #define MIN_NEWSCTL 3000 #define MIN_OUTGOING 400 #define MIN_ARCHIVE 400 /***************************************************************************/ #include <sys/types.h> #include <stdio.h> #ifdef ULTRIX #ifndef BSD #define BSD #endif #ifndef HAVE_STATFS #define HAVE_STATFS #endif #endif #ifndef BSD #ifdef HAVE_STATFS #include <sys/statfs.h> #define FREEBLOCKS statfsb.f_bfree #define FREENODES statfsb.f_ffree struct statfs statfsb; #else /* !HAVE_STATFS */ #include <sys/stat.h> #include <ustat.h> #define FREEBLOCKS ustatb.f_tfree #define FREENODES ustatb.f_tinode struct stat statb; struct ustat ustatb; #endif /* HAVE_STATFS */ #else /* BSD */ #ifdef ULTRIX #include <sys/param.h> #include <sys/mount.h> struct fs_data statfsb; #define FREEBLOCKS statfsb.fd_req.bfreen #define FREENODES statfsb.fd_req.gfree #else /* !ULTRIX */ #define HAVE_STATFS #include <sys/vfs.h> struct statfs statfsb; #define FREEBLOCKS statfsb.f_bavail #define FREENODES statfsb.f_ffree #endif /* ULTRIX */ #endif /* BSD */ main(argc, argv) int argc; char **argv; { long size, minblocks, available, atol(); char *dirname; if (argc < 3) { fprintf(stderr, "usage: %s size place\n", argv[0]); exit(2); } if ((size = atol(argv[1])) == 0) { printf("10000\n"); exit(0); } if (! strcmp (argv[2], "incoming")) { dirname = DIR_INCOMING; minblocks = MIN_INCOMING; } else if (! strcmp (argv[2], "articles")) { dirname = DIR_ARTS; minblocks = MIN_ARTS; } else if (! strcmp (argv[2], "control")) { dirname = DIR_NEWSCTL; minblocks = MIN_NEWSCTL; } else if (! strcmp (argv[2], "outbound")) { dirname = DIR_OUTGOING; minblocks = MIN_OUTGOING; } else if (! strcmp (argv[2], "archive")) { dirname = DIR_ARCHIVE; minblocks = MIN_ARCHIVE; } else { fprintf(stderr, "%s: bad argument type `%s'\n", argv[0], argv[2]); exit(2); } #ifdef HAVE_STATFS #ifndef ULTRIX if (statfs(dirname, &statfsb, sizeof(statfsb), 0) != 0) { perror("statfs failed"); exit(1); } #else /* ULTRIX */ if (statfs(dirname, &statfsb) != 1) { perror("statfs failed"); exit(1); } #endif #else /* !HAVE_STATFS */ if (stat(dirname, &statb) != 0) { perror("stat failed"); exit(1); } if (ustat(statb.st_dev, &ustatb) != 0) { perror("ustat failed"); exit(1); } #endif /* HAVE_STATFS */ available = ((FREEBLOCKS - minblocks) * BLOCKSIZE) / size; if (available <= 0 || FREENODES == 0) available = 0; if (available > 10000) available = 10000; printf("%ld\n", available); exit(0); } ------->8 cut here 8<----------- -- Michael V. Pelletier | "We live our lives with our hands on the CAEN UseNet News Administrator | rear-view mirror, striving to get a better Systems Group Programmer | view of the road behind us. Imagine what's | possible if we look ahead and steer..."
henry@zoo.toronto.edu (Henry Spencer) (07/30/90)
In article <1990Jul27.143341.28425@caen.engin.umich.edu> stealth@caen.engin.umich.edu (Mike Pelletier) writes: >As you may know, the spacefor.c program from the C-news source library will >not compile on DECstation 3100's and their kin... A small clarification: there is no spacefor.c in the C News distribution, as all implementations of spacefor supplied with C News are still shell files. However, I am seriously considering changing this, as the diversity of df output formats approaches the ridiculous, and it looks like it may actually be simpler (!) to use the C interface on systems that supply it. At least there are only three or four variations on it... Sigh. -- The 486 is to a modern CPU as a Jules | Henry Spencer at U of Toronto Zoology Verne reprint is to a modern SF novel. | henry@zoo.toronto.edu utzoo!henry