|
|
1.1 ! root 1: #include "ps.h" ! 2: #include <sys/text.h> ! 3: #include <sys/inode.h> ! 4: #include <sys/file.h> ! 5: ! 6: char * ! 7: fdprint(cp, pp, up) ! 8: char *cp; register struct proc *pp; register struct user *up; ! 9: { ! 10: register j, k; ! 11: struct text x; struct file f; struct inode i; ! 12: char ident[NOFILE], prefix[8]; ! 13: ! 14: if (fflag <= 1) ! 15: sprintf(prefix, "%5d ", pp->p_pid); ! 16: else ! 17: strcpy(prefix, " "); ! 18: ! 19: if (Kread(pp->p_textp, &x) && Kread(x.x_iptr, &i)) ! 20: cp += sprintf(cp, "%sprog: ", prefix), cp = iprint(cp, &i); ! 21: if (Kread(up->u_cdir, &i)) ! 22: cp += sprintf(cp, "%scdir: ", prefix), cp = iprint(cp, &i); ! 23: if (Kread(up->u_rdir, &i)) ! 24: cp += sprintf(cp, "%srdir: ", prefix), cp = iprint(cp, &i); ! 25: for (k = 0; k < NOFILE; k++) ! 26: ident[k] = 0; ! 27: for (k = 0; k < NOFILE; k++) if (!ident[k]) { ! 28: if (!Kread(up->u_ofile[k], &f) || !Kread(f.f_inode, &i)) ! 29: continue; ! 30: cp += sprintf(cp, "%sfd %d", prefix, k); ! 31: for (j=k+1; j<NOFILE; j++) ! 32: if (up->u_ofile[j] == up->u_ofile[k]) ! 33: cp += sprintf(cp, ",%d", j), ++ident[j]; ! 34: cp += sprintf(cp, " at %d: ", f.f_offset); ! 35: cp = iprint(cp, &i); ! 36: } ! 37: return cp; ! 38: } ! 39: ! 40: char * ! 41: iprint(cp, ip) ! 42: register char *cp; register struct inode *ip; ! 43: { ! 44: register char *p; char *lookdir(); ! 45: ! 46: switch (ip->i_mode & IFMT) { ! 47: case IFCHR: ! 48: case IFBLK: ! 49: if (p = lookdir(ip->i_number)) ! 50: cp += sprintf(cp, "%s\n", p); ! 51: else ! 52: cp += sprintf(cp, "(%d/%d)\n", ! 53: major(ip->i_un.i_rdev), minor(ip->i_un.i_rdev)); ! 54: return cp; ! 55: case IFREG: ! 56: cp += sprintf(cp, ip->i_sptr ? "stream" : "file"); break; ! 57: case IFDIR: ! 58: cp += sprintf(cp, "dir"); break; ! 59: default: ! 60: cp += sprintf(cp, "[%o06]", ip->i_mode); break; ! 61: } ! 62: cp += sprintf(cp, " %d on ", ip->i_number); ! 63: if (ip->i_dev == 0 && ip->i_fstyp == 2) ! 64: ip->i_dev = makedev(255, 255); ! 65: if (p = getfs(ip->i_dev)) ! 66: cp += sprintf(cp, "%s\n", p); ! 67: else ! 68: cp += sprintf(cp, "(%d/%d)\n", ! 69: major(ip->i_dev), minor(ip->i_dev)); ! 70: return cp; ! 71: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.