Skip to contentSkip to conversation

dev-io.c: give a better diagnostic upon failed stat

PATCH Jim Meyering 2 participants 2 messages Sep 7, 2007

lore
Share & tools
lore
#0 lore raw

The main change here is to report strerror(errno) upon stat failure:
i.e., the s/log_error/log_sys_error/ part. Also made the "device changed" diagnostic more definite. Ok to commit?

Use log_sys_error after failed stat to report strerror(errno). Use a slightly different diagnostic to report mismatched device number.

---
 lib/device/dev-io.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
lib/device/dev-io.c +9 -4
index 9406903..54ae88e 100644
@@ -359,10 +359,15 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet)
 		return 0;
 	}
 
-	if (!(dev->flags & DEV_REGULAR) &&
-	    ((stat(name, &buf) < 0) || (buf.st_rdev != dev->dev))) {
-		log_error("%s: stat failed: Has device name changed?", name);
-		return 0;
+	if (!(dev->flags & DEV_REGULAR)) {
+		if (stat(name, &buf) < 0) {
+			log_sys_error("%s: stat failed", name);
+			return 0;
+		}
+		if (buf.st_rdev != dev->dev) {
+			log_error("%s: device changed", name);
+			return 0;
+		}
 	}
 
 #ifdef O_DIRECT_SUPPORT
#1 lore raw
Quoted 3 lines · Jim Meyering

The main change here is to report strerror(errno) upon stat failure:
i.e., the s/log_error/log_sys_error/ part. Also made the "device changed" diagnostic more definite. Ok to commit?

Yes.

Alasdair