Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Dec 2002 19:20:15 -0500
From:      Brian Fundakowski Feldman <green@freeBSD.org>
To:        current@freeBSD.org
Subject:   fincore.c strikes again (panic bremfree: bp not locked)
Message-ID:  <200212130020.gBD0KFWg000827@green.bikeshed.org>

next in thread | raw e-mail | index | archive | help
I don't have any more info since for some reason the kernel wasn't saved 
when my system dumped core, but yet again fincore.c causes evidence that 
-CURRENT has regressed again.  I can't find the old thread I'm thinking of, 
but from a slightly different thread, bde knew what was going on.  For 
further reference:


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <machine/param.h>
#include <errno.h>

/*
** print pages of file in core
*/

void usage(char *name)
{
	printf("Usage: %s [-ns] files...\n",name);
	printf("\t-n\t\tDo not print filename\n");
	printf("\t-o\t\tOnly print files with at least one page in core\n");
	printf("\t-s\t\tDo not print file size in pages\n");
}

main(int ac,char **av)
{
	int c;
	int print_name = 1;
	int print_sizepages = 1;
	int only_nonzero = 0;
	int status = 0;

	while((c = getopt(ac,av,"nos")) != -1) {
		switch(c) {
		case 'n':
			print_name = 0;
			break;
		case 'o':
			only_nonzero = 1;
			break;
		case 's':
			print_sizepages = 0;
			break;
		default:
			usage(av[0]);
			exit(1);
		}
	}
	for(; optind < ac ; optind++) {
		int fd;
		int pind,pcount;
		caddr_t addr;
		struct stat statbuf;
		size_t len;
		size_t numpages;
		char *pvec;

		if (stat(av[optind],&statbuf)) {
			perror("stat");
			status = 1;
			continue;
		}
		if (!S_ISREG(statbuf.st_mode)) {
			close(fd);
			continue;
		}
		if ((fd = open(av[optind],O_RDONLY)) < 0) {
			perror(av[optind]);
			status = 1;
			continue;
		}
		if (fstat(fd,&statbuf)) {
			perror("fstat");
			close(fd);
			status = 1;
			continue;
		}
		if (!S_ISREG(statbuf.st_mode)) {
			close(fd);
			continue;
		}
		len = statbuf.st_size;
		numpages = len/PAGE_SIZE + ((len % PAGE_SIZE) != 0);

		if (! (statbuf.st_mode & (S_IFREG|S_IFCHR))) {
			pcount = 0;
		} else if (len) {
			if ((addr = mmap(0,len,PROT_READ,MAP_SHARED,fd,0)) == MAP_FAILED) {
				fprintf(stderr, "mmap (%s): %s\n", av[optind],
				    strerror(errno));
				close(fd);
				status = 1;
				continue;
			}
			pvec = malloc(numpages);
			if (mincore(addr,len,pvec))
			{
				perror("mincore");
				exit(1);
			}
			for(pcount = 0,pind = 0 ; pind < numpages ; pind++) {
				if (pvec[pind]) pcount++;
			}
			free(pvec);
			if (munmap(addr,len)) {
				perror("munmap");
				exit(1);
			}
		} else {
			pcount = 0;
		}
		if (pcount || !only_nonzero) {
			if (print_name) printf("%s: ",av[optind]);
			printf("%d",pcount);
			if (print_sizepages) printf("/%d",numpages);
			printf("\n");
		}
		close(fd);
	}
	exit(status);
}

-- 
Brian Fundakowski Feldman                           \'[ FreeBSD ]''''''''''\
  <> green@FreeBSD.org  <> bfeldman@tislabs.com      \  The Power to Serve! \
 Opinions expressed are my own.                       \,,,,,,,,,,,,,,,,,,,,,,\



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212130020.gBD0KFWg000827>