t_stripealign: Fix fibmap error handling
PATCH 1/1 t_stripealign: Fix fibmap error handling
FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.
We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.
Also, we can't use perror() only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.
--- src/t_stripealign.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
src/t_stripealign.c +5 -2
@@ -76,8 +76,11 @@ int main(int argc, char ** argv)unsigned int bmap =0 ; ret =ioctl (fd,FIBMAP , &bmap); -if (ret <0 ) { -perror ("fibmap" ); +if (ret <=0 ) { +if (ret <0 ) +perror ("fibmap" ); +else +fprintf (stderr,"fibmap error\n" );free (fie);close (fd);return 1 ;
Signature · 1 line
2.20.1
Quoted 21 lines · Carlos Maiolino
FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.
We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.
Also, we can't use
perror()only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.Signed-off-by Carlos Maiolino <[email protected]>--- src/t_stripealign.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)src/t_stripealign.c +0
-0
src/t_stripealign.c int main(int argc, char ** argv) · line 83
Quoted 10 lines
src/t_stripealign.c +5
-2@@ -76,8 +76,11 @@ int main(int argc, char ** argv)unsigned int bmap =0 ; ret =ioctl (fd,FIBMAP , &bmap); -if (ret <0 ) { -perror ("fibmap" ); +if (ret <=0 ) { +if (ret <0 ) +perror ("fibmap" ); +else +fprintf (stderr,"fibmap error\n" );
"fibmap returned no result"?
--D
Quoted 6 lines
src/t_stripealign.c +0
-0free (fie);close (fd);return 1 ;Signature · 1 line
2.20.1
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Carlos Maiolino
FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.
We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.
Also, we can't use
perror()only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.Signed-off-by Carlos Maiolino <[email protected]>--- src/t_stripealign.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)src/t_stripealign.c +0
-0@@ -76,8 +76,11 @@ int main(int argc, char ** argv)unsigned int bmap =0 ;
Quoted 10 lines
src/t_stripealign.c int main(int argc, char ** argv) · line 83
Quoted 8 lines
src/t_stripealign.c +5
-2ret =ioctl (fd,FIBMAP , &bmap); -if (ret <0 ) { -perror ("fibmap" ); +if (ret <=0 ) { +if (ret <0 ) +perror ("fibmap" ); +else +fprintf (stderr,"fibmap error\n" );"fibmap returned no result"?
Fixed on commit. Thanks!
Eryu
Quoted 36 lines · Eryu Guan
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Carlos Maiolino
FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.
We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.
Also, we can't use
perror()only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.Signed-off-by Carlos Maiolino <[email protected]>--- src/t_stripealign.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)src/t_stripealign.c +0
-0@@ -76,8 +76,11 @@ int main(int argc, char ** argv)unsigned int bmap =0 ;Quoted 10 lines
src/t_stripealign.c int main(int argc, char ** argv) · line 83
Quoted 8 lines
src/t_stripealign.c +5
-2ret =ioctl (fd,FIBMAP , &bmap); -if (ret <0 ) { -perror ("fibmap" ); +if (ret <=0 ) { +if (ret <0 ) +perror ("fibmap" ); +else +fprintf (stderr,"fibmap error\n" );"fibmap returned no result"?
Quoted 1 line
Fixed on commit. Thanks!
TZ discrepancy. Thanks for fixing it on commit Eryu :)
Quoted 2 lines
Eryu
Signature · 1 line
Carlos