Skip to contentSkip to conversation

f2fs-tools: show versions if exist

PATCH In review Jaegeuk Kim 2 participants 4 messages Nov 16, 2018 – Nov 17, 2018 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 f2fs-tools: show versions if exist

If it's not defined, we need to skip to show the definition.

---
 include/f2fs_fs.h | 4 ++++
 1 file changed, 4 insertions(+)
include/f2fs_fs.h +4 -0
index cdf54e5..65cc8fd 100644
@@ -1326,7 +1326,11 @@ static inline int is_qf_ino(struct f2fs_super_block *sb, nid_t ino)
 
 static inline void show_version(const char *prog)
 {
+#if defined(F2FS_TOOLS_VERSION) && defined(F2FS_TOOLS_DATE)
 	MSG(0, "%s %s (%s)\n", prog, F2FS_TOOLS_VERSION, F2FS_TOOLS_DATE);
+#else
+	MSG(0, "%s -- version not supported\n", prog);
+#endif
 }
 
 struct feature {
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw

PATCH 2/2 f2fs-tools: create sparse file first before stat

We must create a sparse file first before calling stat().

Fixes eb9d8037ed3b ("f2fs-tools: avoid mounting f2fs if tools already open the device")
---
 lib/libf2fs.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
lib/libf2fs.c +15 -8
index bf2830d..a1a5c02 100644
@@ -793,17 +793,24 @@ int get_device_info(int i)
 #endif
 	struct device_info *dev = c.devices + i;
 
+	if (c.sparse_mode) {
+		fd = open(dev->path, O_RDWR | O_CREAT | O_BINARY, 0644);
+		if (fd < 0) {
+			MSG(0, "\tError: Failed to open a sparse file!\n");
+			return -1;
+		}
+	}
+
 	stat_buf = malloc(sizeof(struct stat));
 	ASSERT(stat_buf);
-	if (stat(dev->path, stat_buf) < 0 ) {
-		MSG(0, "\tError: Failed to get the device stat!\n");
-		free(stat_buf);
-		return -1;
-	}
 
-	if (c.sparse_mode) {
-		fd = open(dev->path, O_RDWR | O_CREAT | O_BINARY, 0644);
-	} else {
+	if (!c.sparse_mode) {
+		if (stat(dev->path, stat_buf) < 0 ) {
+			MSG(0, "\tError: Failed to get the device stat!\n");
+			free(stat_buf);
+			return -1;
+		}
+
 		if (S_ISBLK(stat_buf->st_mode))
 			fd = open(dev->path, O_RDWR | O_EXCL);
 		else
Signature · 1 line
2.19.0.605.g01d371f741-goog
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] f2fs-tools: create sparse file first before stat

Quoted 4 lines · Jaegeuk Kim

We must create a sparse file first before calling stat().

Fixes eb9d8037ed3b ("f2fs-tools: avoid mounting f2fs if tools already open the device")

Thanks,