From: gaoxiang25@huawei.com (Gao Xiang)
Subject: [PATCH v2] erofs-utils: get block device size correctly
Date: Thu, 8 Aug 2019 11:20:24 +0800 [thread overview]
Message-ID: <20190808032024.GA48434@138> (raw)
In-Reply-To: <e551209.248f.16c6f227220.Coremail.shenmeng999@126.com>
On Thu, Aug 08, 2019@10:50:24AM +0800, shenmeng999 wrote:
> Hi hsiangkao:
> I agree with your modification.It's getting better.Thanks!
OK, Let me update it to dev branch as well this evening :)
Thanks,
Gao Xiang
>
>
> At 2019-08-08 02:26:50, "Gao Xiang" <hsiangkao at aol.com>, said:
> >Hi shenmeng,
> >
> >On Wed, Aug 07, 2019@10:36:55PM +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>
> >
> >
> >Thanks for your patch v2 :)
> >
> >It looks good to me, and I update this patch so that
> >autoconf can check these new header files.
> >https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=experimental&id=0f225449962b4a9716985e7530a395a9500d0de6
> >Do you agree with this modification? please share your thought about this.
> >
> >Thanks,
> >Gao Xiang
> >
> >diff --git a/configure.ac b/configure.ac
> >index 6f4eacc..fcdf30a 100644
> >--- a/configure.ac
> >+++ b/configure.ac
> >@@ -73,12 +73,14 @@ AC_CHECK_HEADERS(m4_flatten([
> > fcntl.h
> > inttypes.h
> > linux/falloc.h
> >+ linux/fs.h
> > linux/types.h
> > limits.h
> > stddef.h
> > stdint.h
> > stdlib.h
> > string.h
> >+ sys/ioctl.h
> > sys/stat.h
> > sys/time.h
> > unistd.h
> >diff --git a/lib/io.c b/lib/io.c
> >index 93328d3..15c5a35 100644
> >--- a/lib/io.c
> >+++ b/lib/io.c
> >@@ -9,7 +9,11 @@
> > #define _LARGEFILE64_SOURCE
> > #define _GNU_SOURCE
> > #include <sys/stat.h>
> >+#include <sys/ioctl.h>
> > #include "erofs/io.h"
> >+#ifdef HAVE_LINUX_FS_H
> >+#include <linux/fs.h>
> >+#endif
> > #ifdef HAVE_LINUX_FALLOC_H
> > #include <linux/falloc.h>
> > #endif
> >@@ -21,6 +25,26 @@ static const char *erofs_devname;
> > static int erofs_devfd = -1;
> > static u64 erofs_devsz;
> >
> >+int dev_get_blkdev_size(int fd, u64 *bytes)
> >+{
> >+ errno = ENOTSUP;
> >+#ifdef BLKGETSIZE64
> >+ if (ioctl(fd, BLKGETSIZE64, bytes) >= 0)
> >+ return 0;
> >+#endif
> >+
> >+#ifdef BLKGETSIZE
> >+ {
> >+ unsigned long size;
> >+ if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
> >+ *bytes = ((u64)size << 9);
> >+ return 0;
> >+ }
> >+ }
> >+#endif
> >+ return -errno;
> >+}
> >+
> > void dev_close(void)
> > {
> > close(erofs_devfd);
> >@@ -49,7 +73,12 @@ int dev_open(const char *dev)
> >
> > switch (st.st_mode & S_IFMT) {
> > case S_IFBLK:
> >- erofs_devsz = st.st_size;
> >+ ret = dev_get_blkdev_size(fd, &erofs_devsz);
> >+ if (ret) {
> >+ erofs_err("failed to get block device size(%s).", dev);
> >+ close(fd);
> >+ return ret;
> >+ }
> > break;
> > case S_IFREG:
> > ret = ftruncate(fd, 0);
> >--
> >2.17.1
prev parent reply other threads:[~2019-08-08 3:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-07 14:36 [PATCH v2] erofs-utils: get block device size correctly shenmeng999
2019-08-07 18:26 ` Gao Xiang
2019-08-08 2:50 ` shenmeng999
2019-08-08 3:20 ` Gao Xiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190808032024.GA48434@138 \
--to=gaoxiang25@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.