Skip to contentSkip to conversation

erofs-utils: add missing errors and normalize errors to lower-case

PATCH In review Igor Ostapenko 2 participants 10 messages Jan 28, 2022 – Jan 30, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: add missing errors and normalize errors to lower-case

From: Igor Eisberg <[email protected]>

* Added useful error messages.
* Most errors start with lower-case, let's make all of them lower-case for better consistency.

---
 dump/main.c |  4 +++-
 fsck/main.c | 35 +++++++++++++++++++++++------------
 mkfs/main.c | 32 +++++++++++++++++---------------
 3 files changed, 43 insertions(+), 28 deletions(-)
dump/main.c +3 -1
index 0616113..664780b 100644
@@ -162,8 +162,10 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 		}
 	}
 
-	if (optind >= argc)
+	if (optind >= argc) {
+		erofs_err("missing argument: IMAGE");
 		return -EINVAL;
+	}
 
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
fsck/main.c +23 -12
index 6f17d0e..5667f2a 100644
@@ -202,8 +202,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 		}
 	}
 
-	if (optind >= argc)
+	if (optind >= argc) {
+		erofs_err("missing argument: IMAGE");
 		return -EINVAL;
+	}
 
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
@@ -230,8 +232,12 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path)
 
 	if (utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW) < 0)
 #else
-	if (utime(path, &((struct utimbuf){.actime = inode->i_ctime,
-					   .modtime = inode->i_ctime})) < 0)
+	const struct utimbuf time = {
+		.actime = inode->i_ctime,
+		.modtime = inode->i_ctime,
+	};
+
+	if (utime(path, &time) < 0)
 #endif
 		erofs_warn("failed to set times: %s", path);
 
@@ -512,7 +518,7 @@ static inline int erofs_extract_dir(struct erofs_inode *inode)
 		struct stat st;
 
 		if (errno != EEXIST) {
-			erofs_err("failed to create directory %s: %s",
+			erofs_err("failed to create directory: %s (%s)",
 				  fsckcfg.extract_path, strerror(errno));
 			return -errno;
 		}
@@ -528,8 +534,11 @@ static inline int erofs_extract_dir(struct erofs_inode *inode)
 		 * Try to change permissions of existing directory so
 		 * that we can write to it
 		 */
-		if (chmod(fsckcfg.extract_path, 0700) < 0)
+		if (chmod(fsckcfg.extract_path, 0700) < 0) {
+			erofs_err("failed to set permissions: %s (%s)",
+				  fsckcfg.extract_path, strerror(errno));
 			return -errno;
+		}
 	}
 	return 0;
 }
@@ -551,18 +560,20 @@ again:
 				erofs_warn("try to forcely remove directory %s",
 					   fsckcfg.extract_path);
 				if (rmdir(fsckcfg.extract_path) < 0) {
-					erofs_err("failed to remove: %s",
-						  fsckcfg.extract_path);
+					erofs_err("failed to remove: %s (%s)",
+						  fsckcfg.extract_path, strerror(errno));
 					return -EISDIR;
 				}
 			} else if (errno == EACCES &&
 				   chmod(fsckcfg.extract_path, 0700) < 0) {
+				erofs_err("failed to set permissions: %s (%s)",
+					  fsckcfg.extract_path, strerror(errno));
 				return -errno;
 			}
 			tryagain = false;
 			goto again;
 		}
-		erofs_err("failed to open %s: %s", fsckcfg.extract_path,
+		erofs_err("failed to open: %s (%s)", fsckcfg.extract_path,
 			  strerror(errno));
 		return -errno;
 	}
@@ -768,15 +779,15 @@ int main(int argc, char **argv)
 	err = erofsfsck_check_inode(sbi.root_nid, sbi.root_nid);
 	if (fsckcfg.corrupted) {
 		if (!fsckcfg.extract_path)
-			erofs_err("Found some filesystem corruption");
+			erofs_err("found some filesystem corruption");
 		else
-			erofs_err("Failed to extract filesystem");
+			erofs_err("failed to extract filesystem");
 		err = -EFSCORRUPTED;
 	} else if (!err) {
 		if (!fsckcfg.extract_path)
-			erofs_info("No error found");
+			erofs_info("no errors found");
 		else
-			erofs_info("Extract data successfully");
+			erofs_info("extracted filesystem successfully");
 
 		if (fsckcfg.print_comp_ratio) {
 			double comp_ratio =
mkfs/main.c +17 -15
index c755da1..dd698ff 100644
@@ -381,9 +381,6 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		}
 	}
 
-	if (optind >= argc)
-		return -EINVAL;
-
 	if (cfg.c_blobdev_path && cfg.c_chunkbits < LOG_BLOCK_SIZE) {
 		erofs_err("--blobdev must be used together with --chunksize");
 		return -EINVAL;
@@ -396,24 +393,29 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		return -EINVAL;
 	}
 
+	if (optind >= argc) {
+		erofs_err("missing argument: FILE");
+		return -EINVAL;
+	}
+
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
 		return -ENOMEM;
 
 	if (optind >= argc) {
-		erofs_err("Source directory is missing");
+		erofs_err("missing argument: DIRECTORY");
 		return -EINVAL;
 	}
 
 	cfg.c_src_path = realpath(argv[optind++], NULL);
 	if (!cfg.c_src_path) {
-		erofs_err("Failed to parse source directory: %s",
+		erofs_err("failed to parse source directory: %s",
 			  erofs_strerror(-errno));
 		return -ENOENT;
 	}
 
 	if (optind < argc) {
-		erofs_err("Unexpected argument: %s\n", argv[optind]);
+		erofs_err("unexpected argument: %s\n", argv[optind]);
 		return -EINVAL;
 	}
 	if (quiet)
@@ -456,7 +458,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 
 	buf = calloc(sb_blksize, 1);
 	if (!buf) {
-		erofs_err("Failed to allocate memory for sb: %s",
+		erofs_err("failed to allocate memory for sb: %s",
 			  erofs_strerror(-errno));
 		return -ENOMEM;
 	}
@@ -538,7 +540,7 @@ int parse_source_date_epoch(void)
 
 	epoch = strtoull(source_date_epoch, &endptr, 10);
 	if (epoch == -1ULL || *endptr != '\0') {
-		erofs_err("Environment variable $SOURCE_DATE_EPOCH %s is invalid",
+		erofs_err("environment variable $SOURCE_DATE_EPOCH %s is invalid",
 			  source_date_epoch);
 		return -EINVAL;
 	}
@@ -641,34 +643,34 @@ int main(int argc, char **argv)
 	sb_bh = erofs_buffer_init();
 	if (IS_ERR(sb_bh)) {
 		err = PTR_ERR(sb_bh);
-		erofs_err("Failed to initialize buffers: %s",
+		erofs_err("failed to initialize buffers: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 	err = erofs_bh_balloon(sb_bh, EROFS_SUPER_END);
 	if (err < 0) {
-		erofs_err("Failed to balloon erofs_super_block: %s",
+		erofs_err("failed to balloon erofs_super_block: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 
 	err = erofs_load_compress_hints();
 	if (err) {
-		erofs_err("Failed to load compress hints %s",
+		erofs_err("failed to load compress hints %s",
 			  cfg.c_compress_hints_file);
 		goto exit;
 	}
 
 	err = z_erofs_compress_init(sb_bh);
 	if (err) {
-		erofs_err("Failed to initialize compressor: %s",
+		erofs_err("failed to initialize compressor: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 
 	err = erofs_generate_devtable();
 	if (err) {
-		erofs_err("Failed to generate device table: %s",
+		erofs_err("failed to generate device table: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
@@ -681,7 +683,7 @@ int main(int argc, char **argv)
 
 	err = erofs_build_shared_xattrs_from_path(cfg.c_src_path);
 	if (err) {
-		erofs_err("Failed to build shared xattrs: %s",
+		erofs_err("failed to build shared xattrs: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
@@ -727,7 +729,7 @@ exit:
 	erofs_exit_configure();
 
 	if (err) {
-		erofs_err("\tCould not format the device : %s\n",
+		erofs_err("\tcould not format the device : %s\n",
 			  erofs_strerror(err));
 		return 1;
 	}
Signature · 1 line
2.30.2
#1 lore raw

Hi Igor,

Quoted 47 lines · Igor Ostapenko

From: Igor Eisberg <[email protected]>

* Added useful error messages.
* Most errors start with lower-case, let's make all of them lower-case for better consistency.

---
 dump/main.c |  4 +++-
 fsck/main.c | 35 +++++++++++++++++++++++------------
 mkfs/main.c | 32 +++++++++++++++++---------------
 3 files changed, 43 insertions(+), 28 deletions(-)
dump/main.c +3 -1
index 0616113..664780b 100644
@@ -162,8 +162,10 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 		}
 	}
 
-	if (optind >= argc)
+	if (optind >= argc) {
+		erofs_err("missing argument: IMAGE");
 		return -EINVAL;
+	}
 
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
fsck/main.c +3 -1
index 6f17d0e..5667f2a 100644
@@ -202,8 +202,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 		}
 	}
 
-	if (optind >= argc)
+	if (optind >= argc) {
+		erofs_err("missing argument: IMAGE");
 		return -EINVAL;
+	}
 
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
@@ -230,8 +232,12 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path)
 

fsck/main.c static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path) · line 240

Quoted 10 lines
fsck/main.c +6 -2
 	if (utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW) < 0)
 #else
-	if (utime(path, &((struct utimbuf){.actime = inode->i_ctime,
-					   .modtime = inode->i_ctime})) < 0)
+	const struct utimbuf time = {
+		.actime = inode->i_ctime,
+		.modtime = inode->i_ctime,
+	};
+
+	if (utime(path, &time) < 0)

Can we drop this change since personally I don't want to introduce unnecessary variables if possible?

Quoted 50 lines
fsck/main.c +10 -5
 #endif
 		erofs_warn("failed to set times: %s", path);
 
@@ -512,7 +518,7 @@ static inline int erofs_extract_dir(struct erofs_inode *inode)
 		struct stat st;
 
 		if (errno != EEXIST) {
-			erofs_err("failed to create directory %s: %s",
+			erofs_err("failed to create directory: %s (%s)",
 				  fsckcfg.extract_path, strerror(errno));
 			return -errno;
 		}
@@ -528,8 +534,11 @@ static inline int erofs_extract_dir(struct erofs_inode *inode)
 		 * Try to change permissions of existing directory so
 		 * that we can write to it
 		 */
-		if (chmod(fsckcfg.extract_path, 0700) < 0)
+		if (chmod(fsckcfg.extract_path, 0700) < 0) {
+			erofs_err("failed to set permissions: %s (%s)",
+				  fsckcfg.extract_path, strerror(errno));
 			return -errno;
+		}
 	}
 	return 0;
 }
@@ -551,18 +560,20 @@ again:
 				erofs_warn("try to forcely remove directory %s",
 					   fsckcfg.extract_path);
 				if (rmdir(fsckcfg.extract_path) < 0) {
-					erofs_err("failed to remove: %s",
-						  fsckcfg.extract_path);
+					erofs_err("failed to remove: %s (%s)",
+						  fsckcfg.extract_path, strerror(errno));
 					return -EISDIR;
 				}
 			} else if (errno == EACCES &&
 				   chmod(fsckcfg.extract_path, 0700) < 0) {
+				erofs_err("failed to set permissions: %s (%s)",
+					  fsckcfg.extract_path, strerror(errno));
 				return -errno;
 			}
 			tryagain = false;
 			goto again;
 		}
-		erofs_err("failed to open %s: %s", fsckcfg.extract_path,
+		erofs_err("failed to open: %s (%s)", fsckcfg.extract_path,
 			  strerror(errno));
 		return -errno;
 	}

fsck/main.c int main(int argc, char **argv) · line 782

Quoted 5 lines
fsck/main.c +1 -1
@@ -768,15 +779,15 @@ int main(int argc, char **argv)
 	err = erofsfsck_check_inode(sbi.root_nid, sbi.root_nid);
 	if (fsckcfg.corrupted) {
 		if (!fsckcfg.extract_path)
-			erofs_err("Found some filesystem corruption");
+			erofs_err("found some filesystem corruption");

IMO, how about leaving these conclusive messages starting with upper cases?

fsck/main.c int main(int argc, char **argv) · line 784

Quoted 3 lines
fsck/main.c +1 -1
 		else
-			erofs_err("Failed to extract filesystem");
+			erofs_err("failed to extract filesystem");

ditto.

fsck/main.c int main(int argc, char **argv) · line 788

Quoted 5 lines
fsck/main.c +1 -1
 		err = -EFSCORRUPTED;
 	} else if (!err) {
 		if (!fsckcfg.extract_path)
-			erofs_info("No error found");
+			erofs_info("no errors found");

ditto.

fsck/main.c int main(int argc, char **argv) · line 790

Quoted 3 lines
fsck/main.c +1 -1
 		else
-			erofs_info("Extract data successfully");
+			erofs_info("extracted filesystem successfully");

ditto.

Thanks,
Gao Xiang

Quoted 128 lines
fsck/main.c +0 -0
 		if (fsckcfg.print_comp_ratio) {
 			double comp_ratio =
mkfs/main.c +17 -15
index c755da1..dd698ff 100644
@@ -381,9 +381,6 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		}
 	}
 
-	if (optind >= argc)
-		return -EINVAL;
-
 	if (cfg.c_blobdev_path && cfg.c_chunkbits < LOG_BLOCK_SIZE) {
 		erofs_err("--blobdev must be used together with --chunksize");
 		return -EINVAL;
@@ -396,24 +393,29 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		return -EINVAL;
 	}
 
+	if (optind >= argc) {
+		erofs_err("missing argument: FILE");
+		return -EINVAL;
+	}
+
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
 		return -ENOMEM;
 
 	if (optind >= argc) {
-		erofs_err("Source directory is missing");
+		erofs_err("missing argument: DIRECTORY");
 		return -EINVAL;
 	}
 
 	cfg.c_src_path = realpath(argv[optind++], NULL);
 	if (!cfg.c_src_path) {
-		erofs_err("Failed to parse source directory: %s",
+		erofs_err("failed to parse source directory: %s",
 			  erofs_strerror(-errno));
 		return -ENOENT;
 	}
 
 	if (optind < argc) {
-		erofs_err("Unexpected argument: %s\n", argv[optind]);
+		erofs_err("unexpected argument: %s\n", argv[optind]);
 		return -EINVAL;
 	}
 	if (quiet)
@@ -456,7 +458,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 
 	buf = calloc(sb_blksize, 1);
 	if (!buf) {
-		erofs_err("Failed to allocate memory for sb: %s",
+		erofs_err("failed to allocate memory for sb: %s",
 			  erofs_strerror(-errno));
 		return -ENOMEM;
 	}
@@ -538,7 +540,7 @@ int parse_source_date_epoch(void)
 
 	epoch = strtoull(source_date_epoch, &endptr, 10);
 	if (epoch == -1ULL || *endptr != '\0') {
-		erofs_err("Environment variable $SOURCE_DATE_EPOCH %s is invalid",
+		erofs_err("environment variable $SOURCE_DATE_EPOCH %s is invalid",
 			  source_date_epoch);
 		return -EINVAL;
 	}
@@ -641,34 +643,34 @@ int main(int argc, char **argv)
 	sb_bh = erofs_buffer_init();
 	if (IS_ERR(sb_bh)) {
 		err = PTR_ERR(sb_bh);
-		erofs_err("Failed to initialize buffers: %s",
+		erofs_err("failed to initialize buffers: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 	err = erofs_bh_balloon(sb_bh, EROFS_SUPER_END);
 	if (err < 0) {
-		erofs_err("Failed to balloon erofs_super_block: %s",
+		erofs_err("failed to balloon erofs_super_block: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 
 	err = erofs_load_compress_hints();
 	if (err) {
-		erofs_err("Failed to load compress hints %s",
+		erofs_err("failed to load compress hints %s",
 			  cfg.c_compress_hints_file);
 		goto exit;
 	}
 
 	err = z_erofs_compress_init(sb_bh);
 	if (err) {
-		erofs_err("Failed to initialize compressor: %s",
+		erofs_err("failed to initialize compressor: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 
 	err = erofs_generate_devtable();
 	if (err) {
-		erofs_err("Failed to generate device table: %s",
+		erofs_err("failed to generate device table: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
@@ -681,7 +683,7 @@ int main(int argc, char **argv)
 
 	err = erofs_build_shared_xattrs_from_path(cfg.c_src_path);
 	if (err) {
-		erofs_err("Failed to build shared xattrs: %s",
+		erofs_err("failed to build shared xattrs: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
@@ -727,7 +729,7 @@ exit:
 	erofs_exit_configure();
 
 	if (err) {
-		erofs_err("\tCould not format the device : %s\n",
+		erofs_err("\tcould not format the device : %s\n",
 			  erofs_strerror(err));
 		return 1;
 	}
Signature · 1 line
2.30.2
#2 lore raw
In reply to Igor Ostapenko

Point regarding conclusive messages taken, will revert the relevant lines. As for the time variable, all I did was to match it to the format as in the case of HAVE_UTIMENSAT, just above it.
Although the variable isn't used further, inlining it is unreadable.

You also changed this:

Quoted 10 lines

ret = z_erofs_decompress(&(struct z_erofs_decompress_req) {

.in = raw,

.out = buffer,

.decodedskip = 0,

.inputsize = map.m_plen,

Quoted 9 lines

.decodedlength = map.m_llen,

.alg = map.m_algorithmformat,

.partial_decoding = 0

});

to this:

Quoted 10 lines

struct z_erofs_decompress_req rq = {

.in = raw,

.out = buffer,

.decodedskip = 0,

.inputsize = map.m_plen,

Quoted 12 lines

.decodedlength = map.m_llen,

.alg = map.m_algorithmformat,

.partial_decoding = 0

};

Quoted 1 line

ret = z_erofs_decompress(&rq);

Although that variable could have remained avoided, like in lib/data.c, where it's still avoided:

Quoted 10 lines

ret = z_erofs_decompress(&(struct z_erofs_decompress_req) {

.in = raw,

.out = buffer + end - offset,

.decodedskip = skip,

.inputsize = map.m_plen,

Quoted 9 lines

.decodedlength = length,

.alg = map.m_algorithmformat,

.partial_decoding = partial

});

It's just that inconsistency in code style is an eyesore. ;)

Quoted 270 lines · Igor Ostapenko

From: Igor Eisberg <[email protected]>

* Added useful error messages.
* Most errors start with lower-case, let's make all of them lower-case for better consistency.

---
 dump/main.c |  4 +++-
 fsck/main.c | 35 +++++++++++++++++++++++------------
 mkfs/main.c | 32 +++++++++++++++++---------------
 3 files changed, 43 insertions(+), 28 deletions(-)
dump/main.c +3 -1
index 0616113..664780b 100644
@@ -162,8 +162,10 @@ static int erofsdump_parse_options_cfg(int argc, char
 **argv)
                }
        }
 
-       if (optind >= argc)
+       if (optind >= argc) {
+               erofs_err("missing argument: IMAGE");
                return -EINVAL;
+       }
 
        cfg.c_img_path = strdup(argv[optind++]);
        if (!cfg.c_img_path)
fsck/main.c +3 -1
index 6f17d0e..5667f2a 100644
@@ -202,8 +202,10 @@ static int erofsfsck_parse_options_cfg(int argc, char
 **argv)
                }
        }
 
-       if (optind >= argc)
+       if (optind >= argc) {
+               erofs_err("missing argument: IMAGE");
                return -EINVAL;
+       }
 
        cfg.c_img_path = strdup(argv[optind++]);
        if (!cfg.c_img_path)
fsck/main.c +6 -2
@@ -230,8 +232,12 @@ static void erofsfsck_set_attributes(struct
 erofs_inode *inode, char *path)
 
        if (utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW) < 0)
 #else
-       if (utime(path, &((struct utimbuf){.actime = inode->i_ctime,
-                                          .modtime = inode->i_ctime})) <
 0)
+       const struct utimbuf time = {
+               .actime = inode->i_ctime,
+               .modtime = inode->i_ctime,
+       };
+
+       if (utime(path, &time) < 0)
 #endif
                erofs_warn("failed to set times: %s", path);
fsck/main.c +1 -1
@@ -512,7 +518,7 @@ static inline int erofs_extract_dir(struct erofs_inode
 *inode)
                struct stat st;
 
                if (errno != EEXIST) {
-                       erofs_err("failed to create directory %s: %s",
+                       erofs_err("failed to create directory: %s (%s)",
                                  fsckcfg.extract_path, strerror(errno));
                        return -errno;
                }
fsck/main.c +4 -1
@@ -528,8 +534,11 @@ static inline int erofs_extract_dir(struct
 erofs_inode *inode)
                 * Try to change permissions of existing directory so
                 * that we can write to it
                 */
-               if (chmod(fsckcfg.extract_path, 0700) < 0)
+               if (chmod(fsckcfg.extract_path, 0700) < 0) {
+                       erofs_err("failed to set permissions: %s (%s)",
+                                 fsckcfg.extract_path, strerror(errno));
                        return -errno;
+               }
        }
        return 0;

}

fsck/main.c +4 -2
@@ -551,18 +560,20 @@ again:
                                erofs_warn("try to forcely remove
 directory %s",
                                           fsckcfg.extract_path);
                                if (rmdir(fsckcfg.extract_path) < 0) {
-                                       erofs_err("failed to remove: %s",
-                                                 fsckcfg.extract_path);
+                                       erofs_err("failed to remove: %s
 (%s)",
+                                                 fsckcfg.extract_path,
 strerror(errno));
                                        return -EISDIR;
                                }
                        } else if (errno == EACCES &&
                                   chmod(fsckcfg.extract_path, 0700) < 0) {
+                               erofs_err("failed to set permissions: %s
 (%s)",
+                                         fsckcfg.extract_path,
 strerror(errno));
                                return -errno;
                        }
                        tryagain = false;
                        goto again;
                }
fsck/main.c +5 -5
-               erofs_err("failed to open %s: %s", fsckcfg.extract_path,
+               erofs_err("failed to open: %s (%s)", fsckcfg.extract_path,
                          strerror(errno));
                return -errno;
        }
@@ -768,15 +779,15 @@ int main(int argc, char **argv)
        err = erofsfsck_check_inode(sbi.root_nid, sbi.root_nid);
        if (fsckcfg.corrupted) {
                if (!fsckcfg.extract_path)
-                       erofs_err("Found some filesystem corruption");
+                       erofs_err("found some filesystem corruption");
                else
-                       erofs_err("Failed to extract filesystem");
+                       erofs_err("failed to extract filesystem");
                err = -EFSCORRUPTED;
        } else if (!err) {
                if (!fsckcfg.extract_path)
-                       erofs_info("No error found");
+                       erofs_info("no errors found");
                else
-                       erofs_info("Extract data successfully");
+                       erofs_info("extracted filesystem successfully");
 
                if (fsckcfg.print_comp_ratio) {
                        double comp_ratio =
mkfs/main.c +8 -7
index c755da1..dd698ff 100644
@@ -381,9 +381,6 @@ static int mkfs_parse_options_cfg(int argc, char
 *argv[])
                }
        }
 
-       if (optind >= argc)
-               return -EINVAL;
-
        if (cfg.c_blobdev_path && cfg.c_chunkbits < LOG_BLOCK_SIZE) {
                erofs_err("--blobdev must be used together with
--chunksize");
                return -EINVAL;
@@ -396,24 +393,29 @@ static int mkfs_parse_options_cfg(int argc, char
 *argv[])
                return -EINVAL;
        }
 
+       if (optind >= argc) {
+               erofs_err("missing argument: FILE");
+               return -EINVAL;
+       }
+
        cfg.c_img_path = strdup(argv[optind++]);
        if (!cfg.c_img_path)
                return -ENOMEM;
 
        if (optind >= argc) {
-               erofs_err("Source directory is missing");
+               erofs_err("missing argument: DIRECTORY");
                return -EINVAL;
        }
 
        cfg.c_src_path = realpath(argv[optind++], NULL);
        if (!cfg.c_src_path) {
-               erofs_err("Failed to parse source directory: %s",
+               erofs_err("failed to parse source directory: %s",
                          erofs_strerror(-errno));
                return -ENOENT;
        }
 
        if (optind < argc) {
-               erofs_err("Unexpected argument: %s\n", argv[optind]);
+               erofs_err("unexpected argument: %s\n", argv[optind]);
                return -EINVAL;
        }

if (quiet)

mkfs/main.c +1 -1
@@ -456,7 +458,7 @@ int erofs_mkfs_update_super_block(struct
 erofs_buffer_head *bh,
 
        buf = calloc(sb_blksize, 1);
        if (!buf) {
-               erofs_err("Failed to allocate memory for sb: %s",
+               erofs_err("failed to allocate memory for sb: %s",
                          erofs_strerror(-errno));
                return -ENOMEM;
        }
mkfs/main.c +1 -1
@@ -538,7 +540,7 @@ int parse_source_date_epoch(void)
 
        epoch = strtoull(source_date_epoch, &endptr, 10);
        if (epoch == -1ULL || *endptr != '\0') {
-               erofs_err("Environment variable $SOURCE_DATE_EPOCH %s is
 invalid",
+               erofs_err("environment variable $SOURCE_DATE_EPOCH %s is
 invalid",
                          source_date_epoch);
                return -EINVAL;
        }
mkfs/main.c +7 -8
@@ -641,34 +643,34 @@ int main(int argc, char **argv)
        sb_bh = erofs_buffer_init();
        if (IS_ERR(sb_bh)) {
                err = PTR_ERR(sb_bh);
-               erofs_err("Failed to initialize buffers: %s",
+               erofs_err("failed to initialize buffers: %s",
                          erofs_strerror(err));
                goto exit;
        }
        err = erofs_bh_balloon(sb_bh, EROFS_SUPER_END);
        if (err < 0) {
-               erofs_err("Failed to balloon erofs_super_block: %s",
+               erofs_err("failed to balloon erofs_super_block: %s",
                          erofs_strerror(err));
                goto exit;
        }
 
        err = erofs_load_compress_hints();
        if (err) {
-               erofs_err("Failed to load compress hints %s",
+               erofs_err("failed to load compress hints %s",
                          cfg.c_compress_hints_file);
                goto exit;
        }
 
        err = z_erofs_compress_init(sb_bh);
        if (err) {
-               erofs_err("Failed to initialize compressor: %s",
+               erofs_err("failed to initialize compressor: %s",
                          erofs_strerror(err));
                goto exit;
        }
 
        err = erofs_generate_devtable();
        if (err) {
-               erofs_err("Failed to generate device table: %s",
+               erofs_err("failed to generate device table: %s",
                          erofs_strerror(err));
                goto exit;
        }
@@ -681,7 +683,7 @@ int main(int argc, char **argv)
 
        err = erofs_build_shared_xattrs_from_path(cfg.c_src_path);
        if (err) {
-               erofs_err("Failed to build shared xattrs: %s",
+               erofs_err("failed to build shared xattrs: %s",
                          erofs_strerror(err));
                goto exit;
        }
@@ -727,7 +729,7 @@ exit:
        erofs_exit_configure();
 
        if (err) {
-               erofs_err("\tCould not format the device : %s\n",
+               erofs_err("\tcould not format the device : %s\n",
                          erofs_strerror(err));
                return 1;
        }
--

2.30.2

#3 lore raw
Quoted 1 line · Igor Eisberg

Point regarding conclusive messages taken, will revert the relevant lines.

Thank.

Quoted 4 lines

As for the time variable, all I did was to match it to the format as in the case of HAVE_UTIMENSAT, just above it.
Although the variable isn't used further, inlining it is unreadable.

Please don't. Otherwise, complier will complain
"mixed declarations and code"

and I don't want to initialize such structures at the beginning of any block.

Thanks,
Gao Xiang

#4 lore raw
Quoted 10 lines · Gao Xiang
Quoted 1 line · Igor Eisberg

Point regarding conclusive messages taken, will revert the relevant lines.

Thank.

Quoted 4 lines

As for the time variable, all I did was to match it to the format as in the case of HAVE_UTIMENSAT, just above it.
Although the variable isn't used further, inlining it is unreadable.

Quoted 5 lines

Please don't. Otherwise, complier will complain
"mixed declarations and code"

and I don't want to initialize such structures at the beginning of any block.

Add some word. Actually, I'd like to add:
if (!fsckcfg.extract_path)

	return;

at the beginning of erofsfsck_set_attributes() instead of using "if (!ret && fsckcfg.extract_path)" in the caller.

So the HAVE_UTIMENSAT case needs to be resolved as well.

Btw, I have no idea why it could become unreadable to you, first, it would avoid "mixed declarations and code" unless defining them at the beginning of blocks, and I don't like memset(.., 0, ) and set independently since memset generally is a library function (unless compliers do some built-in tricks) rather than a language feature.

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Gao Xiang

#5 lore raw
Quoted 16 lines · On Sat, 29 Jan 2022, 08:13 Gao Xiang, <[email protected]> wrote:
Quoted 2 lines · Gao Xiang
Quoted 1 line · Igor Eisberg

Point regarding conclusive messages taken, will revert the relevant

lines.

Quoted 4 lines

Thank.

Quoted 1 line

As for the time variable, all I did was to match it to the format as

in the

Quoted 6 lines
Quoted 3 lines

case of HAVE_UTIMENSAT, just above it.
Although the variable isn't used further, inlining it is unreadable.

Please don't. Otherwise, complier will complain
"mixed declarations and code"

Why would it? Declaration of const struct timespec times is inside #ifdef...#else, while the declaration for const struct utimebuf time is inside #else...#endif.
The compiler won't complain because after the preprocessor is done, the compiler only gets one of them, never both. There is no "mixed declarations and code" thanks to the preprocessor...

Quoted 4 lines
Quoted 3 lines

and I don't want to initialize such structures at the beginning of any block.

What exactly is "such structures"? I pointed you to an example where you did just that with struct z_erofs_decompress_req rq variable, I'm just following your code style, and this one stood out as unusual for your code style. Please count how many anonymous struct initializations you have across the whole erofs-utils project. I count only this one, and another in lib/data.c. Everything else is initialized as named variables.

Quoted 1 line

Add some word.

I didn't understand that...

Actually, I'd like to add:

Quoted 6 lines

if (!fsckcfg.extract_path)

        return;

at the beginning of erofsfsck_set_attributes() instead of using "if (!ret && fsckcfg.extract_path)" in the caller.

OK, but then we will have mixed declarations and code, because then we won't be at the beginning of the block...

Quoted 5 lines

So the HAVE_UTIMENSAT case needs to be resolved as well.

Btw, I have no idea why it could become unreadable to you, first, it would avoid "mixed declarations and code" unless defining them at the beginning of blocks,

Again, there is nothing mixed here, because preprocessor.

and I don't like memset(.., 0, ) and set

Quoted 3 lines

independently since memset generally is a library function (unless compliers do some built-in tricks) rather than a language feature.

Forgive me but I don't remember seeing any mention of memset in the whole fsck.c file, so I have no idea why you're telling me this.

Quoted 8 lines

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Gao Xiang

#6 lore raw
Quoted 1 line · Igor Eisberg

On Sat, 29 Jan 2022, 08:13 Gao Xiang, <[email protected]> wrote:

..

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

and I don't want to initialize such structures at the beginning of any block.

Quoted 6 lines

What exactly is "such structures"? I pointed you to an example where you did just that with struct z_erofs_decompress_req rq variable, I'm just following your code style, and this one stood out as unusual for your code style. Please count how many anonymous struct initializations you have across the whole erofs-utils project. I count only this one, and another in lib/data.c. Everything else is initialized as named variables.

Sorry, I didn't express clear. I mean here:

		if (compressed) {
			struct z_erofs_decompress_req rq = {
				.in = raw,
				.out = buffer,
				.decodedskip = 0,
				.inputsize = map.m_plen,
				.decodedlength = map.m_llen,
				.alg = map.m_algorithmformat,
				.partial_decoding = 0
			};

			ret = z_erofs_decompress(&rq);
			if (ret < 0) {
				erofs_err("failed to decompress data of m_pa %" PRIu64 ", m_plen %" PRIu64 " @ nid %llu: %s",
					  mdev.m_pa, map.m_plen,
					  inode->nid | 0ULL, strerror(-ret));
				goto out;
			}
		}

rq is at the beginning of the block, and we use the initialized structure immediately, so I wrote as this.

Quoted 11 lines
Quoted 3 lines

Add some word.

I didn't understand that...

Actually, I'd like to add:

Quoted 3 lines

if (!fsckcfg.extract_path)

        return;
Quoted 6 lines
Quoted 3 lines

at the beginning of erofsfsck_set_attributes() instead of using "if (!ret && fsckcfg.extract_path)" in the caller.

OK, but then we will have mixed declarations and code, because then we won't be at the beginning of the block...

Ok, sorry about confusion, I've made a commit instead.. Take a look at:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=experimental&id=69476e3ffa4985e767d33cb24d020f3669bc2c77

Since I'd like to avoid too many "if (!ret && fsckcfg.extract_path)" in the callers if erofsfsck_set_attributes() uses in other place in the future.

Thanks,
Gao Xiang

#7 lore raw

PATCH 1/1 erofs-utils: add missing errors and normalize errors to lower-case

From: Igor Eisberg <[email protected]>

* Added useful error messages.
* Most errors start with lower-case, let's make all non-summarizing error messages lower-case for better consistency.
* Sorted default values in fsck's main function to match the struct.

---
 dump/main.c |  4 +++-
 fsck/main.c | 44 ++++++++++++++++++++++++++------------------
 mkfs/main.c | 30 ++++++++++++++++--------------
 3 files changed, 45 insertions(+), 33 deletions(-)
dump/main.c +3 -1
index 0616113..664780b 100644
@@ -162,8 +162,10 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 		}
 	}
 
-	if (optind >= argc)
+	if (optind >= argc) {
+		erofs_err("missing argument: IMAGE");
 		return -EINVAL;
+	}
 
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
fsck/main.c +26 -18

109 lines not on this page · raw message

mkfs/main.c +16 -14
index c755da1..5f241a1 100644
@@ -381,9 +381,6 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		}
 	}
 
-	if (optind >= argc)
-		return -EINVAL;
-
 	if (cfg.c_blobdev_path && cfg.c_chunkbits < LOG_BLOCK_SIZE) {
 		erofs_err("--blobdev must be used together with --chunksize");
 		return -EINVAL;
@@ -396,24 +393,29 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		return -EINVAL;
 	}
 
+	if (optind >= argc) {
+		erofs_err("missing argument: FILE");
+		return -EINVAL;
+	}
+
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
 		return -ENOMEM;
 
 	if (optind >= argc) {
-		erofs_err("Source directory is missing");
+		erofs_err("missing argument: DIRECTORY");
 		return -EINVAL;
 	}
 
 	cfg.c_src_path = realpath(argv[optind++], NULL);
 	if (!cfg.c_src_path) {
-		erofs_err("Failed to parse source directory: %s",
+		erofs_err("failed to parse source directory: %s",
 			  erofs_strerror(-errno));
 		return -ENOENT;
 	}
 
 	if (optind < argc) {
-		erofs_err("Unexpected argument: %s\n", argv[optind]);
+		erofs_err("unexpected argument: %s\n", argv[optind]);
 		return -EINVAL;
 	}
 	if (quiet)
@@ -456,7 +458,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 
 	buf = calloc(sb_blksize, 1);
 	if (!buf) {
-		erofs_err("Failed to allocate memory for sb: %s",
+		erofs_err("failed to allocate memory for sb: %s",
 			  erofs_strerror(-errno));
 		return -ENOMEM;
 	}
@@ -538,7 +540,7 @@ int parse_source_date_epoch(void)
 
 	epoch = strtoull(source_date_epoch, &endptr, 10);
 	if (epoch == -1ULL || *endptr != '\0') {
-		erofs_err("Environment variable $SOURCE_DATE_EPOCH %s is invalid",
+		erofs_err("environment variable $SOURCE_DATE_EPOCH %s is invalid",
 			  source_date_epoch);
 		return -EINVAL;
 	}
@@ -641,34 +643,34 @@ int main(int argc, char **argv)
 	sb_bh = erofs_buffer_init();
 	if (IS_ERR(sb_bh)) {
 		err = PTR_ERR(sb_bh);
-		erofs_err("Failed to initialize buffers: %s",
+		erofs_err("failed to initialize buffers: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 	err = erofs_bh_balloon(sb_bh, EROFS_SUPER_END);
 	if (err < 0) {
-		erofs_err("Failed to balloon erofs_super_block: %s",
+		erofs_err("failed to balloon erofs_super_block: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 
 	err = erofs_load_compress_hints();
 	if (err) {
-		erofs_err("Failed to load compress hints %s",
+		erofs_err("failed to load compress hints %s",
 			  cfg.c_compress_hints_file);
 		goto exit;
 	}
 
 	err = z_erofs_compress_init(sb_bh);
 	if (err) {
-		erofs_err("Failed to initialize compressor: %s",
+		erofs_err("failed to initialize compressor: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
 
 	err = erofs_generate_devtable();
 	if (err) {
-		erofs_err("Failed to generate device table: %s",
+		erofs_err("failed to generate device table: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
@@ -681,7 +683,7 @@ int main(int argc, char **argv)
 
 	err = erofs_build_shared_xattrs_from_path(cfg.c_src_path);
 	if (err) {
-		erofs_err("Failed to build shared xattrs: %s",
+		erofs_err("failed to build shared xattrs: %s",
 			  erofs_strerror(err));
 		goto exit;
 	}
Signature · 1 line
2.30.2
#8 lore raw

PATCH 1/1 erofs-utils: add missing errors and normalize errors to lower-case

In reply to Gao Xiang

From: Igor Eisberg <[email protected]>

Had second thoughts about this change I made, because it's making an assumption about the default value of extract_pos (being 0).

---
 fsck/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fsck/main.c +4 -3
index 3be5d66..e669b44 100644
@@ -136,9 +136,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 					return -ENOMEM;
 				strncpy(fsckcfg.extract_path, optarg, len);
 				fsckcfg.extract_path[len] = '\0';
-				/* update position only if path is not root */
-				if (len > 1 || fsckcfg.extract_path[0] != '/')
-					fsckcfg.extract_pos = len;
+				/* if path is root, start writing from position 0 */
+				if (len == 1 && fsckcfg.extract_path[0] == '/')
+					len = 0;
+				fsckcfg.extract_pos = len;
 			}
 			break;
 		case 3:
Signature · 1 line
2.30.2
#9 lore raw
Quoted 6 lines · Igor Ostapenko

From: Igor Eisberg <[email protected]>

Had second thoughts about this change I made, because it's making an assumption about the default value of extract_pos (being 0).

Thanks for these. I've folded this patch into the previous one and apply to experimental branch. You can always resend the whole patch based on -dev or -experimental branch before it's applied to -dev branch (which I will not rebase).

Also, a minor suggestion, it'd be better to do one thing (or some related stuffs) in one patch. So here, even extract_pos modification is needed, IMO, it would be better with a new patch.

Thanks,
Gao Xiang

Quoted 24 lines
---
 fsck/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fsck/main.c +4 -3
index 3be5d66..e669b44 100644
@@ -136,9 +136,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 					return -ENOMEM;
 				strncpy(fsckcfg.extract_path, optarg, len);
 				fsckcfg.extract_path[len] = '\0';
-				/* update position only if path is not root */
-				if (len > 1 || fsckcfg.extract_path[0] != '/')
-					fsckcfg.extract_pos = len;
+				/* if path is root, start writing from position 0 */
+				if (len == 1 && fsckcfg.extract_path[0] == '/')
+					len = 0;
+				fsckcfg.extract_pos = len;
 			}
 			break;
 		case 3:
Signature · 1 line
2.30.2