diff -rupN lustre-1.8.2-orig/lustre/include/lustre/liblustreapi.h lustre-1.8.2/lustre/include/lustre/liblustreapi.h --- lustre-1.8.2-orig/lustre/include/lustre/liblustreapi.h 2010-01-23 04:07:58.000000000 +0200 +++ lustre-1.8.2/lustre/include/lustre/liblustreapi.h 2010-05-09 16:52:03.000000000 +0300 @@ -104,6 +104,7 @@ struct find_param { int csign; int msign; int type; + int negopt; unsigned long long size; int size_sign; unsigned long long size_units; diff -rupN lustre-1.8.2-orig/lustre/utils/lfs.c lustre-1.8.2/lustre/utils/lfs.c --- lustre-1.8.2-orig/lustre/utils/lfs.c 2010-01-23 04:07:58.000000000 +0200 +++ lustre-1.8.2/lustre/utils/lfs.c 2010-05-09 17:34:12.000000000 +0300 @@ -453,8 +453,7 @@ static int lfs_find(int argc, char **arg int new_fashion = 1; int c, ret; time_t t; - struct find_param param = { .maxdepth = -1 }; - char str[1024]; + struct find_param param = { .maxdepth = -1, .negopt = 0, }; struct option long_opts[] = { /* New find options. */ {"atime", required_argument, 0, 'A'}, @@ -483,7 +482,6 @@ static int lfs_find(int argc, char **arg }; int pathstart = -1; int pathend = -1; - int neg_opt = 0; time_t *xtime; int *xsign; int isoption; @@ -497,8 +495,8 @@ static int lfs_find(int argc, char **arg long_opts, NULL)) >= 0) { xtime = NULL; xsign = NULL; - if (neg_opt) - --neg_opt; + if (param.negopt) + --param.negopt; /* '!' is part of option */ /* when getopt_long_only() finds a string which is not * an option nor a known option argument it returns 1 @@ -531,7 +529,7 @@ static int lfs_find(int argc, char **arg * checking done above. */ if (strcmp(optarg, "!") == 0) - neg_opt = 2; + param.negopt = 2; break; case 'A': xtime = ¶m.atime; @@ -547,18 +545,6 @@ static int lfs_find(int argc, char **arg xsign = ¶m.msign; } new_fashion = 1; - if (neg_opt) { - if (optarg[0] == '-') - optarg[0] = '+'; - else if (optarg[0] == '+') - optarg[0] = '-'; - else { - str[0] = '-'; - str[1] = '\0'; - strcat(str, optarg); - optarg = str; - } - } ret = set_time(&t, xtime, optarg); if (ret == INT_MAX) return -1; @@ -581,7 +567,7 @@ static int lfs_find(int argc, char **arg return -1; } } - param.exclude_gid = !!neg_opt; + param.exclude_gid = !!param.negopt; param.check_gid = 1; break; case 'u': @@ -596,7 +582,7 @@ static int lfs_find(int argc, char **arg return -1; } } - param.exclude_uid = !!neg_opt; + param.exclude_uid = !!param.negopt; param.check_uid = 1; break; case FIND_POOL_OPT: @@ -612,13 +598,13 @@ static int lfs_find(int argc, char **arg * is used to find V1 lov attributes */ strncpy(param.poolname, optarg, LOV_MAXPOOLNAME); param.poolname[LOV_MAXPOOLNAME] = '\0'; - param.exclude_pool = !!neg_opt; + param.exclude_pool = !!param.negopt; param.check_pool = 1; break; case 'n': new_fashion = 1; param.pattern = (char *)optarg; - param.exclude_pattern = !!neg_opt; + param.exclude_pattern = !!param.negopt; break; case 'O': { char *buf, *token, *next, *p; @@ -669,7 +655,7 @@ static int lfs_find(int argc, char **arg param.recursive = 1; break; case 't': - param.exclude_type = !!neg_opt; + param.exclude_type = !!param.negopt; switch(optarg[0]) { case 'b': param.type = S_IFBLK; break; case 'c': param.type = S_IFCHR; break; @@ -687,18 +673,6 @@ static int lfs_find(int argc, char **arg }; break; case 's': - if (neg_opt) { - if (optarg[0] == '-') - optarg[0] = '+'; - else if (optarg[0] == '+') - optarg[0] = '-'; - else { - str[0] = '-'; - str[1] = '\0'; - strcat(str, optarg); - optarg = str; - } - } if (optarg[0] == '+') param.size_sign = -1; else if (optarg[0] == '-') diff -rupN lustre-1.8.2-orig/lustre/utils/liblustreapi.c lustre-1.8.2/lustre/utils/liblustreapi.c --- lustre-1.8.2-orig/lustre/utils/liblustreapi.c 2010-01-23 04:07:58.000000000 +0200 +++ lustre-1.8.2/lustre/utils/liblustreapi.c 2010-05-10 04:22:00.000000000 +0300 @@ -1625,28 +1625,29 @@ int llapi_file_lookup(int dirfd, const c * Note: 5th actually means that the value is within the interval * (limit - margin, limit]. */ static int find_value_cmp(unsigned int file, unsigned int limit, int sign, - unsigned long long margin, int mds) + int negopt, unsigned long long margin, int mds) { + int ret = -1; + if (sign > 0) { - if (file < limit) - return mds ? 0 : 1; + if (file <= limit) + ret = mds ? 0 : 1; + } else if (sign == 0) { + if (file <= limit && file + margin >= limit) + ret = mds ? 0 : 1; + else if (file + margin <= limit) + ret = mds ? 0 : -1; + } else if (sign < 0) { + if (file >= limit) + ret = 1; + else if (mds) + ret = 0; } - if (sign == 0) { - if (file <= limit && file + margin > limit) - return mds ? 0 : 1; - if (file + margin <= limit) - return mds ? 0 : -1; - } + if (negopt) + ret = ~ret + 1; - if (sign < 0) { - if (file > limit) - return 1; - if (mds) - return 0; - } - - return -1; + return ret; } /* Check if the file time matches all the given criteria (e.g. --atime +/-N). @@ -1664,7 +1665,8 @@ static int find_time_check(lstat_t *st, /* Check if file is accepted. */ if (param->atime) { ret = find_value_cmp(st->st_atime, param->atime, - param->asign, 24 * 60 * 60, mds); + param->asign, param->negopt, + 24 * 60 * 60, mds); if (ret < 0) return ret; rc = ret; @@ -1672,7 +1674,8 @@ static int find_time_check(lstat_t *st, if (param->mtime) { ret = find_value_cmp(st->st_mtime, param->mtime, - param->msign, 24 * 60 * 60, mds); + param->msign, param->negopt, + 24 * 60 * 60, mds); if (ret < 0) return ret; @@ -1684,7 +1687,8 @@ static int find_time_check(lstat_t *st, if (param->ctime) { ret = find_value_cmp(st->st_ctime, param->ctime, - param->csign, 24 * 60 * 60, mds); + param->csign, param->negopt, + 24 * 60 * 60, mds); if (ret < 0) return ret; @@ -1936,10 +1940,11 @@ obd_matches: goto decided; } - if (param->size_check) + if (param->size_check) { decision = find_value_cmp(st->st_size, param->size, - param->size_sign, param->size_units, - 0); + param->size_sign, param->negopt, + param->size_units, 0); + } if (decision != -1) { llapi_printf(LLAPI_MSG_NORMAL, "%s", path);