diff mbox

[V3] filefrag: filefrag: fix issues with 29758d2

Message ID 5388C989.8050100@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen May 30, 2014, 6:10 p.m. UTC
29758d2 filefrag: exit with error code if an error is hit

introduced a couple errors; in one case it missed returning
a value, and possibly picked up errno from (unchecked) close(),
and in the other used a test where it needed an
assignment.  So capture the error, move perror() directly
after the failed call in both cases, and fix the assignment.

Also fix a precedence problem with:

	if (fe_flags & mask == 0)

which is equivalent to:

	if (fe_flags & (mask == 0))

but we need:

	if ((fe_flags & mask) == 0)

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


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Andreas Dilger May 30, 2014, 9:03 p.m. UTC | #1
On May 30, 2014, at 12:10 PM, Eric Sandeen <sandeen@redhat.com> wrote:

> 29758d2 filefrag: exit with error code if an error is hit
> 
> introduced a couple errors; in one case it missed returning
> a value, and possibly picked up errno from (unchecked) close(),
> and in the other used a test where it needed an
> assignment.  So capture the error, move perror() directly
> after the failed call in both cases, and fix the assignment.
> 
> Also fix a precedence problem with:
> 
> 	if (fe_flags & mask == 0)
> 
> which is equivalent to:
> 
> 	if (fe_flags & (mask == 0))
> 
> but we need:
> 
> 	if ((fe_flags & mask) == 0)
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks good:

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> 
> diff --git a/misc/filefrag.c b/misc/filefrag.c
> index 37c4416..820821b 100644
> --- a/misc/filefrag.c
> +++ b/misc/filefrag.c
> @@ -175,7 +175,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
> 	for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
> 		char hex[6];
> 
> -		if (fe_flags & mask == 0)
> +		if ((fe_flags & mask) == 0)
> 			continue;
> 		sprintf(hex, "%#04x,", mask);
> 		print_flag(&fe_flags, mask, flags, hex);
> @@ -378,17 +378,18 @@ static int frag_report(const char *filename)
> #else
> 	if (fstat(fd, &st) < 0) {
> #endif
> -		close(fd);
> 		rc = -errno;
> 		perror("stat");
> +		close(fd);
> 		return rc;
> 	}
> 
> 	if (last_device != st.st_dev) {
> 		if (fstatfs(fd, &fsinfo) < 0) {
> -			close(fd);
> +			rc = -errno;
> 			perror("fstatfs");
> -			return;
> +			close(fd);
> +			return rc;
> 		}
> 		if (verbose)
> 			printf("Filesystem type is: %lx\n",
> @@ -556,7 +557,7 @@ int main(int argc, char**argv)
> 		int rc2 = frag_report(*cpp);
> 
> 		if (rc2 < 0 && rc == 0)
> -			rc == rc2;
> +			rc = rc2;
> 	}
> 
> 	return rc;
> 


Cheers, Andreas
Theodore Ts'o June 2, 2014, 1:28 a.m. UTC | #2
Thanks, applied.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 37c4416..820821b 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -175,7 +175,7 @@  static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
 	for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
 		char hex[6];
 
-		if (fe_flags & mask == 0)
+		if ((fe_flags & mask) == 0)
 			continue;
 		sprintf(hex, "%#04x,", mask);
 		print_flag(&fe_flags, mask, flags, hex);
@@ -378,17 +378,18 @@  static int frag_report(const char *filename)
 #else
 	if (fstat(fd, &st) < 0) {
 #endif
-		close(fd);
 		rc = -errno;
 		perror("stat");
+		close(fd);
 		return rc;
 	}
 
 	if (last_device != st.st_dev) {
 		if (fstatfs(fd, &fsinfo) < 0) {
-			close(fd);
+			rc = -errno;
 			perror("fstatfs");
-			return;
+			close(fd);
+			return rc;
 		}
 		if (verbose)
 			printf("Filesystem type is: %lx\n",
@@ -556,7 +557,7 @@  int main(int argc, char**argv)
 		int rc2 = frag_report(*cpp);
 
 		if (rc2 < 0 && rc == 0)
-			rc == rc2;
+			rc = rc2;
 	}
 
 	return rc;