[Stgt-devel] [PATCH] fix no blkgetsize64
Arne Redlich
agr
Thu Aug 2 08:48:33 CEST 2007
Pete Wyckoff <pw at osc.edu> writes:
> Fix build for old machines that do not have 64-bit BLKGETSIZE.
>
> Signed-off-by: Pete Wyckoff <pw at osc.edu>
> ---
> usr/util.c | 10 ++++++++++
> 1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/usr/util.c b/usr/util.c
> index 9f54820..54bf399 100644
> --- a/usr/util.c
> +++ b/usr/util.c
> @@ -101,11 +101,21 @@ int backed_file_open(char *path, int oflag, uint64_t *size)
> if (S_ISREG(st.st_mode))
> *size = st.st_size;
> else if (S_ISBLK(st.st_mode)) {
> +#ifdef BLKGETSIZE64
> err = ioctl(fd, BLKGETSIZE64, size);
> if (err < 0) {
> eprintf("Cannot get size, %m\n");
> goto close_fd;
> }
> +#else
> + unsigned long usize;
> + err = ioctl(fd, BLKGETSIZE, &usize);
> + if (err < 0) {
> + eprintf("Cannot get size (ulong), %m\n");
> + goto close_fd;
> + }
> + *size = usize;
> +#endif
Unfortunately there's a minor but nasty bug in here: BLKGETSIZE64 returns
the size in bytes, while BLKGETSIZE returns the number of sectors -
cf. linux/fs.h.
Arne
More information about the stgt
mailing list