All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libf2fs: fix to detect stat() failure
@ 2018-12-10 10:13 Chao Yu
  2019-01-08 23:46 ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2018-12-10 10:13 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
detect such error and handle it correctly.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 lib/libf2fs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index c692bf2da635..6a1040feff32 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
 	st_buf = malloc(sizeof(struct stat));
 	ASSERT(st_buf);
 
-	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+	ret = stat(path, st_buf);
+	if (ret) {
+		MSG(0, "\tError: stat %s failed!\n", path);
+		free(st_buf);
+		return -1;
+	}
+
+	if (S_ISBLK(st_buf->st_mode)) {
 		int fd = open(path, O_RDONLY | O_EXCL);
 
 		if (fd >= 0) {
-- 
2.18.0.rc1

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

* Re: [PATCH] libf2fs: fix to detect stat() failure
  2018-12-10 10:13 [PATCH] libf2fs: fix to detect stat() failure Chao Yu
@ 2019-01-08 23:46 ` Jaegeuk Kim
  2019-01-09  1:59   ` Chao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Jaegeuk Kim @ 2019-01-08 23:46 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel

On 12/10, Chao Yu wrote:
> stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
> detect such error and handle it correctly.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  lib/libf2fs.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
> index c692bf2da635..6a1040feff32 100644
> --- a/lib/libf2fs.c
> +++ b/lib/libf2fs.c
> @@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
>  	st_buf = malloc(sizeof(struct stat));
>  	ASSERT(st_buf);
>  
> -	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
> +	ret = stat(path, st_buf);

We have to allow creating non-existing image file to build userdata.img. Can we
check its errno?

> +	if (ret) {
> +		MSG(0, "\tError: stat %s failed!\n", path);
> +		free(st_buf);
> +		return -1;
> +	}
> +
> +	if (S_ISBLK(st_buf->st_mode)) {
>  		int fd = open(path, O_RDONLY | O_EXCL);
>  
>  		if (fd >= 0) {
> -- 
> 2.18.0.rc1

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

* Re: [PATCH] libf2fs: fix to detect stat() failure
  2019-01-08 23:46 ` Jaegeuk Kim
@ 2019-01-09  1:59   ` Chao Yu
  2019-01-09  4:42     ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2019-01-09  1:59 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel

On 2019/1/9 7:46, Jaegeuk Kim wrote:
> On 12/10, Chao Yu wrote:
>> stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
>> detect such error and handle it correctly.
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  lib/libf2fs.c | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
>> index c692bf2da635..6a1040feff32 100644
>> --- a/lib/libf2fs.c
>> +++ b/lib/libf2fs.c
>> @@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
>>  	st_buf = malloc(sizeof(struct stat));
>>  	ASSERT(st_buf);
>>  
>> -	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
>> +	ret = stat(path, st_buf);
> 
> We have to allow creating non-existing image file to build userdata.img. Can we
> check its errno?

You mean sload flow? so how about?

if (ret) {
	if (errno == ENOENT && c.func == SLOAD)
		return 0;
	MSG(0, "\tError: stat %s failed!\n", path);
	free(st_buf);
	return -1;
}

Thanks,

> 
>> +	if (ret) {
>> +		MSG(0, "\tError: stat %s failed!\n", path);
>> +		free(st_buf);
>> +		return -1;
>> +	}
>> +
>> +	if (S_ISBLK(st_buf->st_mode)) {
>>  		int fd = open(path, O_RDONLY | O_EXCL);
>>  
>>  		if (fd >= 0) {
>> -- 
>> 2.18.0.rc1
> 
> .
> 

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

* Re: [PATCH] libf2fs: fix to detect stat() failure
  2019-01-09  1:59   ` Chao Yu
@ 2019-01-09  4:42     ` Jaegeuk Kim
  2019-01-09  6:19       ` Chao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Jaegeuk Kim @ 2019-01-09  4:42 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel

On 01/09, Chao Yu wrote:
> On 2019/1/9 7:46, Jaegeuk Kim wrote:
> > On 12/10, Chao Yu wrote:
> >> stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
> >> detect such error and handle it correctly.
> >>
> >> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> >> ---
> >>  lib/libf2fs.c | 9 ++++++++-
> >>  1 file changed, 8 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
> >> index c692bf2da635..6a1040feff32 100644
> >> --- a/lib/libf2fs.c
> >> +++ b/lib/libf2fs.c
> >> @@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
> >>  	st_buf = malloc(sizeof(struct stat));
> >>  	ASSERT(st_buf);
> >>  
> >> -	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
> >> +	ret = stat(path, st_buf);
> > 
> > We have to allow creating non-existing image file to build userdata.img. Can we
> > check its errno?
> 
> You mean sload flow? so how about?

mkfs.f2fs on non-existing image file?

> 
> if (ret) {
> 	if (errno == ENOENT && c.func == SLOAD)
> 		return 0;
> 	MSG(0, "\tError: stat %s failed!\n", path);
> 	free(st_buf);
> 	return -1;
> }
> 
> Thanks,
> 
> > 
> >> +	if (ret) {
> >> +		MSG(0, "\tError: stat %s failed!\n", path);
> >> +		free(st_buf);
> >> +		return -1;
> >> +	}
> >> +
> >> +	if (S_ISBLK(st_buf->st_mode)) {
> >>  		int fd = open(path, O_RDONLY | O_EXCL);
> >>  
> >>  		if (fd >= 0) {
> >> -- 
> >> 2.18.0.rc1
> > 
> > .
> > 

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

* Re: [PATCH] libf2fs: fix to detect stat() failure
  2019-01-09  4:42     ` Jaegeuk Kim
@ 2019-01-09  6:19       ` Chao Yu
  2019-01-21  3:37         ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2019-01-09  6:19 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel

On 2019/1/9 12:42, Jaegeuk Kim wrote:
> On 01/09, Chao Yu wrote:
>> On 2019/1/9 7:46, Jaegeuk Kim wrote:
>>> On 12/10, Chao Yu wrote:
>>>> stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
>>>> detect such error and handle it correctly.
>>>>
>>>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>>>> ---
>>>>  lib/libf2fs.c | 9 ++++++++-
>>>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
>>>> index c692bf2da635..6a1040feff32 100644
>>>> --- a/lib/libf2fs.c
>>>> +++ b/lib/libf2fs.c
>>>> @@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
>>>>  	st_buf = malloc(sizeof(struct stat));
>>>>  	ASSERT(st_buf);
>>>>  
>>>> -	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
>>>> +	ret = stat(path, st_buf);
>>>
>>> We have to allow creating non-existing image file to build userdata.img. Can we
>>> check its errno?
>>
>> You mean sload flow? so how about?
> 
> mkfs.f2fs on non-existing image file?

That's not allowed as e2fsprogs does?

mkfs.ext4 /home/image/img
mke2fs 1.44.4 (18-Aug-2018)
The file /home/image/img does not exist and no size was specified.

> 
>>
>> if (ret) {
>> 	if (errno == ENOENT && c.func == SLOAD)
>> 		return 0;
>> 	MSG(0, "\tError: stat %s failed!\n", path);
>> 	free(st_buf);
>> 	return -1;
>> }
>>
>> Thanks,
>>
>>>
>>>> +	if (ret) {
>>>> +		MSG(0, "\tError: stat %s failed!\n", path);
>>>> +		free(st_buf);
>>>> +		return -1;
>>>> +	}
>>>> +
>>>> +	if (S_ISBLK(st_buf->st_mode)) {
>>>>  		int fd = open(path, O_RDONLY | O_EXCL);
>>>>  
>>>>  		if (fd >= 0) {
>>>> -- 
>>>> 2.18.0.rc1
>>>
>>> .
>>>
> 
> .
> 

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

* Re: [PATCH] libf2fs: fix to detect stat() failure
  2019-01-09  6:19       ` Chao Yu
@ 2019-01-21  3:37         ` Jaegeuk Kim
  2019-01-22 12:03           ` Chao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Jaegeuk Kim @ 2019-01-21  3:37 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel

On 01/09, Chao Yu wrote:
> On 2019/1/9 12:42, Jaegeuk Kim wrote:
> > On 01/09, Chao Yu wrote:
> >> On 2019/1/9 7:46, Jaegeuk Kim wrote:
> >>> On 12/10, Chao Yu wrote:
> >>>> stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
> >>>> detect such error and handle it correctly.
> >>>>
> >>>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> >>>> ---
> >>>>  lib/libf2fs.c | 9 ++++++++-
> >>>>  1 file changed, 8 insertions(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
> >>>> index c692bf2da635..6a1040feff32 100644
> >>>> --- a/lib/libf2fs.c
> >>>> +++ b/lib/libf2fs.c
> >>>> @@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
> >>>>  	st_buf = malloc(sizeof(struct stat));
> >>>>  	ASSERT(st_buf);
> >>>>  
> >>>> -	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
> >>>> +	ret = stat(path, st_buf);
> >>>
> >>> We have to allow creating non-existing image file to build userdata.img. Can we
> >>> check its errno?
> >>
> >> You mean sload flow? so how about?
> > 
> > mkfs.f2fs on non-existing image file?
> 
> That's not allowed as e2fsprogs does?

I'm not sure it's spec tho, this patch breaks android build which looks like
regression. Do we have any issue to fix with this patch?

> 
> mkfs.ext4 /home/image/img
> mke2fs 1.44.4 (18-Aug-2018)
> The file /home/image/img does not exist and no size was specified.
> 
> > 
> >>
> >> if (ret) {
> >> 	if (errno == ENOENT && c.func == SLOAD)
> >> 		return 0;
> >> 	MSG(0, "\tError: stat %s failed!\n", path);
> >> 	free(st_buf);
> >> 	return -1;
> >> }
> >>
> >> Thanks,
> >>
> >>>
> >>>> +	if (ret) {
> >>>> +		MSG(0, "\tError: stat %s failed!\n", path);
> >>>> +		free(st_buf);
> >>>> +		return -1;
> >>>> +	}
> >>>> +
> >>>> +	if (S_ISBLK(st_buf->st_mode)) {
> >>>>  		int fd = open(path, O_RDONLY | O_EXCL);
> >>>>  
> >>>>  		if (fd >= 0) {
> >>>> -- 
> >>>> 2.18.0.rc1
> >>>
> >>> .
> >>>
> > 
> > .
> > 

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

* Re: [PATCH] libf2fs: fix to detect stat() failure
  2019-01-21  3:37         ` Jaegeuk Kim
@ 2019-01-22 12:03           ` Chao Yu
  0 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2019-01-22 12:03 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel

On 2019/1/21 11:37, Jaegeuk Kim wrote:
> On 01/09, Chao Yu wrote:
>> On 2019/1/9 12:42, Jaegeuk Kim wrote:
>>> On 01/09, Chao Yu wrote:
>>>> On 2019/1/9 7:46, Jaegeuk Kim wrote:
>>>>> On 12/10, Chao Yu wrote:
>>>>>> stat() can fail due to a lot of reasons, let f2fs_dev_is_umounted()
>>>>>> detect such error and handle it correctly.
>>>>>>
>>>>>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>>>>>> ---
>>>>>>  lib/libf2fs.c | 9 ++++++++-
>>>>>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
>>>>>> index c692bf2da635..6a1040feff32 100644
>>>>>> --- a/lib/libf2fs.c
>>>>>> +++ b/lib/libf2fs.c
>>>>>> @@ -713,7 +713,14 @@ int f2fs_dev_is_umounted(char *path)
>>>>>>  	st_buf = malloc(sizeof(struct stat));
>>>>>>  	ASSERT(st_buf);
>>>>>>  
>>>>>> -	if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
>>>>>> +	ret = stat(path, st_buf);
>>>>>
>>>>> We have to allow creating non-existing image file to build userdata.img. Can we
>>>>> check its errno?
>>>>
>>>> You mean sload flow? so how about?
>>>
>>> mkfs.f2fs on non-existing image file?
>>
>> That's not allowed as e2fsprogs does?
> 
> I'm not sure it's spec tho, this patch breaks android build which looks like
> regression. Do we have any issue to fix with this patch?

No, I think you can remove this patch to make build passed.

Thanks,

> 
>>
>> mkfs.ext4 /home/image/img
>> mke2fs 1.44.4 (18-Aug-2018)
>> The file /home/image/img does not exist and no size was specified.
>>
>>>
>>>>
>>>> if (ret) {
>>>> 	if (errno == ENOENT && c.func == SLOAD)
>>>> 		return 0;
>>>> 	MSG(0, "\tError: stat %s failed!\n", path);
>>>> 	free(st_buf);
>>>> 	return -1;
>>>> }
>>>>
>>>> Thanks,
>>>>
>>>>>
>>>>>> +	if (ret) {
>>>>>> +		MSG(0, "\tError: stat %s failed!\n", path);
>>>>>> +		free(st_buf);
>>>>>> +		return -1;
>>>>>> +	}
>>>>>> +
>>>>>> +	if (S_ISBLK(st_buf->st_mode)) {
>>>>>>  		int fd = open(path, O_RDONLY | O_EXCL);
>>>>>>  
>>>>>>  		if (fd >= 0) {
>>>>>> -- 
>>>>>> 2.18.0.rc1
>>>>>
>>>>> .
>>>>>
>>>
>>> .
>>>
> 
> .
> 

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

end of thread, other threads:[~2019-01-22 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-10 10:13 [PATCH] libf2fs: fix to detect stat() failure Chao Yu
2019-01-08 23:46 ` Jaegeuk Kim
2019-01-09  1:59   ` Chao Yu
2019-01-09  4:42     ` Jaegeuk Kim
2019-01-09  6:19       ` Chao Yu
2019-01-21  3:37         ` Jaegeuk Kim
2019-01-22 12:03           ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.