fts now has flag to keep from crossing mount points
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 23 May 1990 06:00:52 +0000 (22:00 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 23 May 1990 06:00:52 +0000 (22:00 -0800)
SCCS-vsn: usr.bin/find/find.c 4.29
SCCS-vsn: usr.bin/find/function.c 5.5
SCCS-vsn: usr.bin/find/main.c 5.2

usr/src/usr.bin/find/find.c
usr/src/usr.bin/find/function.c
usr/src/usr.bin/find/main.c

index ef87ca8..e7c0c71 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)find.c     4.28 (Berkeley) %G%";
+static char sccsid[] = "@(#)find.c     4.29 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -28,12 +28,10 @@ static char sccsid[] = "@(#)find.c  4.28 (Berkeley) %G%";
 
 FTS *tree;                     /* pointer to top of FTS hierarchy */
 time_t now;                    /* time find was run */
 
 FTS *tree;                     /* pointer to top of FTS hierarchy */
 time_t now;                    /* time find was run */
-dev_t curdev = (dev_t)-1;      /* device number of current tree */
 int ftsoptions;                        /* options passed to ftsopen() */
 int deprecated;                        /* old or new syntax */
 int depth;                     /* set by -depth option */
 int output_specified;          /* one of -print, -ok or -exec was specified */
 int ftsoptions;                        /* options passed to ftsopen() */
 int deprecated;                        /* old or new syntax */
 int depth;                     /* set by -depth option */
 int output_specified;          /* one of -print, -ok or -exec was specified */
-int xdev;                      /* set by -xdev option */
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -205,22 +203,12 @@ find_execute(plan, paths)
                        break;
                }
 
                        break;
                }
 
-               /* always keep curdev up to date, -fstype uses it. */
-               if (xdev && curdev != entry->fts_statb.st_dev &&
-                   curdev != -1 && ftsset(tree, entry, FTS_SKIP)) {
-                       (void)fprintf(stderr, "find: %s: %s.\n",
-                           entry->fts_path, strerror(errno));
-                       exit(1);
-               }
-
                /*
                 * call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
                 * the work specified by the user on the command line.
                 */
                for (p = plan; p && (p->eval)(p, entry); p = p->next);
                /*
                 * call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
                 * the work specified by the user on the command line.
                 */
                for (p = plan; p && (p->eval)(p, entry); p = p->next);
-
-               curdev = entry->fts_statb.st_dev;
        }
        (void)ftsclose(tree);
 }
        }
        (void)ftsclose(tree);
 }
index 24901e2..0f325b1 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)function.c 5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)function.c 5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -300,17 +300,19 @@ f_fstype(plan, entry)
        PLAN *plan;
        FTSENT *entry;
 {
        PLAN *plan;
        FTSENT *entry;
 {
-       extern dev_t curdev;
+       static dev_t curdev;    /* need a guaranteed illegal dev value */
+       static int first = 1;
        struct statfs sb;
        static short val;
 
        /* only check when we cross mount point */
        struct statfs sb;
        static short val;
 
        /* only check when we cross mount point */
-       if (curdev != entry->fts_statb.st_dev) {
+       if (first || curdev != entry->fts_statb.st_dev) {
                if (statfs(entry->fts_accpath, &sb)) {
                        (void)fprintf(stderr, "find: %s: %s.\n",
                            entry->fts_accpath, strerror(errno));
                        exit(1);
                }
                if (statfs(entry->fts_accpath, &sb)) {
                        (void)fprintf(stderr, "find: %s: %s.\n",
                            entry->fts_accpath, strerror(errno));
                        exit(1);
                }
+               first = 0;
                val = plan->flags == MOUNT_NONE ? sb.f_flags : sb.f_type;
        }
        return(plan->flags == MOUNT_NONE ?
                val = plan->flags == MOUNT_NONE ? sb.f_flags : sb.f_type;
        }
        return(plan->flags == MOUNT_NONE ?
@@ -815,17 +817,14 @@ c_user(username)
  *
  *     Always true, causes find not to decend past directories that have a
  *     different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
  *
  *     Always true, causes find not to decend past directories that have a
  *     different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
- *
- *     Note: this checking is done in find_execute().
  */
 PLAN *
 c_xdev()
 {
  */
 PLAN *
 c_xdev()
 {
-       extern int xdev;
        PLAN *new;
     
        PLAN *new;
     
-       xdev = 1;
        ftsoptions &= ~FTS_NOSTAT;
        ftsoptions &= ~FTS_NOSTAT;
+       ftsoptions |= FTS_XDEV;
 
        NEW(T_XDEV, f_always_true);
        return(new);
 
        NEW(T_XDEV, f_always_true);
        return(new);
index f353f43..a18cd49 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -20,7 +20,7 @@ newsyntax(argc, argvp)
        char ***argvp;
 {
        extern char *optarg;
        char ***argvp;
 {
        extern char *optarg;
-       extern int depth, optind, xdev;
+       extern int depth, optind;
        int ch;
        char **argv, **cur;
 
        int ch;
        char **argv, **cur;
 
@@ -38,8 +38,8 @@ newsyntax(argc, argvp)
                        ftsoptions |= FTS_LOGICAL;
                        break;
                case 'x':
                        ftsoptions |= FTS_LOGICAL;
                        break;
                case 'x':
-                       xdev = 1;
                        ftsoptions &= ~FTS_NOSTAT;
                        ftsoptions &= ~FTS_NOSTAT;
+                       ftsoptions |= FTS_XDEV;
                        break;
                case '?':
                default:
                        break;
                case '?':
                default: