Annotation of researchv10no/cmd/worm/wls.c, revision 1.1

1.1     ! root        1: #include       <libc.h>
        !             2: #include       "worm.h"
        !             3: #include       "sym.h"
        !             4: #include       <sys/types.h>
        !             5: #include       <sys/stat.h>
        !             6: #include       <pwd.h>
        !             7: #include       <grp.h>
        !             8: 
        !             9: int lflag = 0;
        !            10: int bflag = 0;
        !            11: 
        !            12: main(argc, argv)
        !            13:        char **argv;
        !            14: {
        !            15:        Superblock s;
        !            16:        register Inode *i;
        !            17:        char *e;
        !            18:        char *dev = "/dev/worm0";
        !            19:        int c;
        !            20:        extern char *optarg;
        !            21:        extern int optind;
        !            22:        void pr();
        !            23: 
        !            24:        while((c = getopt(argc, argv, "lbf:")) != -1)
        !            25:                switch(c)
        !            26:                {
        !            27:                case 'f':       dev = optarg; break;
        !            28:                case 'l':       lflag = 1; break;
        !            29:                case 'b':       bflag = 1; break;
        !            30:                case '?':       usage();
        !            31:                }
        !            32:        dev = mapdev(dev);
        !            33:        if((s.fd = open(dev, 0)) < 0){
        !            34:                perror(dev);
        !            35:                exit(1);
        !            36:        }
        !            37:        if(e = openinode(&s, DO_INODE|SPIN_DOWN)){
        !            38:                fprint(2, "%s: %s\n", dev, e);
        !            39:                exit(1);
        !            40:        }
        !            41:        c = 0;
        !            42:        if(optind < argc)
        !            43:                while(optind < argc){
        !            44:                        if(i = inodeof(argv[optind]))
        !            45:                                pr(i);
        !            46:                        else {
        !            47:                                Fprint(2, "%s not found\n", argv[optind]);
        !            48:                                c = 1;
        !            49:                        }
        !            50:                        optind++;
        !            51:                }
        !            52:        else
        !            53:                inodetraverse(pr);
        !            54:        exit(c);
        !            55: }
        !            56: 
        !            57: char *
        !            58: suid(n)
        !            59: {
        !            60:        static char buf[24];
        !            61:        struct passwd *p;
        !            62:        char *s;
        !            63: 
        !            64:        sprint(buf, "#%d", n);
        !            65:        if(s = (char *)symlook(buf, S_UID, (void *)0))
        !            66:                strcpy(buf, s);
        !            67:        else {
        !            68:                s = strdup(buf);
        !            69:                if(p = getpwuid(n))
        !            70:                        strcpy(buf, p->pw_name);
        !            71:                (void)symlook(s, S_UID, (void *)strdup(buf));
        !            72:        }
        !            73:        return(buf);
        !            74: }
        !            75: 
        !            76: char *
        !            77: sgid(n)
        !            78: {
        !            79:        static char buf[24];
        !            80:        struct group *g;
        !            81:        char *s;
        !            82: 
        !            83:        sprint(buf, "#%d", n);
        !            84:        if(s = (char *)symlook(buf, S_GID, (void *)0))
        !            85:                strcpy(buf, s);
        !            86:        else {
        !            87:                s = strdup(buf);
        !            88:                if(g = getgrgid(n))
        !            89:                        strcpy(buf, g->gr_name);
        !            90:                (void)symlook(s, S_GID, (void *)strdup(buf));
        !            91:        }
        !            92:        return(buf);
        !            93: }
        !            94: 
        !            95: mode(n, sx)
        !            96: {
        !            97:        Fputc(1, (n&4)? 'r':'-');
        !            98:        Fputc(1, (n&2)? 'w':'-');
        !            99:        Fputc(1, (n&1)? sx:'-');
        !           100: }
        !           101: 
        !           102: void
        !           103: pr(i)
        !           104:        register Inode *i;
        !           105: {
        !           106:        char *s;
        !           107: 
        !           108:        if(lflag){
        !           109:                Fputc(1, ((i->mode&S_IFMT) == S_IFDIR)? 'd':'-');
        !           110:                mode(i->mode>>6, ((i->mode&S_IFMT) == S_ISUID)? 's':'x');
        !           111:                mode(i->mode>>3, ((i->mode&S_IFMT) == S_ISGID)? 's':'x');
        !           112:                mode(i->mode, 'x');
        !           113:                Fputc(1, ((i->mode&S_IFMT) == S_IFLNK)? 'L':' ');
        !           114:                s = ctime(&i->ctime);
        !           115:                s += 4;
        !           116:                s[12] = 0;
        !           117:                Fprint(1, "%2d%8s%7s %6ld %s %s\n", 1, suid(i->uid), sgid(i->gid),
        !           118:                        i->nbytes, s, i->name.n);
        !           119:                return;
        !           120:        }
        !           121:        if(bflag)
        !           122:                Fprint(1, "%s\t%ld\n", i->name.n, i->block);
        !           123:        else
        !           124:                Fprint(1, "%s\n", i->name.n);
        !           125: }
        !           126: 
        !           127: usage()
        !           128: {
        !           129:        fprint(2, "Usage: worm ls [-fdevice] [-l] [-b] [files ...]\n");
        !           130:        exit(2);
        !           131: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.