implement the magic characters in specification file names
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 26 May 1990 01:43:35 +0000 (17:43 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 26 May 1990 01:43:35 +0000 (17:43 -0800)
SCCS-vsn: usr.sbin/mtree/mtree.h 5.4
SCCS-vsn: usr.sbin/mtree/spec.c 5.6
SCCS-vsn: usr.sbin/mtree/verify.c 5.3

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

index 7294436..528e382 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)mtree.h     5.3 (Berkeley) %G%
+ *     @(#)mtree.h     5.4 (Berkeley) %G%
  */
 
 #include <string.h>
  */
 
 #include <string.h>
@@ -31,13 +31,13 @@ typedef struct _info {
 #define        F_TYPE  0x100                           /* file type */
        u_short flags;                          /* items set */
 
 #define        F_TYPE  0x100                           /* file type */
        u_short flags;                          /* items set */
 
-       off_t   st_size;
+       off_t   st_size;                        /* size */
        u_long  cksum;                          /* check sum */
        u_long  cksum;                          /* check sum */
-       uid_t   st_uid;
-       gid_t   st_gid;
+       uid_t   st_uid;                         /* owner */
+       gid_t   st_gid;                         /* group */
 #define        MBITS   (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
 #define        MBITS   (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
-       mode_t  st_mode;
-       nlink_t st_nlink;
+       mode_t  st_mode;                        /* mode */
+       nlink_t st_nlink;                       /* link count */
        char    *slink;                         /* symbolic link reference */
 } INFO;
 
        char    *slink;                         /* symbolic link reference */
 } INFO;
 
@@ -46,9 +46,10 @@ typedef struct _entry {
        struct _entry   *next, *prev;           /* left, right */
        INFO    info;                           /* node info structure */
 #define        F_DONE  0x01                            /* directory done */
        struct _entry   *next, *prev;           /* left, right */
        INFO    info;                           /* node info structure */
 #define        F_DONE  0x01                            /* directory done */
-#define        F_VISIT 0x02                            /* visited this node */
+#define        F_MAGIC 0x02                            /* name has magic chars */
+#define        F_VISIT 0x04                            /* visited this node */
        u_char  flags;                          /* flags */
        u_char  flags;                          /* flags */
-       char    *name;                          /* node name */
+       char    name[1];                        /* file name (must be last) */
 } ENTRY;
 
 #define        RP(p)   (p->fts_path + 2)
 } ENTRY;
 
 #define        RP(p)   (p->fts_path + 2)
index e6bec4a..4d457c5 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)spec.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)spec.c     5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -27,7 +27,7 @@ spec()
        ENTRY *centry, *last;
        INFO info, ginfo;
        char buf[2048];
        ENTRY *centry, *last;
        INFO info, ginfo;
        char buf[2048];
-       void *emalloc();
+       ENTRY *emalloc();
 
        ginfo.flags = info.flags = 0;
        ginfo.type = info.type = F_NONE;
 
        ginfo.flags = info.flags = 0;
        ginfo.type = info.type = F_NONE;
@@ -79,9 +79,11 @@ spec()
                        continue;
                }
 
                        continue;
                }
 
-               centry = (ENTRY *)emalloc(sizeof(ENTRY));
-               if (!(centry->name = strdup(p)))
-                       nomem();
+               centry = emalloc(sizeof(ENTRY) + strlen(p));
+               (void)strcpy(centry->name, p);
+#define        MAGIC   "?*["
+               if (strpbrk(p, MAGIC))
+                       centry->flags |= F_MAGIC;
                centry->info = ginfo;
                set(&centry->info);
 
                centry->info = ginfo;
                set(&centry->info);
 
@@ -287,7 +289,7 @@ specerr()
        exit(1);
 }
 
        exit(1);
 }
 
-static void *
+static ENTRY *
 emalloc(size)
        int size;
 {
 emalloc(size)
        int size;
 {
@@ -297,7 +299,7 @@ emalloc(size)
        if (!(p = malloc((u_int)size)))
                nomem();
        bzero(p, size);
        if (!(p = malloc((u_int)size)))
                nomem();
        bzero(p, size);
-       return(p);
+       return((ENTRY *)p);
 }
 
 static
 }
 
 static
index 4750879..357dc9b 100644 (file)
@@ -6,13 +6,14 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)verify.c   5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)verify.c   5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <fts.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <fts.h>
+#include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
 #include "mtree.h"
 #include <errno.h>
 #include <stdio.h>
 #include "mtree.h"
@@ -76,7 +77,9 @@ vwalk()
                }
 
                for (ep = level; ep; ep = ep->next)
                }
 
                for (ep = level; ep; ep = ep->next)
-                       if (!strcmp(ep->name, p->fts_name)) {
+                       if (ep->flags & F_MAGIC && fnmatch(ep->name,
+                           p->fts_name, FNM_PATHNAME|FNM_QUOTE) ||
+                           !strcmp(ep->name, p->fts_name)) {
                                ep->flags |= F_VISIT;
                                if (ep->info.flags&F_IGN) {
                                        (void)ftsset(t, p, FTS_SKIP);
                                ep->flags |= F_VISIT;
                                if (ep->info.flags&F_IGN) {
                                        (void)ftsset(t, p, FTS_SKIP);