}
run_test 56o "check lfs find -mtime for old files =========================="
+test_56p() {
+ [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
+
+ TDIR=$DIR/${tdir}g
+ rm -rf $TDIR
+
+ setup_56 $NUMFILES $NUMDIRS
+
+ chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
+ EXPECTED=$NUMFILES
+ NUMS="`$LFIND -uid $RUNAS_ID $TDIR | wc -l`"
+ [ $NUMS -eq $EXPECTED ] || \
+ error "lfs find -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
+
+ EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
+ NUMS="`$LFIND ! -uid $RUNAS_ID $TDIR | wc -l`"
+ [ $NUMS -eq $EXPECTED ] || \
+ error "lfs find ! -uid $TDIR wrong: found $NUMS, expected $EXPECTED"
+
+ echo "lfs find -uid and ! -uid passed."
+}
+run_test 56p "check lfs find -uid and ! -uid ==============================="
+
+test_56q() {
+ [ $RUNAS_ID -eq $UID ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
+
+ TDIR=$DIR/${tdir}g
+ rm -rf $TDIR
+
+ setup_56 $NUMFILES $NUMDIRS
+
+ chgrp $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
+ EXPECTED=$NUMFILES
+ NUMS="`$LFIND -gid $RUNAS_ID $TDIR | wc -l`"
+ [ $NUMS -eq $EXPECTED ] || \
+ error "lfs find -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
+
+ EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
+ NUMS="`$LFIND ! -gid $RUNAS_ID $TDIR | wc -l`"
+ [ $NUMS -eq $EXPECTED ] || \
+ error "lfs find ! -gid $TDIR wrong: found $NUMS, expected $EXPECTED"
+
+ echo "lfs find -gid and ! -gid passed."
+}
+run_test 56q "check lfs find -gid and ! -gid ==============================="
+
test_57a() {
# note test will not do anything if MDS is not local
remote_mds && skip "remote MDS" && return
"usage: find <dir/file> ... \n"
" [[!] --atime|-A [+-]N] [[!] --mtime|-M [+-]N] [[!] --ctime|-C [+-]N]\n"
" [--maxdepth|-D N] [[!] --name|-n <pattern>] [--print0|-P]\n"
- " [--print|-p] [--obd|-O <uuid>] [[!] --type|-t <filetype>]\n"
+ " [--print|-p] [--obd|-O <uuid[s]>] [[!] --size|-s [+-]N[bkMGTP]]\n"
+ " [[!] --type|-t <filetype>] [[!] --gid|-g N] [[!] --group|-G <name>]\n"
+ " [[!] --uid|-u N] [[!] --user|-U <name>]\n"
"\t !: used before an option indicates 'NOT' the requested attribute\n"
"\t -: used before an value indicates 'AT MOST' the requested value\n"
"\t +: used before an option indicates 'AT LEAST' the requested value\n"},
return res;
}
+static int name2id(unsigned int *id, char *name, int type)
+{
+ if (type == USRQUOTA) {
+ struct passwd *entry;
+
+ if (!(entry = getpwnam(name))) {
+ if (!errno)
+ errno = ENOENT;
+ return -1;
+ }
+
+ *id = entry->pw_uid;
+ } else {
+ struct group *entry;
+
+ if (!(entry = getgrnam(name))) {
+ if (!errno)
+ errno = ENOENT;
+ return -1;
+ }
+
+ *id = entry->gr_gid;
+ }
+
+ return 0;
+}
+
+static int id2name(char **name, unsigned int id, int type)
+{
+ if (type == USRQUOTA) {
+ struct passwd *entry;
+
+ if (!(entry = getpwuid(id))) {
+ if (!errno)
+ errno = ENOENT;
+ return -1;
+ }
+
+ *name = entry->pw_name;
+ } else {
+ struct group *entry;
+
+ if (!(entry = getgrgid(id))) {
+ if (!errno)
+ errno = ENOENT;
+ return -1;
+ }
+
+ *name = entry->gr_name;
+ }
+
+ return 0;
+}
+
static int lfs_find(int argc, char **argv)
{
int new_fashion = 1;
{"ctime", required_argument, 0, 'C'},
{"mtime", required_argument, 0, 'M'},
{"maxdepth", required_argument, 0, 'D'},
+ {"gid", required_argument, 0, 'g'},
+ {"group", required_argument, 0, 'G'},
+ {"uid", required_argument, 0, 'u'},
+ {"user", required_argument, 0, 'U'},
{"name", required_argument, 0, 'n'},
/* --obd is considered as a new option. */
{"obd", required_argument, 0, 'O'},
time_t *xtime;
int *xsign;
int isoption;
+ char *endptr;
time(&t);
optind = 0;
- while ((c = getopt_long_only(argc, argv, "-A:C:D:M:n:PpO:qrs:t:v",
+ while ((c = getopt_long_only(argc, argv, "-A:C:D:g:G:M:n:PpO:qrs:t:u:U:v",
long_opts, NULL)) >= 0) {
xtime = NULL;
xsign = NULL;
new_fashion = 1;
param.maxdepth = strtol(optarg, 0, 0);
break;
+ case 'g':
+ new_fashion = 1;
+ param.gid = strtol(optarg, &endptr, 10);
+ if (optarg == endptr) {
+ fprintf(stderr, "Bad gid: %s\n", optarg);
+ return CMD_HELP;
+ }
+ param.exclude_gid = !!neg_opt;
+ param.check_gid = 1;
+ break;
+ case 'G':
+ new_fashion = 1;
+ ret = name2id(¶m.gid, optarg, GRPQUOTA);
+ if (ret != 0) {
+ fprintf(stderr, "Group: %s cannot be found.\n", optarg);
+ return -1;
+ }
+ param.exclude_gid = !!neg_opt;
+ param.check_gid = 1;
+ break;
+ case 'u':
+ new_fashion = 1;
+ param.uid = strtol(optarg, &endptr, 10);
+ if (optarg == endptr) {
+ fprintf(stderr, "Bad uid: %s\n", optarg);
+ return CMD_HELP;
+ }
+ param.exclude_uid = !!neg_opt;
+ param.check_uid = 1;
+ break;
+ case 'U':
+ new_fashion = 1;
+ ret = name2id(¶m.uid, optarg, USRQUOTA);
+ if (ret != 0) {
+ fprintf(stderr, "User: %s cannot be found.\n", optarg);
+ return -1;
+ }
+ param.exclude_uid = !!neg_opt;
+ param.check_uid = 1;
+ break;
case 'n':
new_fashion = 1;
param.pattern = (char *)optarg;
return 0;
}
-static int name2id(unsigned int *id, char *name, int type)
-{
- if (type == USRQUOTA) {
- struct passwd *entry;
-
- if (!(entry = getpwnam(name))) {
- if (!errno)
- errno = ENOENT;
- return -1;
- }
-
- *id = entry->pw_uid;
- } else {
- struct group *entry;
-
- if (!(entry = getgrnam(name))) {
- if (!errno)
- errno = ENOENT;
- return -1;
- }
-
- *id = entry->gr_gid;
- }
-
- return 0;
-}
-
-static int id2name(char **name, unsigned int id, int type)
-{
- if (type == USRQUOTA) {
- struct passwd *entry;
-
- if (!(entry = getpwuid(id))) {
- if (!errno)
- errno = ENOENT;
- return -1;
- }
-
- *name = entry->pw_name;
- } else {
- struct group *entry;
-
- if (!(entry = getgrgid(id))) {
- if (!errno)
- errno = ENOENT;
- return -1;
- }
-
- *name = entry->gr_name;
- }
-
- return 0;
-}
-
#define ARG2INT(nr, str, msg) \
do { \
char *endp; \