Annotation of 43BSDReno/usr.sbin/mtree/compare.c, revision 1.1

1.1     ! root        1: /*-
        !             2:  * Copyright (c) 1989 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted provided
        !             6:  * that: (1) source distributions retain this entire copyright notice and
        !             7:  * comment, and (2) distributions including binaries display the following
        !             8:  * acknowledgement:  ``This product includes software developed by the
        !             9:  * University of California, Berkeley and its contributors'' in the
        !            10:  * documentation or other materials provided with the distribution and in
        !            11:  * all advertising materials mentioning features or use of this software.
        !            12:  * Neither the name of the University nor the names of its contributors may
        !            13:  * be used to endorse or promote products derived from this software without
        !            14:  * specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)compare.c  5.7 (Berkeley) 5/25/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include <sys/param.h>
        !            25: #include <sys/stat.h>
        !            26: #include <fts.h>
        !            27: #include <errno.h>
        !            28: #include <stdio.h>
        !            29: #include <time.h>
        !            30: #include "mtree.h"
        !            31: 
        !            32: #define        LABEL \
        !            33:        if (!label++) \
        !            34:                (void)printf("%s: ", RP(p)); \
        !            35: 
        !            36: compare(name, s, p)
        !            37:        char *name;
        !            38:        register NODE *s;
        !            39:        register FTSENT *p;
        !            40: {
        !            41:        extern int exitval, uflag;
        !            42:        int label;
        !            43:        char *ftype(), *inotype(), *rlink();
        !            44: 
        !            45:        label = 0;
        !            46:        switch(s->type) {
        !            47:        case F_BLOCK:
        !            48:                if (!S_ISBLK(p->fts_statb.st_mode))
        !            49:                        goto typeerr;
        !            50:                break;
        !            51:        case F_CHAR:
        !            52:                if (!S_ISCHR(p->fts_statb.st_mode))
        !            53:                        goto typeerr;
        !            54:                break;
        !            55:        case F_DIR:
        !            56:                if (!S_ISDIR(p->fts_statb.st_mode))
        !            57:                        goto typeerr;
        !            58:                break;
        !            59:        case F_FIFO:
        !            60:                if (!S_ISFIFO(p->fts_statb.st_mode))
        !            61:                        goto typeerr;
        !            62:                break;
        !            63:        case F_FILE:
        !            64:                if (!S_ISREG(p->fts_statb.st_mode))
        !            65:                        goto typeerr;
        !            66:                break;
        !            67:        case F_LINK:
        !            68:                if (!S_ISLNK(p->fts_statb.st_mode))
        !            69:                        goto typeerr;
        !            70:                break;
        !            71:        case F_SOCK:
        !            72:                if (!S_ISFIFO(p->fts_statb.st_mode)) {
        !            73: typeerr:               LABEL;
        !            74:                        (void)printf("\n\ttype (%s, %s)",
        !            75:                            ftype(s->type), inotype(p->fts_statb.st_mode));
        !            76:                }
        !            77:                break;
        !            78:        }
        !            79:        if (s->flags & F_MODE && s->st_mode != (p->fts_statb.st_mode & MBITS)) {
        !            80:                LABEL;
        !            81:                (void)printf("\n\tpermissions (%#o, %#o%s",
        !            82:                    s->st_mode, p->fts_statb.st_mode & MBITS, uflag ? "" : ")");
        !            83:                if (uflag)
        !            84:                        if (chmod(p->fts_accpath, s->st_mode))
        !            85:                                (void)printf(", not modified: %s)",
        !            86:                                    strerror(errno));
        !            87:                        else
        !            88:                                (void)printf(", modified)");
        !            89:        }
        !            90:        if (s->flags & F_OWNER && s->st_uid != p->fts_statb.st_uid) {
        !            91:                LABEL;
        !            92:                (void)printf("\n\towner (%u, %u%s",
        !            93:                    s->st_uid, p->fts_statb.st_uid, uflag ? "" : ")");
        !            94:                if (uflag)
        !            95:                        if (chown(p->fts_accpath, s->st_uid, -1))
        !            96:                                (void)printf(", not modified: %s)",
        !            97:                                    strerror(errno));
        !            98:                        else
        !            99:                                (void)printf(", modified)");
        !           100:        }
        !           101:        if (s->flags & F_GROUP && s->st_gid != p->fts_statb.st_gid) {
        !           102:                LABEL;
        !           103:                (void)printf("\n\tgroup (%u, %u%s",
        !           104:                    s->st_gid, p->fts_statb.st_gid, uflag ? "" : ")");
        !           105:                if (uflag)
        !           106:                        if (chown(p->fts_accpath, -1, s->st_gid))
        !           107:                                (void)printf(", not modified: %s)",
        !           108:                                    strerror(errno));
        !           109:                        else
        !           110:                                (void)printf(", modified)");
        !           111:        }
        !           112:        if (s->flags & F_NLINK && s->type != F_DIR &&
        !           113:            s->st_nlink != p->fts_statb.st_nlink) {
        !           114:                LABEL;
        !           115:                (void)printf("\n\tlink count (%u, %u)",
        !           116:                    s->st_nlink, p->fts_statb.st_nlink);
        !           117:        }
        !           118:        if (s->flags & F_SIZE && s->st_size != p->fts_statb.st_size) {
        !           119:                LABEL;
        !           120:                (void)printf("\n\tsize (%ld, %ld)",
        !           121:                    s->st_size, p->fts_statb.st_size);
        !           122:        }
        !           123:        if (s->flags & F_SLINK) {
        !           124:                char *cp;
        !           125: 
        !           126:                if (strcmp(cp = rlink(name), s->slink)) {
        !           127:                        LABEL;
        !           128:                        (void)printf("\n\tlink ref (%s, %s)", cp, s->slink);
        !           129:                }
        !           130:        }
        !           131:        if (s->flags & F_TIME && s->st_mtime != p->fts_statb.st_mtime) {
        !           132:                LABEL;
        !           133:                (void)printf("\n\tmodification time (%.24s, ",
        !           134:                    ctime(&s->st_mtime));
        !           135:                (void)printf("%.24s)", ctime(&p->fts_statb.st_mtime));
        !           136:        }
        !           137:        if (label) {
        !           138:                exitval = 2;
        !           139:                putchar('\n');
        !           140:        }
        !           141: }
        !           142: 
        !           143: char *
        !           144: inotype(type)
        !           145:        mode_t type;
        !           146: {
        !           147:        switch(type & S_IFMT) {
        !           148:        case S_IFBLK:
        !           149:                return("block");
        !           150:        case S_IFCHR:
        !           151:                return("char");
        !           152:        case S_IFDIR:
        !           153:                return("dir");
        !           154:        case S_IFREG:
        !           155:                return("file");
        !           156:        case S_IFLNK:
        !           157:                return("link");
        !           158:        case S_IFSOCK:
        !           159:                return("socket");
        !           160:        default:
        !           161:                return("unknown");
        !           162:        }
        !           163:        /* NOTREACHED */
        !           164: }
        !           165: 
        !           166: char *
        !           167: ftype(type)
        !           168:        u_int type;
        !           169: {
        !           170:        switch(type) {
        !           171:        case F_BLOCK:
        !           172:                return("block");
        !           173:        case F_CHAR:
        !           174:                return("char");
        !           175:        case F_DIR:
        !           176:                return("dir");
        !           177:        case F_FIFO:
        !           178:                return("fifo");
        !           179:        case F_FILE:
        !           180:                return("file");
        !           181:        case F_LINK:
        !           182:                return("link");
        !           183:        case F_SOCK:
        !           184:                return("socket");
        !           185:        default:
        !           186:                return("unknown");
        !           187:        }
        !           188:        /* NOTREACHED */
        !           189: }
        !           190: 
        !           191: char *
        !           192: rlink(name)
        !           193:        char *name;
        !           194: {
        !           195:        register int len;
        !           196:        static char lbuf[MAXPATHLEN];
        !           197: 
        !           198:        len = readlink(name, lbuf, sizeof(lbuf));
        !           199:        if (len == -1) {
        !           200:                (void)fprintf(stderr, "mtree: %s: %s.\n",
        !           201:                    name, strerror(errno));
        !           202:                exit(1);
        !           203:        }
        !           204:        lbuf[len] = '\0';
        !           205:        return(lbuf);
        !           206: }

unix.superglobalmegacorp.com

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