fold INFO and ENTRY structures together into NODE structure
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 26 May 1990 03:19:32 +0000 (19:19 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 26 May 1990 03:19:32 +0000 (19:19 -0800)
SCCS-vsn: usr.sbin/mtree/compare.c 5.5
SCCS-vsn: usr.sbin/mtree/create.c 5.9
SCCS-vsn: usr.sbin/mtree/mtree.c 5.7
SCCS-vsn: usr.sbin/mtree/mtree.h 5.5
SCCS-vsn: usr.sbin/mtree/spec.c 5.9
SCCS-vsn: usr.sbin/mtree/verify.c 5.4

usr/src/usr.sbin/mtree/compare.c
usr/src/usr.sbin/mtree/create.c
usr/src/usr.sbin/mtree/mtree.c
usr/src/usr.sbin/mtree/mtree.h
usr/src/usr.sbin/mtree/spec.c
usr/src/usr.sbin/mtree/verify.c

index c9a7bbd..a91d4cf 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)compare.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)compare.c  5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -22,7 +22,7 @@ static char sccsid[] = "@(#)compare.c 5.4 (Berkeley) %G%";
 
 compare(name, s, p)
        char *name;
 
 compare(name, s, p)
        char *name;
-       register INFO *s;
+       register NODE *s;
        register FTSENT *p;
 {
        extern int exitval, uflag;
        register FTSENT *p;
 {
        extern int exitval, uflag;
@@ -59,10 +59,10 @@ typeerr:            LABEL;
                }
                break;
        }
                }
                break;
        }
-       if (s->flags&F_MODE && s->st_mode != (p->fts_statb.st_mode&MBITS)) {
+       if (s->flags & F_MODE && s->st_mode != (p->fts_statb.st_mode & MBITS)) {
                LABEL;
                (void)printf("\n\tpermissions (%#o, %#o%s",
                LABEL;
                (void)printf("\n\tpermissions (%#o, %#o%s",
-                   s->st_mode, p->fts_statb.st_mode&MBITS, uflag ? "" : ")");
+                   s->st_mode, p->fts_statb.st_mode & MBITS, uflag ? "" : ")");
                if (uflag)
                        if (chmod(p->fts_accpath, s->st_mode))
                                (void)printf(", not modified: %s)",
                if (uflag)
                        if (chmod(p->fts_accpath, s->st_mode))
                                (void)printf(", not modified: %s)",
@@ -70,7 +70,7 @@ typeerr:              LABEL;
                        else
                                (void)printf(", modified)");
        }
                        else
                                (void)printf(", modified)");
        }
-       if (s->flags&F_OWNER && s->st_uid != p->fts_statb.st_uid) {
+       if (s->flags & F_OWNER && s->st_uid != p->fts_statb.st_uid) {
                LABEL;
                (void)printf("\n\towner (%u, %u%s",
                    s->st_uid, p->fts_statb.st_uid, uflag ? "" : ")");
                LABEL;
                (void)printf("\n\towner (%u, %u%s",
                    s->st_uid, p->fts_statb.st_uid, uflag ? "" : ")");
@@ -81,7 +81,7 @@ typeerr:              LABEL;
                        else
                                (void)printf(", modified)");
        }
                        else
                                (void)printf(", modified)");
        }
-       if (s->flags&F_GROUP && s->st_gid != p->fts_statb.st_gid) {
+       if (s->flags & F_GROUP && s->st_gid != p->fts_statb.st_gid) {
                LABEL;
                (void)printf("\n\tgroup (%u, %u%s",
                    s->st_gid, p->fts_statb.st_gid, uflag ? "" : ")");
                LABEL;
                (void)printf("\n\tgroup (%u, %u%s",
                    s->st_gid, p->fts_statb.st_gid, uflag ? "" : ")");
@@ -92,18 +92,18 @@ typeerr:            LABEL;
                        else
                                (void)printf(", modified)");
        }
                        else
                                (void)printf(", modified)");
        }
-       if (s->flags&F_NLINK && s->type != F_DIR &&
+       if (s->flags & F_NLINK && s->type != F_DIR &&
            s->st_nlink != p->fts_statb.st_nlink) {
                LABEL;
                (void)printf("\n\tlink count (%u, %u)",
                    s->st_nlink, p->fts_statb.st_nlink);
        }
            s->st_nlink != p->fts_statb.st_nlink) {
                LABEL;
                (void)printf("\n\tlink count (%u, %u)",
                    s->st_nlink, p->fts_statb.st_nlink);
        }
-       if (s->flags&F_SIZE && s->st_size != p->fts_statb.st_size) {
+       if (s->flags & F_SIZE && s->st_size != p->fts_statb.st_size) {
                LABEL;
                (void)printf("\n\tsize (%ld, %ld)",
                    s->st_size, p->fts_statb.st_size);
        }
                LABEL;
                (void)printf("\n\tsize (%ld, %ld)",
                    s->st_size, p->fts_statb.st_size);
        }
-       if (s->flags&F_SLINK) {
+       if (s->flags & F_SLINK) {
                char *cp;
 
                if (strcmp(cp = rlink(name), s->slink)) {
                char *cp;
 
                if (strcmp(cp = rlink(name), s->slink)) {
@@ -121,7 +121,7 @@ char *
 inotype(type)
        mode_t type;
 {
 inotype(type)
        mode_t type;
 {
-       switch(type&S_IFMT) {
+       switch(type & S_IFMT) {
        case S_IFBLK:
                return("block");
        case S_IFCHR:
        case S_IFBLK:
                return("block");
        case S_IFCHR:
index 53cad9b..b2b8dc3 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)create.c   5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)create.c   5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -138,7 +138,7 @@ cwalk()
 
 #define        MAXGID  5000
 #define        MAXUID  5000
 
 #define        MAXGID  5000
 #define        MAXUID  5000
-#define        MAXMODE 0777 + 1
+#define        MAXMODE MBITS + 1
 
 static
 statdir(t, parent, puid, pgid, pmode, tabs)
 
 static
 statdir(t, parent, puid, pgid, pmode, tabs)
@@ -174,7 +174,7 @@ statdir(t, parent, puid, pgid, pmode, tabs)
        *tabs = 1;
        maxuid = maxgid = maxmode = 0;
        for (; p; p = p->fts_link) {
        *tabs = 1;
        maxuid = maxgid = maxmode = 0;
        for (; p; p = p->fts_link) {
-               mode = p->fts_statb.st_mode&0777;
+               mode = p->fts_statb.st_mode & MBITS;
                if (mode < MAXMODE && ++m[mode] > maxmode) {
                        savemode = mode;
                        maxmode = m[mode];
                if (mode < MAXMODE && ++m[mode] > maxmode) {
                        savemode = mode;
                        maxmode = m[mode];
index c27840d..396373f 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)mtree.c    5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)mtree.c    5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -22,7 +22,7 @@ static char sccsid[] = "@(#)mtree.c   5.6 (Berkeley) %G%";
 #include <fts.h>
 #include "mtree.h"
 
 #include <fts.h>
 #include "mtree.h"
 
-ENTRY *root;
+NODE *root;
 int exitval;
 int cflag, dflag, eflag, rflag, uflag;
 
 int exitval;
 int cflag, dflag, eflag, rflag, uflag;
 
index 528e382..4773d5a 100644 (file)
@@ -4,52 +4,47 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)mtree.h     5.4 (Berkeley) %G%
+ *     @(#)mtree.h     5.5 (Berkeley) %G%
  */
 
 #include <string.h>
 #include <stdlib.h>
 
  */
 
 #include <string.h>
 #include <stdlib.h>
 
-typedef struct _info {
+typedef struct _node {
+       struct _node    *parent, *child;        /* up, down */
+       struct _node    *prev, *next;           /* left, right */
+       off_t   st_size;                        /* size */
+       u_long  cksum;                          /* check sum */
+       char    *slink;                         /* symbolic link reference */
+       uid_t   st_uid;                         /* owner */
+       gid_t   st_gid;                         /* group */
+#define        MBITS   (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
+       mode_t  st_mode;                        /* mode */
+       nlink_t st_nlink;                       /* link count */
+
 #define        F_BLOCK 0x001                           /* block special */
 #define        F_CHAR  0x002                           /* char special */
 #define        F_DIR   0x004                           /* directory */
 #define        F_FILE  0x008                           /* regular file */
 #define        F_LINK  0x010                           /* symbolic link */
 #define        F_SOCK  0x020                           /* socket */
 #define        F_BLOCK 0x001                           /* block special */
 #define        F_CHAR  0x002                           /* char special */
 #define        F_DIR   0x004                           /* directory */
 #define        F_FILE  0x008                           /* regular file */
 #define        F_LINK  0x010                           /* symbolic link */
 #define        F_SOCK  0x020                           /* socket */
-#define        F_NONE  0x040                           /* unknown */
        u_short type;                           /* file type */
 
 #define        F_CKSUM 0x001                           /* check sum */
        u_short type;                           /* file type */
 
 #define        F_CKSUM 0x001                           /* check sum */
-#define        F_GROUP 0x002                           /* group */
-#define        F_IGN   0x004                           /* ignore */
-#define        F_MODE  0x008                           /* mode */
-#define        F_NLINK 0x010                           /* number of links */
-#define        F_OWNER 0x020                           /* owner */
-#define        F_SIZE  0x040                           /* size */
-#define        F_SLINK 0x080                           /* link count */
-#define        F_TYPE  0x100                           /* file type */
+#define        F_DONE  0x002                           /* directory done */
+#define        F_GROUP 0x004                           /* group */
+#define        F_IGN   0x008                           /* ignore */
+#define        F_MAGIC 0x010                           /* name has magic chars */
+#define        F_MODE  0x020                           /* mode */
+#define        F_NLINK 0x040                           /* number of links */
+#define        F_OWNER 0x080                           /* owner */
+#define        F_SIZE  0x100                           /* size */
+#define        F_SLINK 0x200                           /* link count */
+#define        F_TYPE  0x400                           /* file type */
+#define        F_VISIT 0x800                           /* file visited */
        u_short flags;                          /* items set */
 
        u_short flags;                          /* items set */
 
-       off_t   st_size;                        /* size */
-       u_long  cksum;                          /* check sum */
-       uid_t   st_uid;                         /* owner */
-       gid_t   st_gid;                         /* group */
-#define        MBITS   (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
-       mode_t  st_mode;                        /* mode */
-       nlink_t st_nlink;                       /* link count */
-       char    *slink;                         /* symbolic link reference */
-} INFO;
-
-typedef struct _entry {
-       struct _entry   *child, *parent;        /* up, down */
-       struct _entry   *next, *prev;           /* left, right */
-       INFO    info;                           /* node info structure */
-#define        F_DONE  0x01                            /* directory done */
-#define        F_MAGIC 0x02                            /* name has magic chars */
-#define        F_VISIT 0x04                            /* visited this node */
-       u_char  flags;                          /* flags */
        char    name[1];                        /* file name (must be last) */
        char    name[1];                        /* file name (must be last) */
-} ENTRY;
+} NODE;
 
 #define        RP(p)   (p->fts_path + 2)
 
 #define        RP(p)   (p->fts_path + 2)
index 3abc81d..051194e 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)spec.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)spec.c     5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -17,20 +17,18 @@ static char sccsid[] = "@(#)spec.c  5.8 (Berkeley) %G%";
 #include <ctype.h>
 #include "mtree.h"
 
 #include <ctype.h>
 #include "mtree.h"
 
-extern ENTRY *root;                    /* root of the tree */
+extern NODE *root;                     /* root of the tree */
 
 static int lineno;                     /* current spec line number */
 
 spec()
 {
 
 static int lineno;                     /* current spec line number */
 
 spec()
 {
+       register NODE *centry, *last;
        register char *p;
        register char *p;
-       ENTRY *centry, *last;
-       INFO info, ginfo;
+       NODE ginfo, *emalloc();
        char buf[2048];
        char buf[2048];
-       ENTRY *emalloc();
 
 
-       ginfo.flags = info.flags = 0;
-       ginfo.type = info.type = F_NONE;
+       bzero((void *)&ginfo, sizeof(ginfo));
        for (lineno = 1; fgets(buf, sizeof(buf), stdin); ++lineno) {
                if (!(p = index(buf, '\n'))) {
                        (void)fprintf(stderr,
        for (lineno = 1; fgets(buf, sizeof(buf), stdin); ++lineno) {
                if (!(p = index(buf, '\n'))) {
                        (void)fprintf(stderr,
@@ -70,7 +68,7 @@ spec()
                        /* don't go up, if haven't gone down */
                        if (!root)
                                noparent();
                        /* don't go up, if haven't gone down */
                        if (!root)
                                noparent();
-                       if (last->info.type != F_DIR || last->flags&F_DONE) {
+                       if (last->type != F_DIR || last->flags & F_DONE) {
                                if (last == root)
                                        noparent();
                                last = last->parent;
                                if (last == root)
                                        noparent();
                                last = last->parent;
@@ -79,18 +77,18 @@ spec()
                        continue;
                }
 
                        continue;
                }
 
-               centry = emalloc(sizeof(ENTRY) + strlen(p));
+               centry = emalloc(sizeof(NODE) + strlen(p));
+               *centry = ginfo;
                (void)strcpy(centry->name, p);
 #define        MAGIC   "?*["
                if (strpbrk(p, MAGIC))
                        centry->flags |= F_MAGIC;
                (void)strcpy(centry->name, p);
 #define        MAGIC   "?*["
                if (strpbrk(p, MAGIC))
                        centry->flags |= F_MAGIC;
-               centry->info = ginfo;
-               set(&centry->info);
+               set(centry);
 
                if (!root) {
                        last = root = centry;
                        root->parent = root;
 
                if (!root) {
                        last = root = centry;
                        root->parent = root;
-               } else if (last->info.type == F_DIR && !(last->flags&F_DONE)) {
+               } else if (last->type == F_DIR && !(last->flags & F_DONE)) {
                        centry->parent = last;
                        last = last->child = centry;
                } else {
                        centry->parent = last;
                        last = last->child = centry;
                } else {
@@ -103,10 +101,10 @@ spec()
 
 static
 set(ip)
 
 static
 set(ip)
-       INFO *ip;
+       register NODE *ip;
 {
 {
-       int type;
-       char *kw, *val;
+       register int type;
+       register char *kw, *val;
        gid_t getgroup();
        uid_t getowner();
        long atol(), strtol();
        gid_t getgroup();
        uid_t getowner();
        long atol(), strtol();
@@ -188,7 +186,7 @@ set(ip)
 
 static
 unset(ip)
 
 static
 unset(ip)
-       register INFO *ip;
+       register NODE *ip;
 {
        register char *p;
 
 {
        register char *p;
 
@@ -297,7 +295,7 @@ specerr()
        exit(1);
 }
 
        exit(1);
 }
 
-static ENTRY *
+static NODE *
 emalloc(size)
        int size;
 {
 emalloc(size)
        int size;
 {
@@ -307,7 +305,7 @@ emalloc(size)
        if (!(p = malloc((u_int)size)))
                nomem();
        bzero(p, size);
        if (!(p = malloc((u_int)size)))
                nomem();
        bzero(p, size);
-       return((ENTRY *)p);
+       return((NODE *)p);
 }
 
 static
 }
 
 static
index 357dc9b..27ae3dd 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)verify.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)verify.c   5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -18,7 +18,7 @@ static char sccsid[] = "@(#)verify.c  5.3 (Berkeley) %G%";
 #include <stdio.h>
 #include "mtree.h"
 
 #include <stdio.h>
 #include "mtree.h"
 
-extern ENTRY *root;
+extern NODE *root;
 
 static char path[MAXPATHLEN];
 
 
 static char path[MAXPATHLEN];
 
@@ -33,7 +33,7 @@ vwalk()
        extern int ftsoptions, dflag, eflag, rflag;
        register FTS *t;
        register FTSENT *p;
        extern int ftsoptions, dflag, eflag, rflag;
        register FTS *t;
        register FTSENT *p;
-       register ENTRY *ep, *level;
+       register NODE *ep, *level;
 
        if (!(t = ftsopen(".", ftsoptions, (int (*)())NULL))) {
                (void)fprintf(stderr,
 
        if (!(t = ftsopen(".", ftsoptions, (int (*)())NULL))) {
                (void)fprintf(stderr,
@@ -81,12 +81,12 @@ vwalk()
                            p->fts_name, FNM_PATHNAME|FNM_QUOTE) ||
                            !strcmp(ep->name, p->fts_name)) {
                                ep->flags |= F_VISIT;
                            p->fts_name, FNM_PATHNAME|FNM_QUOTE) ||
                            !strcmp(ep->name, p->fts_name)) {
                                ep->flags |= F_VISIT;
-                               if (ep->info.flags&F_IGN) {
+                               if (ep->flags & F_IGN) {
                                        (void)ftsset(t, p, FTS_SKIP);
                                        continue;
                                }
                                        (void)ftsset(t, p, FTS_SKIP);
                                        continue;
                                }
-                               compare(ep->name, &ep->info, p);
-                               if (ep->child && ep->info.type == F_DIR &&
+                               compare(ep->name, ep, p);
+                               if (ep->child && ep->type == F_DIR &&
                                    p->fts_info == FTS_D)
                                        level = ep->child;
                                break;
                                    p->fts_info == FTS_D)
                                        level = ep->child;
                                break;
@@ -109,7 +109,7 @@ vwalk()
 }
 
 miss(p, tail)
 }
 
 miss(p, tail)
-       register ENTRY *p;
+       register NODE *p;
        register char *tail;
 {
        extern int dflag, uflag;
        register char *tail;
 {
        extern int dflag, uflag;
@@ -117,20 +117,20 @@ miss(p, tail)
        register char *tp;
 
        for (; p; p = p->next) {
        register char *tp;
 
        for (; p; p = p->next) {
-               if (p->info.type != F_DIR && (dflag || p->flags&F_VISIT))
+               if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
                        continue;
                (void)strcpy(tail, p->name);
                        continue;
                (void)strcpy(tail, p->name);
-               if (!(p->flags&F_VISIT))
+               if (!(p->flags & F_VISIT))
                        (void)printf("missing: %s", path);
                        (void)printf("missing: %s", path);
-               if (p->info.type != F_DIR) {
+               if (p->type != F_DIR) {
                        putchar('\n');
                        continue;
                }
 
                create = 0;
                        putchar('\n');
                        continue;
                }
 
                create = 0;
-               if (!(p->flags&F_VISIT) && uflag)
+               if (!(p->flags & F_VISIT) && uflag)
 #define        MINBITS (F_GROUP|F_MODE|F_OWNER)
 #define        MINBITS (F_GROUP|F_MODE|F_OWNER)
-                       if ((p->info.flags & MINBITS) != MINBITS)
+                       if ((p->flags & MINBITS) != MINBITS)
                                (void)printf(" (not created -- group, mode or owner not specified)");
                        else if (mkdir(path, S_IRWXU))
                                (void)printf(" (not created: %s)",
                                (void)printf(" (not created -- group, mode or owner not specified)");
                        else if (mkdir(path, S_IRWXU))
                                (void)printf(" (not created: %s)",
@@ -140,7 +140,7 @@ miss(p, tail)
                                (void)printf(" (created)");
                        }
 
                                (void)printf(" (created)");
                        }
 
-               if (!(p->flags&F_VISIT))
+               if (!(p->flags & F_VISIT))
                        (void)putchar('\n');
 
                for (tp = tail; *tp; ++tp);
                        (void)putchar('\n');
 
                for (tp = tail; *tp; ++tp);
@@ -150,12 +150,12 @@ miss(p, tail)
 
                if (!create)
                        continue;
 
                if (!create)
                        continue;
-               if (chown(path, p->info.st_uid, p->info.st_gid)) {
+               if (chown(path, p->st_uid, p->st_gid)) {
                        (void)printf("%s: owner/group/mode not modified: %s\n",
                            path, strerror(errno));
                        continue;
                }
                        (void)printf("%s: owner/group/mode not modified: %s\n",
                            path, strerror(errno));
                        continue;
                }
-               if (chmod(path, p->info.st_mode))
+               if (chmod(path, p->st_mode))
                        (void)printf("%s: permissions not set: %s\n",
                            path, strerror(errno));
        }
                        (void)printf("%s: permissions not set: %s\n",
                            path, strerror(errno));
        }