diff options
-rw-r--r-- | bftw.c | 13 | ||||
-rw-r--r-- | bftw.h | 2 | ||||
-rw-r--r-- | parse.c | 8 |
3 files changed, 20 insertions, 3 deletions
@@ -656,10 +656,12 @@ static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de) bool detect_cycles = (state->flags & BFTW_DETECT_CYCLES) && state->status == BFTW_CHILD; + bool mount = state->flags & BFTW_MOUNT; + if ((state->flags & BFTW_STAT) || ftwbuf->typeflag == BFTW_UNKNOWN || (ftwbuf->typeflag == BFTW_LNK && follow) - || (ftwbuf->typeflag == BFTW_DIR && detect_cycles)) { + || (ftwbuf->typeflag == BFTW_DIR && (detect_cycles || mount))) { int ret = ftwbuf_stat(ftwbuf, &state->statbuf, ftwbuf->at_flags); if (ret != 0 && follow && errno == ENOENT) { // Could be a broken symlink, retry without following @@ -719,7 +721,7 @@ static struct dircache_entry *bftw_add(struct bftw_state *state, const char *nam return NULL; } - if (state->flags & BFTW_DETECT_CYCLES) { + if (state->flags & (BFTW_DETECT_CYCLES | BFTW_MOUNT)) { const struct stat *statbuf = state->ftwbuf.statbuf; if (statbuf) { entry->dev = statbuf->st_dev; @@ -910,6 +912,13 @@ int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void } if (state.ftwbuf.typeflag == BFTW_DIR) { + const struct stat *statbuf = state.ftwbuf.statbuf; + if ((flags & BFTW_MOUNT) + && statbuf + && statbuf->st_dev != state.current->dev) { + continue; + } + if (bftw_push(&state, de->d_name) != 0) { goto fail; } @@ -120,6 +120,8 @@ enum bftw_flags { BFTW_FOLLOW = BFTW_FOLLOW_ROOT | BFTW_FOLLOW_NONROOT, /** Detect directory cycles. */ BFTW_DETECT_CYCLES = 1 << 5, + /** Stay on the same filesystem. */ + BFTW_MOUNT = 1 << 6, }; /** @@ -679,6 +679,9 @@ static struct expr *parse_literal(struct parser_state *state) { return parse_depth(state, arg, &state->cmdline->maxdepth); } else if (strcmp(arg, "-mmin") == 0) { return parse_acmtime(state, arg, MTIME, MINUTES); + } else if (strcmp(arg, "-mount") == 0) { + state->cmdline->flags |= BFTW_MOUNT; + return new_option(state, arg); } else if (strcmp(arg, "-mtime") == 0) { return parse_acmtime(state, arg, MTIME, DAYS); } @@ -762,7 +765,10 @@ static struct expr *parse_literal(struct parser_state *state) { break; case 'x': - if (strcmp(arg, "-xtype") == 0) { + if (strcmp(arg, "-xdev") == 0) { + state->cmdline->flags |= BFTW_MOUNT; + return new_option(state, arg); + } else if (strcmp(arg, "-xtype") == 0) { return parse_type(state, arg, eval_xtype); } break; |