[OpenWrt-Devel] fstools: add reusable function for getting fs type txt
diff mbox

Message ID 1454245266-11684-1-git-send-email-banglang.huang@foxmail.com
State Changes Requested
Headers show

Commit Message

=?ISO-8859-1?B?VHltb24=?= Jan. 31, 2016, 1:01 p.m. UTC
Add 'volume_identity_txt()' function so that we can use it to print the coressponding fs 
type as 'char *' type when we need.

Signed-off-by: tymon <banglang.huang@foxmail.com>
---
 libfstools/overlay.c |   10 ++--------
 libfstools/volume.c  |   14 ++++++++++++++
 libfstools/volume.h  |    2 ++
 3 files changed, 18 insertions(+), 8 deletions(-)

Comments

John Crispin Feb. 12, 2016, 8:40 a.m. UTC | #1
Hi Tymon,

few comments inline

On 31/01/2016 14:01, tymon wrote:
> 
> Add 'volume_identity_txt()' function so that we can use it to print the coressponding fs 
> type as 'char *' type when we need.
> 
> Signed-off-by: tymon <banglang.huang@foxmail.com>
> ---
>  libfstools/overlay.c |   10 ++--------
>  libfstools/volume.c  |   14 ++++++++++++++
>  libfstools/volume.h  |    2 ++
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/libfstools/overlay.c b/libfstools/overlay.c
> index cdac23e..21101b0 100644
> --- a/libfstools/overlay.c
> +++ b/libfstools/overlay.c
> @@ -264,13 +264,7 @@ static int overlay_mount_fs(struct volume *v)
>  		return -1;
>  	}
>  
> -	fstype = "jffs2";
> -
> -	switch (volume_identify(v)) {
> -	case FS_UBIFS:
> -		fstype = "ubifs";
> -		break;
> -	}
> +	fstype = volume_identity_txt(v);
>  


identify with and "f" not a "t" please


>  	volume_init(v);
>  
> @@ -359,7 +353,7 @@ int mount_overlay(struct volume *v)
>  		break;
>  	}
>  
> -	ULOG_INFO("switching to jffs2 overlay\n");
> +	ULOG_INFO("switching to %s overlay\n", volume_identity_txt(v));
>  	if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
>  		ULOG_ERR("switching to jffs2 failed - fallback to ramoverlay\n");
>  		return ramoverlay();
> diff --git a/libfstools/volume.c b/libfstools/volume.c
> index e81491e..007d525 100644
> --- a/libfstools/volume.c
> +++ b/libfstools/volume.c
> @@ -50,3 +50,17 @@ struct volume* volume_find(char *name)
>  
>  	return NULL;
>  }
> +
> +char *volume_identity_txt(struct volume *v)
> +{
> +	if (v && v->drv->identify) {

drop the if clause

> +		switch (v->drv->identify(v)) {

call volume_identify() and handle the -1 return case with a "unknown" string

	John




> +		case FS_UBIFS:
> +			return "ubifs";
> +		case FS_JFFS2:
> +			return "jffs2";
> +		}
> +	}
> +
> +	return "UNKNOWN";
> +}
> diff --git a/libfstools/volume.h b/libfstools/volume.h
> index 9c679f7..654f570 100644
> --- a/libfstools/volume.h
> +++ b/libfstools/volume.h
> @@ -77,6 +77,8 @@ static inline int volume_identify(struct volume *v)
>  	return -1;
>  }
>  
> +extern char *volume_identity_txt(struct volume *v);
> +
>  static inline int volume_erase(struct volume *v, int offset, int len)
>  {
>  	if (v && v->drv->erase)
>

Patch
diff mbox

diff --git a/libfstools/overlay.c b/libfstools/overlay.c
index cdac23e..21101b0 100644
--- a/libfstools/overlay.c
+++ b/libfstools/overlay.c
@@ -264,13 +264,7 @@  static int overlay_mount_fs(struct volume *v)
 		return -1;
 	}
 
-	fstype = "jffs2";
-
-	switch (volume_identify(v)) {
-	case FS_UBIFS:
-		fstype = "ubifs";
-		break;
-	}
+	fstype = volume_identity_txt(v);
 
 	volume_init(v);
 
@@ -359,7 +353,7 @@  int mount_overlay(struct volume *v)
 		break;
 	}
 
-	ULOG_INFO("switching to jffs2 overlay\n");
+	ULOG_INFO("switching to %s overlay\n", volume_identity_txt(v));
 	if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
 		ULOG_ERR("switching to jffs2 failed - fallback to ramoverlay\n");
 		return ramoverlay();
diff --git a/libfstools/volume.c b/libfstools/volume.c
index e81491e..007d525 100644
--- a/libfstools/volume.c
+++ b/libfstools/volume.c
@@ -50,3 +50,17 @@  struct volume* volume_find(char *name)
 
 	return NULL;
 }
+
+char *volume_identity_txt(struct volume *v)
+{
+	if (v && v->drv->identify) {
+		switch (v->drv->identify(v)) {
+		case FS_UBIFS:
+			return "ubifs";
+		case FS_JFFS2:
+			return "jffs2";
+		}
+	}
+
+	return "UNKNOWN";
+}
diff --git a/libfstools/volume.h b/libfstools/volume.h
index 9c679f7..654f570 100644
--- a/libfstools/volume.h
+++ b/libfstools/volume.h
@@ -77,6 +77,8 @@  static inline int volume_identify(struct volume *v)
 	return -1;
 }
 
+extern char *volume_identity_txt(struct volume *v);
+
 static inline int volume_erase(struct volume *v, int offset, int len)
 {
 	if (v && v->drv->erase)