Xref: utzoo news.software.b:5961 comp.sources.bugs:2593 Newsgroups: news.software.b,comp.sources.bugs Path: utzoo!utstat!news-server.csri.toronto.edu!math.lsa.umich.edu!caen!ox.com!b-tech!zeeff From: zeeff@b-tech.ann-arbor.mi.us (Jon Zeeff) Subject: Re: C News patch of 7-Sep-1990 Message-ID: <%J4*41*@b-tech.uucp> Organization: Branch Technology References: <1990Sep18.222450.25228@zoo.toronto.edu> <2704@sud509.ed.ray.com> <1990Oct10.034247.27111@decuac.dec.com> Date: Wed, 10 Oct 90 13:29:06 GMT >>[...] The package installed smoothly >>except for problems with one file -- spacefor. > > Speaking of which, has anyone hacked the code from nntpd that reads >free space out of the superblock and made a replacement for spacefor ? If >anyone has, I'll be happy to test it under a few versions of Ultrix. :) Not quite what you wanted, but this might work work. Actually, I find this spacefor more portable (and much faster) than the cnews version. /* Spacefor.c V1.1 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) 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 BLOCKSIZE 1024 /* try 512 for Sys V and 1024 for bsd */ /* Make these the mount points */ #define DIR_INCOMING "/news" #define DIR_ARTS "/news" #define DIR_NEWSCTL "/u" #define DIR_OUTGOING "/u" #define DIR_ARCHIVE "/news" #define MIN_INCOMING 400 #define MIN_ARTS 400 #define MIN_NEWSCTL 3000 #define MIN_OUTGOING 400 #define MIN_ARCHIVE 400 /***************************************************************************/ #include #include #ifndef BSD #ifdef HAVE_STATFS #include #define FREEBLOCKS statfsb.f_bfree #define FREENODES statfsb.f_ffree struct statfs statfsb; #else /* HAVE_STATFS */ #include #include #define FREEBLOCKS ustatb.f_tfree #define FREENODES ustatb.f_tinode struct stat statb; struct ustat ustatb; #endif /* HAVE_STATFS */ #else #define HAVE_STATFS #include struct statfs statfsb; #define FREEBLOCKS statfsb.f_bavail #define FREENODES statfsb.f_ffree #endif 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 if (statfs(dirname, &statfsb, sizeof(statfsb), 0) != 0) { perror("statfs failed"); exit(1); } #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); } -- Jon Zeeff (NIC handle JZ) zeeff@b-tech.ann-arbor.mi.us