From 0cf5dbd40ff3a579208e47eb3260ebf54dfd996e Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Sun, 22 Feb 2009 04:20:25 -0200
Subject: [PATCH 12/31] Improve error handling in free_tid()

This patch improves free_tid()'s error handling by detecting when access()
fails with anything else but EACCES (which is expected) and leaving the
max untouched.

get_jtfile() can't fail, so it's not a problem either.

While at it, remove some unused assignments.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 trans.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/trans.c b/trans.c
index 1effe16..df340d6 100644
--- a/trans.c
+++ b/trans.c
@@ -68,12 +68,13 @@ static void free_tid(struct jfs *fs, unsigned int tid)
 	if (tid == curid) {
 		/* look up the new max. */
 		for (i = curid - 1; i > 0; i--) {
-			/* this can fail if we're low on mem, but we don't
-			 * care checking here because the problem will come
-			 * out later and we can fail more properly */
 			get_jtfile(fs, i, name);
 			if (access(name, R_OK | W_OK) == 0) {
-				curid = i;
+				break;
+			} else if (errno != EACCES) {
+				/* Real error, stop looking for a new max. It
+				 * doesn't hurt us because it's ok if the max
+				 * is higher than it could be */
 				break;
 			}
 		}
-- 
1.6.2.rc0.226.gf08f

