[PATCH 03/35] fs-tests: integck: handle write failures in dir_new

Artem Bityutskiy dedekind1 at gmail.com
Wed Apr 20 06:18:36 EDT 2011


From: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>

Do not die in 'dir_new()' if it cannot create a new directory and
this is not because of ENOSPC. Return NULL for all errors.

Note, not all callers are ready to properly handle all errors so far.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
---
 tests/fs-tests/integrity/integck.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index dd1ba1c..d138a7d 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -284,19 +284,12 @@ static char *cat_strings(const char *a, const char *b)
 static char *cat_paths(const char *a, const char *b)
 {
 	char *str;
-	size_t sz;
-	int as, bs;
-	size_t na, nb;
+	size_t sz, na, nb;
+	int as = 0, bs = 0;
 
-	if (a && !b)
-		return dup_string(a);
-	if (b && !a)
-		return dup_string(b);
-	if (!a && !b)
-		return NULL;
+	assert(a != NULL);
+	assert(b != NULL);
 
-	as = 0;
-	bs = 0;
 	na = strlen(a);
 	nb = strlen(b);
 	if (na && a[na - 1] == '/')
@@ -333,8 +326,7 @@ static void get_fs_space(uint64_t *total, uint64_t *free)
 
 static char *dir_path(struct dir_info *parent, const char *name)
 {
-	char *parent_path;
-	char *path;
+	char *parent_path, *path;
 
 	if (!parent)
 		return cat_paths(fsinfo.mount_point, name);
@@ -454,6 +446,12 @@ static void remove_dir_entry(struct dir_entry_info *entry)
 	free(entry);
 }
 
+/*
+ * Create a new directory "name" in the parent directory described by "parent"
+ * and add it to the in-memory list of directories. In case of success, returns
+ * a pointer to the new 'struct dir_info' object. Returns 'NULL' in case of
+ * failure.
+ */
 static struct dir_info *dir_new(struct dir_info *parent, const char *name)
 {
 	struct dir_info *dir;
@@ -461,8 +459,10 @@ static struct dir_info *dir_new(struct dir_info *parent, const char *name)
 
 	path = dir_path(parent, name);
 	if (mkdir(path, 0777) != 0) {
-		CHECK(errno == ENOSPC);
-		full = 1;
+		if (errno == ENOSPC)
+			full = 1;
+		else
+			pcv("cannot create directory %s", path);
 		free(path);
 		return NULL;
 	}
@@ -2167,7 +2167,7 @@ void remount_tested_fs(void)
 static int integck(void)
 {
 	int ret;
-	int64_t rpt;
+	long rpt;
 
 	CHECK(chdir(fsinfo.mount_point) == 0);
 
-- 
1.7.2.3




More information about the linux-mtd mailing list