[Stgt-devel] [PATCH] fix no blkgetsize64
Pete Wyckoff
pw
Thu Aug 2 15:57:24 CEST 2007
agr at powerkom-dd.de wrote on Thu, 02 Aug 2007 08:48 +0200:
> 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.
Oh! Thanks for pointing that out. The old machine where I found
the need for this did not have the helpful comment in linux/fs.h,
and I was too lazy to actually verify the value was correct.
This patch was motivated by testing on an RHAS3 i686 machine. I was
just going for architectural coverage, and have no plans to run
there. No need to suffer the ugly #define this way either. I'll
drop the patch.
-- Pete
More information about the stgt
mailing list