linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH V3 2/2] mkfs.f2fs: avoid dumplicate extensions
  2015-11-28 10:19 ` [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions Sheng Yong
@ 2015-11-28  3:07   ` Sheng Yong
  2015-11-28  4:00     ` Chao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Sheng Yong @ 2015-11-28  3:07 UTC (permalink / raw)
  To: chao2.yu, jaegeuk; +Cc: linux-f2fs-devel

Before copying an user specified extension to extension_list, check if it
is already in the list.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 176bdea..0a621ae 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -118,6 +118,21 @@ const char *media_ext_lists[] = {
 	NULL
 };

+static bool is_extension_exist(const char *name, const int len)
+{
+	int i, ret;
+
+	for (i = 0; i < F2FS_MAX_EXTENSION; i++) {
+		char *ext = (char *) sb.extension_list[i];
+		ret = strcmp(ext, name);
+
+		if (ret == 0)
+			return 1;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
 	const char **extlist = media_ext_lists;
@@ -143,8 +158,14 @@ static void configure_extension_list(void)
 	/* add user ext list */
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
+		strtrim(&ue);
 		name_len = strlen(ue);
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (name_len > 7) {
+			MSG(0, "\tError: Extension '%s' too long\n", ue);
+			exit(1);
+		}
+		if (!is_extension_exist(ue, name_len))
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;
-- 
1.9.1



------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space
  2015-11-28 10:19 [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space Sheng Yong
@ 2015-11-28  3:53 ` Chao Yu
  2015-11-28 10:19 ` [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions Sheng Yong
  1 sibling, 0 replies; 7+ messages in thread
From: Chao Yu @ 2015-11-28  3:53 UTC (permalink / raw)
  To: Sheng Yong, jaegeuk; +Cc: linux-f2fs-devel

On 11/28/15 6:19 PM, Sheng Yong wrote:
> Add a helper function strtrim() to trim space both at the beginning and end
> of a string.

I'm not sure we should add more logic when processing user defined extension string.

How about waiting for Jaegeuk's opinion?

Thanks,

> 
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
> ---
>  include/f2fs_fs.h |  1 +
>  lib/libf2fs.c     | 24 ++++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> index 359deec..e85b2d0 100644
> --- a/include/f2fs_fs.h
> +++ b/include/f2fs_fs.h
> @@ -768,6 +768,7 @@ enum {
>  
>  extern void ASCIIToUNICODE(u_int16_t *, u_int8_t *);
>  extern int log_base_2(u_int32_t);
> +extern void strtrim(char **str);
>  extern unsigned int addrs_per_inode(struct f2fs_inode *);
>  
>  extern int get_bits_in_byte(unsigned char n);
> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
> index 83d1296..e901289 100644
> --- a/lib/libf2fs.c
> +++ b/lib/libf2fs.c
> @@ -48,6 +48,30 @@ int log_base_2(u_int32_t num)
>  	return ret;
>  }
>  
> +void strtrim(char **str)
> +{
> +	int len = strlen(*str);
> +	char *head = *str;
> +	char *tail = *str + len - 1;
> +
> +	while (head != tail) {
> +		if (*head == ' ')
> +			head++;
> +		else {
> +			*str = head;
> +			break;
> +		}
> +	}
> +
> +	while (tail != head) {
> +		if (*tail == ' ') {
> +			*tail = '\0';
> +			tail--;
> +		} else
> +			break;
> +	}
> +}
> +
>  /*
>   * f2fs bit operations
>   */
> 

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH V3 2/2] mkfs.f2fs: avoid dumplicate extensions
  2015-11-28  3:07   ` [RFC PATCH V3 " Sheng Yong
@ 2015-11-28  4:00     ` Chao Yu
  2015-11-28  4:19       ` Sheng Yong
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2015-11-28  4:00 UTC (permalink / raw)
  To: Sheng Yong, jaegeuk; +Cc: linux-f2fs-devel

On 11/28/15 11:07 AM, Sheng Yong wrote:
> Before copying an user specified extension to extension_list, check if it
> is already in the list.
> 
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
> ---
>  mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 176bdea..0a621ae 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -118,6 +118,21 @@ const char *media_ext_lists[] = {
>  	NULL
>  };
> 
> +static bool is_extension_exist(const char *name, const int len)
> +{
> +	int i, ret;
> +
> +	for (i = 0; i < F2FS_MAX_EXTENSION; i++) {

i < last_extension_position_in_list ?

> +		char *ext = (char *) sb.extension_list[i];
> +		ret = strcmp(ext, name);

if (!strcmp(ext, name))
	return 1;

> +
> +		if (ret == 0)
> +			return 1;
> +	}
> +
> +	return 0;
> +}
> +
>  static void configure_extension_list(void)
>  {
>  	const char **extlist = media_ext_lists;
> @@ -143,8 +158,14 @@ static void configure_extension_list(void)
>  	/* add user ext list */
>  	ue = strtok(ext_str, ",");
>  	while (ue != NULL) {
> +		strtrim(&ue);
>  		name_len = strlen(ue);
> -		memcpy(sb.extension_list[i++], ue, name_len);
> +		if (name_len > 7) {

Shouldn't this be fixed in another patch?

How about:

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 176bdea..78612e4 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -144,7 +144,12 @@ static void configure_extension_list(void)
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
 		name_len = strlen(ue);
+		if (name_len >= 8) {
+			MSG(0, "\tWarn: Extension name (%s) is too long\n", ue);
+			goto next;
+		}
 		memcpy(sb.extension_list[i++], ue, name_len);
+next:
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;

Thanks,

> +			MSG(0, "\tError: Extension '%s' too long\n", ue);
> +			exit(1);
> +		}
> +		if (!is_extension_exist(ue, name_len))
> +			memcpy(sb.extension_list[i++], ue, name_len);
>  		ue = strtok(NULL, ",");
>  		if (i >= F2FS_MAX_EXTENSION)
>  			break;
> 

------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH V3 2/2] mkfs.f2fs: avoid dumplicate extensions
  2015-11-28  4:00     ` Chao Yu
@ 2015-11-28  4:19       ` Sheng Yong
  2015-11-29  6:00         ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Sheng Yong @ 2015-11-28  4:19 UTC (permalink / raw)
  To: Chao Yu, jaegeuk; +Cc: linux-f2fs-devel



On 11/28/2015 12:00 PM, Chao Yu wrote:
> On 11/28/15 11:07 AM, Sheng Yong wrote:
>> Before copying an user specified extension to extension_list, check if it
>> is already in the list.
>>
>> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
>> ---
>>  mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
>>  1 file changed, 22 insertions(+), 1 deletion(-)
>>
>> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
>> index 176bdea..0a621ae 100644
>> --- a/mkfs/f2fs_format.c
>> +++ b/mkfs/f2fs_format.c
>> @@ -118,6 +118,21 @@ const char *media_ext_lists[] = {
>>  	NULL
>>  };
>>
>> +static bool is_extension_exist(const char *name, const int len)
>> +{
>> +	int i, ret;
>> +
>> +	for (i = 0; i < F2FS_MAX_EXTENSION; i++) {
> 
> i < last_extension_position_in_list ?
Then we have to define a new global variable or add a new parameter
to pass the last position in the function.
> 
>> +		char *ext = (char *) sb.extension_list[i];
>> +		ret = strcmp(ext, name);
> 
> if (!strcmp(ext, name))
> 	return 1;
> 
>> +
>> +		if (ret == 0)
>> +			return 1;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>  static void configure_extension_list(void)
>>  {
>>  	const char **extlist = media_ext_lists;
>> @@ -143,8 +158,14 @@ static void configure_extension_list(void)
>>  	/* add user ext list */
>>  	ue = strtok(ext_str, ",");
>>  	while (ue != NULL) {
>> +		strtrim(&ue);
>>  		name_len = strlen(ue);
>> -		memcpy(sb.extension_list[i++], ue, name_len);
>> +		if (name_len > 7) {
> 
> Shouldn't this be fixed in another patch?
This is much better than what I did :)

thanks,
Sheng
> 
> How about:
> 
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 176bdea..78612e4 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -144,7 +144,12 @@ static void configure_extension_list(void)
>  	ue = strtok(ext_str, ",");
>  	while (ue != NULL) {
>  		name_len = strlen(ue);
> +		if (name_len >= 8) {
> +			MSG(0, "\tWarn: Extension name (%s) is too long\n", ue);
> +			goto next;
> +		}
>  		memcpy(sb.extension_list[i++], ue, name_len);
> +next:
>  		ue = strtok(NULL, ",");
>  		if (i >= F2FS_MAX_EXTENSION)
>  			break;
> 
> Thanks,
> 
>> +			MSG(0, "\tError: Extension '%s' too long\n", ue);
>> +			exit(1);
>> +		}
>> +		if (!is_extension_exist(ue, name_len))
>> +			memcpy(sb.extension_list[i++], ue, name_len);
>>  		ue = strtok(NULL, ",");
>>  		if (i >= F2FS_MAX_EXTENSION)
>>  			break;
>>
> 
> .
> 


------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space
@ 2015-11-28 10:19 Sheng Yong
  2015-11-28  3:53 ` Chao Yu
  2015-11-28 10:19 ` [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions Sheng Yong
  0 siblings, 2 replies; 7+ messages in thread
From: Sheng Yong @ 2015-11-28 10:19 UTC (permalink / raw)
  To: chao2.yu, jaegeuk; +Cc: linux-f2fs-devel

Add a helper function strtrim() to trim space both at the beginning and end
of a string.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 include/f2fs_fs.h |  1 +
 lib/libf2fs.c     | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 359deec..e85b2d0 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -768,6 +768,7 @@ enum {
 
 extern void ASCIIToUNICODE(u_int16_t *, u_int8_t *);
 extern int log_base_2(u_int32_t);
+extern void strtrim(char **str);
 extern unsigned int addrs_per_inode(struct f2fs_inode *);
 
 extern int get_bits_in_byte(unsigned char n);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 83d1296..e901289 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -48,6 +48,30 @@ int log_base_2(u_int32_t num)
 	return ret;
 }
 
+void strtrim(char **str)
+{
+	int len = strlen(*str);
+	char *head = *str;
+	char *tail = *str + len - 1;
+
+	while (head != tail) {
+		if (*head == ' ')
+			head++;
+		else {
+			*str = head;
+			break;
+		}
+	}
+
+	while (tail != head) {
+		if (*tail == ' ') {
+			*tail = '\0';
+			tail--;
+		} else
+			break;
+	}
+}
+
 /*
  * f2fs bit operations
  */
-- 
1.9.1


------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions
  2015-11-28 10:19 [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space Sheng Yong
  2015-11-28  3:53 ` Chao Yu
@ 2015-11-28 10:19 ` Sheng Yong
  2015-11-28  3:07   ` [RFC PATCH V3 " Sheng Yong
  1 sibling, 1 reply; 7+ messages in thread
From: Sheng Yong @ 2015-11-28 10:19 UTC (permalink / raw)
  To: chao2.yu, jaegeuk; +Cc: linux-f2fs-devel

Before copying an user specified extension to extension_list, check if it
is already in the list.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 mkfs/f2fs_format.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 176bdea..c170985 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -118,6 +118,24 @@ const char *media_ext_lists[] = {
 	NULL
 };
 
+static bool is_extension_exist(const char *name, const int len)
+{
+	int name_len, min_len;
+	int i, ret;
+
+	for (i = 0; i < F2FS_MAX_EXTENSION; i++) {
+		char *ext = (char *) sb.extension_list[i];
+		name_len = strlen(ext);
+		min_len = name_len < len ? name_len : len;
+		ret = strncmp(ext, name, min_len);
+
+		if (ret == 0 && name_len == len)
+			return 1;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
 	const char **extlist = media_ext_lists;
@@ -143,8 +161,14 @@ static void configure_extension_list(void)
 	/* add user ext list */
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
+		strtrim(&ue);
 		name_len = strlen(ue);
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (name_len > 7) {
+			MSG(0, "\tError: Extension '%s' too long\n", ue);
+			exit(1);
+		}
+		if (!is_extension_exist(ue, name_len))
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;
-- 
1.9.1


------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH V3 2/2] mkfs.f2fs: avoid dumplicate extensions
  2015-11-28  4:19       ` Sheng Yong
@ 2015-11-29  6:00         ` Jaegeuk Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2015-11-29  6:00 UTC (permalink / raw)
  To: Sheng Yong; +Cc: Chao Yu, linux-f2fs-devel

Hi Sheng,

On Sat, Nov 28, 2015 at 12:19:24PM +0800, Sheng Yong wrote:
> 
> 
> On 11/28/2015 12:00 PM, Chao Yu wrote:
> > On 11/28/15 11:07 AM, Sheng Yong wrote:
> >> Before copying an user specified extension to extension_list, check if it
> >> is already in the list.
> >>
> >> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
> >> ---
> >>  mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
> >>  1 file changed, 22 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> >> index 176bdea..0a621ae 100644
> >> --- a/mkfs/f2fs_format.c
> >> +++ b/mkfs/f2fs_format.c
> >> @@ -118,6 +118,21 @@ const char *media_ext_lists[] = {
> >>  	NULL
> >>  };
> >>
> >> +static bool is_extension_exist(const char *name, const int len)
> >> +{
> >> +	int i, ret;
> >> +
> >> +	for (i = 0; i < F2FS_MAX_EXTENSION; i++) {
> > 
> > i < last_extension_position_in_list ?
> Then we have to define a new global variable or add a new parameter
> to pass the last position in the function.

I think it's not a big deal to use F2FS_MAX_EXTENSION.

> > 
> >> +		char *ext = (char *) sb.extension_list[i];

		char *ext = (char *)sb.extension_list[i];
		                   ^^^
Coding style.

> >> +		ret = strcmp(ext, name);
> > 
> > if (!strcmp(ext, name))
> > 	return 1;

Agreed.

> > 
> >> +
> >> +		if (ret == 0)
> >> +			return 1;
> >> +	}
> >> +
> >> +	return 0;
> >> +}
> >> +
> >>  static void configure_extension_list(void)
> >>  {
> >>  	const char **extlist = media_ext_lists;
> >> @@ -143,8 +158,14 @@ static void configure_extension_list(void)
> >>  	/* add user ext list */
> >>  	ue = strtok(ext_str, ",");

How about using strtok(ext_str, ", ") to avoid strtrim() below?

> >>  	while (ue != NULL) {
> >> +		strtrim(&ue);
> >>  		name_len = strlen(ue);
> >> -		memcpy(sb.extension_list[i++], ue, name_len);
> >> +		if (name_len > 7) {
> > 
> > Shouldn't this be fixed in another patch?
> This is much better than what I did :)

+2 :)

Thanks,

> 
> thanks,
> Sheng
> > 
> > How about:
> > 
> > diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> > index 176bdea..78612e4 100644
> > --- a/mkfs/f2fs_format.c
> > +++ b/mkfs/f2fs_format.c
> > @@ -144,7 +144,12 @@ static void configure_extension_list(void)
> >  	ue = strtok(ext_str, ",");
> >  	while (ue != NULL) {
> >  		name_len = strlen(ue);
> > +		if (name_len >= 8) {
> > +			MSG(0, "\tWarn: Extension name (%s) is too long\n", ue);
> > +			goto next;
> > +		}
> >  		memcpy(sb.extension_list[i++], ue, name_len);
> > +next:
> >  		ue = strtok(NULL, ",");
> >  		if (i >= F2FS_MAX_EXTENSION)
> >  			break;
> > 
> > Thanks,
> > 
> >> +			MSG(0, "\tError: Extension '%s' too long\n", ue);
> >> +			exit(1);
> >> +		}
> >> +		if (!is_extension_exist(ue, name_len))
> >> +			memcpy(sb.extension_list[i++], ue, name_len);
> >>  		ue = strtok(NULL, ",");
> >>  		if (i >= F2FS_MAX_EXTENSION)
> >>  			break;
> >>
> > 
> > .
> > 

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-29  6:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-28 10:19 [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space Sheng Yong
2015-11-28  3:53 ` Chao Yu
2015-11-28 10:19 ` [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions Sheng Yong
2015-11-28  3:07   ` [RFC PATCH V3 " Sheng Yong
2015-11-28  4:00     ` Chao Yu
2015-11-28  4:19       ` Sheng Yong
2015-11-29  6:00         ` Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).