All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: get block device size correctly
@ 2019-08-06 15:23 shenmeng999
  2019-08-06 16:29 ` Gao Xiang
  0 siblings, 1 reply; 2+ messages in thread
From: shenmeng999 @ 2019-08-06 15:23 UTC (permalink / raw)


From: shenmeng996 <shenmeng999@126.com>

fstat return block device's size of zero.
use ioctl to get block device's size.

Signed-off-by: shenmeng996 <shenmeng999 at 126.com>
---
 lib/io.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/io.c b/lib/io.c
index 93328d3..ae3ac37 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -9,6 +9,8 @@
 #define _LARGEFILE64_SOURCE
 #define _GNU_SOURCE
 #include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
 #include "erofs/io.h"
 #ifdef HAVE_LINUX_FALLOC_H
 #include <linux/falloc.h>
@@ -49,7 +51,12 @@ int dev_open(const char *dev)
 
 	switch (st.st_mode & S_IFMT) {
 	case S_IFBLK:
-		erofs_devsz = st.st_size;
+		ret = ioctl(fd, BLKGETSIZE64, &erofs_devsz);
+		if (ret) {
+			erofs_err("failed to ioctl(%s).", dev);
+			close(fd);
+			return -errno;	
+		}
 		break;
 	case S_IFREG:
 		ret = ftruncate(fd, 0);
-- 
1.8.3.1

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

* [PATCH] erofs-utils: get block device size correctly
  2019-08-06 15:23 [PATCH] erofs-utils: get block device size correctly shenmeng999
@ 2019-08-06 16:29 ` Gao Xiang
  0 siblings, 0 replies; 2+ messages in thread
From: Gao Xiang @ 2019-08-06 16:29 UTC (permalink / raw)


Hi shenmeng,

On Tue, Aug 06, 2019@11:23:25PM +0800, shenmeng999@126.com wrote:
> From: shenmeng996 <shenmeng999 at 126.com>
>
> fstat return block device's size of zero.
> use ioctl to get block device's size.
>
> Signed-off-by: shenmeng996 <shenmeng999 at 126.com>
> ---
>  lib/io.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/lib/io.c b/lib/io.c
> index 93328d3..ae3ac37 100644
> --- a/lib/io.c
> +++ b/lib/io.c
> @@ -9,6 +9,8 @@
>  #define _LARGEFILE64_SOURCE
>  #define _GNU_SOURCE
>  #include <sys/stat.h>
> +#include <sys/ioctl.h>
> +#include <linux/fs.h>
>  #include "erofs/io.h"
>  #ifdef HAVE_LINUX_FALLOC_H
>  #include <linux/falloc.h>
> @@ -49,7 +51,12 @@ int dev_open(const char *dev)
>
>  	switch (st.st_mode & S_IFMT) {
>  	case S_IFBLK:
> -		erofs_devsz = st.st_size;
> +		ret = ioctl(fd, BLKGETSIZE64, &erofs_devsz);

Thanks for your patch :)

I got some reports of this issue months ago, but I'm afraid
that we should support the legacy BLKGETSIZE approach as well
as what other filesystem userspace tools do...

Could you kindly take some time to make a full patch of it? :)

BTW, from the point of view of use, it's better to generate
a image file indirectly and `dd' to the real device rather than
directly use block device as the output since erofs-utils
will do unaligned read/write even overwrite, which isn't
very friendly to flash-based devices...

Thanks,
Gao Xiang

> +		if (ret) {
> +			erofs_err("failed to ioctl(%s).", dev);
> +			close(fd);
> +			return -errno;
> +		}
>  		break;
>  	case S_IFREG:
>  		ret = ftruncate(fd, 0);
> --
> 1.8.3.1
>

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

end of thread, other threads:[~2019-08-06 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06 15:23 [PATCH] erofs-utils: get block device size correctly shenmeng999
2019-08-06 16:29 ` Gao Xiang

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.