[PATCH V2] xfstests: use stat not lstat when examining devices

Eric Sandeen
2010-06-04T17:34:30Z

Adding a -l option to lstat64 in order to call stat not lstat,
and stat the target of the link, should be a simple fix.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---

diff --git a/common.rc b/common.rc
index 6bf1e12..3539a43 100644
--- a/common.rc
+++ b/common.rc
@@ -584,7 +584,7 @@ _is_block_dev()
exit 1
fi

- [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
+ [ -b $1 ] && src/lstat64 -l $1 | $AWK_PROG '/Device type:/ { print $9 }'
}

# Do a command, log it to $seq.full, optionally test return status
diff --git a/src/lstat64.c b/src/lstat64.c
index 3b68c66..c7c7106 100644
--- a/src/lstat64.c
+++ b/src/lstat64.c
@@ -49,7 +49,7 @@ timesince(long timesec)
void
usage(void)
{
- fprintf(stderr, "Usage: lstat64 [-t] filename ...\n");
+ fprintf(stderr, "Usage: lstat64 [-tl] filename ...\n");
exit(1);
}

@@ -59,13 +59,18 @@ main(int argc, char **argv)
struct stat64 sbuf;
int i, c;
int terse_flag = 0;
+ int follow_flag = 0;

- while ((c = getopt(argc, argv, "t")) != EOF) {
+ while ((c = getopt(argc, argv, "tl")) != EOF) {
switch (c) {
case 't':
terse_flag = 1;
break;

+ case 'l':
+ follow_flag = 1;
+ break;
+
case '?':
usage();
}
@@ -79,7 +84,10 @@ main(int argc, char **argv)
for (i = optind; i < argc; i++) {
char mode[] = "----------";

- if( lstat64(argv[i], &sbuf) < 0) {
+ if (!follow_flag && lstat64(argv[i], &sbuf) < 0) {
+ perror(argv[i]);
+ continue;
+ } else if (follow_flag && stat64(argv[i], &sbuf) < 0) {
perror(argv[i]);
continue;