[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v7 12/35] util: let qemu_fd_getlength support bl
From: |
Eduardo Habkost |
Subject: |
Re: [Qemu-devel] [PATCH v7 12/35] util: let qemu_fd_getlength support block device |
Date: |
Fri, 6 Nov 2015 13:44:53 -0200 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Tue, Nov 03, 2015 at 12:21:30AM +0800, Xiao Guangrong wrote:
> On 11/03/2015 12:11 AM, Vladimir Sementsov-Ogievskiy wrote:
> >On 02.11.2015 12:13, Xiao Guangrong wrote:
> >>lseek can not work for all block devices as the man page says:
> >>| Some devices are incapable of seeking and POSIX does not specify
> >>| which devices must support lseek().
> >>
> >>This patch tries to add the support on Linux by using BLKGETSIZE64
> >>ioctl
> >>
> >>Signed-off-by: Xiao Guangrong <address@hidden>
> >>---
> >> util/osdep.c | 20 ++++++++++++++++++++
> >> 1 file changed, 20 insertions(+)
> >>
> >>diff --git a/util/osdep.c b/util/osdep.c
> >>index 5a61e19..b20c793 100644
> >>--- a/util/osdep.c
> >>+++ b/util/osdep.c
> >>@@ -45,6 +45,11 @@
> >> extern int madvise(caddr_t, size_t, int);
> >> #endif
> >>+#ifdef CONFIG_LINUX
> >>+#include <sys/ioctl.h>
> >>+#include <linux/fs.h>
> >>+#endif
> >>+
> >> #include "qemu-common.h"
> >> #include "qemu/sockets.h"
> >> #include "qemu/error-report.h"
> >>@@ -433,6 +438,21 @@ int64_t qemu_fd_getlength(int fd)
> >> {
> >> int64_t size;
> >>+#ifdef CONFIG_LINUX
> >>+ struct stat stat_buf;
> >>+ if (fstat(fd, &stat_buf) < 0) {
> >>+ return -errno;
> >>+ }
> >>+
> >>+ if ((S_ISBLK(stat_buf.st_mode)) && !ioctl(fd, BLKGETSIZE64, &size)) {
> >>+ /* The size of block device is larger than max int64_t? */
> >>+ if (size < 0) {
> >>+ return -EOVERFLOW;
> >>+ }
> >>+ return size;
> >>+ }
> >>+#endif
> >>+
> >> size = lseek(fd, 0, SEEK_END);
> >> if (size < 0) {
> >> return -errno;
> >
> >Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
> >
> >just a question: is there any use for stat.st_size ? Is it always worse then
> >lseek?
>
> The man page says:
> The st_size field gives the size of the file (if it is a regular file or a
> symbolic link)
> in bytes. The size of a symbolic link is the length of the pathname it
> contains, without a
> terminating null byte.
>
> So it can not work on symbolic link.
stat() and fstat() will get you information for the file pointed by the
symlink. You will get the symlink information only if you use lstat().
--
Eduardo
- Re: [Qemu-devel] [PATCH v7 11/35] util: introduce qemu_file_getlength(), (continued)
[Qemu-devel] [PATCH v7 13/35] hostmem-file: use whole file size if possible, Xiao Guangrong, 2015/11/02
[Qemu-devel] [PATCH v7 14/35] pc-dimm: remove DEFAULT_PC_DIMMSIZE, Xiao Guangrong, 2015/11/02
[Qemu-devel] [PATCH v7 12/35] util: let qemu_fd_getlength support block device, Xiao Guangrong, 2015/11/02
Re: [Qemu-devel] [PATCH v7 12/35] util: let qemu_fd_getlength support block device, Eduardo Habkost, 2015/11/06
Re: [Qemu-devel] [PATCH v7 12/35] util: let qemu_fd_getlength support block device, Eduardo Habkost, 2015/11/06
[Qemu-devel] [PATCH v7 15/35] pc-dimm: make pc_existing_dimms_capacity static and rename it, Xiao Guangrong, 2015/11/02
[Qemu-devel] [PATCH v7 18/35] pc-dimm: rename pc-dimm.c and pc-dimm.h, Xiao Guangrong, 2015/11/02
[Qemu-devel] [PATCH v7 16/35] pc-dimm: drop the prefix of pc-dimm, Xiao Guangrong, 2015/11/02
[Qemu-devel] [PATCH v7 29/35] nvdimm acpi: support function 0, Xiao Guangrong, 2015/11/02
[Qemu-devel] [PATCH v7 25/35] nvdimm acpi: init the resource used by NVDIMM ACPI, Xiao Guangrong, 2015/11/02