⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *sccsid = "@(#)file.c	4.4	(ULTRIX)	3/7/91";#endif/************************************************************************ *									* *			Copyright (c) 1988 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************/#include	"crash.h"#define KERNEL#include	<sys/file.h>#undef KERNEL#include	<sys/smp_lock.h>#include	<sys/gnode_common.h>#include	<ufs/ufs_inode.h>#include	<sys/gnode.h>#include	<sys/namei.h>#include	<rpc/types.h>#include	<sys/mount.h>#include	<sys/text.h>#include	<sys/proc.h>#include	<machine/pte.h>#include	<machine/param.h>#include	<machine/vmparam.h>#include	<sys/vmmac.h>#undef export#define NFSSERVER#include	<nfs/nfs.h>#undef	NFSSERVER#include	<rpc/rpc.h>#include	<nfs/vnode.h>#include	<nfs/dnlc.h#include	<time.h>#define GT_NFS 0x05	/* can't include <sys/fs_types.h> here */struct ucred	cred;pr_filehdr(){	printf(" Slot Type  Ref  Msg   Cred     Islot    Fileops  Offset   Flags\n");}prfile(c, all)	int c;	int	all;{	struct	file	*fp;		fp = &filetab[c];	if(!all && fp->f_count == 0)		return;	printf ("%5d ", c);	/* These types are defined in sys/file.h but are #ifdef'ed out. */	switch (fp->f_type) {		default:			printf ("*%3d",fp->f_type);			break;		case 1:			printf ("file");			break;		case 2:			printf ("sock");			break;		case 3:			printf ("npip");			break; /* DTYPE_PORT */		case 4:			printf ("pipe");			break; /* DTYPE_PIPE */	}	printf(" %4d %4d %8x", fp->f_count, fp->f_msgcount, fp->f_cred);	printf(((fp->f_data != NULL) & (fp->f_type != 2) & (fp->f_type != 4))?	    "%8d " : "     --- ",	    getindex((char *)fp->f_data, gnodebuckets, GNODEBUCKETS));	if (fp->f_ops == NULL)		printf("  *Null*  ",fp->f_ops);	else {		struct Symbol *sp, *search();		sp = search(fp->f_ops);		if (sp != 0)			if(sp->s_name[0] == '_')				printf("%10s", &(sp->s_name[1]));			else				printf("%10s", sp->s_name);		else			printf("0x%08x",fp->f_ops);	}	printf(" %6d ",fp->f_offset);	printf("  %s%s%s%s%s%s%s%s%s\n",	    fp->f_flag & FREAD ? " read" : "",	    fp->f_flag & FWRITE ? " write" : "",	    fp->f_flag & FAPPEND ? " append" : "",	    fp->f_flag & FNDELAY ? " ndelay" : "",	    fp->f_flag & FMARK ? " mark" : "",	    fp->f_flag & FDEFER ? " defer" : "",	    fp->f_flag & FASYNC ? " async" : "",	    fp->f_flag & FSHLOCK ? " shlck" : "",	    fp->f_flag & FEXLOCK ? " exlck" : "");}prgnode(c, operation, match, detail)	int	c;	int	operation;	int	match;	int 	detail;{	int mntnum;	struct gnode *gp;		gp = &gnodetab[c];	switch (operation) {	case 0:		if(gp->g_count == 0) return;		printgnode(gp, c, detail);		break;	case 1:		printgnode(gp, c, detail);		break;	case 2:		if (major(gp->g_dev) == match)			printgnode(gp, c, detail);		break;	case 3:		if (minor(gp->g_dev) == match)			printgnode(gp, c, detail);		break;	case 4:		mntnum =		    getindex((char *)gp->g_mp, mountbuckets, MOUNTBUCKETS);		if (mntnum == match)			printgnode(gp, c, detail);		break;	case 5:		if (gp->g_number == match)			printgnode(gp, c, detail);		break;	case 6:		if (gp->g_uid == match)			printgnode(gp, c, detail);		break;	case 7:		if (gp->g_gid == match)			printgnode(gp, c, detail);		break;	case 8:		if (gp->g_mode &  match)			printgnode(gp, c, detail);		break;	case 9:		if (gp->g_mode &  match)			printgnode(gp, c, detail);		break;	case 10:		if (gp->g_mode == match)			printgnode(gp, c, detail);		break;	case 11:		if (gp->g_lk.l_lock)			printgnode(gp, c, detail);		break;	}	return;}prgnodelist(gp, detail)	register struct gnode *gp;	int detail;{	struct gnode *tgp;	int index;	if(readmem((char *)&tgp, (int)gp, sizeof(tgp))!= sizeof(tgp)) {		printf("could not read gnode gp 0x%x\n", gp);		return;	}		gp = tgp;	while(gp != NULL) {		if((index = getindex((char *)gp, gnodebuckets,		    GNODEBUCKETS)) == -1) {			printf("could not read gnode gp 0x%x\n", gp);			return;		}		printgnode(&gnodetab[index], index, detail);		gp = gnodetab[index].g_freef;	}}printgnode(gp, c, detail)	struct gnode *gp;	int c;	int detail;{	register char	ch;	int mntnum;	int index1 = 0;	int index2 = 0;		if(gp->g_count == 0) {		index1 = getindex((char *)gp->g_freef, gnodebuckets,		    GNODEBUCKETS);		index2 = getindex((char *)gp->g_freeb, gnodebuckets,		    GNODEBUCKETS);	} 	mntnum = getindex((char *)gp->g_mp, mountbuckets, MOUNTBUCKETS);		printf("%4d %3.3x %4.4x%3d %6d %3d %4d %4d %4d %7ld",	    c, major(gp->g_dev), minor(gp->g_dev), mntnum,	    ((gp->g_number  < 1000000) && (gp->g_number > 0)) ?	    gp->g_number : -1, gp->g_count, gp->g_nlink, gp->g_uid,	    gp->g_gid, gp->g_size);		if(index1)		printf("%4d ", index1);	else		printf("     ");	if(index2)		printf("%4d ", index2);	else		printf("     ");	switch(gp->g_mode & GFMT) {		case GFDIR:			ch = 'd';			break;		case GFCHR:			ch = 'c';			break;		case GFBLK:			ch = 'b';			break;		case GFREG:			ch = 'f';			break;		case GFLNK:			ch = 'l';			break;		case GFSOCK:			ch = 's';			break;		default:			ch = '?';	}		printf(" %c", ch);	printf("%s%s%s%3o",	    gp->g_mode & GSUID ? "u" : "-",	    gp->g_mode & GSGID ? "g" : "-",	    gp->g_mode & GSVTX ? "v" : "-",	    gp->g_mode & 0777);	printf("%s%s%s%s%s%s%s%s%s%s%s%s%s\n"," ",	    gp->g_flag & GINCOMPLETE ? " inc" : "",	    gp->g_lk.l_lock ? " lck" : "", 	    gp->g_flag & GUPD ? " upd" : "",	    gp->g_flag & GACC ? " acc" : "",	    gp->g_flag & GMOUNT ? " mnt" : "",	    gp->g_flag & GWANT ? " wnt" : "",	    gp->g_flag & GTEXT ? " txt" : "",	    gp->g_flag & GCHG ? " chg" : "",	    gp->g_flag & GSHLOCK ? " sh" : "",	    gp->g_flag & GEXLOCK ? " x" : "",	    gp->g_flag & GLWAIT ? " wt" : "",	    gp->g_flag & GMOD ? " mod" : "");	if (detail == 2) {		prlock_long(&gp->g_lk,0);	}	if (detail == 3) {		prgnode_long(gp);	}}intgnode_isremote(i, gp)	int i;	struct gnode *gp;{	struct fs_data	fsd;	int		mntnum;	if((mntnum = getindex((char *)gp->g_mp, mountbuckets,	    MOUNTBUCKETS)) == -1) {		printf("gnode %i has bad mount point 0x%x\n", i, gp->g_mp);		return(0);	}	if (!get_fsdata(mntnum, &fsd))		return(0);	if (fsd.fd_fstype != GT_NFS) {		return(0);	}	return(1);}	    prvnode(c, all)	register int		c;	int			all;{	struct rnode	*r;	struct gnode *gp;	struct tm *attr;		gp = &gnodetab[c];	if (!all && gp->g_count==0)		return;	if (!gnode_isremote(c, gp))		return;	r = vtor((struct vnode *)gp);	if (r->r_cred != NULL)	if (!get_cred((unsigned)(r->r_cred), &cred))		return;	printf("%3d %5u %5u %10u",c,r->r_fh.fh_fsid,	    r->r_fh.fh_fno, r->r_fh.fh_fgen);	printf(" %5d %5d %5d %6d %6d",cred.cr_ref,cred.cr_uid,	    cred.cr_gid,cred.cr_ruid,cred.cr_rgid);	printf(" %5d", (int)r->r_error);	printf(" %s%s%s%s%s%s\n",	    r->r_flags & RLOCKED ? "lck " : "",	    r->r_flags & RWANT ? "wnt " : "",	    r->r_flags & RATTRVALID ? "val " : "",	    r->r_flags & REOF ? "eof " : "",	    r->r_flags & RDIRTY ? "drt " : "",	    r->r_flags & ROPEN ? "opn " : "");	printf("cred 0x%x vfsp 0x%x \n", r->r_cred, ((struct vnode *)gp)->g_in.ve.V_vfsp);	printf("unlname 0x%x, unldvp 0x%x", r->r_unlname, r->r_unldvp);	attr=localtime(&r->r_nfsattrtime);	printf(" nfsattrtime %dh %dm %d.%06ds\n",attr->tm_hour,attr->tm_min,	       attr->tm_sec,r->r_nfsattrtime.tv_usec);}do_ufile(c)	int c;{	int i, f, fp;	char fflg;	int *ofile_of;	char *pofile_of;	/* Should also dump the inodes. */	getuarea(c);	printf ("FD  UFLAG  ");	pr_filehdr();	if (U.u_of_count != 0) {		ofile_of = (int *) malloc(U.u_of_count*					  sizeof(int));		pofile_of = (char *) 			malloc(U.u_of_count);				if (readmem((char *)ofile_of, (int)U.u_ofile_of, 			    U.u_of_count*sizeof(int)) !=		    U.u_of_count*sizeof(int)) {			printf(" read error on fd overflow area\n");			return;		}		if (readmem((char *)pofile_of, (int)U.u_pofile_of, 			    U.u_of_count) !=		    U.u_of_count) {			printf(" read error on fd overflow area\n");			return;		}	}	for (i = 0; i <= U.u_omax; ++i) {		if (i > NOFILE_IN_U) {			fp = (int) ofile_of [i - NOFILE_IN_U];			fflg = pofile_of [i - NOFILE_IN_U];		} else {			fp = (int)U.u_ofile[i];			fflg = U.u_pofile[i];		}					if (fp == 0) continue;		f = getindex((char *)fp, filebuckets, FILEBUCKETS);		printf ("%2d    ",i);		printf ("%s%s%s  ",		    (fflg & UF_EXCLOSE) ? "x" : "-",		    (fflg & UF_MAPPED) ? "m" : "-",		    (fflg & UF_INUSE) ? "i" : "-");		f = getindex((char *)fp, filebuckets, FILEBUCKETS);		prfile(f, 1);	}}prblocks (c)		/* print disk blocks associated with inode */	int c;{	int i;	struct gnode *gp;		gp = &gnodetab[c];	printf ("\n");	printf ("gnode number %d (slot %d):\n", gp->g_number, c);	printf ("\n");	printf ("direct:     ");	for (i = 0; i < NDADDR; i++) {		printf("%8d", G_TO_I(gp)->di_db[i]);		if (i % 6 == 5)			printf("\n            ");	}	/* maybe should list blocks referenced by indir blocks */	printf ("\nindirect:   ");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -